akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int):
    s = 0
    if X == 1:
        s += 300000
    elif X == 2:
        s += 200000
    elif X == 3:
        s += 100000
    if Y == 1:
        s += 300000
    elif Y == 2:
        s += 200000
    elif Y == 3:
        s += 100000
    if X == 1 and Y == 1:
        s += 400000
    print(s)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()


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

#define EPS 1e-12

int main()
{
	double xa,ya,xb,yb,xc,yc,xd,yd;
	while(cin>>xa>>ya>>xb>>yb>>xc>>yc>>xd>>yd){
		if( abs((xb-xa)*(xd-xc)+(yb-ya)*(yd-yc)) <= EPS){
			cout << "YES"<<endl;
		}else{
			cout<< "NO"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;

int main() {
 
int N,M;
cin >>N>>M;
 vector<vector<char>> A(N+2,vector<char>(M+2,'a'));
 for(int i=1; i<=N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
 for(int i=1; i<=N; i++){
   for(int j=1; j<=M; j++){
   if(A[i][j]=='#'&&A[i-1][j]!='#'&&A[i+1][j]!='#'&&A[i][j-1]!='#'&&A[i][j+1]!='#')
   {cout<<"No"<<endl; goto end;}
     if(i==N&&j==M)cout<<"Yes"<<endl;
 }}
end: N=N;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main(void) {
    io;
    int a,b,c;
    cin >> a >> b >> c;
    int count = 0;
    if ( a == b && b ==  c) {
        count = 1;
    } else if (a == b && b != c) {
        count = 2;
    } else if (a == c && b != c) {
        count = 2;
    } else if ( a != c && b == c) {
        count = 2;
    } else {
        count = 3;
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double N = sc.nextDouble();
		double ans = 0;
		
		if(N % 2 == 0) {
			ans = N / 2 / N;
			System.out.println(ans);
		} else {
			ans = (N + 1) / 2 / N;
			System.out.println(ans);
		}
		
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	int k,a,b;
	cin>>k>>a>>b;
	if(a%k==0||b%k==0)
		cout<<"OK\n";
	else{
		int x=a/k,y=b/k;
		if(x!=y)
			cout<<"OK\n";
		else
			cout<<"NG\n";
	}
	return 0;	
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll N;
	cin>>N;
	vector<ll> A(N);
	vector<ll> B(N);
	FDS(i,N){
		cin>>A[i]>>B[i];
	}
	vector<pair<ll,ll>> P(N);
	FDS(i,N){
		P[i].first=B[i];
		P[i].second=A[i];
	}
	VSORT(P);
	ll T=0;
	FDS(i,N){
		T+=P[i].second;
		if(T<=P[i].first){
		    continue;
		}
		else cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 6528
function main() {
  var
  n = 0,
  nsum = 0,
  ssum = 0;
  input.forEach(function(line){
    if(line.trim() === '') return;
    n += 1;
    line = line.split(',').map(parseFloat);
    nsum += line[1];
    ssum += line[0] * line[1];
  });
  console.log(ssum);
  console.log((nsum / n).toFixed(0));
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 7652
#include<bits/stdc++.h>
using namespace std;
  
  
struct edge{
  int to,cost;
  bool operator < ( const edge &p)const{
    return (cost == p.cost? to < p.to :cost < p.cost);
  }
};
struct state{
  int pos,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};
  
typedef long long ll;
  
#define MAX 100005
int pa[MAX],ra[MAX];
int t[MAX],h[MAX],d[MAX];
  
vector<edge> G[MAX];
vector<edge> g[MAX];
int n,m;
  
void init();
int find(int x);
void unite(int x,int y);
ll solve();
  
int main(){
  while( scanf("%d",&n)!=EOF){
    init();
    for(int i=1;i<=n;i++)scanf("%d",&h[i]);
    scanf("%d",&m);
    int a,b;
    for(int i=1;i<=m;i++){
      scanf("%d %d",&a,&b);
      g[a].push_back((edge){b,h[b]});
      g[b].push_back((edge){a,h[a]});
      if(h[a]<h[b]){        
        G[a].push_back((edge){b,h[b]});
      }else if(h[a]>h[b]){
        G[b].push_back((edge){a,h[a]});
      }else{        
        unite(a,b);
      }
    }
  
  
    for(int i=1;i<=n;i++){
      sort(g[i].begin(),g[i].end());
      for(int j=1;j<(int)g[i].size();j++){
        if(g[i][j-1].cost==g[i][j].cost){
          unite(g[i][j-1].to,g[i][j].to);
        }else if(g[i][j-1].cost<g[i][j].cost){
          G[ g[i][j-1].to ].push_back( g[i][j] );
        }
      }
    }
  
   
    for(int i=1;i<=n;i++){
      int id=find(i);
      t[id]++;
      if(i==id)continue;
      for(int j=0;j<(int)G[i].size();j++){
        edge e=G[i][j];
        G[id].push_back(e);
      }
    }
   
    cout<<solve()<<endl;
  
    break;
  }
  return 0;
}
  
ll solve(){
  priority_queue< state > Q;
  
  for(int i=1;i<=n;i++){
    if(i==find(i))Q.push((state){i,h[i]});
  }
   
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    int pos=s.pos;
    int cost=d[s.pos];
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      e.to=find(e.to);
      d[e.to]=max(d[e.to],cost+1);      
    }
  }
  ll ans=0;
  for(int i=1;i<=n;i++)ans+= (ll)d[i] * (ll)t[i];  
  return ans;
}
  
void init(){
  for(int i=0;i<MAX;i++){
    pa[i]=i;
    ra[i]=0;
    t[i]=0;
    d[i]=1;
    G[i].clear();
    g[i].clear();
  }  
}
  
  
  
int find(int x){
  if(pa[x]==x)return x;
  else return pa[x]=find(pa[x]);
}
  
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(ra[x]<ra[y])pa[x]=y;
  else {
    pa[y]=x;
    if(ra[x]==ra[y])ra[x]++;
  }  
}

Measured memory_bytes: 23128
def main():
    n = int(input())
    h = list(map(int, input().split()))

    dp = [0] * n
    dp[1] = abs(h[0] - h[1])
    for i in range(2, n):
        dp[i] = min(
            dp[i - 1] + abs(h[i] - h[i - 1]),
            dp[i - 2] + abs(h[i] - h[i - 2])
        )
    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 20516
#include<bits/stdc++.h>
#define ll  long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
void solve()
{
    ll n,m,k,y,res=0,l,cnt0=0,z,sum1=0,cnt1=0,h,res1,cnt2=0;
    cin>>n;
    string s1;
    double sum=0;
    double x;
    while(n--)
    {
        cin>>x;
        cin>>s1;
        if(s1=="BTC")
            sum+=(x*380000.000000);
        else
            sum+=x;

    }
    cout<<sum;
}
int main()
{   speed_up
    ll t;
   // cin>>t;
    t=1;
    while(t--)
        solve();
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if(a>0)cout<<"Positive";
else  if(a==0||(a<0&&b>0)) cout<<"Zero";
else if((abs(b)-abs(a))%2!=0) cout<<"Positive";
else cout<<"Negative";
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    string s; cin >> s;
    REP(i, s.size()){
        cout << "x";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(int i=s;i<n;i++)
	
int main(){
	int N,L;
	cin >> N >> L;
	int ans=0;
	for(int i=1;i<=N;i++) ans+=L+i-1;
	if(L>=0) cout << ans-L;
	else if(L<=0&&0<=L+N-1) cout << ans;
	else cout << ans-(L+N-1);
}

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

using namespace std;

int main(){
  int n;

  cin >> n;
  while(n--){
    string snake;
    cin >> snake;

    string s = snake.substr(0,2);
 

    if(s != ">^" && s != ">\'"){
      puts("NA");
      continue;
    }

    if(s == ">\'"){
      int a = 0;
      int p = 2;
      bool flg = true;
      int len = (int)snake.size();
      for(int i = 2 ; i < len ; i++,p++){
	if(snake[i] == '#') break;
	else if(snake[i] == '=') a++;
	else{
	  flg = false;
	  break;
	}
      }

      if(!flg){
	puts("NA");
	continue;
      }      

      int b = 0,q = p + 1;
      for(int i = q ; i < len ; i++,p++){
	if(snake[i] == '~') break;
	else if(snake[i] == '=') b++;
	else{
	  flg = false;
	  break;
	}
      }

      if(!flg || a == 0 || b == 0 || a != b){
	puts("NA");
	continue;
      }  

      if(a == b && snake[len-1] == '~'){
	puts("A");
      }else{
	puts("NA");
      }
    }else{
      bool ok = true;
      int p = 0;
      string ss = "";
      int len = (int)snake.size();

      if(len < 6 || len % 2){
	puts("NA");
	continue;
      } 

      for(int i = 2 ; i < len-2 ; i++,p++){
	ss += snake[i];
	if(p == 1){
	  p = -1;
	  if(ss != "Q="){
	    ok = false;
	    break;
	  }
	  ss = "";
	}
      }

      if(snake[len-2] == '~' && snake[len-1] == '~' && ok){
	puts("B");
      }else{
	puts("NA");
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1204
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
 
public class Main {
	
	public static void main(String[] args) throws IOException {
		try (Scanner sc = new Scanner(System.in)) {
			final int N = sc.nextInt();
			
			long prev_T = 0, prev_x = 0, prev_y = 0;
			for(int i = 0; i < N; i++){
				final long T = sc.nextLong();
				final long x = sc.nextLong();
				final long y = sc.nextLong();
				
				final long T_diff = T - prev_T;
				final long x_diff = Math.abs(x - prev_x);
				final long y_diff = Math.abs(y - prev_y);
				final long all_diff = x_diff + y_diff;
				
				//System.out.println(T_diff + " " + all_diff);
				if(all_diff > T_diff || all_diff % 2 != T_diff % 2){
					System.out.println("No");
					return;
				}
				
				prev_x = x;
				prev_y = y;
				prev_T = T;
			}
			
			System.out.println("Yes");
		}
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 40768
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

WHITE = '1'
BLACK = '0'

# def count(graph):


def main():
    H, W, K = MI()
    graph = [None] * H

    for i in range(H):
        graph[i] = [int(v) for v in list(S())]

    ans = 10**9
    for i in range(2 ** (H-1)):
        groups = [0]
        for j in range((H-1)):
            if ((i >> j) & 1):
                groups.append(j+1)
        groups.append(H)

        divide_count = 0
        counter = defaultdict(int)
        impossible = False
        for w in range(W):
            current_counter = defaultdict(int)
            for g in range(1, len(groups)):
                prev_div = groups[g-1]
                div = groups[g]
                total = 0
                for h in range(prev_div, div):
                    total += graph[h][w]
                current_counter[g] += total

            # 無理な場合
            if not all(v <= K for v in current_counter.values()):
                impossible = True
                break

            for k, v in current_counter.items():
                counter[k] += v
                if counter[k] > K:
                    divide_count += 1
                    counter = current_counter
                    break
            # print(groups, counter, divide_count)

        if not impossible:
            # print(groups, divide_count + len(groups) - 2)
            ans = min(ans, divide_count + len(groups) - 2)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 52952
import copy

n, a, b, c = list(map(int, input().split(" ")))
l = n*[0]
for i in range(n):
    l[i] = int(input())



def search(abc, l):
    mp = 0
    for x in abc:
        if(x in l): l[l.index(x)] = 0
        else:
            while(True):
                k = 1e9
                d = -1
                for i in range(n):
                    if(l[i] == 0): continue

                    if(abs(x - l[i]) < k):
                        k = abs(x - l[i])
                        d = i

                if(k <= 10):
                    mp += k
                    l[d] = 0
                    break
                else:
                    k = 1e9
                    d = n*[0]
                    d[0] = 1
                    while(sum(d) != n):
                        tree = 0
                        for i in range(n): tree += d[i] * l[i]
                        cost = abs(x - tree)
                        if(tree == 0): cost = 1e9
                        if(sum(d) > 1): cost += (sum(d)-1) * 10
                        if(cost < k):
                            k = cost
                            tmp2 = copy.deepcopy(d)

                        for i in range(n):
                            if(d[i] == 0):
                                d[i] = 1
                                break
                            else: d[i] = 0

                    mp += k
                    for i in range(n):
                        if(tmp2[i] == 1): l[i] = 0
                    break

    return mp

ans = []
ans.append(search([a, b, c], copy.deepcopy(l)))
ans.append(search([a, c, b], copy.deepcopy(l)))
ans.append(search([b, a, c], copy.deepcopy(l)))
ans.append(search([b, c, a], copy.deepcopy(l)))
ans.append(search([c, a, b], copy.deepcopy(l)))
ans.append(search([c, b, a], copy.deepcopy(l)))


print(min(ans))

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a,b;
    int oddtemp=1;
    int ansodd=0;
    int oddnum = 0;
    int ans2odd =0;
    int eventemp=1;
    int anseven = 0;
    int evennum = 0;
    int ans2even =0;
    vector<int> odd;
    vector<int> even;
    for(int i=0;i<n/2;i++){
        cin >> a >> b;
        odd.push_back(a);
        even.push_back(b);
    }
    sort(odd.begin(),odd.end());
    sort(even.begin(),even.end());
    for(int j=0;j<n/2;j++){
        if((odd[j]==odd[j+1]) && (j != n/2-1)){
            oddtemp++;
        }else{
            if(oddtemp > oddnum){
                if(oddnum > ans2odd){
                    ans2odd = oddnum;
                }
                oddnum = oddtemp;
                ansodd = odd[j];
  
            }else if(oddtemp > ans2odd){
                ans2odd = oddtemp;
            }
            oddtemp = 1;
        }
        if((even[j]==even[j+1]) && (j != n/2-1)){
            eventemp++;
        }else{
            if(eventemp > evennum){
                if(evennum > ans2even){
                    ans2even = evennum;
                }
                evennum = eventemp;
                anseven = even[j];
            }else if(eventemp > ans2even ){
                ans2even = eventemp;
                
            }
            eventemp=1;
        }
        
    }
    if(anseven != ansodd){
        cout << (n - (oddnum + evennum)) << endl;
    }else{
     if(evennum == oddnum){
         if(ans2odd == ans2even){
             cout << (n - (evennum + ans2odd)) << endl;
         }else if(ans2odd > ans2even){
             cout << (n - (evennum + ans2odd)) << endl;
         }else{cout << (n - (evennum + ans2even)) << endl;}
     }
     else if(evennum>oddnum){
        cout << (n - (evennum + ans2odd)) << endl;
    }else{
        cout << (n - (oddnum + ans2even)) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 892
import collections

n = int(input())
a = list(map(int, input().split()))

b = collections.deque()
for i, v in enumerate(a):
    if i % 2 == 0:
        b.append(v)
    else:
        b.appendleft(v)

ans = ' '.join(map(str, b if n % 2 == 0 else reversed(b)))
print(ans)

Measured memory_bytes: 29124
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	args := []int{nextInt(), nextInt(), nextInt()}
	five := 0
	seven := 0
	for _, v := range args {
		if v == 5 {
			five += 1
		} else if v == 7 {
			seven += 1
		}
	}
	if five == 2 && seven == 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma G++ optimize(2)
#pragma GCC optimize(3)
#pragma G++ optimize(3)
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#include<bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
const int md=1000000007;
const int mxn=200005;
int n,m,mx,ans,dp[mxn],f[mxn];
char s[mxn];
inline void add(int&x,int y){
	x+=y;
	if(x>=md)x-=md;
}
signed main(){
	int i,j,t;
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for(i=1;i<=m;++i)if(s[i]!=s[1])break;mx=i-1;
	if(mx==m){
		dp[0]=f[i]=ans=1;
		for(int i=0;i<=n;++i){
			if(i>=2)dp[i]=f[i-2];
			f[i]=(f[i-1]+dp[i])%md;
			if(n-i>1)add(ans,dp[i]*(n-i)%md);
		}
		printf("%d\n",ans);
		return 0;
	}
	if(n&1)return 0*puts("0");
	if(!(mx&1))++mx;
	for(t=0;i<=m;++i){
		if(s[i]==s[1])++t;
		else{
			if(t&1)mx=min(mx,t);
			t=0;
		}
	}
	n>>=1,mx=mx+1>>1;
	dp[0]=f[0]=1;
	for(i=0;i<=n;++i){
		if(i){
			dp[i]=(md+f[i-1]-(i-mx-1>=0?f[i-mx-1]:0))%md;
			f[i]=(f[i-1]+dp[i])%md;
		}
		if(n-i<=mx) add(ans,(n-i)*dp[i]*2%md);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 3584
a,b,c = map(int,input().split(" "))
if a==1 and b == 0 and c == 0:
  print("Close")
  
elif a==0 and b == 1 and c == 0:
  print("Close")
  
elif a==1 and b == 1 and c == 0:
  print("Open")
  
elif a==0 and b == 0 and c == 1:
  print("Open")
  
else:
  print("Close")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vl;

const int N = 2e5 + 123;
int n, a[N], ans;
map <int, int> cnt;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		cnt[-a[i]]++;
	}
	for (auto i : cnt) {
		int val = i.F;
		while (cnt[val] > 0) {
			cnt[val]--;
			for (int j = 0; j <= 30; j++) {
				int need = -((1 << j) - (-val));
				if (cnt.count(need) && cnt[need] > 0) {
					//cout << -need << ' ' << -val << '\n';
					cnt[need]--;
					ans++;
				}
			}
		}
	}
	cout << ans;
}


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

int h, n, arr[100001], brr[100001], dp[100001], ans;

int main()
{
    cin>>h>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>arr[i]>>brr[i];
    }

    memset(dp, 0x3f, sizeof(dp));
    dp[h]=0;
    ans=1e9;
    for(int i=1; i<=n; i++)
    {
        for(int j=h; j>0; j--)
        {
            dp[max(0, j-arr[i])]=min(dp[max(0, j-arr[i])], dp[j]+brr[i]);
        }
        ans=min(ans, dp[0]);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  vector<long long> dp(90001, 0);
  dp[0] = 1;
  int sum = 0;
  REP(i, n) {
    for (int j = sum; j >= 0; --j) {
      (dp[j + a[i]] += dp[j]) %= MOD;
      (dp[j] *= 2) %= MOD;
    }
    sum += a[i];
  }
  long long ans = 1;
  REP(i, n) (ans *= 3) %= MOD;
  long long except = 0;
  FOR(i, (sum + 1) / 2, 90001) (except += dp[i]) %= MOD;
  ans -= except * 3;
  if (sum % 2 == 0) {
    dp.assign(90001, 0);
    dp[0] = 1;
    sum = 0;
    REP(i, n) {
      for (int j = sum; j >= 0; --j) {
        (dp[j + a[i]] += dp[j]) %= MOD;
      }
      sum += a[i];
    }
    ans += dp[sum / 2] * 3;
  }
  ((ans %= MOD) += MOD) %= MOD;
  cout << ans << '\n';
  return 0;
}


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

#define int long long

const int Mod = 924844033;
const int G = 5;
const int MaxN = 3e6 + 10;

struct Edge {
    int To, Next;
}Road[MaxN];

int N, M;
int Cnt = 0, Last[MaxN];

void Add(int U, int V) {
    Road[++Cnt] = (Edge) {V, Last[U]};
    Last[U] = Cnt; 
}

int Size[MaxN];
int Coe[MaxN];
using namespace std;

void Dfs(int Now, int Pa) {
    Coe[N] += 1; Size[Now] = 1;
    for(int i = Last[Now]; i; i = Road[i].Next) {
        int To = Road[i].To;
        if(To ^ Pa) {
            Dfs(To, Now); 
            Coe[Size[To]] -= 1;
            if(Coe[Size[To]] < 0) Coe[Size[To]] = (Coe[Size[To]] + Mod) % Mod;
            Size[Now] += Size[To]; 
        }
    }
    Coe[N - Size[Now]] -= 1;
    if(Coe[N - Size[Now]] < 0) Coe[N - Size[Now]] = (Coe[N - Size[Now]] + Mod) % Mod;
}

int Kasumi(int A, int B) {
    int Ans = 1, Base = A;
    B = (B + (Mod - 1)) % (Mod - 1);
    while(B) {
        if(B & 1) Ans = Base * Ans % Mod;
        Base = Base * Base % Mod;
        B >>= 1;
    }
    return Ans;
} 

int Fac[MaxN], Inv[MaxN];

void Init() {
    Fac[0] = 1; Inv[0] = 1;
    for(int i = 1; i <= N << 1; i++) Fac[i] = Fac[i - 1] * i % Mod;
    for(int i = 1; i <= N << 1; i++) Inv[i] = Kasumi(Fac[i], Mod - 2);
}

int C(int A, int B) {
    return Fac[A] % Mod * Inv[B] % Mod * Inv[A - B] % Mod;
} 

int Rev[MaxN];

#define Swap(A, B) A ^= B ^= A ^= B

void Ntt(int *A, int N, int Flag) {
    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 W = Kasumi(G, Flag * (Mod - 1) / (i << 1));
        for(int j = 0; j < N; j += (i << 1)) {
            int Wn = 1;
            for(int k = 0; k < i; k++, Wn = Wn * W % Mod) {
                int x = A[j + k], y = A[i + j + k] * Wn % Mod;
                A[j + k] = (x + y) % Mod;
                A[i + j + k] = (x - y + Mod) % Mod;
            }
        }
    }
    if(!~Flag) {
        int T = Kasumi(N, Mod - 2);
        for(int i = 0; i < N; i++) A[i] = A[i] * T % Mod;
    }
}

int Ans[MaxN];
int A[MaxN], B[MaxN];

main() {
    scanf("%lld", &N);
    for(int i = 1, A, B; i <= N - 1; i++) scanf("%lld%lld", &A, &B), Add(A, B), Add(B, A);
    Init(); Dfs(1, 0);
    for(int i = 0; i <= N; i++) A[i] = Coe[i] * Fac[i] % Mod, B[i] = Inv[i];
    std::reverse(B, B + N + 1);
    int Len = 1, Log = 0;
    while(Len <= (N << 1)) Len <<= 1, Log += 1;
    for(int i = 0; i < Len; i++) Rev[i] = (Rev[i >> 1] >> 1) | ((i & 1) << (Log - 1));	
    Ntt(A, Len, 1); Ntt(B, Len, 1);
    for(int i = 0; i < Len; i++) A[i] = A[i] * B[i] % Mod;
    Ntt(A, Len, -1);
    for(int i = 0; i < Len; i++) Ans[i] = A[i];
    for(int i = 1; i <= N; i++) {
        int P = Ans[N + i] * Inv[i] % Mod;
        P = (P + Mod) % Mod;
        printf("%lld\n", P % Mod);
    }
} 

Measured memory_bytes: 63360
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
    int a,b;
    double c;
    scanf("%d%d", &a,&b);
    printf("%d ",a/b);
    printf("%d ", a%b);
    c = a * 1.0;
    printf("%f\n", c / b);
    return 0;
}


Measured memory_bytes: 2060
#include <iostream>

using namespace std;

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) cout << "1\n";
    else cout << (h * w + 1) / 2 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace::std;
int main()
{
        int N,j;
        int i;
        int countprim;
        countprim=0;
        cin>>N;
        int*nums=new int[N];
        for(i = 0; i < N; i ++) cin >> nums[i];
        for(i=0;i<N;i++)
        {
                int x = sqrt(nums[i]);
                bool ifprime = true;
                for(j=2;j<=x;j++)
                {
                        if(nums[i] % j == 0) {
                                ifprime = false;
                                break;
                        }
                }
                if(ifprime)
                        countprim++;
        }

        cout<<countprim<<endl;
}



Measured memory_bytes: 3148
from itertools import product
K = int(input())

ans = []
for l in range(10):
    for s in range(1, 10):
        for pattern in product([-1, 0, 1], repeat=l):
            X = [s]
            for p in pattern:
                if not (0 <= X[-1] + p <= 9):
                    break
                X.append(X[-1] + p)
            else:
                ans.append(int(''.join(map(str, X))))

ans.sort()
print(ans[K - 1])


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

signed main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	b = a;
	sort(b.begin(), b.end());
	const int a_max = b[n-1], a_nmax = b[n-2];

	for (int i = 0; i < n; ++i) {
		if (a[i] == a_max) cout << a_nmax << endl;
		else cout << a_max << endl;
	}
}


Measured memory_bytes: 3200
/*input
STS
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double

typedef pair<int,int> pi;

typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define gcd __gcd

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  int ans = n;
  int i = 0;
  stack<char> a;
  while(i < n){
  	if(a.empty())a.push(s[i]);
  	else if(s[i] == 'T' && a.top() == 'S')a.pop();
    else a.push(s[i]);
  	i++;
  } 
  cout << a.size();
  return 0;
}

Measured memory_bytes: 720
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<int, int>p;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	int dist[1003][1003];
	for (int i = 0; i < 1003; i++) {
		for (int j = 0; j < 1003; j++) {
			dist[i][j] = INT_MAX;
		}
	}
	queue<p>que;
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < w; j++) {
			if (s[j] == '#') {
				que.push(p(i, j));
				dist[i][j] = 0;
			}
		}
	}
	int ans = 0;
	while (!que.empty()) {
		int x = que.front().first;
		int y = que.front().second;
		que.pop();
		if (x > 0&&dist[x-1][y]>dist[x][y]+1) {
			dist[x - 1][y] = dist[x][y] + 1;
			ans = max(ans, dist[x - 1][y]);
			que.push(p(x - 1, y));
		}
		if (x < h-1 && dist[x + 1][y]>dist[x][y] + 1) {
			dist[x + 1][y] = dist[x][y] + 1;
			ans = max(ans, dist[x + 1][y]);
			que.push(p(x + 1, y));
		}
		if (y >0 && dist[x][y-1]>dist[x][y] + 1) {
			dist[x][y-1] = dist[x][y] + 1;
			ans = max(ans, dist[x][y-1]);
			que.push(p(x, y-1));
		}
		if (y<w-1&& dist[x ][y+1]>dist[x][y] + 1) {
			dist[x][y+1] = dist[x][y] + 1;
			ans = max(ans, dist[x ][y+1]);
			que.push(p(x , y+1));
		}
	}
	cout << ans;
}

Measured memory_bytes: 12432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
LL facctorialMethod(int k);
int main(){
    LL a,b,c,d;
    cin >> a >> b >> c >> d;
    while(a > 0 && c > 0){
        c = c - b;
        if(c <= 0) break;
        a = a - d;
//        cout << "a :" << a << endl;
//        cout << "c :" << c << endl;
    }

//        cout << "a :" << a << endl;
//        cout << "c :" << c << endl;

    if(c <= 0){
        cout << "Yes" << endl;
    } 
    else{
        cout << "No" << endl;
    } 

    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int A, B, C, D;
    std::cin >> A >> B >> C >> D;
    std::cout << max(min(B, D) - max(A, C), 0) << std::endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class ProgramD
    {
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split(' ');

            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);

            string s = Console.ReadLine();
            List<int> LR = new List<int>();

            int count = 1;


            for(int i = 1;i < n;i++)
            {
                string si = s.Substring(i, 1);
                string si_p = s.Substring(i-1,1);
                
                if(si != si_p)
                {
                    LR.Add(count);
                    count = 1;
                }
                else
                {
                    count++;
                }

                if(i == n -1)
                    LR.Add(count);
            }

            long ans = LR.Sum() - LR.Count();
            long LRlen = LR.Count();
            
            for(int i = 0;i < k;i++)
            {
                if(LRlen == 2)
                {
                    ans += 1;
                    break;
                }
                else if((LRlen == 1))
                {
                    break;
                }
                else
                {
                    ans += 2;
                    LRlen -= 2;
                }

            }

            if(ans >= n)
                ans = n -1 ;

            Console.WriteLine(ans);

        }
}

Measured memory_bytes: 18012
#include <stdio.h>

int main(void){
    int n;

    scanf("%d", &n);
#if 0
    if(n == 1) printf("%f\n", (float)n);
    else if((n % 2) == 0) printf("%f\n", 0.5);
    else printf("%f\n", (float)((n/2) + 1)/n);
#endif

    printf("%f\n", (double)((n - n / 2) / (double)n));

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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

    while(true) {
      int x = in.nextInt();
      int y = in.nextInt();
      if (x == 0 && y == 0) break;
      if (x > y) {
        int t = x;
        x = y;
        y = t;
      }
      System.out.println(x + " " + y);
    }
  }
}

Measured memory_bytes: 35804
#include <algorithm>
#include <cstdio>
#include <map>

int main()
{
#ifdef LOCAL_JUDGE
    freopen("B.in", "r", stdin);
#endif
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    std::map<std::pair<int, int>, int> cnt;
    while (k --) {
        int x, y;
        scanf("%d%d", &x, &y);
        for (int i = std::max(x - 2, 1); i <= x && i + 2 <= n; ++ i) {
            for (int j = std::max(y - 2, 1); j <= y && j + 2 <= m; ++ j) {
                cnt[{i, j}] ++;
            }
        }
    }
    long long result[10] = { 0 };
    result[0] = (n - 2LL) * (m - 2LL);
    for (auto it : cnt) {
        result[0] --;
        result[it.second] ++;
    }
    for (int i = 0; i < 10; ++ i) {
        printf("%lld\n", result[i]);
    }
}


Measured memory_bytes: 56448
N, M = map(int, input().split())

a = [0]*N
for i in range(N):
  a[i] = list(map(int, input().split()))

b = [0]*M
for i in range(M):
  b[i]= int(input())

c = [0]*N
for i in range(N):
  for aj, bj in zip(a[i], b):
    c[i] += aj * bj
    
for ci in c:
  print(ci)


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

/**
 * @description:
 * @author: Jetman
 * @create: 2020-08-29 14:39
 **/
public class Main {

    Scanner sc = new Scanner(System.in);

    private void slove() {
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i=0;i<n;i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        //a = Arrays.stream(a).distinct().toArray();
        int len = a.length;
        int ans = 0;
        for (int i = 0; i < len; i++) {
            for (int j = i+1; j < len; j++) {
                for (int k = j+1; k < len; k++) {
                    int d = a[i];
                    int b = a[j];
                    int c = a[k];
                    if (b == c || c == d || d == b) {
                        continue;
                    }
                    int[] s = {b,c,d};
                    Arrays.sort(s);
                    if (s[0] + s[1] > s[2]) {
                        ans++;
                    }
                }
            }
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Main().slove();
    }
}


Measured memory_bytes: 41568
q= int(input())
ac,wa,tle,re = 0,0,0,0
for _ in range(q):
    q = input()
    if q == "AC": ac+=1
    elif q == "WA": wa+=1
    elif q == "TLE": tle+=1
    else : re+=1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)
    


Measured memory_bytes: 9196
import math

def checkDisInt(y, z):
    disSum = 0
    for i in range(D):
        disSum += (y[i] - z[i])**2
    if int(math.sqrt(disSum))**2 == disSum:
        return True
    return False

N, D = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if checkDisInt(X[i], X[j]):
            ans += 1

print(ans)


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

using namespace std;

typedef long long ll;

ll H, W;

ll max(ll a, ll b, ll c) {
	return max(a, max(b, c));
}
ll min(ll a, ll b, ll c) {
	return min(a, min(b, c));
}

int main() {
	cin >> H >> W;

	ll ans = 1145141919810893;
	for (int i = 1; i < H; i++) {
		ll s1 = i * W, s2 = 0, s3 = 0;
		if (W % 2 == 0) {
			s2 = (H - i) * (W / 2LL);
			s3 = (H - i) * (W / 2LL);
		}
		else {
			s2 = (H - i) * (W / 2LL);
			s3 = (H - i) * (W - (W / 2LL));
		}
		ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3));
	}

	for (int i = 1; i < W; i++) {
		ll s1 = i * H, s2 = 0, s3 = 0;
		if (H % 2 == 0) {
			s2 = (W - i) * (H / 2LL);
			s3 = (W - i) * (H / 2LL);
		}
		else {
			s2 = (W - i) * (H / 2LL);
			s3 = (W - i) * (H - (H / 2LL));
		}
		ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3));
	}
	
	for (int i = 1; i < H; i++) {
		ll s1 = i * W, s2 = (H - i) / 2LL * W, s3 = (H - i - (H - i) / 2LL) * W;
		ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3));
	}

	for (int i = 1; i < W; i++) {
		ll s1 = i * H, s2 = (W - i) / 2LL * H, s3 = (W - i - (W - i) / 2LL) * H;
		ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3));
	}

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

Measured memory_bytes: 256
# https://drken1215.hatenablog.com/entry/2019/06/21/230200

def main():
    MOD = 10 ** 9 + 7

    N, M = map(int, input().split())
    *s, = map(int, input().split())
    *t, = map(int, input().split())

    dp = [[0] * (M + 1) for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N + 1):
        for j in range(M + 1):
            if j > 0:
                dp[i][j] += dp[i][j - 1]
            if i > 0:
                dp[i][j] += dp[i - 1][j]
            if i > 0 and j > 0 and s[i - 1] != t[j - 1]:
                dp[i][j] -= dp[i - 1][j - 1]
            dp[i][j] %= MOD
    print(dp[N][M])


if __name__ == '__main__':
    main()


Measured memory_bytes: 72540
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef int long long i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1000000007; // 10000000000000007ll;

const double eps = 1e-8;

const i64 MAXN = 300004;

i64 n, k;
i64 a[MAXN];

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> k;
    i64 R = 0;
    while (n) {
        R += 1;
        n /= k;
    }
    cout << R << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.util.Arrays;

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 Alice=0;
		int Bob=0;
		int ans=0;

		for(int i=0;i<N;i++) A[i]=sc.nextInt();
		Arrays.sort(A); 

		for(int i=0;i<N;i++){
			if(i%2==0) Alice+=A[i];
			else Bob+=A[i];
		}

		if(Alice>Bob) ans=Alice-Bob;
		else ans=Bob-Alice;

		System.out.println(ans);
	}
}

Measured memory_bytes: 23380
#ベルマンフォード法
#正の閉路がない時は普通のベルマンフォード法
n,m=list(map(int,input().split()))
es=[]
for i in range(m):
  a,b,c=list(map(int,input().split()))
  es.append((a-1,b-1,c))
import sys
def Bellmanford(n,m,s,es):
  d=[-float("INF")]*n
  d[s]=0
  cnt=0
  while(1):
    update=False
    for p,q,r in es:
      if d[p]!=-float("INF") and d[q]<d[p]+r:
        d[q]=d[p]+r
        update=True
    cnt+=1
    if not update:
      break
    if cnt==n-1:
      memo=d[n-1]
    if cnt==n:
      #正のループがある
      if d[n-1]>memo:
        print(float("INF"))
        sys.exit()
      else:
        print(d[n-1])
        sys.exit()
  print(d[n-1])
  
Bellmanford(n,m,0,es)  
    
    
      
  
  

  

Measured memory_bytes: 70204
#include <bits/stdc++.h>  //2fat2code a.k.a grandmixer420
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define int long long
using namespace std;

int x,y,n[6];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    for(int i=1;i<=3;i++){
        cin >> x >> y;
        n[x]++;
        n[y]++;
    }
    sort(n+1,n+5);
    if(n[1]==0) rc("NO");
    else if(n[4]>=3) rc("NO");
    else rc("YES");
}


Measured memory_bytes: 256
// NK
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define all(x) x.begin(), x.end()

int main(){
  //#ifndef ONLINE_JUDGE
  //freopen("ia.txt", "r", stdin);
  //freopen("oa.txt", "w", stdout);
  //#else
  ios::sync_with_stdio(false), cin.tie(nullptr);
  //#endif

  string a;
  int k;
  cin>>a>>k;
  int n=a.size();

  ll ans=0;
  if (k==1){
    for (int i=0; i<n; i++){
      if (!i) ans+=-'0' + a[i];
      else ans+=9;
    }
    cout<<ans<<'\n';
    return 0;
  }
  if (k==2){
    for (int i=1; i<n-1; i++){
      for (int j=i+1; j<n; j++){
        ans+=9*9;
      }
    }

    bool sw=0;
    for (int i=1; i<n; i++){
      if (!sw) ans+=a[i]-'0';
      else ans+=9;
      if (a[i]!='0') sw=1;
    }

    ll curr=a[0]-'0'-1;
    for (int i=1; i<n; i++){
      ans+=curr*9;
    }
    cout<<ans<<'\n';
    return 0;
  }
  for (int i=1; i<n-2; i++){
    for (int j=i+1; j<n-1; j++){
      for (int jj=j+1; jj<n; jj++){
        ans+=9*9*9;
      }
    }
  }

  ll curr=a[0] - '0' -1;
  for (int j=1; j<n-1; j++){
    for (int jj=j+1; jj<n; jj++){
      ans+=curr*9*9;
    }
  }

  int i;
  for (i=1; i<n-1; i++){
    if (a[i]!='0'){
      for (int j=i+1; j<n-1; j++)
        for (int jj=j+1; jj<n; jj++)
          ans+=9*9;

      bool sw=0;
      for (int j=i+1; j<n; j++){
        if (!sw) ans+=a[j]-'0';
        else ans+=9;
        if (a[j]!='0') sw=1;
      }

      curr=a[i]-'0'-1;
      for (int j=i+1; j<n; j++){
        ans+=curr*9;
      }
      break;
    }
  }
  cout<<ans<<'\n';

  return 0;
}


Measured memory_bytes: 256