akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        Scanner scanner = new Scanner(System.in);
 
        String str = scanner.next();
        String order,change;
        int Q = scanner.nextInt();
        int a,b;
 
        for(int loop = 0; loop < Q; loop++){
            order = scanner.next();
 
            if(order.equals("print")){
 
                a = scanner.nextInt();
                b = scanner.nextInt();
 
                print(str,a,b);
 
            }else if(order.equals("reverse")){
 
                a = scanner.nextInt();
                b = scanner.nextInt();
 
                str = reverse(str,a,b);
 
            }else{
 
                a = scanner.nextInt();
                b = scanner.nextInt();
                change = scanner.next();
 
                str = replaceStr(str,a,b,change);
            }
        }
    }
 
    private static void print(String str,int a,int b){
        String output = str.substring(a, b+1);
        System.out.println(output);
    }
 
    private static String reverse(String str,int a,int b){
 
        char work[] = str.toCharArray();
 
        int num = b-a+1;
        char tmp;
 
        for(int i = 0; i < num/2; i++){
 
            tmp = work[a+i];
            work[a+i] = work[b-i];
            work[b-i] = tmp;
        }
 
        return String.valueOf(work).substring(0, str.length());
    }
 
    private static String replaceStr(String str,int a,int b,String change){
 
        char ch[] = change.toCharArray();
        char work[] = str.toCharArray();
 
        for(int i = a; i <= b; i++){
            work[i] = ch[i-a];
        }
 
        return String.valueOf(work).substring(0,str.length());
    }
}


Measured memory_bytes: 29324
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		long A=sc.nextLong();
		char op=sc.next().toCharArray()[0];
		long B=sc.nextLong();
		long ans=0;
		if(op=='+')ans=A+B;
		else ans=A-B;
		System.out.println(ans);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 21972
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    h=II()
    w=II()
    n=II()
    if h<w:h,w=w,h
    ans=(n+h-1)//h
    print(ans)
main()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

signed main(){
	int N,X,Y;
	int A[110];
	cin>>N>>X>>Y;
	REP(i,N){
		cin>>A[i];
	}
	int ans=0,ans2=0,ans3=0;
	REP(i,N){
		if(A[i]<=X){
			ans++;
		}
		else if(X+1<=A[i]&&A[i]<=Y){
			ans2++;
		}
		else{
			ans3++;
		}
	}
	DEB(ans)DEB(ans2)DEB(ans3)END
	cout<<min({ans,ans2,ans3})<<endl;
	return 0;
}


Measured memory_bytes: 256
var lines = [];


var readline = require("readline");
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {

    var tmp = lines.shift().split(" ");
    var H = Number(tmp[0]);
    var W = Number(tmp[1]);

    var tmp = lines.shift().split(" ");
    var h = Number(tmp[0]);
    var w = Number(tmp[1]);

    var sum = H * W;
    var reduce = H * w + W * h - h * w;

    console.log(sum - reduce);
});


Measured memory_bytes: 7628
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def keta(n):
    return len(str(n))

def main():
    n = int(input().strip())
    i = 1
    ans = INF
    while i**2 <= n:
        if n % i == 0:
            ans = min(ans, max(keta(i), keta(n//i)))
        i += 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
n=int(input())
a=list(map(int, input().split()))
import fractions
from functools import reduce

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

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

m=lcm(a)-1
ans=0
for x in a:
    ans+=m%x
print(ans)

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

#define int int64_t

signed main() {
  int n, z, w; cin >> n >> z >> w;
  vector<int> cards;
  cards.emplace_back(z);
  cards.emplace_back(w);
  for (int i=0; i<n; ++i) {
    int x; cin >> x;
    cards.emplace_back(x);
  }
  cout << max(abs(cards.rbegin()[0]-cards.rbegin()[1]),
	      abs(cards.rbegin()[0]-w))<< '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int hiyou = sc.nextInt();
			int month = 0;
			int flg = 0;
			if(hiyou == 0 ) break;
			for(int i = 0 ; i < 12 ; i++){
				int m = sc.nextInt();
				int n = sc.nextInt();
				hiyou -= m - n;
				if(hiyou <= 0 && flg == 0) {
					month = i + 1;
					flg = 1;
				}
			}
			if(month == 0){
				System.out.println("NA");
			} else {
				System.out.println(month);
			}
			
		}
		sc.close();
	}

}

Measured memory_bytes: 35280
import math
import numpy as np
from operator import mul

# 整数Nを桁ごとのリストにする
# l = [int(x) for x in list(str(N))]

# リストliから重複を削除したリストli_uniqを作成
#li_uniq = []
#for i in li:
#    if x not in li_uniq:
#        li_uniq.append(x)

# 複数行のinput - list版
#list = [list(map(int, input().split())) for i in range(N)]
# 複数行のinput - dictionary版
# key = a, value = b
#for i in range(N):
#    a, b = map(int, input().split())
#    dict[a] = b


N = int(input())
dest = [[0,0,0]]
dest1 = [list(map(int, input().split())) for i in range(N)] # (ti xi yi)のリスト
dest = dest + dest1
yn = 0

for i in range(N):
    t_int = dest[i+1][0] - dest[i][0]
    t_min = abs(dest[i+1][1] - dest[i][1]) + abs(dest[i+1][2] - dest[i][2])
    if t_int >= t_min and (t_int - t_min)%2 == 0:
        continue
    else:
        yn += 1

if yn > 0:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 37060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define fo(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef double ld;
typedef long long L;
typedef vector<int> VI;
typedef pair<int,int> pa;
const int oo=~0u>>3,N=111;

int main(){
#ifdef flukehn
	freopen("a.in","r",stdin);
#endif
	ios::sync_with_stdio(0);
	L n,ans=0,i;
	cin>>n;
	for(i=1;i*i<=n;++i){
		if(n%i==0){
			L m=n/i-1;
			if(m>i)ans+=m;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
while True:
    n=int(input())
    if n==0:
        break
    else:
        A=[0]*(n+10)
        A[0]=1
        A[1]=1
        A[2]=2
        if n==1:
            print(1)
        elif n==2:
            print(1)
        else:
            for i in range(3,n+1):
                A[i]=A[i-1]+A[i-2]+A[i-3]
            print(A[n]//3650+1)


Measured memory_bytes: 5596
from collections import Counter


def main():
    # n,m = [int(z) for z in input().split()]
    # table =[
    #     [int(z) for z in input().split()]
    #     for _ in range(n)
    # ]
    input()
    s = input()

    a = Counter(s)
    AL = "abcdefghijklmnopqrstuvwxyz"

    v = [a[b] + 1 for b in AL if a[b] != 0]

    res = 1
    V = 10 ** 9 + 7
    for a in v:
        res *= a % V
        res %= V
    print(res - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {

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

	    String result = execute(sc.nextInt(),sc.nextInt(),sc.nextInt());
        System.out.println(result);
    }

    public static String execute(int x, int y, int z){
        //偶数と偶数、奇数と奇数でのみ組み合わせ
        return z + " " + x + " " + y;
    }
}


Measured memory_bytes: 21716
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,m,d;
int col[2222];
char c[4]={'R','Y','G','B'};
int main()
{
	getiii(n,m,d);
	for(int i=d;i<=2000;i++)col[i]=1-col[i-d];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			putchar(c[col[i+j]<<1|col[i-j+1000]]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

public static partial class Program
{
    public static void Main()
    {
        var n = CRL().ToInt();
        var ais = CRL().ArrayInts();

        var lgcd = new int[n];
        var rgcd = new int[n];

        lgcd[0] = 0;
        rgcd[n - 1] = 0;

        for (int i = 1; i < n; i++)
        {
            lgcd[i] = GCD(lgcd[i - 1], ais[i - 1]);
        }

        for (int i = n - 2; i >= 0; i--)
        {
            rgcd[i] = GCD(rgcd[i + 1], ais[i + 1]);
        }

        var max = 0;
        for (int i = 0; i < n; i++)
        {
            max = Math.Max(max, GCD(lgcd[i], rgcd[i]));
        }

        CWL(max);
    }
}

public static partial class Program
{
    //テンプレここから
    public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
    public static int GCD(int a, int b) => b == 0 ? a : GCD(b, a % b);
    public static long LCM(long a, long b) => a * b / GCD(a, b);
    public static int LCM(int a, int b) => a * b / GCD(a, b);
    public static int ToInt(this double d) => (int) d;
    public static long ToLong(this double d) => (long) d;
    public static int ToInt(this string str) => int.Parse(str);
    public static long ToLong(this string str) => long.Parse(str);
    public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static int[] ArrayInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static string CRL() => Console.ReadLine();
    public static string RL() => ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static void WL(object obj) => WriteLine(obj);
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static long[] dx = new long[] {0, -1, 0, 1};
    public static long[] dy = new long[] {-1, 0, 1, 0};
    public static long mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array) => array.OrderBy(x => x).ToArray();
    public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray();
    public static long[] DSort(this long[] array) => array.OrderByDescending(x => x).ToArray();
    public static int[] DSort(this int[] array) => array.OrderByDescending(x => x).ToArray();
    public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);

    public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);

    //テンプレここまで
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int d[200][200];

int main()
{
    ios::sync_with_stdio(false);
    int N, M, R;
    cin >> N >> M >> R;

    vector<int> A(R);
    rep(i, R) {
        cin >> A[i];
        A[i]--;
    }

    rep(i, N) rep(j, N) d[i][j] = (i == j ? 0 : INF);
    rep(i, M) {
        int U, V, C;
        cin >> U >> V >> C;
        U--, V--;
        d[U][V] = d[V][U] = C;
    }

    rep(k, N) rep(i, N) rep(j, N) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    ll ans = INFLL;
    sort(A.begin(), A.end());

    do {
        ll tmp = 0;
        for (int i=1; i<R; i++) tmp += d[A[i-1]][A[i]];
        ans = min(ans, tmp);
    } while (next_permutation(A.begin(), A.end()));

    cout << ans << endl;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(100000000)

import sys
input = sys.stdin.readline

N,Q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N-1)]
px = [list(map(int,input().split())) for _ in range(Q)]

query = [0] * N
ans = [0] * N

for p,x in px:
    query[p-1] = query[p-1] + x
    
adj_list = [[] for _ in range(N)]
for a,b in ab:
    adj_list[a-1].append(b-1)
    adj_list[b-1].append(b-1)

memo = [True] * N

def dfs(v,val):
    child = adj_list[v]
    memo[v] = False
    val += query[v]
    ans[v] = val
    for s in child:
        if memo[s]:
            dfs(s,val)
    return 
        
dfs(0,0)
print(*ans)

Measured memory_bytes: 326476
#include <iostream>
#include <string>
#include <utility>
#include <queue>

using namespace std;

typedef pair<int, int> P;

const int MAX_N = 50;
const int MAX_M = 50;
const int INF = 1000000;

char maze[MAX_N][MAX_M];
int N, M;

int d[MAX_N][MAX_M];
int dx[4] = {0, -1, 0, 1}, dy[4] = {1, 0, -1, 0};

int main(){
  int black = 0;
  cin >> N >> M;
  string s;
  for(int i = 0; i < N; i++){
    cin >> s;
    for(int j = 0; j < M; j++){
      maze[i][j] = s[j];
      d[i][j] = INF;
      if(s[j] == '#') black++;
    }
  }
  d[0][0] = 0;
  queue<P> que;
  que.push(P(0,0));
  while(que.size()){
    P p = que.front();
    que.pop();
    if(p.first == N-1 && p.second == M-1) break;
    for(int i = 0; i < 4; i++){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(nx >= 0 && nx < N && ny >= 0 && ny < M && maze[nx][ny] != '#' && d[nx][ny] == INF){
        que.push(P(nx,ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  if(d[N-1][M-1] != INF) cout << N*M - black -1 - d[N-1][M-1] << endl;
  else cout << "-1" << endl; 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // 
    
    int a,b;
    
    cin>>a>>b;
    
   if(b%a==0){
       cout<<a+b<<endl;
   }
    
    else{
        cout<<b-a<<endl;
    }
        
    
    
    return 0;
    
    
}


Measured memory_bytes: 256
import math
n, k = map(int,input().split())
total = 0
mod = 10**9+7
max_value = (n*(n+1)) //2
for a in range(k,n+1):
    high = (max_value-(n-a)*(n-a+1)//2)
    low = (a*(a-1)) //2
    total += high - low + 1
total += 1 # k = n+1
print(total%mod)

Measured memory_bytes: 9192
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskD {
        static int[] num;
        static int n , k ;
        static long[][][] dp = new long[100][4][2];
        static long ok(int pos , int nonz , int ch1) {
            if (nonz > k) return 0;
            if (pos == n) {
                if (nonz == k) return 1;
                return 0;
            }
            if (dp[pos][nonz][ch1] != -1) return dp[pos][nonz][ch1];
            long res = 0;
            int lmt = 0;
            if (ch1 == 1) lmt = 9;
            else lmt = num[pos];
            for (int i = 0; i <= lmt; i++) {
                int n1 = nonz;
                int n2 = ch1;
                if (ch1 == 0 && i < lmt) n2 = 1;
                if (i != 0) n1++;
                if (n1 <= k) res += ok(pos + 1, n1, n2);
            }
            dp[pos][nonz][ch1] = res;
            return res;
        }
        public void solve(int testNumber, InputReader in, PrintWriter out){
            for (int i = 0; i <dp.length; i++) {
                for (int j = 0; j <dp[i].length ; j++) {
                    for (int l = 0; l <dp[i][j].length ; l++) {
                        dp[i][j][l]=-1;
                    }
                }
            }
            String s = in.next();
            k = in.nextInt();
            n =s.length();
            num = new int[s.length()];
            for (int i = 0; i <n; i++) {
                num[i]=s.charAt(i)-'0';
            }
            System.out.println(ok(0,0,0));





        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt(){return  Integer.parseInt(next());}
        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 24916
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int cnt = 0;
  for(int i=0;i<n-2;i++){
    if((a[i]<a[i+1]&&a[i+1]<a[i+2])||(a[i]>a[i+1]&&a[i+1]>a[i+2])){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
#define cont continue
//#define minn 999999999
//#define maxx 0
ll gcd(ll a, ll b);

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}
ll modulo(ll a, ll b)
{
    ll r = a % b;
    return r < 0 ? r + b : r;
}
//ncr
ull ncr(ull n, ull r)
{
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    ull ans = 1;
    ull i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
class abc
{
    public:
    ll val;
    ll ind;
};
bool fun1(abc x,abc y)
{
    return x.val>y.val;
}
///////////////////////////////////////////////////////
///////////////////////////////////////////
ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}
ll fact[100000+2];
ll ncrfast(ll n, ll r, ll p)
{
   if (r==0)
      return 1;
    return (fact[n]* modInverse(fact[r], p) % p *
            modInverse(fact[n-r], p) % p) % p;
}
///////////////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*ll tc;
    cin>>tc;
    while(tc--)
    {}*/
    /*ll n;
    cin>>n;
    string s;
    cin>>s;
    ll L=0;
    ll R=0;
    rep(i,0,n)
    {
        if( s[i]=='L' )
        L++;
        else
        {
            R++;
        }
        
    }
    L=-1*L;
    ll ans=1;
    ans+=R-L;
    cout<<ans<<endl;*/
    char a;
    cin>>a;
    a++;
    cout<<a<<endl;
}


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

using namespace std;


int N;
string S;

void rec(int idx1, bool t1, int idx2, bool t2, int idx, bool t3)
{
  vector< int > v(N, -1);
  v[idx] = t3;
  v[idx1] = t1;
  v[idx2] = t2;

  queue< int > que;
  que.push(idx1);
  que.push(idx2);

  while(!que.empty()) {
    int p = que.front();
    que.pop();
    int s = (p - 1 + N) % N;
    int t = (p + 1) % N;
    if(v[p]) {  // 真実
      if(S[p] == 'o') {
        if(~v[s] && ~v[t]) {
          if(v[s] != v[t]) return;
          continue;
        }
        if(~v[s]) v[t] = v[s], que.push(t);
        else v[s] = v[t], que.push(s);
      } else if(S[p] == 'x') {
        if(~v[s] && ~v[t]) {
          if(v[s] == v[t]) return;
          continue;
        }
        if(~v[s]) v[t] = v[s] ^ 1, que.push(t);
        else v[s] = v[t] ^ 1, que.push(s);
      }
    } else { // 逆
      if(S[p] == 'o') {
        if(~v[s] && ~v[t]) {
          if(v[s] == v[t]) return;
          continue;
        }
        if(~v[s]) v[t] = v[s] ^ 1, que.push(t);
        else v[s] = v[t] ^ 1, que.push(s);
      } else if(S[p] == 'x') {
        if(~v[s] && ~v[t]) {
          if(v[s] != v[t]) return;
          continue;
        }
        if(~v[s]) v[t] = v[s], que.push(t);
        else v[s] = v[t], que.push(s);
      }
    }
  }

  for(int i = 0; i < N; i++) {
    if(v[i]) cout << "S";
    else cout << "W";
  }
  cout << endl;
  exit(0);
}

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

  if(count(begin(S), end(S), 'o') == N) {
    cout << string(N, 'S') << endl;
    return (0);
  }

  for(int i = 0; i < S.size(); i++) {
    if(S[i] == 'x') {
      for(int j = 0; j < 2; j++) {
        for(int k = 0; k < 2; k++) {
          rec((i + N - 1) % N, j, (i + 1) % N, k, i, j != k);
        }
      }
      break;
    }
  }


  cout << -1 << endl;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>a>>b;
    Cout(max({a+b,a-b,a*b}));
    return 0;
}


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

namespace arc095_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var XL = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
            var XL2 = new List<long>();

            for (int i = 0; i < N; i++)
                XL2.Add(XL[i]);

            XL2.Sort();
            var l = XL2[(int)N / 2 - 1];
            var r = XL2[(int)N / 2];

            for (int i = 0; i < N; i++) 
                if (XL[i] <= l)
                    Console.WriteLine(r);
                else 
                    Console.WriteLine(l);
        }
    }
}


Measured memory_bytes: 42824
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int, int> P;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int main() {
	int n, a[100];
	cin >> n;
	REP(i, n) {
		cin >> a[i];
	}
	SORT(a,n);
	REVERSE(a, n);
	int ans = 0;
	REP(i, n) {
		if (i % 2 == 0)ans += a[i];
		else ans -= a[i];
	}
	cout << ans;
}



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

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numH = 0;
		int numW = 0;
		int h = 0;
		int w = 0;

		try {
			scanner = new Scanner(System.in);
			numH = scanner.nextInt();
			numW = scanner.nextInt();
			h = scanner.nextInt();
			w = scanner.nextInt();

			int total = numH * numW;
			int col = h * numW;
			int row = w * (numH - h);
			System.out.println(total - col - row);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numM = 0;
		int numC = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numM = scanner.nextInt();
			numC = scanner.nextInt();
			int[] bArray = new int[numM];
			int[][] aArray = new int[numN][numM];

			for (int i = 0; i < bArray.length; i++) {
				bArray[i] = scanner.nextInt();

			}
			for (int i = 0; i < aArray.length; i++) {
				for (int j = 0; j < aArray[i].length; j++) {
					aArray[i][j] = scanner.nextInt();
				}
			}
			int cnt = 0;

			for (int i = 0; i < aArray.length; i++) {
				int res = 0;
				for (int j = 0; j < aArray[i].length; j++) {
					res += (aArray[i][j] * bArray[j]);
				}
				if (res + numC > 0) {
					cnt++;
				}
			}

			System.out.println(cnt);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	public static class LComp implements Comparator<Long[]> {

		@Override
		public int compare(Long[] o1, Long[] o2) {
			return Long.compare(o1[0], o2[0]);
		}

	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		long numM = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numM = scanner.nextLong();

			Long[][] wk = new Long[numN][2];

			for (int i = 0; i < numN; i++) {
				wk[i][0] = scanner.nextLong();
				wk[i][1] = scanner.nextLong();
			}

			Arrays.sort(wk, new LComp());

			long resNumM = numM;
			long res = 0;
			for (int i = 0; i < wk.length; i++) {
				if (resNumM == 0) {
					break;
				}
				long key = wk[i][0];
				long value = wk[i][1];
				if (resNumM >= value) {
					res += (key * value);
					resNumM -= value;
				} else {
					res += (key * resNumM);
					resNumM = 0;
				}

			}

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

using namespace std;

int gain(int pre, int cur, int post){
    return abs(pre - cur) + abs(cur - post) - abs(pre - post);
}

int main(){
    int N;
    cin >> N;
    int A[N+2]; A[0] = 0;
    int total = 0;

    for(int i=1; i<=N; i++) {
        cin >> A[i];
        total += abs(A[i] - A[i-1]);
    }
    A[N+1] = 0;
    total += abs(A[N]);
    for(int i=1; i<=N; i++){
        cout << total - gain(A[i-1], A[i], A[i+1]) << endl;;
    }
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

vector<int> edge[100000];
int dp[100000][11];

void dfs(int v, int d, int c) {
  if (d < 0 or dp[v][d]) return ;
  dp[v][d] = c;
  dfs(v, d - 1, c);
  for (int ch : edge[v]) {
    dfs(ch, d - 1, c);
  }
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M; cin >> N >> M;
  REP(i, M) {
    int a, b; cin >> a >> b; a--, b--;
    edge[a].emplace_back(b);
    edge[b].emplace_back(a);
  }

  int Q; cin >> Q;
  vector<tuple<int, int, int>> query;
  REP(i, Q) {
    int v, d, c; cin >> v >> d >> c; v--;
    query.emplace_back(v, d, c);
  }

  REP(i, Q) {
    int v, d, c; tie(v, d, c) = query[Q-i-1];
    dfs(v, d, c);
  }

  REP(i, N) cout << dp[i][0] << endl;

  return 0;
}


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

int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;

    double conc_max = 0;
    int water=0,sugar=0;

    for(int i=0; i<=f/(100*a); i++){
        for(int j=0; j<=(f-100*a*i)/(100*b); j++){
            for(int k=0; k<=(f-100*a*i-100*b*j)/c; k++){
                for(int l=0; l<=(f-100*a*i-100*b*j-c*k)/d;l++){
                    double conc,origin;
                    if(i==0 && j==0 && k==0 && l==0){
                        continue;
                    }
                    conc = (double)(c*k+d*l)/(100*a*i+100*b*j+c*k+d*l);
                    origin = (double)e/(100+e);
                    if(conc <= origin && conc >= conc_max){
                        conc_max = conc;
                        water = 100*a*i + 100*b*j;
                        sugar = c*k + d*l;
                    }
                }
            }
        }
    }
    cout << water+sugar << " " << sugar << endl;
}

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

main()
{
  int a,b,c,d,e,k;
  
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  cin >> k;
  
  if(e-a <= k)
     cout << "Yay!";
  else
    cout << ":(";
  
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(all(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
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 () {
  string n = stin();
  vi hon = {2,4,5,7,9};
  vi pon = {0,1,6,8};
  vi bon = {3};
  if (incl(hon,n.back()-'0')) puts("hon");
  else if (incl(pon,n.back()-'0')) puts("pon");
  else puts("bon");
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N; cin >> N;
  int a[N]; int M = 0; int res = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i]; M = max(M, a[i]);
  }
  while (M > 0) {
    int l = 0;
    for (int i = 0; i < N; i++) {
      if (a[i] > 0) {l = i; break;}
    }
    for (int i = l; l < N; i++) {
      if (a[i] == 0) {break;}
      if (a[i] > 0) {a[i]--;}
    }
    M = 0;
    for (int i = 0; i < N; i++) {
      M = max(M, a[i]);
    }
    res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;

typedef long long int ll;
typedef string str;

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;   
    while (y) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll nCrModP(ll n, ll r, ll p) 
{ 
    if (!r) 
      return 1; 
  
	ll fac[n+1]; 
   	fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p; 
}

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

void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}



int main ()
{
	
	ll t,n,m,k,i,j;
	cin >> t;
    if(t%1000==0)
        n=0;
    else
        n=1000-t%1000;
	cout << n << "\n";
	return 0;
}

Measured memory_bytes: 3628
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctype.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
const long long int mod = 998244353;
long long int power(long long int x,long long int y){  
    long long int res = 1;
    x = x % mod;
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % mod;  
        y = y>>1;
        x = (x*x) % mod; 
    }  
    return res;
}  
long long int inv(long long int a){return power(a,mod-2);}
long long int add(long long int a,long long int b){return (a+b)%mod;}
long long int sub(long long int a,long long int b){return (a-b+mod)%mod;}
long long int mul(long long int a,long long int b){return ((a)*(b))%mod;}
long long int divi(long long int a,long long int b){return (a*inv(b))%mod;}
ll fact[10000001];
void pre(){
}
ll ncr(ll n,ll r){
    if(n<r) return 0;
    return divi(fact[n],mul(fact[r],fact[n-r]));
}
ll dp[3001][3001]{0};
void solve(){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    for(int i=0;i<3000;i++){
        dp[0][i]=power(a,i);
        dp[i][0]=power(b,i);
    }
    for(int i=1;i<=c-a;i++){
        for(int j=1;j<=d-b;j++){
            dp[i][j]=sub(add(  mul(dp[i-1][j],(b+j)) , mul(dp[i][j-1],(a+i))) ,(dp[i-1][j-1]*(a+i-1)*(b+j-1))%mod);
        }
    }
    cout<<dp[c-a][d-b]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    solve();
}





Measured memory_bytes: 73972
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
long long num;
long long solve(long long  mod){
    if(mod==0){
        return 0;
    }
    return 1+solve((mod*10+7)%num);
}
int main()
{
cin>>num;
if(num%2==0||num%10==5){
    printf("-1\n");
}
else{
    cout<<solve(7%num)+1<<endl;
}




    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;

int main(){
  scanf("%d",&n);
  int ct=0;
  int cx=0, cy=0;
  while(n--){
    int t,x,y;
    scanf("%d%d%d",&t,&x,&y);
    int span = t-ct;
    int len = abs(x-cx) + abs(y-cy);
    if(span < len || span%2 != len%2){
      puts("No");
      return 0;
    }
    ct = t;
    cx = x;
    cy = y;
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    long long int n;
    cin>>n;
    long long int a;
    long long int c;
    for(long long int i=0;i<1000001;i++){
        if(n<=i*i){
       a=i;
       break;
        }
    }
    
      long long int b;
    for(long long int i=a;i>0;i--){
        if(n%i==0){
            b=i;
            break;
        }
    }
c=n/b;
cout<<c+b-2;
    return 0;
}


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

int color[600][600][2];
int N, D[2];
vector<pair<int, int>> pr[2];

void dfs(int i, int j, int k, int c){
    if(color[i][j][k]) return;
    color[i][j][k] = c;

    for(auto& p : pr[k]){
        int x = i+p.first, y = j+p.second;
        if(0<=x && x<2*N && 0<=y && y<2*N) dfs(x, y, k, -c);
    }
}

int main(){
    cin >> N >> D[0] >> D[1];
    
    for(int i=-2*N; i<=2*N; i++) for(int j=-2*N; j<=2*N; j++){
        for(int k=0; k<2; k++) if(i*i + j*j == D[k]) pr[k].push_back({i, j});
    }

    for(int i=0; i<2*N; i++) for(int j=0; j<2*N; j++) for(int k=0; k<2; k++) dfs(i, j, k, 1);

    map<int, vector<pair<int, int>>> mp;
    for(int i=0; i<2*N; i++) for(int j=0; j<2*N; j++){
        int code = 10*color[i][j][0] + color[i][j][1];
        mp[code].push_back({i, j});
    }
    for(auto& p : mp){
        auto v = p.second;
        if(v.size() >= N*N){
            int num = 0;
            for(auto& a : v){
                printf("%d %d\n", a.first, a.second);
                num++;
                if(num == N*N) return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 30580
#include<stdio.h>

int main(void)
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a+b>c+d)
    {
        printf("Left\n");
    }
    else if(a+b==c+d)
    {
        printf("Balanced\n");
    }
    else
    {
        printf("Right\n");
    }
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 1e9 + 7;
const int N = 2e5 + 10, M = 1e3 + 10;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;

#define pi acos(-1)

char str[N << 1];

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    if(a == 0)
        puts("0");
    else if(b == 0)
        cout << n << endl;
    else
    {
        if(a >= n)
            cout << n << endl;
        else
        {
            if(a + b >= n)
                cout << a << endl;
            else
            {
                ll d = n / (a + b);
                ll ans = d * a;
                d = n - (a + b) * d;
                ans += min(d, a);
                cout << ans << endl;
            }
            
        }
        
    }
    
    return 0;
}

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

int a[105] ;

int main(){
	int N ;
	cin >> N ;
	for( int i = 0 ; i < N ; i++ ){
		cin >> a[i] ;
	}
	bool ok = true ;
	for( int i = 0 ; i < N ; i++ ){
		if( a[i]%2 == 0 && (a[i]%3 != 0 && a[i]%5 != 0 ) ){
			ok = false ;
			break ;
		}
	}
	if(ok) puts("APPROVED");
	else puts("DENIED");




	return 0 ;
}

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

static class D
{
    static void Main()
    {
        int[] nm = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
        int n = nm[0];
        int m = nm[1];

        var edges = Enumerable.Range(0, n).Select(_ => new List<int>()).ToList();
        var deg = Enumerable.Repeat(0, n).ToList();

        for (int i = 0; i < n - 1 + m; i++) {
            int[] ab = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            int a = ab[0] - 1;
            int b = ab[1] - 1;
            edges[a].Add(b);
            ++deg[b];
        }

        var par = Enumerable.Repeat(-1, n).ToList();

        var queue = new Queue<int>();
        for (int i = 0; i < n; i++) {
            if (deg[i] == 0) {
                par[i] = 0;
                queue.Enqueue(i);
            }
        }
        while (queue.Count > 0) {
            int i = queue.Dequeue();
            foreach (int j in edges[i]) {
                if (par[j] == -1) {
                    --deg[j];
                    if (deg[j] == 0) {
                        par[j] = i + 1;
                        queue.Enqueue(j);
                    }
                }
            }
        }
        for (int i = 0; i < n; i++) {
            Console.WriteLine(par[i]);
        }
    }
}


Measured memory_bytes: 32888