akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 100010
ll a[N],b[N],n;
int main(){
    cin>>n;
    lol(i,n)cin>>a[i]>>b[i];
    sort(a,a+n); sort(b,b+n);
    ll j=0,cnt=0,ans=0;
    lol(i,n){
	for(;b[j]<a[i];j++)cnt--;
	cnt++;
	ans=max(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4728
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
using namespace std;
typedef long long ll;

int main()
{
	int *t, *x, *y;
	int n;
	cin >> n;
	t = new int [n + 1];
	x = new int [n + 1];
	y = new int [n + 1];
	for (int i = 1; i <= n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}
	for (int i = 0; i < n; i++) {
		int dxy = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		int dt = t[i + 1] - t[i];
		if (dt < dxy || (dxy + dt) % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	delete[] t, x, y;
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(void){
  int n;
  char s[101];
  int max = 0;
  int count = 0;
  scanf("%d%s", &n, s);
  
  for(int i = 0; i < n; i++){
    if(s[i] == 'I') count++;
    else count--;
    
    if(max < count) max = count;
  }
  
  printf("%d\n", max);
  return 0;
}

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

int n;
vector<int> a;

void abc094d() {
  sort(a.begin(), a.end());
  ll ans1 = a[n - 1], ans2, eps = 1e9;
  for (int i = 0; i < n - 1; i++) {
    if (abs(((ans1 + 1) / 2) - a[i]) < eps) {
      eps = abs((ans1 + 1) / 2 - a[i]);
      ans2 = a[i];
    }
  }
  cout << ans1 << ' ' << ans2 << '\n';
  return;
}

int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  abc094d();
  return 0;
}

Measured memory_bytes: 640
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
int main() {
	string S;
	cin >> S;
	int N = S.size();
	reverse(S.begin(), S.end());
	vector<int> pw(N);
	pw[0] = 1;
	for(int i = 1; i < N; ++i) {
		pw[i] = 3LL * pw[i - 1] % mod;
	}
	int ans = 0, cur = 1;
	for(int i = N - 1; i >= 0; --i) {
		if(S[i] == '1') {
			ans = (ans + 1LL * cur * pw[i]) % mod;
			cur = 2LL * cur % mod;
		}
	}
	ans = (ans + cur) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ctoi(x) x-'0'
#define pshb(a) cin >> x;a.push_back(x)
#define fr(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false);
#define Test ll q ; cin>>q ; while (q--)
#define ph push_back
#define f first
#define s second
using namespace std ;
int main ()
{
    string s ;
    cin>>s ;
    bool r =0 ;
    Test
    {
        ll x , y;
        string c ;
        cin>>x ;
        if (x==1)
            r=1-r;
        else
        {
            cin>>y>>c ;
            if (y==1)
            {
                if (r)
                    s.ph(c[0]) ;
                else
                s.insert(0,c) ;
            }
            else
            {
                if (!r)
                s.ph(c[0]) ;
                else
                    s.insert(0,c) ;
            }
        }

    }
    if (r)
        reverse(s.begin() , s.end()) ;
    cout<<s ;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
int n;
int ans;
int gcd(int a,int b)
{
	if(b==0)
	{
		return a;
	}
	return gcd(b,a%b);
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				ans+=gcd(i,gcd(j,k));
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3596
def chmin(a,b):
    if a > b:
        a = b
    else:
        pass
    return a    
N, K = map(int, input().split())    
H = list(map(int, input().split()))

dp = [float("inf") for _ in range(N)]
dp[0] = 0

for i in range(N-1):
    for j in range(1, min(K+1, N-i)):
        dp[i+j] = chmin(dp[i+j], dp[i]+abs(H[i+j]-H[i]))

print(dp[N-1])

Measured memory_bytes: 56928
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int k, s, cnt = 0;
	cin >> k >> s;
	for(int i = 0;i <= k;i++){
		for(int j = 0;j <= k;j++){
			if(s-i-j <= k and s-i-j >= 0) cnt++;
		}
	}
	cout << cnt << endl;
	rtn 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define ll long long
#define MOD 998244353

int n, k, h[100005][5];
ll dp[100005][5];

int main()
{
    memset(dp, 0, sizeof(dp));
    cin>>n;
    for(int i = 1; i <= n; i++)
        for(int j = 0; j < 3; j++)
            cin>>h[i][j];

    for(int i = 1; i <= n; i++)
        for(int j = 0; j < 3; j++)
            for(int k = 0; k < 3; k++)
                if(j!=k)
                    dp[i][j] = max(dp[i][j], h[i][j]+dp[i-1][k]);


    ll ans = max(dp[n][0],max(dp[n][1],dp[n][2]));
    cout<<ans<<endl;

    return 0;
}


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

using namespace std;

#define endl "\n"

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

    int t, w;
    cin >> t >> w;
    vector<int> weight(t);
    vector<int> value(t);

    for (int i = 0; i < t; i++) {
        cin >> weight[i] >> value[i];
    }

    long dp[t + 1][w + 1];
    memset(dp, 0, sizeof dp);

    for (int i = 1; i <= t; i++) {
        for (int j = 1; j <= w; j++) {
            if (j >= weight[i - 1]) {
                dp[i][j] = max(dp[i - 1][j - weight[i - 1]] + value[i - 1], dp[i - 1][j]);
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j]);
            }
        }
    }

    cout << dp[t][w] << endl;

    return 0;
}

Measured memory_bytes: 82524
n,s=open(0)
n=int(n)
a=l=s[0]<'W'>s[-2]
r=f=0
for b,c in zip(s,s[1:-1]):f^=b==c;a=a*(n<1or n)*(l-r)**f%(10**9+7);n-=1;r+=f;l+=f^1
print(a*(l==r))

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

const ll mod = 1e9 + 7;

ll power(ll a, ll b) {
	if (b == 0) {
		return 1;
	}
	ll s = power(a, b / 2);
	s *= s;
	if (b & 1) return (s*a);
	return s;
}

ll a[10];
ll b[10];
ll n;
map<ll,ll> m;
ll ans=1e18;

bool isposs(ll c){
    while(c){
        if(m[c%10]!=0){
            return false;
        }
        c/=10;
    }
    return true;
}

ll find_num(ll s){
    ll answer=0;
    for(ll i=0;i<s;i++){
        answer=answer*10+b[i];
    }
    return answer;
}


void solve(ll i,ll size){
    if(i==size){
        ll num=find_num(size);
        if(num>=n && isposs(num))
            ans=min(ans,num);
        return ;
    }
    for(ll k=i;k<size;k++){
        swap(b[i],b[k]);
        solve(i+1,size);
        swap(b[i],b[k]);
    }
    return;
}

ll Size(ll a){
    ll ans=0;
    while(a){
        ans++;
        a/=10;
    }
    return ans;
}

int main() {

	// ll n;
    cin>>n;
    ll k;
    cin>>k;
    for(ll i=0;i<10;i++){
        b[i]=i;
    }
    for(ll i=0;i<k;i++){
        cin>>a[i];
        m[a[i]]++;
    }
    ans=-1;
    while(ans==-1){
        if(isposs(n)){
            ans=n;
            break;
        }
        n++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
a=list(map(int,input().split()))
px=a[0]
py=a[1]
ans=""
while px!=a[2]:
    ans+="R"
    px+=1
while py!=a[3]:
    ans+="U"
    py+=1
while px!=a[0]:
    ans+="L"
    px-=1
while py!=a[1]:
    ans+="D"
    py-=1
ans+="D"
py-=1
while px!=a[2]+1:
    ans+="R"
    px+=1
while py!=a[3]:
    ans+="U"
    py+=1
ans+="LU"
px-=1
py+=1
while px!=a[0]-1:
    ans+="L"
    px-=1
while py!=a[1]:
    ans+="D"
    py-=1
ans+="R"
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
string s;
long long n,c,s1,s2;
int main(){
	cin>>s;
    for(int i=0;i<s.size();i++)if(s[i]=='B')c++,s1+=i;
    for(int i=s.size()-c;i<s.size();i++)s2+=i;
    cout<<s2-s1<<endl;
	return 0;
} 

Measured memory_bytes: 640
#include<stdio.h>

int main()
{
    int A,B,C,Div;
    1<=A<=100;
    1<=B<=100;
    1<=C<=100;
    scanf("%d %d %d", &A, &B, &C);
    Div = B/A;
    if(Div == 0)
        printf("0\n");
    else if(Div > 0 && Div > C)
        printf("%d\n",C);
    else
        printf("%d\n",Div);

    return 0;
}


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

int n, m;
vector<int> odd, a, b;

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int cur;
        cin >> cur;
        if (cur % 2 == 0) {
            a.push_back(cur);
        } else {
            odd.push_back(cur);
        }
    }

    if (odd.size() > 2) {
        cout << "Impossible\n";
        return 0;
    }
    if (!odd.empty()) {
        a.insert(a.begin(), odd.back());
        odd.pop_back();
    }
    if (!odd.empty()) {
        a.push_back(odd.back());
        odd.pop_back();
    }

    for (int i = 0; i < m; i++) {
        if (i == 0) {
            if (m == 1) {
                b.push_back(1);
                if (a[i] - 1 > 0) {
                    b.push_back(a[i] - 1);
                }
            } else {
                if (a[i] % 2 == 0) {
                    b.push_back(1);
                    b.push_back(a[i]);
                } else {
                    b.push_back(a[i] + 1);
                }
            }
        } else if (i + 1 < m) {
            b.push_back(a[i]);
        } else {
            if (a[i] - 1 > 0) {
                b.push_back(a[i] - 1);
            }
        }
    }

    for (int i = 0; i < m; i++) {
        cout << a[i];
        if (i + 1 < m) {
            cout << ' ';
        }
    }
    cout << '\n' << b.size() << '\n';
    for (int i = 0; i < b.size(); i++) {
        cout << b[i];
        if (i + 1 < b.size()) {
            cout << ' ';
        }
    }
    cout << '\n';

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long x = in.nextLong();
		long y = in.nextLong();
		if (Math.abs(x) == Math.abs(y)) {
			System.out.println(1);
		} else if (x < y) {
			if ((Math.signum(x) == Math.signum(y)) || (x == 0 || y == 0)) {
				System.out.println(y - x);
			} else {
				System.out.println(Math.abs(x + y) + 1);
			}
		} else if (Math.signum(x) == Math.signum(y)) {
			System.out.println(Math.abs(y - x) + 2);
		} else {
			System.out.println(Math.abs(y + x) + 1);
		}
		in.close();
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

/*
4/N = 1/h + 1/n + 1/w
4hnw/N = nw+hw+hn
N = 4hnw/nw+hw+hn

4hnw = w(h+n)N+hnN
w(4hn-hN-nN) = hnN

*/

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

    ll ans[3] = {0};
    rep1(h, 3500)rep1(n, 3500){
        ll r = h*n*N;
        ll l = (4*h*n-h*N-n*N);
        if (l<=0) continue;
        if (r%l == 0){
            ans[0] = h;
            ans[1] = n;
            ans[2] = r/l;            
            break;
        }
    }

    show(ans);
}



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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = InputNumList();
            
            WriteLine(a.Sum() - a.Max());
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}



Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	string s;
	cin>>s;
	if(s[0]=='9'||s[1]=='9')cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

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

  if(s.size()%2!=0){
    ANS("No");
    return 0;
  }

  REP(i,s.size()){
      if(i%2 == 0 && s[i] == 'h'){

      }
      else if(i%2 ==1 && s[i] == 'i'){
      }
      else{
        ANS("No");
        return 0;
      }
  }

  ANS("Yes");
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

// 2020/7/7　ABC172から１週間以上経ったけど再挑戦
public class Main {

	public static int n;
	public static int m;
	public static long k;
	public static long a_sum[];
	public static long b_sum[];

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		n = new Integer(Integer.parseInt(sc.next())); // 机Aの冊数
		m = new Integer(Integer.parseInt(sc.next())); // 机Bの冊数
		k = new Integer(Integer.parseInt(sc.next())); // 読書時間
		long a[] = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = new Integer(Integer.parseInt(sc.next()));
		}
		long b[] = new long[m];
		for (int j = 0; j < m; j++) {
			b[j] = new Integer(Integer.parseInt(sc.next()));
		}

		// 累積和を作る。a_sum[i]は、机Aの本をi冊読んだときにかかる時間
		a_sum = new long[n + 1];
		for (int i = 0; i < n + 1; i++) {
			if (i != 0) {
				a_sum[i] = a_sum[i - 1] + a[i - 1];
			} else {
				a_sum[i] = 0;
			}
			//System.out.print(a_sum[i] + ", ");
		}
		log("");
		b_sum = new long[m + 1];
		for (int j = 0; j < m + 1; j++) {
			if (j != 0) {
				b_sum[j] = b_sum[j - 1] + b[j - 1];
			} else {
				b_sum[j] = 0;
			}
			//System.out.print(b_sum[j] + ", ");
		}
		log("");

		// 机Aをi冊読んだとしたら机Bは何冊読めるか、を全iについて調べる
		int highscore = 0;
		for (int i = 0; i < n + 1; i++) {

			// すでに時間オーバーの場合
			if (k < a_sum[i]) {
				continue;
			}

			int score = check(i);
			if (highscore < score) {
				highscore = score;
			}
		}

		System.out.println(highscore);

	}

	public static int check(int i) {

		// 机A終了時点の残り時間
		long zan = k - a_sum[i];

		log("★机Aを" + i + "冊読んだ。あと" + zan + "分残っている。");

		// 机Bを1冊も読むことができない場合
		if (zan < b_sum[0]) {
			log("⇒机Bを1冊も読むことができない");
			return i;
		}

		// 机Bが1冊だけの場合
		if (m == 0) {
			log("⇒机Bが1冊だけ");
			return i + 1;
		}

		// 机Bを全冊読める場合
		if (b_sum[m] <= zan) {
			log("⇒机Bを全冊読める");
			return i + m;
		}

		// 以下、b_sum[]から探す。普通に探すとΟ(m)かかるけど二分探索ならΟ(logm)で済む。
		// 探すのは「c冊読んだけどもう1冊読むとオーバーする」ようなc。
		int l = 0;
		int r = m;
		int c;

		while (true) {

			// cの目星を付ける。lとrの中間あたりとする。これが二分探索。
			c = l + ((r - l) / 2);

			// 見つけた場合
			if (b_sum[c] <= zan && zan < b_sum[c + 1]) {
				log("⇒机Bは" + c + "冊読める");
				return i + c;
			}

			// まだまだ時間が余っている場合
			if (b_sum[c] < zan) {
				log("　机Bを" + c + "冊読んでも時間がまだ余っている");
				l = c;
			}

			// すでにオーバーしている場合
			if (zan < b_sum[c]) {
				log("　机Bを" + c + "冊読むとオーバーしてしまう");
				r = c;
			}

		}
	}

	public static void log(String str) {
		//System.out.println(str);
	}
}


Measured memory_bytes: 69820
let rec select acc trace = function
  | [] -> acc
  | x :: xs -> select ((trace, x, xs) :: acc) (x :: trace) xs
let select xs = select [] [] xs

(* 与えられたリストからn要素を選ぶ順列 *)
let rec perm : int -> 'a list -> 'a list list = fun n xs ->
  match n, xs with
  | 0, _ -> [[]]
  | _, [] -> []
  | n, xs ->
      List.concat @@
        List.map (fun (xs, x, ys) ->
          List.map (fun xs -> x :: xs) @@
            perm (n - 1) @@ List.rev_append xs ys) @@ select xs;;


let () = Scanf.scanf "%d\n" @@ fun n ->
  let ps = Array.to_list @@ Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun p -> p in
  let qs = Array.to_list @@ Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun q -> q in
  let perms = 
    List.mapi (fun i xs -> (i, xs)) @@
    List.sort compare @@
    perm n @@
    Array.to_list @@
    Array.init n succ in
  Printf.printf "%d\n" @@ abs @@
  fst (List.find (fun (_, xs) -> xs = ps) perms)
  - fst (List.find (fun (_, xs) -> xs = qs) perms)




Measured memory_bytes: 18304
#include <bits/stdc++.h>
 
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
 
using namespace std;

int mai=0;



void bfs(int x, int y, vector<string>s){
	if(s[x][y]=='#') return;

	map<ii,int>ma;

	int i,j,e;
	pair<int,int>aux;


	queue<pair<int,pair<int,int>>>q;
	q.push(make_pair(0,make_pair(x,y)));

	while(q.empty()==false){
		
		i = q.front().second.first;
		j = q.front().second.second;
		e = q.front().first;
		aux = make_pair(i,j);

		if(ma[aux]!=0){
			q.pop();
			continue;
		}

		
		q.pop();

		mai = max(e, mai);
		ma[aux]++;


		if(s[i][j+1]=='.' and ma[make_pair(i,j+1)]==0){
			q.push(make_pair(e+1,make_pair(i,j+1)));
		}


		if(j!=0 and s[i][j-1]=='.' and ma[make_pair(i,j-1)]==0){
			q.push(make_pair(e+1,make_pair(i,j-1)));
		}


		if(s[i+1][j]=='.' and ma[make_pair(i+1,j)]==0){
			q.push(make_pair(e+1,make_pair(i+1,j)));
		}


		if(i!=0 and s[i-1][j]=='.' and ma[make_pair(i-1,j)]==0){
			q.push(make_pair(e+1,make_pair(i-1,j)));
		}

	}

}
 
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n,m;
	string s;
	
	cin >> n >> m;
	vector<string>v(n+1);

	for(int i=0;i<n;i++){
		cin >> v[i];
		v[i].push_back('#');
	}

	for(int j=0;j<m;j++){
		v[n].push_back('#');
	}


	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			bfs(i,j,v);
		}
	}

	cout << mai << endl;

	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
mod=10**9+7
def pow_r(x, n):
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2%mod, n // 2)%mod
    else:  # standard case ② n is odd
        return x * pow_r(x ** 2%mod, (n - 1) // 2)%mod
h,w,t=map(int,input().split())
groups=gcd(h,t)*gcd(w,t)
unit=(h//gcd(h,t),w//gcd(w,t))
cnt=(2**(unit[0])+2**(unit[1])-3)%mod
unitd=gcd(unit[0],unit[1])
cnt+=pow_r(2,unitd)%mod
print(pow_r(cnt,groups))


Measured memory_bytes: 539660
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iterator>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector <int> a(n, -1);
	bool ok = true;
	for (int t = 0; t < m; ++t) {
		int s, c;
		cin >> s >> c;
		if (a[s - 1] != -1 && a[s - 1] != c)
			ok = false;
		else
			a[s - 1] = c;
	}
	bool first = true;
	if (ok && !(a[0] == 0 && n > 1)) {
		for (auto c : a) {
			if (c == -1 && first && n > 1)
				c = 1;
			else if (c == -1)
				c = 0;

			cout << c;
			first = false;
		}
	}
	else
		cout << -1;
	return 0;
}

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

using namespace std;

void rwFile() {
    freopen("INP.inp", "r", stdin);
    freopen("OUT.out", "w", stdout);
}

void solveA() {
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) cout << "Yes";
    else cout << "No";
}

void solveB() {
    int n; cin >> n;
    string s; cin >> s;
    int res = 0;
    for (int i = 0; i + 2 < n; i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') res++;
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    ///rwFile();
    ///solveA();
    solveB();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll x; cin >> x;
    rep(i, 100000) if(i*(i+1)/2 >= x) {
        cout << i << endl;
        return 0;
    }
}

Measured memory_bytes: 3552
#include <iostream>
#include <queue>
#include <vector>
#include <set>
using namespace std;
queue<int> que;
vector<int> G[100010];
bool used[100010];
int ans[100010];
set<int> s[100010];

void bfs(int z){
	que.push(z);
	while(que.size()){
		int x = que.front();
		que.pop();
		if(used[x]) continue;
		used[x] = true;
		for(int v:G[x]){
			s[v].erase(x);
			if(!s[v].size()){
				que.push(v);
				ans[v] = x + 1;
			}
		}
	}
}

int main(){
	int i,n,m,p;
	cin >> n >> m;
	for(i=0;i<m + n - 1;i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		s[b].insert(a);
	}
	for(i=0;i<n;i++){
		used[i] = false;
	}
	for(i=0;i<n;i++){
		if(s[i].size()==0) p = i;
	}
	bfs(p);
	ans[p] = 0;
	for(i=0;i<n;i++){
		cout << ans[i] << endl;
	}
}
	

Measured memory_bytes: 16128
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

struct UnionFind{
private:
    vector<int> par;
    vector<int> rank;
    vector<int> sz;

public:
    //n要素で親を初期化、par[x]はxの親を表す
    UnionFind(int n){
        par.resize(n,0);
        rank.resize(n,0);
        sz.resize(n,1);
        rep(i,n){
            par[i] = i;
        }
    }

    //木の根を求める
    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    //xとyの属する集合を併合
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        else{
            par[y] = x;
            sz[x] += sz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    //xとyが同じ集合に属するか否か
    bool same(int x, int y){
        return root(x) == root(y);
    }

    //xが属する集合のサイズを返す
    int size(int x){
        return sz[root(x)];
    }
};

int main(){
    ll n,m; cin >> n >> m;
    bitset<n_max> lang(0);
    vvl graph(n);

    UnionFind uf(m);

    rep(i,n){
        ll k; cin >> k;
        rep(j,k){
            ll l; cin >> l;
            l--;
            graph[i].emplace_back(l);
            lang[l] = 1;
        }
    }

    rep(i,n){
        rep(j,graph[i].size() - 1){
            uf.unite(graph[i][j], graph[i][j+1]);
        }
    }

    bool ok = true;
    ll par = -1;

    rep(i,m){
        if(lang[i]){
            if(par == -1){
                par = uf.root(i);
                continue;
            }
            if(par != uf.root(i)){
                ok = false;
                break;
            }
        }
    }

    cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 6912
import math
def solve(n, a, b, c, d, e):
    return math.ceil(n / min(a, b, c, d, e)) + 4



if __name__ == "__main__":
    n = int(input())
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())
    print(solve(n, a, b, c, d, e))


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

int main()
{
    string a,b;
    int s=0;
    cin>>a>>b;
    if(a[0]==b[0])
    {
        s++;
    }
    if(a[1]==b[1])
    {
        s++;
    }
    if(a[2]==b[2])
    {
        s++;
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

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

Measured memory_bytes: 256
MOD = 998244353

N, S = map(int, input().split())
A = list(map(int, input().split()))

dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1

p = [[0 for k in range(N + 1)] for j in range(S + 1)]
p[0][0] = 1

for i in range(N):
    for j in range(S + 1):
        dp[i + 1][j] += dp[i][j] * 2
        p[j]
        if j >= A[i]:
            dp[i + 1][j] += dp[i][j - A[i]]
        dp[i + 1][j] %= MOD

print(dp[N][S])

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

int w;
int h;
int ans;
vector <vector<char>> maps;

bool check(int x, int y){
if (0>x || x>=h || 0>y || y>=w){
return false;
}
if (maps[x][y]!='.'){
return false;
}
return true;
}

void bfs(int x, int y){
vector <vector<int>> move = {{1,0},{-1,0},{0,1},{0,-1}};
for (const auto& e: move){
if (check(x+e[0],y+e[1])){
ans+=1;
maps[x+e[0]][y+e[1]]='#';
bfs(x+e[0],y+e[1]);
}
}
}

int main(){
cin >> w >> h;
bool flag = false;
int pos_x;
int pos_y;
while (w!=0 || h!=0){
vector <vector<char>> rawmaps(h,vector<char>(w+1));
ans = 0;
for (int i = 0; i < h; i++){
for (int j = 0; j < w; j++){
cin >> rawmaps[i][j];
if (rawmaps[i][j]=='@'){
pos_x=i;
pos_y=j;
}
}
}
maps = rawmaps;

bfs(pos_x,pos_y);
cout << ans+1 << endl;
cin >> w >> h;
}
}


Measured memory_bytes: 3148
import collections
 
n=int(input())
v=list(map(int,input().split()))
 
even=v[0::2]
odd=v[1::2]
 
even_count=collections.Counter(even).most_common()
odd_count=collections.Counter(odd).most_common()
 
#最多出現のものが重複していない
if even_count[0][0]!=odd_count[0][0]:
    print(n-even_count[0][1]-odd_count[0][1])
    
#最多出現のものが重複
else:
    if len(even_count)==1:
        a=0
    else:
        a=even_count[1][1]
 
    if len(odd_count)==1:
        b=0
    else:
        b=odd_count[1][1]    
    
    ans1=n-a-odd_count[0][1]
    ans2=n-even_count[0][1]-b
    print(min(ans1,ans2))

Measured memory_bytes: 21084
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        int ans = (int)Math.pow(3,N);
        int cnt = 0;
        
        for(int i=0; i<N; i++){
            a[i] = sc.nextInt();
            if(a[i]%2 == 0){
                cnt++;
            }
        }
        //System.out.println(ans+":"+cnt);
        ans -= (int)Math.pow(2,cnt);
        System.out.println(ans);
    }
}

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

using namespace std;

int dp[3111][3111];
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    char s[3111], t[3111];
    memset(dp, 0, sizeof dp);
    scanf("%s", s+1);
    scanf("%s", t+1);
    int lenS = strlen(s+1);
    int lenT = strlen(t+1);
    for (int i = 1; i <= lenS; i++) {
        for (int j = 1; j <= lenT; j++) {
            if (s[i] == t[j]) {
                dp[i][j] = dp[i-1][j-1]+1;
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    stack<char> ans;
    int i = lenS, j = lenT;
    while (dp[i][j]) {
        if (s[i] == t[j]) {
            ans.push(s[i]);
            i--;j--;
        } else if (dp[i][j-1]>dp[i-1][j]) j--;
        else i--;
    }
    if (ans.empty()) cout << "" << endl;
    else {
        while(!ans.empty()) {
            cout<<ans.top();
            ans.pop();
        }
        cout<<endl;
    }
}


Measured memory_bytes: 38144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class _C
{
	void _()
	{
		var A_B_C = _Ns();

		var x = new List<int>();
		x.Add(A_B_C[0]);
		x.Add(A_B_C[1]);
		x.Add(A_B_C[2]);
		x.Sort();
		x.Reverse();

		long a = 0;
		if (
			(x[0]*x[1]*x[2])%2==0
			){
			;
		} else {
			a=(long)x[1] * x[2];
		}
		Console.WriteLine(a);
	}	

	static void Main(string[] args)
  {
    new _C()._();
  }

  #region

  string _S()
  {
    return Console.ReadLine();
  }

  string[] _Ss()
  {
    return Console.ReadLine().Split();
  }

  int[] _N(int n)
  {
    var x = new int[n];
    for (var i = 0; i < n; i++)
    {
      x[i] = int.Parse(Console.ReadLine());
    }
    return x;
  }

  int[] _Ns()
  {
    var ss = Console.ReadLine().Split();

    var x = new int[ss.Length];
    for (var i = 0; i < ss.Length; i++)
      x[i] = int.Parse(ss[i]);

    return x;
  }
  #endregion
}


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

long long int my_Min(long long int x,long long int y){
    if(x <= y){
        return x;
    }else{
        return y;
    }
}

int main(){
    long long int N,A,B;
    cin >> N >> A >>B;
    if((B - A) % 2 == 0){
        cout << (B - A)/2;
    }else{
        cout << (my_Min(A-1, N-B) + ((B-A+1)/2));
    }
}

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

int main(){
  int q;
  int c,a,n;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> c >> a >> n;
    int ans = min(c,min(a,n));
    c -= ans, a -= ans, n -= ans;
    int tmp = min(c/2,a);
    ans += tmp;
    c -= tmp*2, a-=tmp;
    ans += c/3;
    cout << ans << endl;
  }
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    string s;
    ll k;
    cin>>s;
    cin>>k;
    string ans;
    for(auto v:s)
    {
        if(v=='a')
        {
            ans+='a';
            continue;
        }
        //cout<<'z'-v<<endl;
        if('z'-v<k)
        {
            k-=('z'-v+1);
            ans+='a';
            continue;
        }
        ans+=v;
    }
    k%=26;
    ans.back()+=k;
    if(ans.back()>'z')ans.back()-=26;
    cout<<ans<<endl;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n,k;cin >> n >> k;
    int r,s,p;
    cin >> s >> p >> r;
    string e;cin >> e;
    ll sum = 0;
    rep(i,e.size()){
        if(e[i]=='s') sum += s;
        else if(e[i]=='r') sum += r;
        else sum += p;
    }
    //cout << sum << endl;
    int gu=0,choki=0,pa=0;
    rep(i,e.size()){
        if(i+k<e.size() && e[i]==e[i+k]){
            if(e[i]=='s'){choki++; e[i+k] = '#';}
            if(e[i]=='p'){pa++; e[i+k] = '!';}
            if(e[i]=='r'){gu++; e[i+k] = '=';}
        }
    }
    //cout << choki << " " << pa << " " << gu << endl;
    ll mai = choki * s + pa * p + gu * r;
    cout << sum - mai << endl;
}

Measured memory_bytes: 512
//A-can7t wait for holiday
#include <iostream>
#include <string>
using namespace std;

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

   if(S == "SUN") ans=7;
   else if(S == "MON") ans=6;
   else if(S == "TUE") ans=5;
   else if(S == "WED") ans=4;
   else if(S == "THU") ans=3;
   else if(S == "FRI") ans=2;
   else if(S == "SAT") ans=1;

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long int lint;
int main() {
	int X;
	cin >> X;
	int sum = 0;
	for (int ia = 1; ia < 1000000; ia++) {
		if (sum < X) {
			sum += ia;
		}
		else {
			cout << ia-1 << endl;
			break;
		}
	}
}



	


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

namespace Test
{
  public class Program
  {
    public static void Main()
    {
      var n = int.Parse(Console.ReadLine());
      
      if (n == 0)
      {
        Console.WriteLine("0");
        return;
      }
      
      var s = string.Empty;
      
      while (n != 0)
      {
        var quotient = n / (-2);
        var remain = n % (-2);
        if (n < 0)
        {
          remain *= -1;
          quotient += remain;
        }
        
        s = $"{remain}{s}";
        n = quotient;
      }
      Console.WriteLine(s);
    }
  }
}


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

using namespace std;

typedef long long ll;

const ll INF = 1LL << 60;

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

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

int main() {
  int A, B;
  cin >> A >> B;

  int ans = 0;
  int sum = 0;
  
  if (B == 1) {
    cout << ans << endl;
    return 0;
  }
  
  while (true) {
    ans++;
    sum += A;
    
    if (B <= sum) break;
    
    sum--;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(){

	string str;

	while (getline(cin, str)){
		for (int i = 0; i < str.size(); i++){
			if ((str[i] == ' ') || (str[i] == '.')) str[i] = str[i];
			else str[i] = (char)((int)str[i] - 32);
		}
		cout << str << endl;
	}

	return 0;
}

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

fac = [0] * (10**6+5)
ifac = [0] * (10**6+5)
d = 10**9 + 7

def mpow(x, n):
    ans = 1
    while n != 0:
        if n&1:
            ans = ans * x % d
        x = x*x % d
        n = n >> 1
    return ans

def comb(a, b):
    if a == 0 and b == 0:
        return 1
    if a < b or a < 0:
        return 0
    tmp = ifac[a-b] * ifac[b] % d
    return tmp * fac[a] % d

def main():
    global fac, ifac
    x, y = map(int, input().strip().split())
    if (x + y) % 3 != 0:
        print(0)
        return
    k = (x+y) // 3
    q = x - k
    if x - 2 * q < 0 or q < 0:
        print(0)
        return

    fac[0] = 1
    ifac[0] = 1
    for i in range(10**6+1):
        fac[i+1] = fac[i]*(i+1) % d
        ifac[i+1] = ifac[i]*mpow(i+1, d-2) % d

    print(comb(k, q) % d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 58372
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

int main() {
    int N, M;
    cin >> N >> M;

    vector<int> A(M, 0);
    for (int i = 0; i < N; i++) {
        int Ki;
        cin >> Ki;
        for (int j = 0; j < Ki; j++) {
            int Aij;
            cin >> Aij;
            A[Aij - 1]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < M; i++) {
        if (A[i] == N) {
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n,k; ll ar[N],dp[N][N][2];
ll findans(ll l,ll r,ll flg){
	if(l>r) return 0;

	if(dp[l][r][flg]!=-1){
		return dp[l][r][flg];
	}

	if(flg){
		ll a,b;
		a=findans(l+1,r,1-flg)+ar[l];
		b=findans(l,r-1,1-flg)+ar[r];
		return dp[l][r][flg]=max(a,b);
	}
	else{
		ll a,b;
		a=findans(l+1,r,1-flg)-ar[l];
		b=findans(l,r-1,1-flg)-ar[r];
		return dp[l][r][flg]=min(a,b);
	}
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,l,k;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	memset(dp,-1,sizeof(dp));
	ll an=findans(1,n,1);
	cout<<an;
	return 0;
}

Measured memory_bytes: 145000
#include<stdio.h>

int main(void){
  int n;
  scanf("%d",&n);
  int p[n];
  int i;
  for(i=0;i<n;i++){
  	scanf("%d",&p[i]);
  }
  int cout=0;
  for(i=0;i<n-2;i++){
    if(p[i]<p[i+1]){
      if(p[i+1]<=p[i+2]){
      cout+=1;
      }
    }
    if(p[i+2]<p[i+1]){
      if(p[i+1]<=p[i]){
        cout+=1;
      }
    }
    
  }
	printf("%d",cout);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>

using namespace std;

int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  int x[100001];
  for(int i = 0; i < n; i++) {
    cin >> x[i];
  }

  long long min_n = 0;
  for(int i = 0; i < n-1; i++) {
    if((x[i+1] - x[i])*a > b) {
      min_n += b;
    }else {
      min_n += a*(x[i+1] - x[i]);
    }
  }
  cout << min_n << endl;
  return 0;
}


Measured memory_bytes: 640
let base = 1000000007

let rec input n =
    if n <= 0
    then []
    else Scanf.scanf " %d" (fun x -> x :: (input (n - 1)))

let calc a n = List.fold_left (fun x y -> (x + y) mod base) 0 (List.mapi (fun i x -> (x * (n - 1 - 2 * i)) mod base) a)

let () =
    let (n, m) = Scanf.scanf "%d %d" (fun x y -> x, y) in
    let xs = input n in
    let ys = input m in
    let x_combi = calc xs n in
    let y_combi = calc ys m in
    print_int ((x_combi * y_combi) mod base);
    print_newline ();;


Measured memory_bytes: 16512
# encoding:utf-8

import numpy as np
import random


A = int(input())
B = int(input())
C = int(input())
X = int(input())

answer = 0
cash = X

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500+j*100+k*50 == X:
                answer += 1


print(answer)


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

int main(){
   int n, b;
   bool cards[4][14];
   char a;

   for(int i = 0; i < 4; i++){
       for(int j = 0; j < 15; j++){
           cards[i][j] = false;
       }
   }

   cin >> n;
    for(int i = 0; i < n; i++){
       cin >> a >> b;
       if (a == 'S') cards[0][b] = true;
       if (a == 'H') cards[1][b] = true;
       if (a == 'C') cards[2][b] = true;
       if (a == 'D') cards[3][b] = true;
    }

    for(int i = 0; i < 4; i++){
       for(int j = 1; j<= 13; j++){
            if(cards[i][j] == false){
                if( i == 0)   a = 'S';
                if( i == 1)   a = 'H';
                if( i == 2)   a = 'C';
                if( i == 3)   a = 'D';
            cout << a << " " << j << endl;
            }
            else continue;
       }

   }

   return 0;
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

bool check(string s) {
    return s.substr(0,SZ(s)/2)==s.substr(SZ(s)/2,SZ(s)/2);
}
signed main() {
    string s;
    cin>>s;
    for(int i=SZ(s)-2;i>=0;i-=2) {
        if(check(s.substr(0,i))) {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/perl

my ($N,$M) = map { $_ - 0 } split(/\s+/,<STDIN>);

my $r = 0;

if( $N > 1 ){
  $r += ( $N * ( $N - 1 ) ) / 2;
}
if( $M > 1 ){
  $r += ( $M * ( $M - 1 ) ) / 2;
}
print "$r\n";


Measured memory_bytes: 640
#include <iostream>
typedef long long ll;
using namespace std;

int main(void) {
    ll X,K,D;
    cin >> X >> K >> D;
    ll ans;
    X = abs(X);
    if (X / D > K) {
        ans = X - (K * D);
    }else{
        ll e = (X / D);
        K -= e;
        X -= e * D;
        if (K % 2 == 1) X = abs(X - D);
        ans = X;
    }
    cout << ans << endl;;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){/*
	long long x;
	cin >> x;
	char two[33] = {};
	int i, j;
	for (i = 1 ; i <= 32 ; i++)
		two[i] = '0';
	for (i = 1 ; x != 0 ; i++){
		two[i] = two[i] + x % 2;
		x = x / 2;
	}
	char a[33] = {};
	char b[33] = {};
	for (i = 1 ; i <= 16 ; i++)
		a[i] = two[i];
	for (i = 17 ; i <= 32 ; i++)
		b[i - 16] = two[i];
	for (i = 1 ; i <= 32 ; i++)
		cout << a[i];
	for (i = 17 ; i <= 32 ; i++)
		b[i] = a[i - 16];
	strcpy(two, b);
	long long ans = 0;
	for (i = 32 ; i >= 1 ; i--)
		ans += (int(two[i]) - '0') * pow(2, i - 1);
	cout << ans << endl;
	*/
	int n, m;
	int a[101] = {};
	cin >> n >> m;
	int i, j;
	int s = 0;
	for (i = 1 ; i <= n ; i++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	for (i = n ; i >= n - m + 1 ; i--)
		s += a[i];
	cout << s << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

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

    ll N, K, S;
    cin >> N >> K >> S;

    ll dummy;
    if (S == 1000000000) {
        dummy = 1;
    }
    else {
        dummy = 1000000000;
    }

    Vl ans(N);

    for (int i = 0; i < K; ++i) {
        ans[i] = S;
    }
    for (int i = K; i < N; ++i) {
        ans[i] = dummy;
    }

    for (int i = 0; i < N - 1; ++i) {
        cout << ans[i] << " ";
    }
    cout << ans[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;

int main() {
    
    cin.sync_with_stdio(0); cin.tie(0); 
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        int n,k,s;cin>>n>>k>>s;
        int a[n];
        rep(i,k)a[i]=s;
        int l;
        if(s==((1000000000))){
            l=1;
        }
        else{
            l=1000000000;
        }
        repA(i,k,n-1)a[i]=l;
        rep(i,n)cout<<a[i]<<" ";
    }
    return 0;   
}

Measured memory_bytes: 1664
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
c = Counter(s)
m = 0
for v in c.values():
	m = max(m, v)
ans = []
for k, v in c.items():
	if v == m:
		ans.append(k)
ans.sort()
print(*ans, sep="\n")

Measured memory_bytes: 35824
from operator import itemgetter

n, m = map(int, input().split())
arr_a = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for i in range(m)] 

# aをソート
al = sorted(arr_a)

# Ciでソート
l = sorted(e, key=itemgetter(1), reverse=True)

c_arr = []

for i in range(len(l)):
    c_arr.extend( [ l[i][1] ] * l[i][0] )
    
    if len(c_arr) >= n:
        c_arr = c_arr[0:n]
        break

for i in range(len(c_arr)):
    if c_arr[i] > al[i]:
        al[i] = c_arr[i]
    else:
        break

print(sum(al))


    



Measured memory_bytes: 29768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int32_t main(){
    fast_io;
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(k>= s.size()){
        show(s);
    }
    else{
        show(s.substr(0,k) + "...");
    }
    return 0;
}

Measured memory_bytes: 3640
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
a,b = [0],[0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
  
ans = 0
j = M
for i in range(N + 1):
  if(a[i] > K):
    break
  while(a[i] + b[j] > K):
    j -= 1
  ans = max(ans, i+j)
print(ans)

Measured memory_bytes: 47400