akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
   public class Main {
			public static void main(String[] args) {
				Scanner sc = new Scanner(System.in);
				Long H= sc.nextLong();
				Long W = sc.nextLong();
				Long s=H*W;
				if(H==1||W==1) {
					System.out.println(1);
				}else if(H%2==0||W%2==0) {
					System.out.println(s/2);
				}else {
					System.out.println(s/2+1);
				}
			}
   }
		

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define MAXN 500
#define LL long long int

int N, K, A[MAXN + 3], sumA;

bool check(int g) {
    int r[MAXN + 3];
    LL sumNeg[MAXN + 3], sumPos[MAXN + 3];

    for (int i = 1; i <= N; i++)
        r[i] = A[i]%g;

    sort(r + 1, r + N + 1);

    sumNeg[0] = 0;
    for (int i = 1; i <= N; i++) sumNeg[i] = sumNeg[i - 1] + r[i];

    sumPos[N + 1] = 0;
    for (int i = N; i >= 1; i--) sumPos[i] = sumPos[i + 1] + (g - r[i]);

    for (int i = 1; i <= N - 1; i++) {
        if (sumNeg[i] == sumPos[i + 1] && sumNeg[i] <= K)
            return true;
    }

    //Corner case, no need to perform operation
    if (sumNeg[N] == 0)
        return true;

    return false;
}

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

    sumA = 0;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        sumA += A[i];
    }

    int answer = 0;
    for (int g = 1; g * g <= sumA; g++) {
        if (sumA % g == 0) {
            if (check(g)) answer = max(answer, g);
            if (check(sumA/g)) answer = max(answer, sumA/g);
        }
    }

    cout << answer << endl;
}


Measured memory_bytes: 256
import java.util.*;

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

        String w = sc.nextLine();//キーワード
        String t;
        String str = "";
        String end ="END_OF_TEXT";
        String check ="";
        
        int i;
        int j;
        int count=0;
        
//        ArrayList<String> strArray = new ArrayList<String>();
 //       int last =array.indexOf(end)
 //       int empty =array.indexOf();
        while(sc.hasNextLine()){
            t = sc.nextLine();
 //           strArray.add(sc.next());
//            String[] strArrayArray = sc.next();
            if(end.equals(t)){
                break;
            }else{
            str = str + " " +t;
            }
        }
//  System.out.print("&" + str);
  
 //       strArray.add() = str.split(" ");
        String[] strArray = str.split(" ");
//while(empty != -1);
//        for(i = 0; i < strArray.size(); i++){
        //System.out.println("&" + strArray.length);
        for(i = 0; i < strArray.length; i++){
//                 System.out.println("#"+strArray[i]);
            if(w.equalsIgnoreCase(strArray[i])){   
 //                System.out.println("@"+strArray[i]);
//                for(j=0; j < w.length(); j++){
//                    check += strArray[i+j];
//                        System.out.println(check);
//                    }if(w.equalsIgnoreCase(check)){
                        count++;
//                        i+=w.length()-1;
 //                            System.out.println("@"+check);
                    }
//                    check = "";
        }System.out.println(count);
    }
}






Measured memory_bytes: 26256
import java.util.*;
public class Main {
    static class Store implements Comparable<Store>
    {
        long cans,price;
        Store(long cans,long price){
            this.cans =  cans;
            this.price = price;
        }
        public int compareTo(Store s){
            if(s.price < this.price)return 1;
            if(s.price > this.price) return -1;
            return 0;
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long M = sc.nextInt();
        ArrayList<Store> stores = new ArrayList<>();
        for(int i = 0 ; i < N ; i++){
            long cost = sc.nextLong();
            long cans = sc.nextLong();
            Store newStore = new Store(cans,cost);
            stores.add(newStore);
        }
        Collections.sort(stores);
        long sum = 0;
        long taken = 0;
        for(int i = 0 ; i < stores.size() ; i++){
            long count = Math.min(M-taken,stores.get(i).cans);
            sum += count * stores.get(i).price;
            taken += count;
            if(taken >= M){
                break;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 67560
import sys,queue
INF = 10**20
def LI(): return [int(x) for x in sys.stdin.readline().split()]

V,E,r = LI()
dist = [[] for _ in range(V)]
for _ in range(E):
    a,b,d = LI()
    dist[a].append((b,d))

short = [INF for _ in range(V)]
short[r] = 0
q = queue.PriorityQueue()

q.put((0,r))
while not q.empty():
    dt,n = q.get()
    if dt > short[n]:
        continue
    for p,d in dist[n]:
        if short[n] + d < short[p]:
            short[p] = short[n] + d
            q.put((short[p],p))
for i in short:
    print (i if i < INF else 'INF')




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

int N, K, a[100100], dp[100100];

int f(int n) {
	if (n==1) return 0;
	if (n==2) return abs(a[2] - a[1]);
	if (dp[n] != -1) return dp[n];
	dp[n] = 2e9;
	for(int i=1; i<=K; i++)
		if (n-i>0)
			dp[n] = min(dp[n], f(n-i) + abs(a[n] - a[n-i]));
				
	return dp[n];
}

int main() {
	cin >> N >> K;
	for(int i=1; i<=N; i++)
		cin >> a[i];
	memset(dp, -1, sizeof(dp));
	cout << f(N) << endl;
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>

using namespace std;

static const int maxsize = 1000000;
struct card {
	char mark;
	int number;
	bool operator==(const card& a) {
		if (a.mark == this->mark && a.number == this->number)
			return true;
		else
			return false;
	}
};

void showSeq(int a[],int n) {
	for (int i = 0; i < n; i++) {
		if (i > 0)cout << " ";
		cout << a[i];
	}
	cout << endl;
}

int insertionSort(int a[], int n, int g) {
	// 针对元素个数为n的数组a，以间隔g进行插入排序
	// 例：a=[3,8,5,2,7,9,1,4],g=2, 则分为[3，5，7，1]，[8,2,9,4] 两组分别进行插入排序
	int cnt = 0;
	for (int i = g; i < n; i++) {
		int v = a[i]; // 待插入的值
		int j = i - g; // 同组的前一个元素 例i=2，属于第1组，前一个元素为3,下标为0
		while (j >= 0 && a[j] > v) {
			swap(a[j], a[j + g]);
			j = j - g;
			cnt++;
		}
		a[j + g] = v;
	}
	return cnt;
}

void shellSort(int a[], int n,int &cnt, int &m,int G[]) {
	int n1 = n;
	n1 = n;
	int i = 0;
	while(n1/3>0) {
		G[i] = n1 / 3 + 1;
		n1 = n1 / 3 + 1;
		m++;
		i++;
	}
	G[i] = 1;
	for (int j = 0; j < m; j++) {
		cnt+=insertionSort(a, n, G[j]);
	}
}

int main()
{
	int n;
    int a[maxsize];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i]; 
	}
	int cnt = 0, m = 1;
	int G[100];
	shellSort(a, n,cnt,m,G);

	cout << m << endl;
	showSeq(G, m);
	cout << cnt << endl;
	for (int i = 0; i < n; i++) {
		cout << a[i] << endl;
	}
	


    return 0;
}


Measured memory_bytes: 7004
[n,m] = [int(i) for i in input().split()]
dic_AC = {}
dic_WA = {}
for i in range(1,n+1):
    dic_AC[i] = 0
    dic_WA[i] = 0

for i in range(m):
    [p,s] = [j for j in input().split()]
    if s == "AC":
        dic_AC[int(p)] = 1
    else:
        if dic_AC[int(p)] == 0:
            dic_WA[int(p)] += 1
ans_1 = sum(dic_AC.values())
ans_2 = 0
for i in range(1,n+1):
    if dic_AC[i] == 1:
        ans_2 += dic_WA[i]
print(ans_1,ans_2)


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\01.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;


int main() {

    ll n, m;
    cin >> n >> m;

    ll b = m / n;
    ll max = sqrt(m) + 1;

    vector<ll> facs;
    for (ll i = max; i >= 1; i--) {
        if (m % i == 0) {
            facs.push_back(i);
            facs.push_back(m / i);
        }
    }

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

    ll ans = *(--upper_bound(facs.begin(), facs.end(), b));

    cout << ans << endl;


}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
bool used[400][400];
char mp[400][400];
int h, w;
char t[2] = { '#','.' };
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int main() {
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> mp[i][j];
		}
	}
	ll ans = 0;
	rep(i, h) {
		rep(j, w) {
			if (used[i][j])continue;
			if (mp[i][j] == '.')continue;
			queue<P> q; used[i][j] = true; q.push({ i,j });
			int cur = 0; int cw = 0, cb = 0;
			while (!q.empty()) {
				int len = q.size();
				if (cur % 2 == 0)cb += len;
				else cw += len;
				cur ^= 1;
				rep(aa,len){
					P p = q.front(); q.pop();
					rep(k, 4) {
						int nx = p.first + dx[k];
						int ny = p.second + dy[k];
						if (nx < 0 || ny < 0 || nx >= h || ny >= w)continue;
						if (used[nx][ny])continue;
						if (mp[nx][ny] != t[cur])continue;
						q.push({ nx,ny }); used[nx][ny] = true;
					}
				}
			}
			ans += (ll)cw*cb;
		}
	}
	cout << ans << endl;
	//stop
		return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

void paint(vector< vector<int> > &white, int sx, int sy, int x, int y) {
	for(int i = sx; i < x; ++i) {
		for(int j = sy; j < y; ++j) {
			white[i][j] = 0;
		}
	}
}

int main(void) {
	int w, h, n;
	cin >> w >> h >> n;
	
	vector< vector<int> > white(w, vector<int>(h, 1));
	
	for(int i = 0; i < n; ++i) {
		int x, y, a;
		cin >> x >> y >> a;
	
		if( a == 1 ) paint(white, 0, 0, x, h);
		if( a == 2 ) paint(white, x, 0, w, h);
		if( a == 3 ) paint(white, 0, 0, w, y);
		if( a == 4 ) paint(white, 0, y, w, h);
	}
	
	int ans = 0;
	for(int i = 0; i < w; ++i) {
		for(int j = 0; j < h; ++j) {
			if( white[i][j] == 1 ) ans++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
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 int INF = 1<<29;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int main(){
    string s;
    cin >> s;
    int k, n = s.size();
    cin >> k;
    ll dp[110][2][110] = {0};
    dp[0][0][0] = 1;
    for(int i = 0; i < n; i++){
        int D = s[i] - '0';
        for(int j = 0; j < 2; j++){
            for(int x = 0; x < 110; x++){
                for(int d = 0; d <= (j ? 9 : D); d++){
                    dp[i+1][j || d < D][x + (d == 0)] += dp[i][j][x];
                }
            }
        }
    }
    cout << dp[n][0][n-k] + dp[n][1][n-k] << endl;
    return 0;
}


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

class MainClass
{
    static void Main()
    {
        var r = ReadLine().Split();
        var N = int.Parse(r[0]);
        var K = long.Parse(r[1]);//X

        var all = new long[N];all[0] = 1;
        var patty = new long[N];patty[0] = 1;
        for (int i = 0; i < N-1; i++)
        {
            all[i + 1] = all[i] * 2 + 3;
            patty[i + 1] = patty[i] * 2 + 1;
        }

        int now = N-1;
        long ans = 0;
        while (now > 0)
        {
            if (K >= all[now] + 2)
            {
                K -= all[now] + 2;
                ans += patty[now]+1;
            }
            else if (K == all[now] + 1)
            {
                K = 0;
                ans += patty[now];
            }
            else
            {
                K--;
            }
            now--;
        }
        //WriteLine(K);
        if (now == 0&&K>0)
        {
            K = Min(K, 5);
            var s = "BPPPB".Substring(0, (int)K);
            if (s.Length > 0)
                ans += s.Count(_ => _ == 'P');
        }
        WriteLine(ans);
    }
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int a , b , c , d;

int main()
{
    _FastIO;
    cin >> a >> b >> c >> d;
    int x = 0;
    while(a > 0 && c > 0){
        if(x % 2)
            a -= d;
        else
            c -= b;
        x++;
    }
    if(a < 1){
        cout << "No" << endl;
    }
    else
        cout << "Yes" << endl;
    return 0;
}


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

int main(){

    int a,b,W;
    cin >> W >> a >> b;

    if(fabs(b - a) <=  W){
        cout << '0' << endl;
        return 0;
    }

    int left = fabs(b-(a+W));
    int right = fabs(a-(b+W));

    if(left <= right)cout << left << endl;
    else cout << right << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

vector<vector<int>> graph;

ll dfs(int K, int now, int from){
    int color;

    if(from==-1){
        color=K-1;
    }else{
        color=K-2;
    }
    if(K<graph[now].size()){
        return 0;
    }else{
        ll case_num=1;
        for(auto e : graph[now]){
            if(e==from){
                continue;
            }
            case_num *= color;
            color--;
            case_num%=mod;
        }
        for(auto e : graph[now]){
            if(e==from){
                continue;
            }
            case_num*=dfs(K, e, now);
            case_num%=mod;
        }
        return case_num;
    }
}

int main(){
    int N, K;
    cin >> N >> K;
    graph.resize(N);
    for(int i=0; i<N-1; i++){
        int a,b;
        cin >> a >> b;
        a--,b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    ll ans = K*dfs(K,0,-1);
    ans%=mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define mk make_pair
#define endl '\n'

#define PI 3.14159265358979323846264338327950L

double calcAngle(int h, int m)  
{
    double hour_angle = (h * 30 + 0.5*m);  
    double minute_angle = 6 * m;
    double angle = abs(hour_angle - minute_angle);
    angle = min(360 - angle, angle);
    return angle;  
}  
int main()
{
    IOS;
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double ans=0;
    double ang=calcAngle(h,m);
    double anr = cos ( ang * PI / 180.0 );
    ans+=(double)a*a + (double)b*b -(double)a*2*b*anr;
    ans=sqrt(ans);
    cout<<setprecision(13)<<ans; 
}

Measured memory_bytes: 4136
using System;
using System.Linq;

namespace ABC078
{
    public class Problem_A
    {
      public static void Main(string[] args)
      {
        var inputs = Console.ReadLine().Split().Select(s => s[0]).ToArray();
        var ans = inputs[0] == inputs[1] ? "=" : inputs[0] < inputs[1] ? "<" : ">";
        Console.WriteLine(ans);
      }
    }
}


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

int main(void){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  ll ans = 1000000007;
  rep(i,100001) {
    ll cost = 2 * c * i + max(x-i,0) * a + max(y-i,0) * b;
    ans = min(ans,cost);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main(void){
   int a,b,c,d,e,f,g,h;
   cin >>a >> b >> c >> d;
   cin >>e >>f>>g>>h;
    
   if ((a+b+c+d)>(e+f+g+h)) cout << a+b+c+d <<endl;
   else if ((a+b+c+d)<(e+f+g+h)) cout << e+f+g+h <<endl;
   else cout << a+b+c+d <<endl;
    
    
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>

using namespace std;

int N;
long long int M;
long long int MOD = 1000000007;

long long int POW(long long int a, int p) {
	if (p == 0) { return 1; }
	if (p % 2 == 0) {
		long long int tmp=POW(a, p / 2);
		return tmp*tmp%MOD;
	}
	else {
		return a*POW(a, p - 1) % MOD;
	}
}

long long int INV(long long int k) {

	return POW(k, MOD - 2);
}

long long int C(int n, int m) {

	long long int U=1, D=1;

	for (int i = 0; i < m; i++) {
		U *= (n - i); U %= MOD;
		D *= (m - i); D %= MOD;
	}
	return U*INV(D) % MOD;
}

int main(void) {

	cin >> N >> M;

	long long int ans = 1;
	long long int tmp = M;
	for (int i = 2; i*i <= M; i++) {
		int cnt = 0;
		while (tmp%i == 0) { tmp /= i; cnt++; }
		//cout << "cnt= " << cnt << endl;
		ans *= C(N + cnt - 1, cnt);
		ans %= MOD;
      }

	if (tmp > 1) { ans *= N;  ans %= MOD; }

	/*for (int i = 1; i <= 3; i++) {
		for (int j = 1; j <= i; j++) {
			cout << "C[" << i << "][" << j << "]= " << C(i,j) << endl;
		}
	}*/

	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string taro, hana;
  int n, taro_re, hana_re;
  taro_re = hana_re = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> taro >> hana;
    if (taro == hana) {
      taro_re++;
      hana_re++;
    } else if (taro > hana) {
      taro_re += 3;
    } else if (taro < hana) {
      hana_re += 3;
    }
  }
  cout << taro_re << " " << hana_re << endl;
}


Measured memory_bytes: 3140
#include <iostream>

using namespace std;

typedef long long ll;

ll modulo = 1e9+7;

ll fact(ll n){
  ll ans = 1;
  for(int i = 1;i <= n;i++){
    ans = (ans * i) % modulo;
  }
  return ans;
}

ll logpow(ll ans, ll pow, ll rest){
  if(pow == 1){
    return (ans * rest) % modulo;
  }else if(pow % 2 == 0){
    return logpow((ans * ans) % modulo, pow / 2, rest);
  }else{
    return logpow((ans * ans) % modulo, (pow - 1) / 2, (rest * ans) % modulo);
  }
}

ll getj(ll n, ll m, ll i) {
  ll dn = n - i;
  ll dm = 2 * i - m;
  if(dn == dm && 0 <= dn && dn <= i) {
    return dn;
  } else {
    return -1;
  }
}



int main()
{
  ll n, m, i, j, facti, factj, factij;
  cin >> n >> m;
  if((n + m) % 3 == 0){
    i = (n + m) / 3;
    j = getj(n, m, i);
    if(j == -1){
      cout << 0;
      return 0;
    }
    facti = fact(i);
    factj = fact(j);
    factij = fact(i - j);
    cout << (facti * logpow((factj * factij % modulo), modulo - 2, 1)) % modulo;
  }else{
    cout << 0;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string w[n];
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>w[i];
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(w[i]==w[j]){ans++;}
        }
    }
    for(int i=0;i<n-1;i++){
        string s=w[i];
        string t=w[i+1];
        int word=s.size();
        if(s[word-1]!=t[0]){ans++;}
    }
    if(ans!=0){puts("No");}
    else{puts("Yes");}
    return 0;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  int p;cin>>p;
  bool isAllEven = true;
  rep(i,n){
    int a;cin>>a;
    if(a%2)isAllEven = false;
  }
  if(isAllEven){
    if(!p)print(1ll<<n);
    else print(0);
  } else print(1ll<<(n-1));
  return 0;
}



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

struct Node {
	long double l, r; long long a, b;
};
bool operator<(const Node &a1, const Node &a2) {
	if (a1.l < a2.l) return true;
	return false;
}

class ConvexHullTrick {
public:
	vector<Node> U;
	void init() {
		U.push_back(Node{ -1e9, 1e9, 0, (1LL << 43) });
	}
	long double cross_point(Node E, Node F) {
		if (E.a > F.a) swap(E, F);
		long double D1 = 2.0L * (F.a - E.a);
		long double D2 = F.b - (E.b + (F.a - E.a) * (F.a - E.a));
		return 1.0L * F.a + 1.0L * D2 / D1;
	}
	void add(long long a, long long b) {
		while (U.size() >= 1) {
			Node E = U[U.size() - 1];
			long double T = cross_point(E, Node{ -1e9, 1e9, a, b });

			if (T < E.l) {
				U.pop_back();
			}
			else {
				U[U.size() - 1].r = T;
				U.push_back(Node{ T, 1e9, a, b });
				break;
			}
		}
		if (U.size() == 0) {
			U.push_back(Node{ -1e9, 1e9, a, b });
		}
	}
	long long query(long long T) {
		Node BASE = Node{ 1.0L * T, 1.0L * T, 0LL, 0LL };
		int pos1 = lower_bound(U.begin(), U.end(), BASE) - U.begin();
		pos1--;
		return U[pos1].b + (T - U[pos1].a) * (T - U[pos1].a);
	}
};

long long N, C, H[1 << 18], dp[1 << 18];
ConvexHullTrick X;

int main() {
	cin >> N >> C;
	for (int i = 1; i <= N; i++) cin >> H[i];
	X.add(H[1], 0); dp[1] = 0;
	for (int i = 2; i <= N; i++) {
		dp[i] = X.query(H[i]) + C;
		X.add(H[i], dp[i]);
	}
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 17516
"""
1. スタート地点の座標を取得
2. スタート地点からbfsをして到達可能な”.”の数を数える
"""

from collections import deque

def bfs(h, w, f, s):
    count = 1
    q = deque()
    q.append(s)

    move = ((0, 1), (0, -1), (1, 0), (-1, 0))

    while q:
        i, j = q.popleft()

        for di, dj in move:
            ni , nj = i + di, j + dj
            if 0 <= ni < w and 0 <= nj < h and f[ni][nj] == ".":
                count += 1
                q.append((ni, nj))
                f[ni][nj] = "#"

    return count

def search_atmark(h, w, f):
    for i in range(h):
        for j in range(w):
            if f[i][j] == "@":
                return (i, j)

def solve(h, w, f):
    s = search_atmark(w, h, f)
    return bfs(h, w, f, s)

if __name__ == '__main__':
    while(True):
        w, h = map(int, input().split())
        if w == 0 and h == 0:
            break

        f = [list(input()) for i in range(h)]
        print(solve(w, h, f))



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

typedef long long LL;

const int N=524288,mod=200003;
const double pi=acos(-1);

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

struct comp{
  double x,y;
  comp(double X=0,double Y=0){x=X;y=Y;}
  comp operator + (const comp &p)const{return comp(x+p.x,y+p.y);}
  comp operator - (const comp &p)const{return comp(x-p.x,y-p.y);}
  comp operator * (const comp &p)const{return comp(x*p.x-y*p.y,x*p.y+y*p.x);}
  comp operator * (const double &p)const{return comp(x*p,y*p);}
  comp operator / (const double &p)const{return comp(x/p,y/p);}
};

comp wn[2][N+9];

void Get_wn(){
  for (int i=0;i<N;++i){
	wn[0][i]=comp(cos(2*i*pi/N),sin(2*i*pi/N));
	wn[1][i]=comp(cos(2*i*pi/N),-sin(2*i*pi/N));
  }
}

int len,rev[N+9];

void Get_len(int n){
  int l=0;
  for (len=1;len<=n;len<<=1) ++l;
  for (int i=0;i<len;++i) rev[i]=rev[i>>1]>>1|(i&1)<<l-1;
}

comp pw[N+9];

void FFT(comp *a,int n,int t){
  for (int i=0;i<n;++i)
	if (i<rev[i]) swap(a[i],a[rev[i]]);
  for (int i=1;i<n;i<<=1){
	int tl=N/(i<<1);
	for (int j=0;j<i;++j) pw[j]=wn[t][j*tl];
	for (int j=0;j<n;j+=i<<1)
	  for (int k=0;k<i;++k){
		comp x=a[j+k],y=pw[k]*a[i+j+k];
		a[j+k]=x+y;a[i+j+k]=x-y;
	  }
  }
  if (!t) return;
  for (int i=0;i<n;++i) a[i]=a[i]/n;
}

int n,a[N+9];
int pw2[N+9],cnt[N+9];

void Get_pw2(){
  pw2[0]=1;
  for (int i=1;i<mod<<1;++i) pw2[i]=mul(pw2[i-1],2);
  for (int i=0;i<mod-1;++i){
	cnt[i]=a[pw2[i]];
	//if (cnt[i]) printf("%d : %d\n",i,cnt[i]);
  }
}

comp tc[N+9];
LL c[N+9];
LL ans;

void Get_ans(){
  Get_len(mod<<1);
  /*for (int i=0;i<mod;++i)
	if (cnt[i]){
	  for (int j=0;j<mod;++j) c[i+j]+=1LL*cnt[i]*cnt[j];
	}
  //for (int i=0;i<mod<<1;++i) if (c[i]) printf("%d :  %lld\n",i,c[i]);
  */
  for (int i=0;i<mod;++i) tc[i]=comp(1.0*cnt[i],0);
  FFT(tc,len,0);
  for (int i=0;i<len;++i) tc[i]=tc[i]*tc[i];
  FFT(tc,len,1);
  for (int i=0;i<len;++i) c[i]=(LL)(tc[i].x+0.5);
  for (int i=0;i<mod;++i) c[i<<1]-=cnt[i];
  for (int i=0;i<mod<<1;++i){
	c[i]>>=1;
	ans+=c[i]*pw2[i];
  }
}

void work(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i){
	int x;
	scanf("%d",&x);
	if (x) ++a[x];
  }
  Get_wn();
  Get_pw2();
  Get_ans();
  printf("%lld\n",ans);
}

int main(){
  int T=1;
  //scanf("%d",&T);
  for (;T--;) work();
  return 0;
}

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

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


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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

const int MAXN = 1e5+1;
const ll oo = 2e18;

int gains[MAXN][3];
int dp[MAXN][3];

void solve() {
	int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> gains[i][0] >> gains[i][1] >> gains[i][2];
    }

    dp[0][0] = dp[0][1] = dp[0][2] = 0;

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

    cout << max(dp[n][0], max(dp[n][1],dp[n][2])) << '\n';
}

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
		FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
		clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
		fclose(FIN);
		cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
using namespace std;

const int mxN = 1e5+1;
int dp[mxN], h[mxN];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    // dp[i] == min cost to reach a point i from upto k last steps
    int n, k;
    cin >> n >> k;
    
    for(int i = 0; i < n; i++)
        cin >> h[i];
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 1; j <= k; j++) {
            if(i+j == n) break;
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout << dp[n-1] << '\n';
}


Measured memory_bytes: 4428
#include<stdio.h>

int main (void){

  int w,c,s; 
 
  for(;;){
  scanf("%d",&w);
  if(w>30){
    c = 1150 + 10*125 + 10*140 + (w-30)*160;
    }
  else if(w>20){
    c = 1150 + 10*125 + (w-20)*140;
    }
  else if(w>10){
    c = 1150 +(w-10)*125;
    }
  else if(w>=0){
    c = 1150;
    }
  if(w==-1)break;
  
  s = 4280 - c;
  
  printf("%d\n",s);
  }
return 0;
}

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

int main(){
int a,total = 0,mini = 0,sec = 0;
  for(int i = 1;i <= 4;i++){
    cin >> a;
  total = total + a;
  }
  mini = total / 60;
  sec = total % 60;
  cout << mini << endl;
  cout << sec << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;

int main(){
    double W, H, x, y;
    double cx, cy;
    int flag = 0;
    cin >> W >> H >> x >> y;

    cx = W / 2.0;
    cy = H / 2.0;

    if(cx == double(x) && cy == double(y)){
        flag = 1;
    }

    cout << W*H/2 << " " << flag << endl;
}


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

using namespace std;

#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define LL long long
#define ULL unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<LL,int>
#define PLL pair<LL,LL>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<LL,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};






int main()
{
    FAST();
    LL i,n,a[85],ans=1000,cnt=0,cur=1000;
    bool buy[85],sell[85];
    cin >> n;
    for(i=1;i<=n;i++)cin >> a[i],buy[i]=sell[i]=true;
    for(i=1;i<n;i++)
    {
        if(a[i] >= a[i+1])buy[i]=sell[i+1]=false;
        else buy[i+1]=sell[i]=false;
    }
    for(i=1;i<=n;i++)
    {
        if(buy[i])cnt=cur/a[i],cur%=a[i];
        else if(sell[i])cur+=cnt*a[i],cnt=0,ans=max(ans,cur);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3548
A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K=int(input())

print(A[K-1])

Measured memory_bytes: 3060
import itertools
N, M = map(int, input().split())

G = {k: set() for k in range(N+1)}
for _ in range(M):
    a, b = map(int, input().split())
    # 無向グラフ
    G[a].add(b)
    G[b].add(a)

ans = 0
for p in itertools.permutations(range(2, N+1)):
    c = 1
    for n in p:
        if n not in G[c]:
            break
        c = n
    else:
        ans += 1

print(ans)


Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Linq;

public class MainApp
{
    static public void Main(string[] args)
    {
        int[] x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        if ((x[1] * 10 + x[2]) % 4 == 0) Console.WriteLine("YES");
        else Console.WriteLine("NO");

    }


}

Measured memory_bytes: 13396
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD=1e9+7;
inline int add(int a,int b)
{a+=b;return a>=MOD?a-MOD:a;}
inline void Add(int &a,int b)
{a+=b;a>=MOD?a-=MOD:1;}
inline int mul(int a,int b)
{return 1LL*a*b%MOD;}
inline void Mul(int &a,int b)
{a=1LL*a*b%MOD;}
int ksm(int a,int b)
{
	int ans=1;
	for(;b;b>>=1,Mul(a,a))
		if(b&1)Mul(ans,a);
	return ans;
}
const int Q=5555;
vector<int> g[Q];
int rt,ct=0,n;
int si[Q];
void dfs(int x,int last)
{
	int mx=0;
	si[x]=1;
	for(int y :g[x]){
		if(y==last)continue;
		dfs(y,x);
		si[x]+=si[y];
		mx=max(mx,si[y]);
	}
	mx=max(mx,n-si[x]);
	if((mx<<1)<=n)++ct,rt=x;
}
int f[Q];
int fac[Q],ifac[Q];
inline int C(int n,int m)
{return mul(fac[n],mul(ifac[m],ifac[n-m]));}
inline int P2(int x)
{return mul(x,x);}
int main()
{
	scanf("%d",&n);
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],MOD-2);
	for(int i=n;i;--i)
		ifac[i-1]=mul(ifac[i],i);
	for(int i=1,x,y;i<n;i++)
		scanf("%d%d",&x,&y),g[x].push_back(y),g[y].push_back(x);
	dfs(1,0);
	if(ct>1)return 0&printf("%d\n",mul(fac[n/2],fac[n/2]));
	dfs(rt,0);
	int maxn=0;
	f[0]=1;
	for(int y:g[rt]){
		int val=si[y];
		maxn+=val; 
		for(int j=maxn;j;--j)
			for(int k=min(j,val);k;--k)
				Add(f[j],mul(f[j-k],mul(P2(C(val,k)),fac[k])));
	}
	int als=0;
	for(int i=0,ty=1;i<=n;i++,ty=MOD-ty)
		Add(als,mul(ty,mul(f[i],fac[n-i])));
	printf("%d\n",als);
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
 int h, m, s;
 scanf("%d", &s);
 m = s / 60;
 s = s - m * 60;
 h = m / 60;
 m = m - h * 60;
 printf("%d:%d:%d\n", h, m, s);
 return 0;
}

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

#define  ll   long long
#define  pb  push_back
#define  mp  make_pair
#define  MAX  500006
#define  MAX1  10000008
#define  mem(a,v)   memset(a,v,sizeof(a))

template <typename T>
T mymax (T a,T b){return (a>b)?a:b;}
template <typename T>
T mymin (T a,T b){return (a<b)?a:b;}
template <typename T>
T myabs (T a){return (a<0)?(-1*a):a;}
template <typename T>
T mysqrt (T x){if (x == 0 | x == 1)return x;int start = 1, End = x, ans;while (start <= End){int mid = (start + End) / 2;if (mid*mid == x)return mid;if (mid*mid < x){start = mid + 1;ans = mid;}else End = mid-1;}return ans;}

void fastIO (){ios_base::sync_with_stdio(false);cin.tie(0); cout.precision(20);}

ll A[MAX];
ll B[MAX];
ll C[MAX];
vector< ll >V;
vector< ll >Ans;
vector< pair<ll,ll> >VP;
map< ll,ll >M;
vector<ll>prime;
bool mark[MAX1];
ll N=1e7;
void seive (){int limit = sqrt(N*1.0)+2;mark[1]=1;for (int i=4;i<=N;i+=2)mark[i]=1;prime.push_back(2);for (int i=3;i<=N;i+=2){if(!mark[i]){prime.push_back(i);if(i<=limit){for (int j=i*i;j<=N;j+=i*2)mark[j]=1;}}}}

int main ()
{
    fastIO();
    ll a,b,c,n,m,k,p,q,r;
    ll cnt=0,cntr=0,sum=0,ans=1,check=0;
    float x,y,z;
    ll Max= 0,Max1=-1e18+1;
    ll Min = 1e18;
    string s,s1,s3,s4;

    cin>>n>>m;
    
    if(n==1||m==1){
        cout<<1<<endl;return 0;
    }

    ans=n*m;
    ans/=2;
    if(n%2&&m%2)ans++;
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
const int N=200005;
int n,a[N],dp[N],ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)dp[a[i]]=dp[a[i]-1]+1;
	for(int i=1;i<=n;i++)ans=max(ans,dp[i]);
	cout<<n-ans<<endl;
}


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

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int r=sc.nextInt();
		if(n>=10) {
			System.out.println(r);
		}else {
			System.out.println((r+100*(10-n)));
		}

	}

}


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

using namespace std;

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

    int G = __gcd(A, B);

    int divisor_count = 0, k_th_divisor;
    for(int i = G; i >= 1 && divisor_count < K; i--)
    {
        if(G%i == 0)
        {
            divisor_count++;

            if(divisor_count == K)
                k_th_divisor = i;
        }
    }

    cout << k_th_divisor;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=2e5;
const int inf=1e9;
int main(){
	long N,K;cin>>N>>K;
	long ans = 0; long a,b;
	for(long i = K; i < N+2; i++){
		a = i * (i - 1) / 2;
		b = N * (N+1) / 2 - (N-i) * (N-i+1) / 2;
        (ans += b - a + 1) %= mod;
	}cout<<ans<<endl;
}

Measured memory_bytes: 3632
def main():
    n, ma, mb = map(int, input().split())
    arr = [list(map(int, input().split())) for _ in range(n)]
    dp = [{} for _ in range(n+1)]
    dp[0][(0, 0)] = 0
    for i in range(n):
        for ky in dp[i].keys():
            if ky in dp[i+1]:
                if dp[i+1][ky] > dp[i][ky]:
                    dp[i+1][ky] = dp[i][ky]
            else:
                dp[i+1][ky] = dp[i][ky]
            t = (ky[0]+arr[i][0], ky[1]+arr[i][1])
            if t in dp[i+1]:
                if dp[i+1][t] > dp[i][ky]+arr[i][2]:
                    dp[i+1][t] = dp[i][ky]+arr[i][2]
            else:
                dp[i+1][t] = dp[i][ky]+arr[i][2]
    ans = float("inf")
    for i in range(1, 41):
        t = (ma*i, mb*i)
        if t in dp[n]:
            if ans > dp[n][t]:
                ans = dp[n][t]
    if ans == float("inf"):
        print("-1")
    else:
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 30424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const int maxn = 200005;

int main()
{
	int n,a[105];
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]&1&&i&1)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
bool a[10];
bool check(int x){
	for(int j=x;j>0;j/=10){if(a[j%10]) return true;	}
	return false;
}

int main(){
    long long n,k;
    cin>>n>>k;
 
	for(int i=0;i<k;i++){ int x;cin>>x;
		a[x]=true;
	}
	int j;
	for(j=n;check(j);j++);
 
    cout<<j<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    ll n3=n/3,n5=n/5,n15=n/15;
    cout<<(n*(n+1))/2-(n3*(6+(n3-1)*3))/2-(n5*(10+(n5-1)*5))/2+(n15*(30+(n15-1)*15))/2;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
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 sm(vector<int> ac, int x, int y){
	int sum = 0;
  	for(int i = x; i <= y; i++){
    	sum += ac.at(i);
    }
  	return sum;
}	
	
int main() {
	int q;	cin >> q;
  	vector<int> l(q),r(q);
  	rep(i,q){
    	cin >> l.at(i) >> r.at(i);
    	l.at(i);	r.at(i);}
  	
  	int mx = pow(10,5);
  	vector<int> ac(mx,0);
	for(int i = 1; i <= mx/2; i++){
      	int nm = 2*i - 1;
      	if(IsPrime(nm) && IsPrime((nm+1)/2)){
        	ac.at(nm-1) = 1;
        } 
    }
  	
  	vector<int> sm(mx+1,0);
  	rep(i,mx) sm.at(i+1) = sm.at(i) + ac.at(i);
  	rep(i,q){
    	cout << (sm.at(r.at(i)) - sm.at(l.at(i)-1)) << endl;
    }
  	
}


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

string s;
long long ans=0;

int main(){
	cin >> s;
	long long n=s.length();
	for (int i=0;i<n/2;i++){
		if (s[i]!=s[n-i-1]) ans++;
	}
	cout << ans << "\n";
}

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

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

}


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n;
	cin >> n;
	int x1 = floor(n / 1.08);
	int x2 = ceil(n / 1.08);
	int n1 = floor(x1 * 1.08);
	int n2 = floor(x2 * 1.08);
	if(n1 == n) cout << x1;
	else if(n2 == n) cout << x2;
	else cout << ":(";
	return 0;
}


Measured memory_bytes: 3640
let rec read a b ab o =
  try let btype = Scanf.scanf "%d,%s\n" (fun x y-> y) in
      match btype with
        "A" -> read (a+1) b ab o
        | "B" -> read a (b+1) ab o
        | "AB" -> read a b (ab+1) o
        | "O" -> read a b ab (o+1)
        | _ -> ()
  with
    End_of_file -> Printf.printf "%d\n%d\n%d\n%d\n" a b ab o
in read 0 0 0 0;;

Measured memory_bytes: 2268
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <cstdio>
using namespace std;

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using vvvll = V<V<V<ll>>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vvpll = V<vpll>;
using vtpll = V<tpll>;
using vst = V<str>;
using vch = V<char>;
using vvch = V<vch>;
using dqll = deque<ll>;
using vdqll = V<dqll>;
using pqll = priority_queue<ll>;
using vpqll = V<pqll>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin() 
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define ba back()
#define fr front()
#define pob pop_back()
#define pof pop_front()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,n) substr(a,n)
#define cfs(a) cout<<fixed<<setprecision(a) //
/*vvll v(n,vll(m)) n行m列  continue
A.erase(A.begin()+i); 配列Aのi番目を消せる
std::binary_search(v.bgn,v.en,a); 二分探索
abs(a,b)   pow(a,n)  to_string  stoll
auto Iter=lower_bound(v.bgn,v.en,a); v[i]>=aとなる初のv[i]
v.insert(lower_bound(v.bgn,v.en,a),b); bを入れられる
lower upper  co(*Iter) co(Iter-v.bgn) v[i]>=aとなる初のi
vvll v(100001,vll(0)); v[a].pb(b); v[b].pb(a);
pqll pq; pq.push(ai); pq.top(); pq.pop();
priority_queue<ll,vll,greater<ll>> pqg; 昇順
vdqll dq(3);  dq[0].pb(1); dq[0].pb(2); dq[0].pf(0);
dq[0].fr→0 dq[0].ba→1 dq[0].pof; dq[0].fr→1
que.sz while(!que.empty())
ll a=1,b=2,c=4,xo; xo=a^b^c; if(a^b^c==0)co(xo)→7(miss) if(xo==0)co(xo)→なし
a<<b→a*2^b a>>b→a/2^b
rep(i,1<<10)rep(j,10)if((i>>j)&1)→iの二進で1となる桁のjのみ 
*/

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}
#define comuse Comuse()
ll combi(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;
}
ll pow_mod(ll a,ll n,ll mod){
  ll res=1;        //n=k_2  pow(a,k_2)
  for(;n>0;n/=2){  //ex,pow(a,1011_2)=a^8*a^2*a^1
    if(n%2==1)res=(res*a)%mod;
    a=(a*a)%mod;
  }
  return res;
}
ll digit_sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0)break;
  }
  return m;
}
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}

int main(){
  ll n;
  cin>>n;
  vll b(n-1);
  FOR(i,0,n-1){
    cin>>b[i];
  }
  vll a(n);
  a[0]=b[0];
  a[n-1]=b[n-2];
  FOR(i,1,n-1){
    a[i]=min(b[i-1],b[i]);
  }
  ll ans=0;
  FOR(i,0,n){
    ans+=a[i];
  }
  co(ans);
}
  

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

int main() {
	int count[4];
	for (int i = 0; i < 4; i++) {
		count[i] = 0;
	}
	int a;
	for (int i = 0; i < 4; i++) {
		cin >> a;
		if (a == 1) {
			count[0]++;
		}
		else if (a == 9) {
			count[1]++;
		}
		else if (a == 7) {
			count[2]++;
		}
		else if (a == 4) {
			count[3]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		if (count[i] == 1) {
			ans++;
		}
	}
	if (ans == 4) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

int gcd(int a, int b){
    if(a < b){
        swap(a, b);
    }

    int r = a % b;
    while(r > 0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

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

    int n;
    cin >> n;

    for(int i = 1; i <= 3500; i++){
        for(int j = 1; j <= 3500; j++){
            int x = n * i * j;
            int y = 4 * i * j - n * i - n * j;

            if(y <= 0){
                continue;
            }

            if(x % y == 0){
                cout << i << " " << j << " " << x / y << endl;
                return 0;
            }
        }
    }

    return 0;
}


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

int main() {
  
  int a, b, x;
  cin >> a >> b;
  
  x = a * b;
    
  if (x % 2 == 0){
    cout << "Even" << endl;
  }
    else if (x % 2 > 0) {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256