akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_V = (int)1e5 + 1;

int n;
double p;

class edge{
public:
	int to;
	double cost;
	edge(){}
	edge(int _to, double _cost):to(_to),cost(_cost){}
};

vector<edge> G[MAX_V];
int depth[MAX_V];
int cnt[MAX_V];
double sum = 0.0;
bool visit[MAX_V];

void dfs(int v, int d){
	visit[v] |= true;
	depth[v] = d;
	for (int i = 0; i < (int)G[v].size(); ++i){
		if (!visit[G[v][i].to]){
			sum += G[v][i].cost * pow(p,(d+1.0));
			dfs(G[v][i].to, d+1);
		} // end if
	} // end for
}

int main(){
	
	// init
	for (int i = 0; i < MAX_V; ++i) G[i].clear();
	memset(depth, 0, sizeof(depth));
	memset(cnt, 0, sizeof(cnt));
	memset(visit, false, sizeof(visit));

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> p >> n;
	for (int i = 0; i < n - 1; ++i){
		int from, to, cost;
		cin >> from >> to >> cost;
		--from;
		--to;
		G[from].push_back(edge(to,(double)cost));
		G[to].push_back(edge(from,(double)cost));
	} // end for

	dfs(0,0);
	for (int i = 0; i < n; ++i){
		++cnt[depth[i]];
	} // end for
/*
	// debug
	for (int i = 0; i < n; ++i){
		cerr << "v: " << i << " depth: " << depth[i] << endl;
	} // end for
*/
	++cnt[0]; // ????????±??? 0 ????????§ ???????¨?????????????0???????????????????????????????????????

	double res = 0.0;
	for (int i = 0; i < n; ++i){
		res += (double)cnt[i] * sum * pow(p,i);
	} // end for
	cout << setprecision(9) << res << endl;

	return 0;
}

Measured memory_bytes: 17672
def e_max_gcd(N, K, A):
    def divisor_list(n):
        """n の正の約数のリスト"""
        ret = []
        for k in range(1, int(n**0.5) + 1):
            if n % k == 0:
                ret.append(k)
                if k != n // k:
                    ret.append(n // k)
        ret.sort()
        return ret

    ans = 1  # 任意の整数は1の倍数
    for c in divisor_list(sum(A)):  # sum(A)の約数が解の candidate
        r = sorted([a % c for a in A])
        # rをある位置で左右に分けたとき、「左」には-1、「右」には+1する操作を
        # 行って全要素をcの倍数にしたい。このとき、「左」の要素の和の分だけ
        # 操作してよいが、それはKを超えてはならない。
        # 最初、すべての要素を「左」に入れる。
        # 「左」の要素の関数値A(-1してcの倍数にするための操作回数)は最初sum(r)とし、
        # 「右」の要素の関数値B(+1してcの倍数にするための操作回数)は最初0とする。
        # ここで「左」の要素eを右から順に「右」に入れていくとすると、1つ入れるごとに
        # A の値は e だけ減り、B の値は c - e だけ増える。
        # よって A-B の値は1つ「右」に入れるごとに c だけ減る。
        # ゆえに、「右」に何個の要素を入れるべきかは sum(r)//c からわかる。
        if sum(r[:N - sum(r) // c]) <= K:
            ans = max(ans, c)
    return ans

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(e_max_gcd(N, K, A))

Measured memory_bytes: 42864
N = int(input())
B = [int(i) for i in input().split()]
maxA = []
B.reverse()
maxA.append(B[0])
if N == 0:
    print(0)
    exit()

for i in range(1,N-1):
    if B[i] <= B[i-1]:
        maxA.append(B[i])
    else:
        maxA.append(B[i-1])
   
print(sum(maxA)+B[-1])

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

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

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

	for (int i = 0; i < S.length(); i++) {
		for (int j = i + 1; j < S.length(); j++) {
			if (S[i] == S[j]) {
				cout << "no";
				return 0;
			}
		}
	}
	cout << "yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,cnt=0;
    cin >> n;
    long a[n],b[n];
    for(int i=0;i<n;i++) cin >> a[i] >> b[i];
    for(int i=n-1;0<=i;i--){
        a[i] += cnt;
        cnt += (b[i]-a[i]%b[i])%b[i];
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1792
if __name__ == '__main__':
    N = (int)(input())
    A = list(map(int,input().split()))

    swapOperation = 0

    flag = 1
    while flag == 1:
        flag = 0
        for j in range( N-1, 0, -1):
            if A[j] < A[j-1]:
                v = A[j]
                A[j]=A[j-1]
                A[j-1]=v
                flag = 1
                swapOperation += 1
    print(" ".join(map(str,A)))
    print(swapOperation)

Measured memory_bytes: 7732
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        if (isKaibun(S) && isKaibun(S.substring(0, S.length()/2))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    public static boolean isKaibun(String s) {
        boolean result = true;
        int len = s.length();
        for (int i=0; i<=len/2; i++) {
            if (s.charAt(i) != s.charAt(len-1-i)) {
                result = false;
                break;
            }
        }
        return result;
    }
}

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

int main() {
    long long N, A, B;
    cin >> N >> A >> B;
    
    if (A > B) cout << 0 << endl;
    else if (A == B) cout << 1 << endl;
    else if (N == 1) cout << 0 << endl;
    else cout << (A + (N - 1) * B) - (A * (N - 1) + B) + 1 << endl;
    
    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string color;
    // char tiles[10010];
    cin >> color;
    int len = color.length();
    if(len == 1){
        cout << 0;
        return 0;
    }
    char one = '1', zero = '0';
    int ansone = 0, anszero = 0;
    for(int i = 0; i < len; i++){
        if(color[i] == one) anszero++;
        else if(color[i] == zero) ansone++;
        char temp = one;
        one = zero;
        zero = temp;
    }
    // cout << anszero << " " << ansone << endl;
    cout << min(ansone, anszero) << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
void chmin(int &a, int b) { if (a > b) a = b; }

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll MOD = (ll)pow(10.0, 9.0) + 7;
pint dx[4] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
char da[4] = { 'R', 'L', 'D', 'U' };
char dax[4] = { -1, 1, -1, 1 };
char dax2[4] = { 1, -1, 1, -1 };
ll min(ll a, ll b)
{

	return (a < b) ? a : b;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }


int main() {
	
	ll N;

	cin >> N;

	cout << 180 * (N - 2) << endl;

	return 0;

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!
    val t = readLine()!!
    for (i in 0 until t.length) {
        var isSame = true
        for (j in 0 until t.length) {
            val si = if ((j + i) >= t.length) {
                j + i - t.length
            } else {
                j + i
            }
            if (t[j] != s[si]) isSame = false
        }
        if (isSame) {
            println("Yes")
            return
        }
    }
    println("No")
}

Measured memory_bytes: 33528
import sys

n,m=map(int,input().split())
ans=[0]*(m+1)
output=0

for i in range(n):
    k=list(map(int,input().split()))
    for j in range(1,len(k)):
        ans[k[j]]+=1

for i in ans:
    if i==n:
        output+=1

print(output)

Measured memory_bytes: 9188
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

class program
{
    static public int mod = 1000000007;
    static void Main()
    {
        int k = rint();
        int[] ab = inta();
        int a = ab[0] % k;
        int b = ab[1] - ab[0];
        int ans = a == 0 ? k : a + b;
        WriteLine(ans >= k ? "OK" : "NG");
    }

    static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; }
    static string rstr() { return ReadLine(); }
    static int rint() { return int.Parse(ReadLine()); }
    static long rlong() { return long.Parse(ReadLine()); }
    static string[] stra() { return ReadLine().Split(' '); }
    static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); }
    static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; }
    static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } }
    static long LCM(long a, long b) { return a * b / GCD(a, b); }
    static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } }
    static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) {  Write(" "); Write(a[i]); } WriteLine(); }
}


Measured memory_bytes: 27500
#include<iostream>
#include<vector>
#include<queue>
#include<map>
using namespace std;
vector<long long int>v[2001];
long long int dist[2001] = { 0 };
map<long long int, long long int >m;
void bfs(long long int s)
{
	queue<long long int>q;
	bool visited[2001] = { false };
	q.push(s);
	dist[s] = 0;
	visited[s] = true;
	while(!q.empty())
	{
		long long int a = q.front();q.pop();
		for(long long int i=0;i<v[a].size();i++)
		{
			
			if(!visited[v[a][i]])
			{
				dist[v[a][i]] = dist[a]+1;
				
				q.push(v[a][i]);
			visited[v[a][i]]=true;
			}
		}
	}
	
}
main()
{
	long long int n , x, y;
	cin >> n >> x >> y;
	v[x].push_back(y);
	v[y].push_back(x);
	
	for(long long int i=1;i<n;i++)
	{
			v[i].push_back(i+1);
	v[i+1].push_back(i);
	}
	for(long long int i=1;i<n;i++)
	{
	bfs(i);
	for(long long int j=i+1;j<=n;j++)
	m[dist[j]]++;
    dist[n+2] = { 0 };
 	}
	for(long long int i=1;i<n;i++)
	cout << m[i] << endl;
	 return 0;
}

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

int main() {
  int n, q, i;
  string s;
  cin >> n >> q >> s;
  
  vector<int> x(n);
  x.at(0) = 0;
  for(i = 1; i < n; i++){
    if(s.at(i - 1) == 'A' && s.at(i) == 'C') x.at(i) = x.at(i - 1) + 1;
    else x.at(i) = x.at(i - 1);
  }
  
  int l, r;
  for(i = 0; i < q; i++){
    cin >> l >> r;
    cout << x.at(r - 1) - x.at(l - 1) << endl;
  }
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0スタート
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1スタート
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからbまで
#define P(x) cout<<x<<endl  //変数xを改行付きで出力
#define INF 1000000007  //最大値兼MOD
typedef long long ll;
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; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
/*
./a.exe
*/
string s;
cin>>s;
int count = 0;
rep0(i,(int)s.length())if(s[i] == '2')count++;
cout<<count<<endl;
return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
set<ll> enum_divisors(ll n){
    set<ll> res;
    for(ll i = 1; i <= sqrt(n); i++){
        if(n % i == 0){
            res.insert(i);
            if(n / i != i)
                res.insert(n / i);
        }
    }
    return res;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> a(n);
set<ll> ans;
rep(i,n)
    cin >> a[i];
map<ll,ll> mp;
for(ll i = n - 1; 0 <= i; i--){
    if(mp[i + 1] % 2 != a[i]){
        ans.insert(i + 1);
        set<ll> st = enum_divisors(i + 1);
        for(auto v : st){
            mp[v]++;
        }
    }
}
cout << ans.size() << endl;
for(auto v : ans){
    cout << v << endl;
}
}

Measured memory_bytes: 21928
# -*- coding: utf-8 -*-
"""
Created on Wed May  6 02:13:01 2020

@author: shinba
"""
import sys

N = int(input())
S = input()

R = []
G = []
B = []

for i in range(N):
    if S[i] == "R":
        R.append(i+1)
    elif S[i] == "G":
        G.append(i+1)
    else:
        B.append(i+1)

if R==[] or G==[] or B==[]:
    print(0)
    sys.exit()
    
ans = len(R)*len(G)*len(B)

m = min(B)
M = max(B)

for i in R:
    for j in G:
        a = 2*j - i 
        b = (i+j)//2 if (i+j)%2 == 0 else 0
        c = 2*i - j
        if m <= a <= M:
            if S[a-1] == "B":
                ans -= 1
        if b != 0 and S[b-1] == "B":
            ans -= 1
        if m <= c <= M:
            if S[c-1] == "B":
                ans -= 1
            
print(ans)
        


Measured memory_bytes: 9176
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class UnionFind {
    int n;
    vector<int> uni;
    int forest_size;
public:
    explicit UnionFind(int n) : n(n), uni(static_cast<u32>(n), -1), forest_size(n) {};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        forest_size--;
        return true;
    }
    int size(){ return forest_size; }
    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};

int main() {
    int h, w;
    while(cin >> h >> w, h){
        vector<string> v(h);
        UnionFind uf(h*w);
        for (auto &&i : v) cin >> i;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if(i && v[i][j] == v[i-1][j])  uf.unite(i*w+j, (i-1)*w+j);
                if(j && v[i][j] == v[i][j-1]) uf.unite(i*w+j, i*w+j-1);
            }
        }
        cout << uf.size() << "\n";
    }
    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 1000000007

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> a;
  for(int i=1;i*i<=N;i++){
    a.push_back(i);
    if(i!=N/i){
      a.push_back(N/i);
    }
  }
  sort(a.begin(),a.end());
  int n=a.size();
  vector<int> cnt(n);
  cnt[0]=1;
  for(int i=1;i<n;i++){
    cnt[i]=a[i]-a[i-1];
  }
  vector<vector<ll>> dp(K,vector<ll>(n));
  for(int i=0;i<n;i++){
    dp[0][i]=(ll)cnt[i];
  }
  for(int j=1;j<K;j++){
    ll sum=0;
    for(int i=n-1;i>=0;i--){
      sum+=dp[j-1][(n-1)-i];
      sum%=MOD;
      dp[j][i]=sum*(ll)cnt[i]%MOD;
    }
  }

  ll ans=0;
  for(int i=0;i<n;i++){
    ans+=dp[K-1][i];
    ans%=MOD;
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 53828
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

n,q=parseMap(split(readline()))
con=[[] for i in 1:n]       # 要素同士のつながりを表す配列
ans=zeros(Int,1,n)          # 各要素の数

# 子のカウンタに親のカウンタの値を足していく関数
function dfs(q,oya)
    for child in con[q]
        if child==oya
            continue
        end
        ans[child]+=ans[q]
        dfs(child,q)
    end
end

function main()
    for i in 1:n-1
        a,b=parseMap(split(readline()))
        push!(con[a],b)
        push!(con[b],a)
    end
    for i in 1:q
        p,x=parseMap(split(readline()))
        ans[p]+=x
    end
    dfs(1,-1)
    println(join(ans," "))
end
main()

Measured memory_bytes: 303516
#include<stdio.h>
   
#define MAX 100000
   
   int parent(int i){
   
  return i/2;
}
   
int left(int i){
   
  return 2 * i;
}
   
int right(int i){
   
  return 2 * i + 1;
}

int main(){
  int i,n,A[MAX+1];
   
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
   
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) >= 1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= n)printf("left key = %d, ",A[left(i)]);
    if(right(i) <= n)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
   
  return 0;
}
   

Measured memory_bytes: 608
s = input()

if s[0] != 'A':
    print('WA')
    exit()

cnt = 0
for c in s[2:-1]:
    if c == 'C':
        cnt += 1
if cnt != 1:
    print('WA')
    exit()

for c in s:
    if c == 'A' or c == 'C':
        continue
    if c.isupper():
        print('WA')
        exit()
print('AC')

Measured memory_bytes: 38384
#include<stdio.h>
#include<string.h>
#define gc() getchar()
int in() {   // 非負整数の入力
    int n = 0; int c;
    c = gc();
    do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
    return n;
}
int comp(const void* a, const void* b)//用来做比较的函数。
{
    return *(int*)b - *(int*)a;
}
int comp1(const void* a, const void* b)//用来做比较的函数。
{
    return *(int*)a - *(int*)b;
}
int min(int a, int b)
{
    return a < b ? a : b;
}
int A[100000], B[100000], C[100000],D[200000];
int main()
{
    int x, y, a, b, c,i,tmp;
    long long sum = 0;
    x = in(), y = in(), a = in(), b = in(), c = in();
    for (i = 0; i < a; i++) A[i] = in();
    for (i = 0; i < b; i++) B[i] = in();
    for (i = 0; i < c; i++) C[i] = in();
    qsort(A, a, sizeof(int), comp);
    qsort(B, b, sizeof(int), comp);
    qsort(C, c, sizeof(int), comp);
    for (i = 0;i<x+y; i++)
    {
        if (i < x)
            D[i] = A[i];
        else
            D[i] = B[i - x];
    }
    qsort(D, x+y, sizeof(int), comp1);
    for (i = 0;i<min(x+y,c); i++)
    {
        if (D[i] < C[i])
            D[i] = C[i];
        else
            break;
    }
    for (i = 0; i < x + y; i++)
        sum += D[i];
    printf("%lld", sum);
}

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, ll>;

int main()
{
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i];
    vector<int> dic(110, 0);
    for (int i = 0; i < n; ++i)
    {
        ++dic[p[i]];
    }

    int ans = -1;
    int minval = 1000;
    for (int i = 0; i < 110; ++i)
    {
        if (dic[i] == 0)
        {
            if (minval > abs(x - i))
            {
                minval = abs(x - i);
                ans = i;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    map<int, int> num;
    for (int i = 0; i < 3; i++) {
        int a;
        cin >> a;
        num[a]++;
    }

    if (num[5] == 2 and num[7] == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

const int inf = ((long long)1 << 31) - 1;

int n, m, q;
int t[(int)16e6];

int& acecss(int i, int j){
	return t[(2 * m - 1) * i + j];
}

void init(){
	int p = 1;
	while(p < n){
		p *= 2;
	}
	n = p;
	int q = 1;
	while(q < m){
		q *= 2;
	}
	m = q;
	fill_n(t, (2 * n - 1) * (2 * m - 1), inf);
}

void update(int i, int j, int x){
	int k = i + n - 1;
	int l = j + m - 1;
	acecss(k, l) = x;
	while(l > 0){
		l = (l - 1) / 2;
		acecss(k, l) = min(acecss(k, l * 2 + 1), acecss(k, l * 2 + 2));
	}
	while(k > 0){
		k = (k - 1) / 2;
		l = j + m - 1;
		acecss(k, l) = min(acecss(k * 2 + 1, l), acecss(k * 2 + 2, l));
		while(l > 0){
			l = (l - 1) / 2;
			acecss(k, l) = min(acecss(k * 2 + 1, l), acecss(k * 2 + 2, l));
		}
	}
}

int query(int a, int b, int c, int d, int p, int q, int r, int s, int k, int l){
	if(b <= p || q <= a){
		return inf;
	}
	if(a <= p && q <= b){
		if(d <= r || s <= c){
			return inf;
		}
		if(c <= r && s <= d){
			return acecss(k, l);
		}
		int f = query(a, b, c, d, p, q, r, (r + s) / 2, k, l * 2 + 1);
		int g = query(a, b, c, d, p, q, (r + s) / 2, s, k, l * 2 + 2);
		return min(f, g);
	}
	int f = query(a, b, c, d, p, (p + q) / 2, r, s, k * 2 + 1, l);
	int g = query(a, b, c, d, (p + q) / 2, q, r, s, k * 2 + 2, l);
	return min(f, g);
}

int main(){
	while(1){
		scanf("%d%d%d", &n, &m, &q);
		if(n == 0 && m == 0 && q == 0){
			break;
		}

		int r = n;
		int c = m;

		init();

		rep(i, r){
			rep(j, c){
				int x;
				scanf("%d", &x);
				update(i, j, x);
			}
		}

		/*
		rep(i, 2 * n - 1){
			rep(j, 2 * m - 1){
				printf("%d ", acecss(i, j));
			}
			printf("\n");
		}
		*/

		rep(i, q){
			int a, b, c, d;
			scanf("%d%d%d%d", &a, &b, &c, &d);
			printf("%d\n", query(a, c + 1, b, d + 1, 0, n, 0, m, 0, 0));
		}
	}
	return 0;
}

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

int main(void) {
    ll n; cin >> n;
    ll a; cin >> a;
    ll b; cin >> b;

    if(n<=a){
        cout << n;
        return 0;
    }


    ll num = n/(a+b);

    ll rest = n - num*(a+b);

    ll add;
    if(rest <= a) {
        add = rest;
    }else {
        add = a;
    }

    ll ans = (num) * a + add;
    cout << ans << endl;

    return 0;
}


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

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

int memo[500][500];
int D, N, T[500], A[500], B[500], C[500]; 

int rec(int d, int c){
	if(d == D)
		return 0;
	if(memo[d][c] != -1)
		return memo[d][c];
	
	int res = 0;	
	for(int i = 0; i < N; ++i){
		if(A[i] <= T[d] && T[d] <= B[i])
			res = max(res, rec(d + 1, C[i]) + abs(c - C[i]));
	}
	return memo[d][c] = res;
}

int main() {
	memset(memo, -1, sizeof(memo));
	cin >> D >> N;
	for(int i = 0; i < D; ++i)
		cin >> T[i];
	for(int i = 0; i < N; ++i)
		cin >> A[i] >> B[i] >> C[i];
	
	int ans = 0;
	for(int i = 0; i < N; ++i){
		if(A[i] <= T[0] && T[0] <= B[i])
			ans = max(ans, rec(1, C[i]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2164
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for(int i = 1; ; i++) {
            int x = sc.nextInt();
            if(x == 0) break;
        System.out.println("Case " + i + ": " + x);
        }        
    }
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main() {
    int a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
for i in range(1, N):
  if H[i] - H[i - 1]:
    H[i] -= 1
  
for i in range(1, N):
  if H[i] < H[i - 1]:
    print('No')
    exit()
    
print('Yes')

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

int main(){
   int e, y, x;
   cin >> e >> y;
   if (e == 0){
       if(y <= 1911){
           x = y - 1867;
           cout << "M" << x << endl;
       }
       else if(y <= 1925){
           x = y - 1911;
           cout << "T" << x << endl;
       }
       else if(y <= 1988){
           x = y - 1925;
           cout << "S" << x << endl;
       }
       else{
           x = y - 1988;
           cout << "H" << x << endl;
       }
   }
   else if(e == 1){
       x = y + 1867 ;
       cout << x << endl;
   }
   else if(e == 2){
       x = y + 1911;
       cout << x << endl;
   }
   else if(e == 3){
       x = y + 1925;
       cout << x << endl;
   }
   else{
       x = y + 1988;
       cout << x << endl;
   }
}


Measured memory_bytes: 3096
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Harshad
 */

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

class a1 {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s; in>>s;
        int i=0;
        reverse(s.begin(), s.end());
        while(i<s.length()){
            if(s.substr(i, 5)=="maerd" or s.substr(i, 5)=="esare") i+=5;
            else if(s.substr(i, 7)=="remaerd") i+=7;
            else if(s.substr(i, 6)=="resare") i+=6;
            else{
                out<<"NO";
                return;
            }
        }
        out<<"YES";
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	a1 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;

const int mod = 1e9 + 7;

int n, a, b, c, d;
int dp[1001][1001];
int fact[1001][1001];
int m[1001][1001];

int add(int a, int b){
  return (a + b) % mod;
}
int mul(int a, int b){
  return ll(a) * b % mod;
}
int pow(int a, int n){
  int b = a;
  int s = 1;
  while(n){
    if(n & 1){
      s = mul(s, b);
    }
    n >>= 1;
    b = mul(b, b);
  }
  return s;
}
int inv(int a){
  return pow(a, mod - 2);
}

int main(){
  cin >> n >> a >> b >> c >> d;

  fact[0][1] = 1;
  for(int i = 1; i <= n; ++i){
    fact[i][1] = mul(fact[i - 1][1], i);
    for(int j = 2; j <= n; ++j){
      fact[i][j] = mul(fact[i][j - 1], fact[i][1]);
    }
  }

  for(int i = 1; i <= n; ++i){
    for(int k = 1; k <= n; ++k){
      m[i][k] = inv(mul(fact[i][k], fact[k][1]));
    }
  }

  dp[a - 1][0] = 1;
  for(int i = a; i <= b; ++i){
    rep(j, n + 1){
      dp[i][j] = dp[i - 1][j];
      for(int k = c; k <= d && k * i <= j; ++k){
        dp[i][j] = add(mul(dp[i - 1][j - k * i], m[i][k]), dp[i][j]);
      }
    }
  }
  cout << mul(fact[n][1], dp[b][n]) << endl; 
  return 0;
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
#define ld long double
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

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


int main() {
    ll n; cin >> n;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];
    
    ll c[] = {0, 0, 0};
    ll ans = 1;
    rep(i, 0, n){
        ll cnt = 0; int id = -1;
        if(a[i] == c[0]){
            cnt++; id = 0;
        }
        if(a[i] == c[1]){
            cnt++; id = 1;
        }
        if(a[i] == c[2]){
            cnt++; id = 2;
        }
        if(id == -1){
            co(0);
            return 0;
        }
        ans *= cnt;
        ans %= MOD;
        c[id]++;
    }
    co(ans);

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;

int main(){
    long long x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    
    if(x/d > k){
        cout << x - d*k << endl;
    }else{
        long long e = x/d;// till into the round trip
        if((k - e) % 2 == 0){
            cout << x - d*e << endl; 
        }else{
            cout << -(x - d*e - d) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3180
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [list(map(int,input().split())) for _ in range(M)]

amin = min(a)
bmin = min(b)
ans = amin + bmin
for c_ in c:
    tmp = a[c_[0]-1] + b[c_[1]-1] - c_[2]
    ans = min(ans,tmp)

print(ans)

Measured memory_bytes: 38488
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

const ll inf = 1e18+7;
const ll mod = 1e9+7;

int main(){
	ll n;
	cin >> n;
	cout << (n-1)*n/2 << endl;
	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++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int A, B, T;
    cin >> A >> B >> T;
    cout << (T/A)*B << endl;
    return 0;
}



Measured memory_bytes: 256
#pragma region Template

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <bitset>
#include<map>
#include<cmath>
#include <set>
#include<limits.h>
#include<fstream>

#define lli long long int
#define us unsigned short
#define mod 1000000007
#define INF 1e9+5

#define vi vector<int>
#define vus vector<unsigned short>
#define vlli vector<long long int>
#define vs vector<string>
#define mii map<int,int>
#define mlli map<long long int,long long int>

#define w(t) int t; cin>>t;while(t--)

using namespace std;

#pragma endregion

int main()
{
	string s, t;
	cin >> s >> t;
	string ans;

	vector<vlli> dp(s.size()+1, vector<lli>(t.size() + 1));

	for (lli i = 1; i <= s.size(); i++)
	{
		for (lli j = 1; j <= t.size(); j++)
		{
			if (s[i - 1] == t[j - 1])
			{
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}

	lli i = s.size(), j = t.size();

	while (i > 0 && j > 0)
	{
		if (s[i - 1] == t[j - 1])
		{
			ans += s[i - 1];
			i--; j--;
		}
		else if (dp[i][j - 1] > dp[i - 1][j])
			j--;
		else
			i--;
	}
	
	reverse(ans.begin(),ans.end());

	cout << ans <<endl;

	return 0;
}


Measured memory_bytes: 72448
import fractions
a,b,c,d=map(int,input().split())

def lcm(x,y):
    return (x*y)//fractions.gcd(x,y)

ans=(b-a+1)-(b//c)+((a-1)//c)-(b//d)+((a-1)//d)+(b//lcm(c,d))-((a-1)//lcm(c,d))
print(ans)

Measured memory_bytes: 5304
import java.io.*;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
	public static void main(String[] args) throws IOException {

	  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	  //int N = sc.nextInt();
	  //String n = br.readLine();
	  int N = Integer.parseInt(br.readLine());
    //System.out.println(N);
    String str = br.readLine();
	  String C[] = str.split(" ");;
    String C2[] = new String[N];
  
	  /**/for(int i = 0;i < N;i++){
		   C2[i] = C[i];
	  }
	  /**///for(int i = 0;i < N;i++) System.out.print(C[i]+" ");
	  /**///System.out.println();
	  String Cr[] = new String[N];
	  String C2r[] = new String[N];
	  Cr = BubbleSort(C, N);
	  //if(Cr.equals(C)){
		  System.out.println("Stable");
	  //}
	  //else System.out.println("Not Stable");
	  C2r = SelectionSort(C2, N);
	  if(Arrays.equals(Cr, C2r)){
		  System.out.println("Stable");
	  }
	  else System.out.println("Not stable");
	}
	public static String[] BubbleSort(String[] C, int N){
		for(int i = 0;i < N - 1;i++){
			for(int j = N - 1;j > i;j--){
				if(C[j].charAt(1) < C[j - 1].charAt(1)){
					String tmp = C[j];
					C[j] = C[j - 1];
					C[j - 1] = tmp;
				}
			}
		}
		for(int i = 0;i < N;i++){
			 System.out.print(C[i]);
			 if(i != N - 1) System.out.print(" ");
		}
		System.out.println();
		return C;
	} 
	public static String[] SelectionSort(String[] C, int N){
		for(int i = 0;i < N;i++){
			int minj = i;
			for(int j = i;j < N;j++){
				if(C[j].charAt(1) < C[minj].charAt(1)){
					minj = j;
				}
			}
			String tmp = C[i];
			C[i] = C[minj];
			C[minj] = tmp;
    }
    for(int i = 0;i < N;i++){
      System.out.print(C[i]);
      if(i != N - 1) System.out.print(" ");
   }
   System.out.println();
		return C;
	}
}



Measured memory_bytes: 24256
#include<iostream>
#include<cstdio>
#define N 12345
using namespace std;
int f[N][N];
int main()
{
	scanf("%d%d%d",&f[1][1],&f[1][2],&f[2][2]);
	int a = f[2][2] * 3;
	f[1][3] = a - f[1][1] - f[1][2];
	f[3][1] = a - f[1][3] - f[2][2];
	f[3][3] = a - f[1][1] - f[2][2];
	f[2][1] = a - f[1][1] - f[3][1];
	f[2][3] = a - f[2][1] - f[2][2];
	f[3][2] = a - f[1][2] - f[2][2];
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
			printf("%d ",f[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
#n-k+1Ci*k-1Ci-1
def inv_mod(a):
  return pow(a,MOD-2,MOD)

MOD = 10**9 + 7
fact = [1] * (n+1)
for n in range(1,n+1):
  fact[n] = (n*fact[n-1])%MOD
#print(fact[0:5])
fact_inv = [1] * (n+1)
fact_inv[n] = inv_mod(fact[n])
for i in range(n,0,-1):
  fact_inv[i-1] = (i*fact_inv[i])%MOD
#for i in range(5):
#    print(fact_inv[i]*fact[i]) 

for i in range(1,k+1):
    if (n-k+1>=i):
        x=fact[n-k+1]*(fact_inv[i]*fact_inv[n-k+1-i])%MOD
        y=fact[k-1]*(fact_inv[i-1]*fact_inv[k-i])%MOD
        print(x*y%MOD)
    else:
        print(0)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int ans,loop;
  int Bbf=1000000,Baf=0;
  for(loop=0;loop<N-1;loop++){
    cin >> Baf;
    if(Bbf>Baf){
      ans+=Baf;
    }else{
      ans+=Bbf;
    }
    Bbf=Baf;
  }
  ans+=Baf;
  cout << ans << endl;
  return 0;
}
    

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

int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	
	while(1){
		c=c-b;
		if(c<=0){
			cout<<"Yes"<<endl;
			break;
		}
		a=a-d;
		if(a<=0){
			cout<<"No"<<endl;
			break;
		}
	}
	
	// your code goes here
	return 0;
}

Measured memory_bytes: 3636
while data = gets
	data.chomp
	hai = data.split
	hai.collect! {|i|i.to_i}
	hai.sort.reverse!
	a = hai[0]
	b = hai[1]
	while (r = a % b) != 0 
		a = b
		b = r
	end
	
	
	print b, " ", hai[0] * hai[1] /b, "\n"
end

Measured memory_bytes: 6092
fun main(args: Array<String>) {
    val s = readInputLine().split("T")
    val (x, y) = readInputLine().split(" ").map { it.toInt() }

    var xPoses = mutableSetOf(s.first().length)
    var yPoses = mutableSetOf(0)

    for ((i, ss) in s.drop(1).withIndex()) {
        val posesOrig = if (i % 2 == 0) yPoses else xPoses
        val newPoses = mutableSetOf<Int>()

        for (p in posesOrig) {
            newPoses.add(p + ss.length)
            newPoses.add(p - ss.length)
        }

        if (i % 2 == 0) {
            yPoses = newPoses
        } else {
            xPoses = newPoses
        }
    }

    if (xPoses.contains(x) && yPoses.contains(y)) {
        println("Yes")
    } else {
        println("No")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 116608
n = int(input())
F = [list(map(int,input().split())) for _ in range(n)]
P = [list(map(int,input().split())) for _ in range(n)]
ans = -10**9
def bfs(x):
    if len(x) == 10:
        if 1 in x:
            global ans
            a = 0
            for i in range(n):
                f,p = F[i],P[i]
                c = 0
                for j in range(10):
                    if x[j] == f[j] == 1: c+=1
                a+=p[c]
            ans = max(ans,a)
    else:
        bfs(x + [0])
        bfs(x + [1])
bfs([])
print(ans)

Measured memory_bytes: 43632
#include <bits/stdc++.h>
using namespace std;
int a[1001][1001];
int main()
{
    int n,m,MAX;
    while(scanf("%d%d",&n,&m)&&(n||m))
    {
        MAX=0;
        for(int i=0; i<m; i++)
            for(int j=0; j<n; j++)
                scanf("%d",&a[i][j]);
        for(int i=0; i<n; i++)
        {
            int sum=0;
            for(int j=0; j<m; j++)
                sum+=a[j][i];
            MAX=max(MAX,sum);
        }
        printf("%d\n",MAX);
    }
    return 0;
}



Measured memory_bytes: 3424
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
N=int(input())
print(str.lower(num2alpha(N)))

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;

    rep(i, n) {
        cout << s[i] << t[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

        int a = n - h + 1;
        int b = n - w + 1;

        System.out.println(a * b);
    }

}










Measured memory_bytes: 21844
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions

t = stdin.readline().rstrip()
if t == 'ABC':
    print('ARC')
else:
    print('ABC')


Measured memory_bytes: 72648
// Tenshi ni Fureta yo!

#include <bits/stdc++.h>

using namespace std;

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

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define MP make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline int chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline int chkmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template<typename T> inline T sqr(const T &val) { return val * val; }

namespace fastIO
{
	const int MAX_BUFFER_SIZE = 1 << 16;

	char buffer[MAX_BUFFER_SIZE], *cur = buffer, *ed = buffer;

	inline char getc() { return *(cur == ed ? ed = buffer + fread(buffer, 1, MAX_BUFFER_SIZE, stdin), cur = buffer : cur)++; }
}
using fastIO::getc;

template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getc());
	for(; !isdigit(ch); ch = getc()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getc()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

// END tpl.

const int MOD = 998244353;

inline int fpm(int x, int y)
{
	int res = 1;
	for(; y; y >>= 1, x = (LL) x * x % MOD) if(y & 1) res = (LL) res * x % MOD;
	return res;
}

inline int inv(int x) { assert(x); return fpm(x, MOD - 2); }

namespace MATH
{
	const int n = (int) 1e6;

	int fac[n + 5], ifac[n + 5];

	inline void init()
	{
		fac[0] = 1;
		for(int i = 1; i <= n; ++i) fac[i] = (LL) fac[i - 1] * i % MOD;
		ifac[n] = inv(fac[n]);
		for(int i = n - 1; i >= 0; --i) ifac[i] = (LL) ifac[i + 1] * (i + 1) % MOD;
	}

	inline int C(int N, int M) { return N < 0 || M < 0 || N < M ? 0 : (LL) fac[N] * ifac[N - M] % MOD * ifac[M] % MOD; }
}
using MATH::fac;
using MATH::ifac;
using MATH::C;

const int MAXN = (int) 5e5;

int n, m;

inline void input()
{
	n = read<int>(), m = read<int>();
}

inline void solve()
{
	int ans = 0;
	for(int i = 0; i <= min(n, m); ++i) (ans += (i & 1 ? -1 : +1) * (LL) C(n, i) * C(m, i) % MOD * fac[i] % MOD * fpm(m + 1, n - i) % MOD * fpm(n + 1, m - i) % MOD) %= MOD;
	printf("%d\n", (ans + MOD) % MOD);
}

int main()
{
#ifdef K_ON
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	MATH::init();
	input();
	solve();

	return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if((a>=2&&a<=13)&&(b>=2&&b<=13))
	{
		if(a>b)
			printf("Alice\n");
		else if(a<b)
			printf("Bob\n");
		else if(a==b)
			printf("Draw\n");
	}
	else if(a==1&&(b>=2&&b<=13))
	{
		printf("Alice\n");
	}
	else if(b==1&&(a>=2&&a<=13))
		printf("Bob\n");
	else if(a==1&&b==1)
		printf("Draw\n");
	return 0;
}

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

typedef long long lint;
typedef pair<int, int> P;
#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())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    string s, t;
    cin >> s >> t;
    string ans;
    bool flag = false;
    repr(i, s.size() - t.size() + 1){
        ans = s;
        rep(j, s.size()){
            if(ans[j] == '?'){
                ans[j] = 'a';
            }
        }
        REP(j, i, i + t.size()){
            ans[j] = t[j-i];
        }
        rep(j, s.size()){
            if(s[j] != '?' && s[j] != ans[j]){
                flag = false;
                break;
            }
            flag = true;
        }
        if(flag){
            break;
        }
    }
    if(flag){
        cout << ans << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,m; long long r;
   scanf("%d %d",&n,&m);
   
   if(n>m)
    swap(n,m);
   
   if(n==1 )
   {
       r= (m==1?1:m-2);
   }
 else
   r=(n-2)*(m-2LL);
   printf("%lld\n",r);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    char X[202020];
    scanf("%s", X);
    int l = strlen(X);
    
    // 2. 'T' が 来たら, stack から 'S' を 取り除く.
    stack<char> st;
    rep(i, l){
        char c = X[i];
        if(st.empty()){
            st.push(c);
            continue;
        }
        char t = st.top();
        if(c == 'T' && t == 'S') st.pop();
        else                     st.push(c);
    }
    
    // 3. 出力.
    printf("%d\n", st.size());
    return 0;
    
}

Measured memory_bytes: 4080
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll n;
    cin >> n;
    vector<ll> num(5);
    vector<ll> people(6);

    ll min_num = 1000000000000000;
    for ( int i = 0; i < 5; i++ ) {
        cin >> num[i];
        min_num = min(min_num, num[i]);
    }

    if ( n % min_num == 0 ) {
        cout << n / min_num + 4;
    }
    else {
        cout << n / min_num + 5;
    }

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  vll a(n,0);
  vector<vll> to(n);

  REP1(i,n){
    cin>>a[i];
    a[i]--;
    to[a[i]].push_back(i);
  }

  REP(i,n)cout<<to[i].size()<<endl;
}



Measured memory_bytes: 15872
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String n = sc.next();
    String s = "abcdefghijklmnopqrstuvwxyz";
    String j = "";
    for(int i=0; i<25; i++){
      if(n.equals(s.substring(i,i+1))){
        System.out.println(s.substring(i+1,i+2));
        return;
      }
    }
    
    return;
  }
}


Measured memory_bytes: 21076
S = gets.chomp
Q = gets.to_i.times.map{ gets.split }
buf = Array.new(S.size + 2 * Q.size, '')
S.size.times do |i|
  buf[Q.size + i] = S[i]
end
dir = 1 # 1 - forward direction, 2 - reverse direction
l = Q.size
r = Q.size + S.size - 1

Q.each do |q|
  t = q.shift.to_i
  if t == 2
    f = q.shift.to_i
    c = q.shift
    if f == dir
      l -= 1
      buf[l] = c
    else
      r += 1
      buf[r] = c
    end
  else
    dir = dir == 1 ? 2 : 1
  end
end
puts dir == 1 ? (buf.join) : (buf.join.reverse)

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

int main(void){
  	int a,b,c;
  	cin>>a>>b>>c;
  	
  	if(a+b==c||a+c==b||b+c==a) cout << "Yes" << endl;
  	else cout << "No" << endl;
  
  	return 0;
}	

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
A.sort()
# print(A)
multiple = [0]*(A[-1]+1)
for i in range(n):
    now = A[i]
    while(now <= A[-1]):
        multiple[now] += 1
        now += A[i]
ans = 0
for i in range(n):
    if(multiple[A[i]] == 1):
        ans += 1
# print(multiple)
print(ans)

Measured memory_bytes: 32348