akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
ll gcd(ll a, ll b) {
    return __gcd(a,b);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    ll g = gcd(n,m);
    ll jn = n/g, jm = m/g;
    bool good = true;
    rep(i,0,g) {
        if(s[i*jn]!=t[i*jm]) good = false;
    }
    ll ans = -1;
    if(good) {
        ans = n*(m/g);

    }
    cout << ans << endl;
}


Measured memory_bytes: 640
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
money = 0
now = 0
for i in a:
    money += abs(now - i)
    now = i


for i in range(1, n+1):
    if a[i-1] <= a[i+1]:
        if a[i - 1] <= a[i] <= a[i + 1]:
            print(money)
        elif a[i] < a[i - 1]:
            print(money - 2 * (a[i - 1] - a[i]))
        elif a[i + 1] < a[i]:
            print(money - 2 * (a[i] - a[i + 1]))
    else:
        if a[i + 1] <= a[i] <= a[i - 1]:
            print(money)
        elif a[i] < a[i + 1]:
            print(money - 2 * (a[i + 1] - a[i]))
        elif a[i - 1] < a[i]:
            print(money - 2 * (a[i] - a[i - 1]))




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

#define ll long long
#define ss second
#define ff first
#define pb push_back

using namespace std;

const int N = 1e6 + 69;

ll n, x, y, m;
ll answer[N] ;
vector <ll> gr[N], new_gr[N], answer_without[N];

void dfs_tree(int x,int p){

        new_gr[x].pb(0);
        answer_without[x].pb(0);
        for(int i = 0; i < gr[x].size(); i++ ){
                int to = gr[x][i];
                if(to == p) continue;
                dfs_tree(to,x);
                answer_without[x].pb(0);
                new_gr[x].pb(to);
        }
        new_gr[x].pb(0);
        answer_without[x].pb(0);
}

void dfs(int x,int p){

        answer[x] = 1;

        vector <ll> pre(new_gr[x].size(),1),suf(new_gr[x].size(),1);

        for(int i = 1; i < new_gr[x].size() - 1; i++){
                int to = new_gr[x][i];
                dfs(to,x);
                answer[x] *= answer[to] + 1;
                answer[x] %= m;
                pre[i] = pre[i-1] * (answer[to] + 1);
                pre[i] %= m;
        }

        for(int i = new_gr[x].size() - 2; i >= 1; i--){
                int to = new_gr[x][i];
                suf[i] = suf[i+1] * (answer[to] + 1);
                suf[i] %= m;
        }

        for(int i = 1; i < new_gr[x].size() - 1; i++){
                answer_without[x][i] = pre[i-1] * suf[i+1];
                answer_without[x][i] %= m;
        }

}

void dfs1(int x,ll ans){
        //cout << x << " " << answer[x] << endl;
        answer[x] *= (ans + 1);
        answer[x] %= m;

        for(int i = 1; i < new_gr[x].size() - 1; i++){
                int to = new_gr[x][i];
                dfs1(to,answer_without[x][i]*(ans+1)%m);
        }
}

int main(){

        ios::sync_with_stdio(0);

        cin >> n >> m;


        for(int i = 1; i < n; i++){
                cin >> x >> y;
                gr[x].pb(y);
                gr[y].pb(x);
        }

        dfs_tree(1,0);

        dfs(1,0);

        dfs1(1,0);

        for(int i = 1; i <= n; i++){
                cout << answer[i] << endl;
        }
}


Measured memory_bytes: 96640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int numTest = Integer.parseInt(stdIn.next());

        int numAC = 0;
        int numWA = 0;
        int numTLE = 0;
        int numRE = 0;
        for (int i = 0; i < numTest; i++) {
            String result = stdIn.next();
            if ("AC".equals(result)) {
                numAC++;
            } else if ("WA".equals(result)) {
                numWA++;
            } else if ("TLE".equals(result)) {
                numTLE++;
            } else if ("RE".equals(result)) {
                numRE++;
            }
        }
        System.out.println("AC x "+ numAC);
        System.out.println("WA x "+ numWA);
        System.out.println("TLE x "+ numTLE);
        System.out.println("RE x "+ numRE);
        stdIn.close();
    }

}

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

int main() {
    int f = 0, first, last;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == 'A' && f == 0) {
            first = i;
            f = 1;
        }
        if(s[i] == 'Z') last = i;
    }
    cout << last-first+1 << '\n';
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10 ** 5)

N, M = map(int, input().split())
V = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(lambda x: int(x) - 1, input().split())
    V[x].append(y)

dp = [None for _ in range(N)]

def dfs(x):
    if dp[x] is not None:
        return dp[x]
    if not V[x]:
        dp[x] = 0
        return 0
    l = max(dfs(v) for v in V[x]) + 1
    dp[x] = l
    return l

print(max(dfs(v) for v in range(N)))


Measured memory_bytes: 106708
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int ans = 1;
    for (int i=1; i<n; i++) {
        int cnt = 0;
        rep(j, i) {
            if (h[j] <= h[i]) cnt++;
            else break;
        }
        if (cnt == i) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    
    print(a.replace('2017','2018'))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {
	public static void main(String[] args) {
		// code to read values
		// code to call required method
		// code to display the result
		// System.out.println(Math.ceil(2.5));
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[1000001];
		long sum = 0;
		for (int i = 0; i < n; i++) {
			int val = sc.nextInt();
			arr[val]++;
			sum += val;
		}
		int k = sc.nextInt();
		while (k > 0) {
			// System.out.println("hey");
			int old = sc.nextInt();
			int recent = sc.nextInt();
			arr[recent] += arr[old];
			sum += -(arr[old] * old) + (arr[old] * recent);
			arr[old] = 0;
			System.out.println(sum);
			k--;
		}
	}

}

Measured memory_bytes: 61936
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;


public class Main {

    public void solve() {
        out.println(next().chars().mapToObj(c -> (char)c).filter(c -> c == '1').count());
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 27476
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,flag=0;
    scanf("%d",&n);
    for(int i=1;i<=9;i++)
    {
            for(int j=1;j<=9;j++)
{

        if(i*j==n)
        {
         flag=1;
        }
}}

    if(flag==1)
    printf("Yes\n");
    else
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int S = sc.nextInt();
    int answer=0;
    for(int i=0;i<=K;i++){
      if(i>S){
        break;
      }
      for(int j=0;j<=K;j++){
        if(i+j>S){
          break;
        }
        if(S-i-j>=0&&S-i-j<=K){
            answer++;
        }
      }
    }
    System.out.println(answer);
  }
  

  
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, count = 0; cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) {
    cin >> a.at(i); a.at(i)--;
  }
  for(int i = 0; ;) {
    if(count > N) {
      cout << -1 << endl;
      return 0;
    }
    i = a.at(i);
    count++;
    if(i == 1) {
      cout << count << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int n;
int a[100];
int M, m, s;
int main()
{
	cin >> n;
	while(n!=0)
	{	
		cin >> a[0];
		M=a[0];
		m=a[0];
		s=a[0];
		for(int i=1; i<n; i++)
		{
			cin >> a[i];
			M=max(M, a[i]);
			m=min(m, a[i]);
			s+=a[i];
		}
		cout << (s-M-m)/(n-2) << endl;
		cin >> n;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n>>k;
    cout << n*k ;

    return 0;
}

Measured memory_bytes: 3652
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scan := bufio.NewScanner(os.Stdin)
	scan.Scan()

	input, err := strconv.Atoi(scan.Text())
	if err != nil {
		panic(err)
	}

	for index := 1; index <= input; index++ {
		if index%3 == 0 || strings.Contains(strconv.Itoa(index), "3") {
			fmt.Print(" ")
			fmt.Print(index)
		}
	}

	fmt.Println()
}



Measured memory_bytes: 1192
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const double EPS = 1e-10;
vector<int> S[1000];
int main() {
	int N;
	cin >> N;
	int k = 2;
	while (1) {
		if (k*(k - 1) / 2 >= N) break;
		k++;
	}
	if (k*(k - 1) / 2 > N) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	cout << k << endl;
	int x = 1;
	for (int i = 0; i < k; i++) {
		for (int j = i + 1; j < k; j++) {
			S[i].push_back(x);
			S[j].push_back(x);
			x++;
		}
	}
	for (int i = 0; i < k; i++) {
		cout << S[i].size();
		for (int j = 0; j < S[i].size(); j++) {
			cout << " " << S[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
bool IsPrime(int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}
int kazu[213456];
signed main() {
	int n, a, b, c = 0; cin >> n;
    for (int h = 1; h < 100000; h++) {
        if (IsPrime(h) && IsPrime((h + 1) / 2)) c++;
        kazu[h] = c;
    }
	for (int h = 0; h < n; h++) {
		cin >> a >> b;
        cout << kazu[b] - kazu[a - 1] << endl;
	}
}

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

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

using namespace std;

int c[11];

int main(){
	rep(i, 3){
		int v;
		cin >> v;
		++c[v];
	}
	cout << (c[5] == 2 && c[7] == 1 ? "YES" : "NO") << endl; 
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            // Input
            int N = Integer.parseInt(sc.next());
            Integer[] a = new Integer[N];
            for (int i = 0; i < N; i++) {
                a[i] = Integer.parseInt(sc.next());
            }
            Arrays.sort(a, Collections.reverseOrder());

            // Calc
            long ans = 0; int cnt = 0, index = 1;
            for (int i = 0; i < N; i++) {
                switch(i) {
                    case 0:
                        break;
                    case 1:
                        ans += a[0];
                        break;
                    default:
                        if (cnt == 2) {
                            cnt = 0;
                            index++;
                        }
                        cnt++;
                        ans += a[index];
                }
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 63692
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		
		int yonbai=0,kisuu=0,guusuu=0;
		
		for(int i=0; i<n; i++){
			int a = sc.nextInt();
			if(a % 4 == 0){
				yonbai++;
			}
			else if(a % 2 != 0){
				kisuu++;
			}
			else{
				guusuu++;
			}
		}
		
		
		//System.out.println("yonbai:" + yonbai + "kisuu:" + kisuu + "guusuu" + guusuu);
		
		if(yonbai >= kisuu){
			System.out.println("Yes");
		}
		else if(yonbai == kisuu - 1 && guusuu == 0){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long LL;

const int INF = 0x3f3f3f3f;


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

    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        cout << 'x';
    }
    cout << endl;

    return 0;
}



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

string keyence = "keyence";
int number = 1;

int main() {
    string S;
    getline(cin, S);
    if(S.find(keyence) != string::npos) {
        string sentou = S.substr(0,7);
        if(sentou == keyence){
            cout << "YES" << endl;
            return 0;
        }
        string matubi = S.substr(S.length() - 7, 7);
        if(matubi == keyence) {
            cout << "YES" << endl;
            return 0;
        }
        cout << "NO" << endl;
        return 0;
    }
    if(S.front() != keyence[0]) {
        cout << "NO" << endl;
        return 0;
    }
    int f = 0;
    for(int i = 1; i < S.length(); i++) {
        if(keyence[number] != S[i]) {
            string nokori = "";
            for(;number < 7;number++) 
                nokori += keyence[number];
            if(nokori == S.substr(S.length() - nokori.length(), nokori.length())){
                cout << "YES" << endl;
                return 0;
            } else {
                cout << "NO" << endl;
                return 0;
            }
        } else {
            number++;
        }
    }
}


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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vector<pair<int,int> > vec(n);
    for(int i=0;i<n;++i)
    {
    	int a,b;
    	cin>>a>>b;
    	vec[i]=make_pair(b,a);
    }

    sort(vec.begin(),vec.end());

    int flag=0;
    ll count=0;
    for(int i=0;i<n;++i)
    {
    	count+=vec[i].second;
    	if(count>vec[i].first)
    	{
    		flag=1;
    		break;
    	}
    }

    if(flag==1)
    {
    	cout<<"No"<<endl;
    }
    else
    {
    	cout<<"Yes"<<endl;
    }






}


Measured memory_bytes: 1920
#include <iostream>
using namespace std;
int main(void){
    int m,f,b;
    cin >> m >> f >> b;
    int x=b-m;
    if(x<=0){
        cout << "0" << endl;
    }
    else if(x>0){
        int y=f-x;
        if(y>=0){
            cout << x << endl;
        }
        else{
            cout << "NA" << endl;
        }
    }
}



Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 1000;
int a[3][maxn], b[maxn], c[maxn];
int n;
int main()
{
    cin>>n;
    for(int i = 1; i <= 2; i++)
        for(int j = 1; j<= n; j++)
            cin>>a[i][j];
    for(int i = 1; i <= n; i++) b[i] = b[i-1] + a[1][i];
    for(int i = 1; i <= n; i++) c[i] = max(b[i] + a[2][i], c[i-1] + a[2][i]);
    cout<<c[n]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAXN 401
 
long long int v[MAXN],N;
long long int rangeTree[MAXN];
long long int memo[MAXN][MAXN];
 
inline long long int query(int a,int b){
	return rangeTree[b] - rangeTree[a] + v[a]; 
}
 
inline long long int dp(int a, int b){
	if(memo[a][b] != -1)return memo[a][b];
	if(a == b - 1)return memo[a][b] = v[a] + v[b];
	if(a == b)return 0;
	long long int ans = LLONG_MAX;
	for(int i = a; i < b; i++){
		ans = min(ans,dp(a,i) + dp(i + 1,b));
	}
	return memo[a][b] = ans + query(a,b);
}
 
int main() {
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> v[i];
	}
	rangeTree[0] = v[0];
	for(int i = 1; i < N; i++){
		rangeTree[i] = rangeTree[i - 1] + v[i];
	}
	memset(memo,-1,sizeof(memo));
	cout << dp(0,N - 1);
	return 0;
}

Measured memory_bytes: 1536
// link:
// [prajwal1721]
// g++ -Wall -Wextra -Wshadow filename.cpp
// ./a.out >input <output
/*comments:
*/



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



typedef long long int ll;
void solve()
{
    ll n,t,m;cin>>n>>m;
    ll a[n][m]={0};
    char c;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>c;
            if(c=='.')a[i][j]=1;
            else a[i][j]=0;
        }
    }
    ll dp[n][m]={0};
    dp[0][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(a[i][j]==0)continue;
            if(i==0 && j==0 )continue;
            dp[i][j]=0;
            if(i-1>=0 && a[i-1][j])dp[i][j]+=dp[i-1][j];
            if(j-1>=0 && a[i][j-1])dp[i][j]+=dp[i][j-1];
            dp[i][j]%=mod;
        }
    }
    /*
    for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
               cout<<dp[i][j]<<" ";
        cout<<"\n";
        }
        */
    cout<<dp[n-1][m-1]<<"\n";

}


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


    return 0;
}

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

int main()
{
	int N, P;
	cin >> N >> P;
	vector<int> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	vector<vector<long long>> C( N + 1, vector<long long>( N + 1 ) );
	for( int i = 0; i < N + 1; i++ ) {
		for( int j = 0; j <= i; j++ ) {
			if( j == 0 || j == i ) C[i][j] = 1;
			else C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
		}
	}
	int even = 0;
	int odd = 0;
	for( int i = 0; i < N; i++ ) {
		if( A[i] % 2 ) odd++;
		else even++;
	}

	long long ans = 0;
	if( P == 0 ) {
		long long e = 0;
		for( int i = 0; i <= even; i++ ) {
			e += C[even][i];
		}
		long long o = 0;
		for( int i = 2; i <= odd; i += 2 ) {
			o += C[odd][i];
		}
		if( even > 0 && o > 0 ) ans = (o + 1) * e;
		else ans = e + o;
	}
	else {
		long long e = 0;
		for( int i = 0; i <= even; i++ ) {
			e += C[even][i];
		}
		long long o = 0;
		for( int i = 1; i <= odd; i += 2 ) {
			o += C[odd][i];
		}
		if( even > 0 && odd > 0 ) ans = o * e;
		else ans = o;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  int area = a * b;
  int length = a * 2 + b * 2;
  System.out.println(area + " " +length);
  }
}

Measured memory_bytes: 25988
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}

int main(void){
    ll n;
    cin>>n;
    if(n==0) {
        cout<<0<<endl;
        return 0;
    }
    ll now=2;
    ll nowmi=1;
    vector<int> ans;
    while(n){
        if(n%now==0){
            ans.push_back(0);
        }
        else {
            ans.push_back(1);
            n-=nowmi;
        }
        now*=2;
        nowmi*=(-2);
    }
    reverse(ans.begin(), ans.end());
    rep(i, ans.size()) cout<<ans[i];
    cout<<endl;
    return 0;
}

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

using namespace std;

class Inverse {
private:
  long long mod;
	vector<long long> inv;
  
public:
  Inverse() {}
  
	Inverse(long long mod, long long n = 1000000) : mod(mod) {
    inv = vector<long long>(n, 1);
    for (int i = 2; i < n; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
  }
  
	long long operator()(long long a) const {
		if (a < (int)inv.size()) return inv[a];
		long long b = mod, x = 1, y = 0;
		while (b) {
			long long t = a / b;
			swap(a -= t * b, b);
			swap(x -= t * y, y);
		}
		return (x %= mod) < 0 ? x + mod : x;
	}
};

class Mint {
private:
  static long long mod;
  static Inverse inverse;
  long long val;
	
public:
	Mint() {}

	Mint(const long long& val) {
    this->val = val % mod;
    if (this->val < 0) this->val += mod;
  }

  static void setMod(const long long& m) {
    mod = m;
    inverse = Inverse(m);
  }
	
	Mint operator+=(const Mint& m) {
		val += m.val;
		if (val >= mod) val -= mod;
		return *this;
	}
  
	Mint operator-=(const Mint& m) {
		val -= m.val;
		if (val < 0) val += mod;
		return *this;
	}
  
	Mint operator*=(const Mint& m) {
		val *= m.val;
		val %= mod;
		return *this;
	}
  
	Mint operator/=(const Mint& m) {
		val *= inverse(m.val);
		val %= mod;
		return *this;
	}
	
	Mint operator+(const Mint& m) const {
		Mint res = *this;
		res += m;
		return res;
	}
	
	Mint operator-(const Mint& m) const {
		Mint res = *this;
		res -= m;
		return res;
	}
	
	Mint operator*(const Mint& m) const {
		Mint res = *this;
		res *= m;
		return res;
	}
	
	Mint operator/(const Mint& m) const {
		Mint res = *this;
		res /= m;
		return res;
	}
	
	Mint operator++() {return val += 1;}
	
	operator long long() {
		return val;
	}
};

Mint pow(const Mint& m, long long n) {
  if (n == 0) {
    return 1;
  } else if (n < 0) {
    return pow(m, -n);
  }
  Mint mm = pow(m, n / 2);
  mm *= mm;
  if (n % 2) mm *= m;
  return mm;
}

long long Mint::mod = 1000000007;
Inverse Mint::inverse(1000000007);

ostream& operator<<(ostream& os, Mint a) {
	os << (long long)a;
	return os;
}

istream& operator>>(istream& is, Mint& a) {
	long long n;
	is >> n;
	a = n;
	return is;
}

int main() {
  Mint m;
  int n;
  cin >> m >> n;
  cout << pow(m, n) << endl;
}

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

#define MOD 998244353LL

long long fac[1000001],finv[1000001],inv[1000001];

void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<1000001;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}

long long COM(int n,int k){
	if(n<k)return 0;
	if(n<0 || k<0)return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
 
long long MODpow(long long a,int b){
	if(b==0)return 1;
	if(b%2==0){
		long long t=MODpow(a,b/2);
		return (t*t)%MOD;
	}
	return (a*MODpow(a,b-1))%MOD;
}

int main(){
	COMinit();
	int N,M,K;
	cin >> N >> M >> K;
	long long ans=0;
	vector<long long> po(N,1);
	for(int i=0;i<N-1;i++)po[i+1]=(po[i]*(M-1))%MOD;
	
	for(int k=0;k<=K;k++){
		long long add=M;
		add*=po[N-1-k];
		add%=MOD;
		add*=COM(N-1,k);
		add%=MOD;
		ans+=add;
		ans%=MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 28336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000001
#define INFL 1000000000000000001
ll s,x;
int main(void){
	scanf("%lld",&s);
	ll no=0,yes=1000000000;
	while(yes-no>1LL){
		ll med=(no+yes)/2LL;
		if(s<=med*med)yes=med;
		else no=med;
	}
	x=yes;
	if(x*x-s>x){
		printf("%lld %lld %lld %lld %lld %lld\n",0,0,x,1,x*x-s-x,x-1LL);
	}else{
		printf("%lld %lld %lld %lld %lld %lld\n",0,0,x,1,x*x-s,x);
	}
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
     int k,a,b,sum=0;
     scanf("%d",&k);
     scanf("%d%d",&a,&b);
     for(a=a;a<=b;a++)
     {
          if((a%k)==0)
          {
               sum++;
          }
     }
     if(sum==0)
     {
          printf("NG\n");
     }
     else
     {
           printf("OK\n");
     }
}


Measured memory_bytes: 1632
#include <iostream>
#define MAX 100001
#define SENTINEL 2000000000
using namespace std;

struct Node
{
    int parent, left, right;
};

Node T[MAX];

int n, D[MAX], S[MAX], De[MAX], H[MAX];
int max = 0;

void print(int u)
{
    cout << "node " << u;
    cout << ": parent = " << T[u].parent;
    cout << ", sibling = " << S[u];
    cout << ", degree = ";
    int degree = 0;
    if (T[u].left != -1)
        degree++;
    if (T[u].right != -1)
        degree++;
    cout << degree;
    cout << ", depth = " << D[u];
    cout << ", height = " << H[u];
    if (T[u].parent == -1)
        cout << ", root";
    else if (T[u].left == -1 && T[u].right == -1)
        cout << ", leaf";
    else
        cout << ", internal node";
    cout << endl;
}

void setDepth(int u, int p)
{
    D[u] = p;
    if (T[u].left != -1)
        setDepth(T[u].left, p + 1);
    if (T[u].right != -1)
        setDepth(T[u].right, p + 1);
}

int setHeight(int u)
{
    int h1 = 0, h2 = 0;
    if (T[u].left != -1)
        h1 = setHeight(T[u].left) + 1;
    if (T[u].right != -1)
        h2 = setHeight(T[u].right) + 1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        T[i].parent = T[i].left = T[i].right = -1;
        S[i] = -1;
    }
    int id, left, right;

    for (int i = 0; i < n; i++)
    {
        cin >> id >> left >> right;
        T[id].left = left;
        T[id].right = right;
        if (left != -1)
            T[left].parent = id;
        if (right != -1)
            T[right].parent = id;
        if (left != -1 && right != -1)
        {
            S[left] = right;
            S[right] = left;
        }
    }
    int root = 0;
    for (int i = 0; i < n; i++)
    {
        if (T[i].parent == -1)
            root = i;
    }
    setDepth(root, 0);
    setHeight(root);
    for (int i = 0; i < n; i++)
    {
        print(i);
    }
    return 0;
}



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

int main(){
	int N;
	int p[200][3];
	int s[200][3] = {0};
	bool uni = true;
	cin >> N;
	
	for(int i = 0; i < N; i++){
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}
	
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < N; j++){
			uni = true;
			for(int k = 0; k < N; k++){
				if(j == k) continue;
				if(p[j][i] == p[k][i]){
						s[j][i] = s[k][i] = 0;
						uni = false;
				}
			}
			if(uni == true){
				s[j][i] = p[j][i];
			}
		}
	}
	
	for(int i = 0; i < N; i++){
		cout << s[i][0] + s[i][1] + s[i][2] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1164
program prob2
    implicit none
    character(len=100)::S
    character(len=7)::a
    integer::i,l
    a = "keyence"

    read(*,*) S
    l = len_trim(S)

    do i = 0, 7
        if(S(1:i) .eq. a(1:i) .and. S(l-6+i:l) .eq. a(i+1:7))then
            write(*,*) "YES"
            stop
        end if
    end do

    write(*,*) "NO"
    stop
end program

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 200005;
long long a[MX], b[2][MX][16], ans = 1e15;
int n;
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%lld", a+i);
	rep(k,2){
		rep(i,16) b[k][n-1][i] = i*2;
		for(int i = n-1; i > 0; i--){
			int t = 0;
			if(a[i-1] <= a[i]) for(; a[i-1] <= a[i]>>(t*2+2); t++);
			else for(; a[i-1] > a[i]<<-t*2; t--);
			rep(j,16) b[k][i-1][j] = j*2 + (j-t > 15 ? b[k][i][15] + (j-t-15) * (n-i) * 2 : b[k][i][max(0,j-t)]);
		}
		if(!k) rep(i,n/2) swap(a[i], a[n-1-i]);
	}
	rep(i,n) ans = min(ans, b[0][i][0] + b[1][n-i][0] + i);
	printf("%lld\n", ans);
}

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

main() {
  long n; cin>>n;
  long p = 1;
  long sum = 0;
  while (p <= n) {
    if (p%5 != 0 && p%3 != 0) sum += p;
    p++;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3640
#include <stdio.h>


int main()
{

    char a[4];
    scanf("%s", a);

    int j = 0;
    for (int i = 0; i < 3; i++)
    {
        if (a[i] == '7')
        {
            j = 1;
            break;
        }
    }

    if (j == 1)
        printf("Yes");
    else
    {
        printf("No");
    }

    printf("\n");
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>
#include <bitset>
#include <cassert>


// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

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

int a[11];
int r[11];

ll gcd(ll m, ll n){
	return n ? gcd(n, m%n) : m;
}
ll lcm(ll m, ll n){
	return m / gcd(m, n) * n;
}

int n, m, d;
int calc_max(int rem){
	if (rem < 0) return -1;

	ll x = 1;
	ll val = 0;
	rep(i, m){
		if (r[i] < 0) continue;
		rep(j, 100) {
			if (val%a[i] == r[i]) break;
			val += x;
		}
		if (val > rem) return -1;
		if (val%a[i] != r[i]) return -1;
		x = lcm(x, a[i]);
	}

	return (rem - val) / x*x + val;
}

int main(){
	cin >> n >> m >> d;
	rep(i, m) cin >> a[i];

	while (d--){
		rep(i, m) cin >> r[i];
		n = calc_max(n);
	}
	cout << n << endl;

	return 0;
}

Measured memory_bytes: 1164
def resolve():
    a, v = list(map(int, input().split()))
    b, w = list(map(int, input().split()))
    t = int(input())

    diff_dist = abs(a-b)
    diff_speed = abs(v-w)
    
    if a == b:
        print('YES')
    elif w >= v:
        print('NO')
    elif diff_dist > diff_speed * t:
        print('NO')
    else:
        print('YES')


if 'unittest' not in globals():
    resolve()

Measured memory_bytes: 61860
n = int(input())
s = [input() for _ in range(n)]

cnt = 0
for i in range(n):
    cnt += s[i].count("AB")
cnt_a = 0
cnt_b = 0
cnt_ab = 0
for i in range(n):
    len_s = len(s[i])
    if s[i][0] == "B" and s[i][len_s - 1] == "A":
        cnt_ab += 1
    elif s[i][len_s - 1] == "A":
        cnt_a += 1
    elif s[i][0] == "B":
        cnt_b += 1
if cnt_a == cnt_b == 0 and cnt_ab > 0:
    print(cnt + cnt_ab - 1)
else:
    print(cnt + min(cnt_a, cnt_b) + cnt_ab)

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

#define ll long long

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  
  for (int i = 0; i < N; i++) {
    ll x;
    cin >> x;
    
    a[i] = x - (i+1);
  }
  
  
  sort(a.begin(), a.end());
  
  ll b = a[N/2];
  
  ll ans = 0;
  
  for (int i = 0; i < N; i++) {
    ans += abs(a[i] - b);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4840
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn func(a: &Vec<i64>, tar: i64) -> i64 {
    let mut tmp = 0;
    let mut sum = 0;
    let mut sig = tar;
    for i in 0..a.len() {
        sum += a[i];
        if sum.signum() != sig {
            let d = sum.abs() + 1;
            tmp += d;
            sum += d * sig;
        }
        sig *= -1;
    }
    tmp
}


fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0];
    let a: Vec<i64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let ans = cmp::min(func(&a, 1), func(&a, -1));

    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void)
{
    int w, h, n;
    int x;
    int y;
    int a;
    int i, j, l;
    int plot[100][100] = { 0 };
    int cnt = 0;

    scanf("%d %d %d", &w, &h, &n);
    for (i = 0; i < w; i++) {
        for (j = 0; j < h; j++) {
            plot[i][j] = 0;
        }
    }
    for (l = 0; l < n; l++) {
        scanf("%d %d %d", &x, &y, &a);
        if (a == 1) {
            for (i = 0; i < x; i++) {
                for (j = 0; j < h; j++) {
                    plot[i][j] = 1;
                }
            }
        }else if (a == 2) {
            for (i = x; i < w; i++) {
                for (j = 0; j < h; j++) {
                    plot[i][j] = 1;
                }
            }
        }else if (a == 3) {
            for (i = 0; i < w; i++) {
                for (j = 0; j < y; j++) {
                    plot[i][j] = 1;
                }
            }
        }else if (a == 4) {
            for (i = 0; i < w; i++) {
                for (j = y; j < h; j++) {
                    plot[i][j] = 1;
                }
            }
        }
    }
    for (i = 0; i < w; i++) {
        for (j = 0; j < h; j++) {
            if (plot[i][j] == 0) {
                cnt++;
            }
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string a, b;
int dp[3100][3100];
pair<int, int> back[3100][3100];
bool inc[3100][3100];
int main () {
	cin >> a >> b;
	for (int i=1; i<=a.size(); i++) {
		for (int j=1; j<=b.size(); j++) {
			if (dp[i-1][j] > dp[i][j]) {
				dp[i][j] = dp[i-1][j];
				back[i][j] = {i-1, j};
			}
			if (dp[i][j-1] > dp[i][j]) {
				dp[i][j] = dp[i][j-1];
				back[i][j] = {i, j-1};
			}
			if (a[i-1] == b[j-1] && dp[i-1][j-1]+1 > dp[i][j]) {
				dp[i][j] = dp[i-1][j-1]+1;
				back[i][j] = {i-1, j-1};
				inc[i][j] = true;
			}
		}
	}
	pair<int, int> cur = {a.size(), b.size()};
	string o = "";
	while (cur != make_pair(0, 0)) {
		if (inc[cur.first][cur.second]) o += a[cur.first-1];
		cur = back[cur.first][cur.second];
	}
	reverse(o.begin(), o.end());
	cout << o << endl;
}

Measured memory_bytes: 121652
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const LL MOD = 1000000007LL;

int main() {
	int N;
	cin >> N;
	int a[50];
	int M = 0, m = 1 << 30;
	int M_pos = 0, m_pos = 0;
	vector<P> v;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (M <= a[i]) {
			M = a[i];
			M_pos = i;
		}
		if (m >= a[i]) {
			m = a[i];
			m_pos = i;
		}
	}
	bool posi;
	if (m >= 0) {
		posi = 1;
	}
	else if (M <= 0) {
		posi = 0;
	}
	else if (M >= abs(m)) {
		for (int i = 0; i < N; i++) {
			if (i == M_pos) continue;
			v.emplace_back(M_pos, i);
		}
		posi = 1;
	}
	else {
		for (int i = 0; i < N; i++) {
			if (i == m_pos) continue;
			v.emplace_back(m_pos, i);
		}
		posi = 0;
	}
	if (posi) {
		for (int i = 1; i < N; i++) v.emplace_back(i - 1, i);
	}
	else {
		for (int i = N - 1; i > 0; i--) v.emplace_back(i, i - 1);
	}
	cout << v.size() << endl;
	for (int i = 0; i < v.size(); i++) {
		cout << v[i].first + 1 << " " << v[i].second + 1 << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int p[20005];
	int a[20005];
	int b[20005];
	for(int i=1;i<=n;i++)
	a[i]=i*20000;
	int now=1e9;
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
		b[p[i]]=now-a[p[i]];
		now++;
	}
	printf("%d",a[1]);
	for(int i=2;i<=n;i++)
	printf(" %d",a[i]);
	printf("\n");
	printf("%d",b[1]);
	for(int i=2;i<=n;i++)
	printf(" %d",b[i]);
	printf("\n");
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
	cin >> n >> m >> k;
	vi v(m);
	REP(i,m) {
		cin >> v[i];
		if(v[i]>k){
			cnt++;
		}else{
			sum++;
		}
	}
	cout << min(cnt, sum) << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	A := make([][]int, 2)
	for i := 0; i < 2; i++ {
		A[i] = make([]int, N)
		for j := 0; j < N; j++ {
			fmt.Scan(&A[i][j])
		}
	}
	ans := 0
	for i := 0; i < N; i++ { // どこで下に移動するか？
		t := 0
		for j := 0; j <= i; j++ {
			t += A[0][j]
		}
		for j := i; j < N; j++ {
			t += A[1][j]
		}
		ans = max(ans, t)
	}
	fmt.Println(ans)
}
func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
 
#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;
 
typedef long long ll;
const ll mod=1e9+7;
 
using pear = pair<int,int>;
 
int main(){
    int a, b; cin >>a >>b;
    if(a-2*b > 0)cout << a - b*2 << endl;
    else cout << 0<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
const long long mod = 1000000007;
typedef long long ll;

ll n,q;
string s,t;
ll l[100005],r[100005],cnt[100005];

int main() {
  cin >> n >> q >> s;
  rep(i,q) cin >> l[i] >> r[i], l[i]--,r[i]--;
  for(int i=1;i<n;i++){
    cnt[i]=cnt[i-1];
    if(s[i-1]=='A'&&s[i]=='C') cnt[i]++;
  }
  rep(i,q)
  cout << cnt[r[i]]-cnt[l[i]] << endl; 
}

Measured memory_bytes: 3456
# coding: utf-8
a,b,c=map(int,input().split())
if a==b==c and a%2==0:
    print(-1)
    exit()
count=0
while not (a%2 or b%2 or c%2):
    count+=1
    a,b,c=b//2+c//2,a//2+c//2,a//2+b//2
print(count)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

void test(){
	ll a;
	cin>>a;
	cout<< a + (a*a) + (a*a*a)<<"\n";	
}

int main(){
	int tests=1;
//	cin>>tests;
	while(tests--){
		test();
	}
}

Measured memory_bytes: 3648
r, g, b, n = map(int, input().split())
ball = [0, r, g, b]
dp = [[0] * 4 for _ in range(n+1)]
dp[0][0] = 1

for i in range(n+1):
    for k in range(4):
        if k == 0:
            if i != 0:
                dp[i][k] = 0
        else:
            if i - ball[k] < 0:
                dp[i][k] = dp[i][k-1]
            else:
                dp[i][k] = dp[i-ball[k]][k] + dp[i][k-1]

print(dp[n][3])

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

int main(){
    int K,S;
    cin>>K>>S;
    long long ans = 0;

    for(int x=0; x<=K; x++){
        for(int y=0; y<=K; y++){
            int z = S - x - y;
            if(z >= 0 && z <= K) ans++;
        }
    }    

    cout<<ans<<endl;

    return 0;
}

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

int main(){
	int n;
	cin>>n;
	int po[394]={0};
	for(int i=0,a,b,c;i<n;i++){
		cin>>a>>b>>c;
		for(int j=a;j<=b;j++)po[j]=max(po[j],c);
	}
	
	for(int i=1;i<=393;i++){
		for(int j=1;j<=i;j++){
			if(po[i]>0&&po[j]>0&&i+j<=393){
				po[i+j]=max(po[i+j],po[i]+po[j]);
			}
		}
	}
	
	int m;
	cin>>m;
	int data[394];
	data[0]=1;
	for(int i=1;i<=m;i++){
		cin>>data[i];
		if(po[data[i]]==0)data[0]=0;
	}
	
	if(!data[0])cout<<-1<<endl;
	else{
		for(int i=1;i<=m;i++){
			cout<<po[data[i]]<<endl;
		}
	}
	/*
	cout<<"#"<<endl;
	for(int i=1;i<=10;i++){
		cout<<po[i]<<endl;
	}
	*/
	return 0;
}


Measured memory_bytes: 1164
n = int(input())
a = list(map(int, input().split()))
arriv = {}
l = []

for i in range(1, n + 1):
    arriv[i] = a[i - 1]

arriv_2 = sorted(arriv.items(), key = lambda x:x[1])

for i in range(n):
    l.append(str(arriv_2[i][0]))

print(' '.join(l))


Measured memory_bytes: 103008
import java.util.Scanner;

class Main{
	static int[][] dp;




	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		double[] p = new double[N];
		for(int i = 0;i < N;i++){
			p[i] = sc.nextDouble();
		}
		double[][] dp = new double[N+1][N+1];			//dp[i][j] = i番目までj枚面がでる確率
	dp[0][0] = 1;
		for(int i= 0;i < N;i++){
			for(int j = 0;j < N;j++){
				dp[i+1][j+1] += p[i] * dp[i][j];
				dp[i+1][j]   += (1-p[i])*dp[i][j];
			}
			
		}
		double ans = 0;
		for(int i = (N+1)/2;i <= N;i++){
			ans += dp[N][i];
		}
		System.out.println(ans);
		
		
	}

}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 124808
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;

int main(void){
	int H,W;cin>>H>>W;
	vector<vector<char>> VVI = vector<vector<char>>(H,vector<char>(W,0));
	rep(aa,H)rep(bb,W)cin>>VVI[aa][bb];

	int cnt = 0;
	for(int i = 0; i < H; i++){
		for(int t = 0; t < W; t++){
			cnt = 0;
			if(VVI[i][t] == '.'){
				cnt = 0;
				for(int x = -1; x <= 1; x++){
					for(int y = -1; y <= 1; y++){
						if(i + y >= 0 && t + x >= 0 && i + y < H && t + x < W){
							if(VVI[i + y][t + x] == '#')	cnt++;
						}
					}
				}
				VVI[i][t] = to_string(cnt)[0];
			}
		}
	}
	//出力
	rep(j , H){
		rep(q , W){
			cout<<VVI[j][q];
		}
		cout<<endl;
	}

}


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

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

const int mod = 1000000007;
const int inf = 1000000007;

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> dp(M);
  for (int k = 0; k < n; k++) {
    if (dp[a[k]] != 0) {
      dp[a[k]] = 2;
      continue;
    }
    for (int i = a[k]; i < M; i += a[k]) {
      dp[i]++;
    }
  }
  int res = 0;
  for (int k = 0; k < n; k++) {
    if (dp[a[k]] == 1) res++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 8016
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Pass = Tuple!(long, "x", long, "y");

void main()
{
    long x, y, z, k;
    scan(x, y, z, k);
    auto a = aryread();
    auto b = aryread();
    auto c = aryread();

    auto ab = new long[](x * y);
    long tmp;
    foreach (i; iota(x))
        foreach (j; iota(y))
            ab[tmp++] = a[i] + b[j];
    ab.sort!"a > b"();
    ab = ab.take(min(k, ab.length));
    auto abc = new long[](k * z);
    tmp = 0;
    foreach (i; iota(ab.length))
        foreach (j; iota(z))
            abc[tmp++] = ab[i] + c[j];
    abc.sort!"a > b"();
    abc = abc.take(k);
    foreach (e; abc)
        e.writeln();
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 36732
H,W=map(int,input().split())
h=range(H)
w=range(W)
S=[input() for _ in h]
M=[[-1]*W for _ in h]
k=0
for y in h:
 for x in w:
  if M[y][x]!=-1:continue
  M[y][x]=k;Q=[(y,x)]
  while len(Q)>0:
   i,j=Q.pop();s=S[i][j];p=i+1;q=i-1;r=j+1;t=j-1
   if p<H and M[p][j]==-1 and s!=S[p][j]:M[p][j]=k;Q+=[(p,j)]
   if i>0 and M[q][j]==-1 and s!=S[q][j]:M[q][j]=k;Q+=[(q,j)]
   if r<W and M[i][r]==-1 and s!=S[i][r]:M[i][r]=k;Q+=[(i,r)]
   if j>0 and M[i][t]==-1 and s!=S[i][t]:M[i][t]=k;Q+=[(i,t)]
  k+=1
s={}
d={}
for i in h:
 for j in w:
  m=M[i][j]
  if S[i][j]=='#':s[m]=s.get(m,0)+1
  else:d[m]=d.get(m,0)+1
print(sum(s.get(i,0)*d.get(i,0)for i in range(k)))

Measured memory_bytes: 18024