akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long  LL;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-4
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline LL rd() {
	LL x = 0;
	char c = getchar();
	bool f = false;
	while (!isdigit(c)) {
		if (c == '-') f = true;
		c = getchar();
	}
	while (isdigit(c)) {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return f ? -x : x;
}

/*ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; }
*/

/*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
	if (!b) {
		x = 1; y = 0; return a;
	}
	ans = exgcd(b, a%b, x, y);
	ll t = x; x = y; y = t - a / b * y;
	return ans;
}
*/


int n;

int a[maxn];

int main() {
//	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;int sum=0;
    bool fg=1;
    for(int i=1;i<=n;i++)rdint(a[i]),sum+=a[i];
    for(int i=1;i<=n;i++){
    	if(a[i]%10!=0)fg=0;
	}
	if(fg==1){
		cout<<0<<endl;return 0;
	}
    if(sum%10!=0){
    	cout<<sum<<endl;
	}
    else{
    	sort(a+1,a+1+n);
    	for(int i=1;i<=n;i++){
    		if((sum-a[i])%10!=0){
    			cout<<sum-a[i]<<endl;
    			return 0;
			}
		}
	}
}






Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<k;i++)
struct Point {double x,y;};
void koch(int n,Point a,Point b){
    if(n==0)return;
    Point s,t,u;
    double th=M_PI*60.0/180.0;
    s.x=(2.0*a.x+1.0*b.x)/3.0;
    s.y=(2.0*a.y+1.0*b.y)/3.0;
    t.x=(1.0*a.x+2.0*b.x)/3.0;
    t.y=(1.0*a.y+2.0*b.y)/3.0;
    u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
    u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
    koch(n-1,a,s);
    cout<<s.x<<" "<<s.y<<endl;
    koch(n-1,s,u);
    cout<<u.x<<" "<<u.y<<endl;
    koch(n-1,u,t);
    cout<<t.x<<" "<<t.y<<endl;
    koch(n-1,t,b);
}
int main(){
    Point a,b;
    int n;
    cin>>n;
    a.x=0;a.y=0;b.x=100;b.y=0;
    cout<<a.x<<" "<<a.y<<endl;
    koch(n,a,b);
    cout<<b.x<<" "<<b.y<<endl;
    return 0;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Grid = vector<string>;
using GroupCnt = vector<vector<int>>;

void solve() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int H, W, K;
    cin >> H >> W >> K;

    Grid grid(H);
    for (int i = 0; i < H; ++i) cin >> grid[i];

    int ans = INT_MAX;
    for (int bit = 0; bit < (1 << H - 1); ++bit) {
        int g = 0;
        vector<int> row(H);
        for (int i = 0; i < H; ++i) {
            row[i] = g;
            if (bit>>i & 1) ++g;
        }
        ++g;
        GroupCnt group_cnt(g, vector<int>(W, 0));
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                group_cnt[row[i]][j] += grid[i][j] - '0';
            }
        }
        int num = g - 1;
        vector<int> curr(g);
        auto add_j = [&](int j) {
            for (int i = 0; i < g; ++i) {
                curr[i] += group_cnt[i][j];
            }
            for (int i = 0; i < g; ++i) {
                if (K < curr[i]) return false;
            }
            return true;
        };
        for (int j = 0; j < W; ++j) {
            if (!add_j(j)) {
                num++;
                curr = vector<int>(g);
                if (!add_j(j)) {
                    num = INT_MAX;
                    break;
                }
            }
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define ck(a,b) (0<=(a)&&(a)<(b))

using namespace std;

int main(){
	int N,ans=1;
	cin>>N;
	int A[100002]={0};
	A[2]++;
	REP(i,0,N){
		int a,b;
		cin>>a>>b;
		A[a]++,A[b+1]--;
	}
	REP(i,3,N+2){
		A[i]+=A[i-1];
	}
	for(int i=N+1;i>=2;i--){
		if(A[i]>=i){
			ans=i;
			break;
		}
	}
	p(ans-1);
	return 0;
}

Measured memory_bytes: 3468
import math

def distance(p, q):
    return math.sqrt(p ** 2 + q ** 2)

ans = 0

n, d = map(int, input().split())

for _ in range(n):
    x, y = map(int, input().split())
    dist = distance(x, y)
    if dist <= d:
        ans += 1

print(ans)


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

int main(){
  int N,K; cin >> N >> K;
  vector<ll> V(N);
  for(int i=0;i<N;i++){
    cin >> V[i];
  }
  ll Vmax = 0;
  for(int i=1;i<=min(N,K);i++){
    for(int j=0;j<=i;j++){
      vector<ll> Vcur;
      // j jewels from right side, i-j jewels from left side.
      for(int k=0;k<j;k++){
        Vcur.push_back(V[k]);
      }
      for(int k=0;k<i-j;k++){
        Vcur.push_back(V[N-1-k]);
      }
      sort(Vcur.begin(),Vcur.end());
      // Now you have i jewels. You can throw away up to K - i jewels.
      ll Vsum = 0;
      for(int k=0;k<Vcur.size();k++){
        if(Vcur[k]>=0){
          Vsum += Vcur[k];
        }else{
          if(k>=K-i){
            Vsum += Vcur[k];
          }
        }
      }
      Vmax = max(Vsum,Vmax);
    }
  }
  cout << Vmax << endl;
}

Measured memory_bytes: 3636
n,x,m=map(int,input().split())

mod=[0]*(m)

mod[x%m]=1
ans=x

for i in range(2,n+1):
    x=(x**2)%m
    #print(i,x)
    if mod[x]==0:
        ans+=x
        mod[x]=i
    else:
        #過去に2度来たことがある
        if mod[x]==-1:
            break
        #過去に1度来たことがある
        else:
            turn=i-mod[x]
            ans+=x*(((n-i)//turn+1))
            mod[x]=-1

print(ans)


    




Measured memory_bytes: 66252
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N, M;
	cin >> N >> M;
	long long ans = 0;
	if (N <= M / 2) {
		ans += N;
		N = 0;
		M -= ans * 2;
	}
	else {
		ans += M / 2;
		M = 0;
		N -= ans;
	}
	if (M != 0) {
		ans += M / 4;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
int main(){
   int n,d;
   long long  s=0,answer=0,g;
   cin >> n >> d;
   vector<vector<int>> a(n,vector<int>(d));
   for(int i=0; i<n; i++){
       for(int j=0; j<d; j++){
           cin >> a.at(i).at(j);
       }
   }
   for(int i=0; i<n-1; i++){
       for(int j=i+1; j<n; j++){
           for(int k=0; k<d; k++){
               s+=(a.at(i).at(k)-a.at(j).at(k))*(a.at(i).at(k)-a.at(j).at(k));
           }
           if(s==0) answer++;
           else{
               g=sqrt(s);
               if(s==1) answer++;
               else if(s%g==0 && s/g==g) answer++;
           }
           s=0;
       }
   }
   cout << answer << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a[11]={0},b,c,i,j;
	for(i=0;i<11;i++){
		scanf("%d",&a[i]);
		}
		for(i=0;i<10;i++){
			for(j=i;j<10;j++){
				if(a[i]<a[j]){
					b=a[i];
					a[i]=a[j];
					a[j]=b;
				}
			}
		}
		for(i=0;i<3;i++){
			printf("%d\n",a[i]);
		}
		}

Measured memory_bytes: 2728
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, M := sc.nextInt(), sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < M; i++ {
		x, y := sc.nextInt()-1, sc.nextInt()-1
		G[x] = append(G[x], y)
	}
	done := make([]bool, N)
	d := make([]int, N)
	var search func(cur int) int
	search = func(cur int) int {
		res := 0
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !done[next] {
				r := search(next) + 1
				if res < r {
					res = r
				}
			} else {
				if res < d[next]+1 {
					res = d[next] + 1
				}
			}
		}
		done[cur] = true
		d[cur] = res
		return res
	}
	ans := 0
	for i := 0; i < N; i++ {
		if !done[i] {
			search(i)
		}
		if ans < d[i] {
			ans = d[i]
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 22784
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define up(x,y) (x<y?x=y:0)
#define dn(x,y) (x>y?x=y:0)
#define ad(x,y) (x=(x+(y))%M)
#define mu(x,y) (x=x*(y)%M)
#define fi first
#define se second
#define pq priority_queue
#define br putchar('\n')
#define pb push_back
#define isinf(x) (x>=INF?-1:x)

using namespace std;

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

inline ll read()
{
    char c;ll out=0,f=1;
    for (c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());if (c=='-'){f=-1;c=getchar();}
    for (;c>='0'&&c<='9';c=getchar()){out=(out<<3)+(out<<1)+c-'0';}return out*f;
}
void write(ll x)
{
	if (x<0){putchar('-');write(-x);return;}
    if (x>9){write(x/10);}putchar(x%10+'0');
}

const int N=200010;

set<int> g[N];
int h,w,n,ans=0x7fffffff;

int main()
{
	int i,x,y;
	
	h=read();
	w=read();
	n=read();
	
	for (i=1;i<=w;++i)
	{
		g[i].insert(h+1);
	}
	for (i=1;i<=h+1;++i)
	{
		g[w+1].insert(i);
	}
	
	for (i=1;i<=n;++i)
	{
		x=read();
		y=read();
		g[y].insert(x);
	}
	
	dn(ans,*g[1].lower_bound(1)-1);
	for (x=2,y=1;x<ans;++x)
	{
		if (g[y+1].find(x)==g[y+1].end())
		{
			++y;
		}
		dn(ans,*g[y].lower_bound(x)-1);
	}
	
	cout<<ans;
	
	return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int X; cin >> X;
  YES(X==7 or X==5 or X==3);

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Deadly Dice Game
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), T = sc.nextInt();
			if((n|T)==0)break;
			char[] a = sc.next().toCharArray();
			double[][] dp = new double[n][2];
			for(int i=0;i<n;i++)dp[i][0]=a[i]=='R'?1:0;
			int x = 1;
			for(int t=1;t<=T;t++,x=1-x)for(int i=0;i<n;i++){
				double p = 0;
				for(int k=1;k<7;k++)p+=dp[(i+k)%n][1-x]/6;
				dp[i][x] = p;
			}
			double res = 0;
			for(int i=0;i<n;i++)res= Math.max(res, dp[i][1-x]);
			System.out.printf("%.9f\n", res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int sufr[n],sufg[n],sufb[n];
    fr(i,0,n){
        sufr[i]=sufg[i]=sufb[i]= 0;
    }
    fr(i,0,n){
        if(s[i]=='R')
        sufr[i]=1;
        else if(s[i]=='G')
        sufg[i]=1;
        else
        sufb[i]=1;
    }
    fb(i,n-2,0){
        sufr[i]+=sufr[i+1];
        sufg[i]+=sufg[i+1];
        sufb[i]+=sufb[i+1];
    }
    /*
    cout<<"sufr: ";
    fr(i,0,n)
    cout<<sufr[i]<<" ";
    cout<<endl;
    */
    ll ans=0;
    fr(i,0,n-2){
        fr(j,i+1,n-1){
            if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R')){

                ans+=sufb[j+1];
                if(j+j-i<n&&(s[j+j-i]=='B'))
                ans--;
            }
            if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R')){
                ans+=sufg[j+1];
                if(j+j-i<n&&(s[j+j-i]=='G'))
                ans--;
            }
            if((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B')){
                ans+=sufr[j+1];
                if(j+j-i<n&&(s[j+j-i]=='R'))
                ans--;
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3712
def main():
    a, b = map( int, input().split())
    if a > 0:
        print("Positive")
        return
    if a <= 0 and b >= 0:
        print("Zero")
        return
    if (b-a+1)%2 == 0:
        print("Positive")
    else:
        print("Negative")
if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
INF = 10 ** 7
n, m = gets.split.map(&:to_i)
edges = []
m.times do
  a, b = gets.split.map(&:to_i).map(&:pred)
  a, b = b, a if a > b
  edges << [a, b]
end
edges.sort! { |a, b| (a[0] <=> b[0]).nonzero? || (b[1] <=> a[1]) }
ngs = Hash.new(INF)
edges.each do |from, to|
  ngs[from] = to if ngs[from] > to
end
nearest_ng = INF
ans = 0
n.times do |i|
  if nearest_ng <= i
    ans += 1
    nearest_ng  = INF
  end
  nearest_ng = ngs[i] if nearest_ng > ngs[i]
end
puts ans


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

#define N 100

static int d[ N + 1 ];
static int n;

int
judge (
  const int *d
  )
{
  int i;

  for ( i = 2; i < n; ++i )
  {
    if ( d[ i - 1 ] - d[ i - 2 ] != d[ i ] - d[ i - 1 ] )
      return ( 0 );
  }

  return ( 1 );
}

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i, j;

  for ( ; ; )
  {
    scanf ( "%d", &n );
    if ( n == 0 ) break ;
    for ( i = 0; i <= n; ++i )
      scanf ( "%d", &d[ i ] );
    
    for ( i = 0; i <= n; ++i )
    {
      int t[ N ];
      int sp = 0;

      for ( j = 0; j <= n; ++j )
      {
        if ( j == i ) continue ;

        t[ sp++ ] = d[ j ];
      }

      if ( judge ( t ) )
      {
        printf ( "%d\n", d[ i ] );
        break ;
      }
    }
  }

  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 600
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int inf=1e8,maxn=305;
inline int read(){int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}
int n,m,ans,cnt[maxn],a[maxn][maxn];
bool cho[maxn];
inline void init(){
	n=read(); m=read();
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			a[i][j]=read();
		}
	}
	ans=inf;
	memset(cho,1,sizeof(cho));
	for (int k=1;k<=m;k++){
		memset(cnt,0,sizeof(cnt));
		for (int i=1;i<=n;i++){
			for (int j=1;j<=m;j++){
				if (cho[a[i][j]]){
					cnt[a[i][j]]++;
					break;
				}
			}
		}
		int mx=0;
		for (int i=1;i<=m;i++){
			if ((!mx)||(mx&&cnt[mx]<cnt[i])){
				mx=i;
			}
		}
		cho[mx]=0;
		ans=min(cnt[mx],ans);
	}
	printf("%d\n",ans);
}
int main(){
	init();
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

string S;
ll K;

int main() {
    cin >> S;
    cin >> K;
    if (K == 1) {
        cout << S[0] << endl;
        return 0;
    }
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != '1' && K - 1 >= i) {
            cout << S[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define endl "\n"
#include <map>
#include <numeric>
#include <stack>
#define ll long long int
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s, t;
    cin >> s >> t;
    int cnt=0, n=s.size();
    for(int i=0; i<n; ++i)
    {
        if(s[i]!=t[i])
        {
            ++cnt;
        }
    }cout << cnt;

    //1 3 1 5 3 6
    //2 6 5 4 2 4//

	return 0;
}


Measured memory_bytes: 3736
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#include <cassert>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET{IOSET(){cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main Code
int main() {
    int x;
    cin >> x;
    cout << (x >= 30 ? "Yes\n" : "No\n");
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int>vec(n);
  for (int i = 0 ; i < n ; i++){
    cin >> vec.at(i);
  }
  int s = 0;
  s += vec.at(0);
  for (int j = 1; j < n; j++){
    if (vec.at(j) > vec.at (j-1)){
      s += vec.at(j) - vec.at(j-1);
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc001 D
"""

n, m = map(int, input().split())
ali = list(map(int, input().split()))

if m == 1 and ali[0] == 1:
    print(1)
    print(1)
    print(1)
    exit()

if m == 1:
    print(ali[0])
    print(2)
    print(ali[0]-1, 1)
    exit()

flag = 0
c = []
for a in ali:
    if a % 2 == 1:
        if flag == 0:
            lm = a
            flag += 1
        elif flag == 1:
            rm = a
            flag += 1
        elif flag == 2:
            print('Impossible')
            exit()
    else:
        c.append(a)

if flag == 0:
    lm = c[0]
    del c[0]
    rm = c.pop()

if flag == 1:
    rm = c.pop()

b = [lm+1] + c
d = [lm] + c + [rm]

if rm > 1:
    b.append(rm-1)


print(" ".join(map(str, d)))
print(len(b))
print(" ".join(map(str, b)))


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    ll ans=-1,k;
    cin>>s;
    for(ll i=0;i<(ll)s.length();i++){
        k=0;
        for(ll j=i;j<(ll)s.length();j++){
            if(s[j]=='A' || s[j]=='C' || s[j]=='G' || s[j]=='T')k++;
            else break;
        }
        ans=max(ans,k);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
int main(void){

    int n;
    while(cin>>n,n){

        int a[100050] ={};
        int t = 0;
        int s = 0;
        cin>>s;
        a[0] = 1;
        t++;
        for(int i = 1;i < n;i++){
            int x;
            cin>>x;
            if(i%2 == 1){
                if((t+s)%2 == x){
                    if(t>1){
                        a[t-2] += a[t-1]+1;
                        a[t-1] = 0;
                        t--;
                    }
                    else{
                        a[t-1]++;
                        s = 1 - s;
                    }
                }
                else{
                    a[t-1]++;
                }
            }
            else{
                if((t+s)%2 == x){
                    a[t]++;
                    t++;
                }
                else{
                    a[t-1]++;
                }
            }
        }
        int ans = 0;
        for(int i = 0;i < t;i++){
            if(i%2 == s){
                ans += a[i];
            }
        }
        cout<<ans<<endl;

    }
    return 0;
}

Measured memory_bytes: 1556
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;
struct pos
{
    int x;
    int y;
    long long h;
};

int main(int argc, char const *argv[])
{
    int n;cin>>n;
    long long  x,y,h;
    vector<pos> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i].x>>v[i].y>>v[i].h;
    }
    int ii=0;
    while (v[ii].h==0)ii++;
    vector<pos> ans;
    int num =0 ;
    for(int cx=0;cx<=100;cx++){
        for(int cy=0;cy<=100;cy++){
            long long temp_h;
            temp_h = v[ii].h + abs(v[ii].x-cx) + abs(v[ii].y-cy);
            pos temp;
            temp.x=cx;
            temp.y=cy;
            temp.h=temp_h;
            ans.push_back(temp);
        }
    }
    for(auto a:ans){
        bool is_done = true;
        for(int i=0;i<n;i++){
            if(v[i].h!=max(a.h-abs(a.x-v[i].x)-abs(a.y-v[i].y),0LL)){
                is_done = false;
                break;
            }
        }
        if(is_done){
            cout << a.x << " " << a.y << " " << a.h << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(20);
    int n;cin >> n;
    cout << (n+1)/2 << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define endl '\n'
#define MOD 1000000007
#define MOD2 998244353

using namespace std;
typedef long long int ll;

int dp[100010];

int f(int pos, int h[])
{
	if (pos == 0) return 0;
	int &ret = dp[pos];
	if (ret != -1) return ret;
	ret = 1000000001;
	if (pos > 0) ret = min(ret, abs(h[pos]-h[pos-1]) + f(pos-1, h));
	if (pos > 1) ret = min(ret, abs(h[pos]-h[pos-2]) + f(pos-2, h));
	return ret;
}

int main(void)
{
	fast;
	#ifndef ONLINE_JUDGE
	// freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
	#endif

	int n; cin >> n;
	int h[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}
	memset(dp, -1, sizeof dp);
	cout << f(n-1, h);
}

Measured memory_bytes: 7296
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <memory.h>
#include <math.h>
#include <queue>
#include <map>
#include <stack>
#include <bitset>

#define INFI 0x7fffffff

using namespace std;

#define MAXN 40010


int main()
{
    string buf;
    cin>>buf;
    buf.insert(4," ");
    cout<<buf<<endl;
    return 0;
}


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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int n,a,b;
int main() {
	read(n);read(a);read(b);
	if(a%2 == b%2){
		cout<<"Alice\n";
	}else{
		cout<<"Borys\n";
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int D = nextInt();
		String ans = "";
		if(D==25){
			ans="Christmas";
		}else if(D==24){
			ans="Christmas Eve";
		}else if(D==23){
			ans="Christmas Eve Eve";

		}else {
			ans="Christmas Eve Eve Eve";

		}




		System.out.println(ans);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21076
using System;
using System.Linq;
using System.Collections.Generic;
 
namespace ConsoleApp1 {
    public class Class1 {
        static void Main(string[] args) {
            var X = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
            var a = X[0];
            var b = X[1];
            var c = X[2];
            if (4 * a * b < (c - a - b) * (c - a - b) && (c - a - b) > 0) {
                Console.Write("Yes");
            } else {
                Console.Write("No");
            }
        }
    }
}

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

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (u == s) {
    a = a-1;
  } else if (u == t) {
    b = b-1;
  }

 printf("%d %d", a, b);
  return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 100007;
int n, m;
string s;
int dest[N];
vector<int> ans;

int32_t main() {

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

    cin >> n >> m >> s;
    
    int i = max(0LL, n-m);
    ans.push_back(n);
    int prev = n;
    while(prev > 0) {
        while(s[i] == '1') i++;
        if(prev == i) {
            cout << -1 << endl;
            exit(0);
        }
        ans.push_back(i);
        prev = i;
        i = max(0LL, i-m);
    }

    reverse(ans.begin(), ans.end());
    for(int i = 1; i < (int)ans.size(); ++i) {
        cout << ans[i] - ans[i-1] << ' ';
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 1480
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def main():
    import sys
    read = sys.stdin.read
    N, K = (int(i) for i in input().split())
    A = [int(s) for s in read().rstrip().split('\n')]
    from itertools import accumulate
    S = list(accumulate([0] + A))
    B = [s - K*i for i, s in enumerate(S)]
    c = {b: i+1 for i, b in enumerate(sorted(set(B)))}
    f = Bit(N+1)
    ans = 0
    for j in range(N+1):
        ans += f.sum(c[B[j]])
        f.add(c[B[j]], 1)
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

    s[3] = '8';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3504
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    string a,b;
    cin >> a >> b;
    if(a=="H" && b=="H") cout << "H" << endl;
    if(a=="H" && b=="D") cout << "D" << endl;
    if(a=="D" && b=="H") cout << "D" << endl;
    if(a=="D" && b=="D") cout << "H" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
using namespace std;
int main () {
	int N;
	cin >> N;
std::vector<pair<int,int>> red(N);
std::vector<pair<int,int>> blue(N);
	for (int i = 0; i < N; ++i)
	{
		int x,y;
		cin >> x >> y;
		red[i] = make_pair(x,y);
	}
	for (int i = 0; i < N; ++i)
	{
		int x,y;
		cin >> x >> y;
		blue[i] = make_pair(x,y);
	}
	sort(red.begin(), red.end());
	std::sort(blue.begin(), blue.end(), [](auto &left, auto &right) {
    return left.second < right.second;
});
	reverse(red.begin(), red.end());
	//reverse(blue.begin(), blue.end());
	int count = 0;
	for (int bi = 0; bi < N; ++bi)
	{
		int target = -1;
		for (int ri = 0; ri < N; ++ri)
		{
			if(blue[bi].first > red[ri].first){
				if(blue[bi].second > red[ri].second){
					if(target == -1 || red[target].second < red[ri].second){
						target = ri;
					}
				}
			}
			if(target != -1){
				count++;
				red[target] = make_pair(2 * N + 1,2 * N + 1);
                break;
			}
		}
	}
	cout << count << endl;
}

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

using VVP = vector<vector<P>>;

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

int main(){
    int A,B,M;
    cin >> A >> B >> M;
    VI a(A), b(B);
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    
    VVP coupon(A);
    rep(i,M){
        int x,y,c;
        cin >> x >> y >> c;
        P pair;
        pair.first = y-1; pair.second = c;
        coupon[x-1].push_back(pair);
    }

    int bmin_id = (int)(min_element(b.begin(), b.end()) - b.begin());
    int bmin = b[bmin_id];

    int ans = 1000000;
    rep(i,A){
        chmin(ans, a[i] + bmin);
        for(auto x : coupon[i]){
            int y = x.first;
            int c = x.second;
            chmin(ans, a[i]+b[y]-c);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5504
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    sushi = ["a"]
    alt = [chr(ord("a") + i) for i in range(n)]
    for i in range(n-1):
        sushi = [ans + x for ans in sushi for x in alt[:len(set(ans)) + 1]]
    for i in sushi:
        print(i)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 19904
/**
 * @brief  0-1ナップサック問題(0-1 knapsack problem)は次の問題である
 *
 *         泥棒がある店に盗みに入ってn個の品物を見つけた. i番目の品物はviドルの価値があり、重さはwiポンドである
 *         ただし、viとwiは整数である. 彼はできるだけ高価な品物を盗りたいが、彼のナップサックでは高々Wポンド(Wは整数)の荷物しか運べない
 *
 *         各品物は盗るか残すかのどちらかなので、この問題は0-1ナップサック問題と呼ばれる
 *         この泥棒は品物の一部だけを盗ったり、同じものを複数回盗ることはできない
 *
 * @note   n個の各品物について、「盗る」か「残す」かの組み合わせをすべて調べるアルゴリズムの計算効率はΟ(2^n)となってしまい、　
 *         大きな入力nに対して解くことができないが、品物の大きさw, ナップサックの大きさWがともに整数であれば、
 *         0-1ナップサック問題は動的計画法によりΟ(nW)の計算効率で厳密解を求めることができる
 *
 * @note   次のような変数を用意する
 *
 *           v[n+1]       i番目の品物の価値が記録されている1次元配列
 *           w[n+1]       i番目の品物の重さが記録されている1次元配列
 *           C[n+1][W+1]  i個目までの品物を考慮して大きさjのナップサックに入れる場合の価値の合計の最大値をC[i][j]とする2次元配列
 *
 *         考慮する品物の数i, 各iにおけるナップサックの重さjを増やしていき、C[i][j]を変更していく. C[i][j]の値は、
 *
 *           1. C[i - 1][j - 品物iの重さ] + 品物iの価値
 *           2. C[i - 1][j]
 *
 *         の大きい方となる. ここで1.はこの時点で品物iを盗る、2.はこの時点で品物iを残す、という処理に対応する
 *         ただし、1.の場合は、品物iの重さがjを超えない場合に限る
 *
 * @date   2016/05/05
 */



//********************************************************************************
// 必要なヘッダファイルのインクルード
//********************************************************************************

#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>



//********************************************************************************
// 型シノニム
//********************************************************************************

using index_t  = std::int_fast32_t;
using value_t  = std::int_fast32_t;
using weight_t = std::int_fast32_t;

using indices_t = std::vector<index_t>;
using values_t  = std::vector<value_t>;
using weights_t = std::vector<weight_t>;

using dptbl_t   = std::vector<values_t>;



//********************************************************************************
// 関数の定義
//********************************************************************************

/**
 * @brief  動的計画法を用いて0-1ナップサック問題(0-1 knapsack problem)を解きます
 *
 * @param  const value_t& v i番目の品物の価値が記録されている1次元配列v
 * @param  const value_t& w i番目の品物の重さが記録されている1次元配列w
 * @param  weight_t       W ナップサックに詰めこめる最大の重さW
 */
value_t __01_knapsack__(const values_t& v, const weights_t& w, weight_t W)
{    
    index_t n = v.size();              // n = v.length
    dptbl_t C(n+1, values_t(W+1, 0));  // Cを(n+1) x (W+1)型の新しい行列とする

    for (index_t i = 1; i <= n; i++) {

        for (weight_t j = 1; j <= W; j++) {

            if (w[i] <= j) {
                C[i][j] = std::max(C[i - 1][j - w[i]] + v[i], C[i - 1][j]);
            }
            else {
                C[i][j] = C[i - 1][j];
            }
        }
    }
    
    return C[n][W];
}



//********************************************************************************
// エントリポイント
//********************************************************************************

int main()
{
    using namespace std;

    int n, W;
    cin >> n >> W;
    
    values_t  v(n + 1, 0);
    weights_t w(n + 1, 0);

    for (int i = 1; i <= n; i++) {
        cin >> v[i] >> w[i];
    }
    
    cout << __01_knapsack__(v, w, W) << endl;
    
    
    return 0;
}

Measured memory_bytes: 10700
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,k,q,i,ind,a[200000];
	cin>>n>>k>>q;
	for(i=1;i<=n;i++) a[i]=(-1)*q;
	for(i=0;i<q;i++) {
		cin>>ind;
		a[ind]++;
	}
	for(i=1;i<=n;i++) {
		if(a[i]<=(-1)*k) cout<<"No\n";
		else cout<<"Yes\n";
	}
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>

using namespace std;

char s[25];
int n, l; 

int calc1(){
	char last = '+';
	int l = strlen(s);
	int ret = 0; 
	for(int i = 0; i < l; i += 2){
		int d = s[i] - '0';
		if(last == '+') ret += d;
		else ret *= d;
		last = s[i + 1]; 
	}
	return ret;
} 

int calc2(){
	char last = '*';
	int ret = 0, mul = 1;
	int l = strlen(s);
	for(int i = 0; i < l; i += 2){
		int d = s[i] - '0';
		if(last == '+') ret += mul, mul = d;
		else mul *= d;
		//printf("mul = %d ret = %d\n", mul, ret);
		last = s[i + 1];
	} 
	ret += mul;
	return ret;
}

int main(){
	while(scanf("%s%d", s, &n) == 2) {
		int l = strlen(s); s[l] = '+'; s[l + 1] = 0; 
		int ans1 = calc1(), ans2 = calc2();
		//printf("%d %d\n", ans1, ans2);
		if(ans1 == n && ans2 == n) puts("U");
		else if(ans1 != n && ans2 != n) puts("I");
		else if(ans1 == n) puts("L");
		else puts("M"); 
		
	}
	return 0;
} 

Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

	ll a[3];
	rep(i, 3) cin >> a[i];

	ll b[3];
	rep(i, 3) cin >> b[i];

	vector<vector<ll>> dp(4, vector<ll>(n+1, 0));
	dp[0][0] = n;
	
	rep(i, 3){
		rep(j, n+1) {
			chmax(dp[i+1][j], dp[i][j]);
			if(j-a[i] >= 0) chmax(dp[i+1][j], dp[i+1][j-a[i]] + b[i] - a[i]); 
		}
	}

	ll m = 0;
	rep(j, n+1) chmax(m, dp[3][j]);

	vector<vector<ll>> dp2(4, vector<ll>(m+1, 0));
	dp2[0][0] = m;

	rep(i, 3){
		rep(j, m+1){
			chmax(dp2[i+1][j], dp2[i][j]);
			if(j-b[i] >= 0) chmax(dp2[i+1][j], dp2[i+1][j-b[i]] + a[i] - b[i]);
		}
	}

	ll ans = 0;
	rep(j, m+1) chmax(ans, dp2[3][j]);
	cout << ans << endl;
}


Measured memory_bytes: 979976
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x; cin >> x;
    cout << (x == 0 ? 1 : 0) << '\n';
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    VI a(n), b(m);
    REP(i,n) cin >> a[i];
    REP(i,m) cin >> b[i];
    int p = *max_element(ALL(a));
    int q = *min_element(ALL(b));

    FOR(i,x+1,y){
        if (i > p && i <= q){
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;

    return 0;
}


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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

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

inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int MAXN=3e5+5,MOD=1e9+7;
int mp[8][2],dp[MAXN][8];
inline void add(int &x,int y){x=((x+y<MOD)?x+y:x+y-MOD);}
int main() {
	mp[0][1]=1;
	mp[0][0]=2;
	mp[1][1]=3;
	mp[1][0]=4;
	mp[2][1]=5;
	mp[2][0]=6;
	mp[3][1]=3;
	mp[3][0]=3;
	mp[4][1]=1;
	mp[4][0]=7;
	mp[5][1]=1;
	mp[5][0]=2;
	mp[6][1]=2;
	mp[6][0]=2;
	mp[7][1]=4;
	mp[7][0]=4;
	string s;
	cin>>s;
	s="@"+s;
	dp[0][0]=1;
	for(int i=1;i<(int)s.length();++i){
		if(s[i]=='0'){
			for(int j=0;j<8;++j){
				add(dp[i][mp[j][0]],dp[i-1][j]);
			}
		}
		else if(s[i]=='1'){
			for(int j=0;j<8;++j){
				add(dp[i][mp[j][1]],dp[i-1][j]);
			}
		}
		else{
			for(int j=0;j<8;++j){
				add(dp[i][mp[j][0]],dp[i-1][j]);
				add(dp[i][mp[j][1]],dp[i-1][j]);
			}
		}
	}
	cout<<(dp[s.length()-1][1]+dp[s.length()-1][3])%MOD<<endl;
	return 0;
}

Measured memory_bytes: 10076
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;


int main(){
  int N,C[510],S[510],F[510];
  ll now=0;
  cin>>N;
  for(int i=0;i<N-1;i++){
    cin>>C[i]>>S[i]>>F[i];
  }

  for(int i=0;i<N-1;i++,now=0){
    now=S[i]+C[i];
    for(int j=i+1;j<N-1;j++){
      if(now<=S[j]) now=S[j];
      else{
        if(now%F[j]!=0) now+=F[j]-now%F[j];
      }
      now+=C[j];
    }
    cout<<now<<endl;
  }
  cout<<0<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100000

int main (void)
{
  int i,j=0,a,b,x,y,d[MAX],gcd;
  
  scanf ("%d %d",&x,&y);
  
  if (x > y){
    a = y;
    b = x;
  }else{
    a = x;
    b = y;
  }
  if (a == b)
    gcd = a;
  else{
    for (i = 1 ; i <= (b % a) ; i++){
      if ((b % a) % i == 0){
	d[j] = (b % a)/i;
	j++;
      }
    }
    for (j = 0 ; j <= (b % a) ; j++){
      if (d[j] <= a && a%d[j] == 0){
	gcd = d[j];
	break;
      }
      else continue;
    }
  }
  printf ("%d\n",gcd);
  
  return 0;
}

Measured memory_bytes: 600
import heapq

N, M = map(int, input().split())
A = list(map(lambda x:[-int(x),int(x)], input().split()))
heapq.heapify(A)

for m in range(M):
  x = heapq.heappop(A)
  x[1] //= 2
  x[0] = -x[1]
  heapq.heappush(A, x)
ans = 0
for a in A:
  ans += a[1]
print(ans)


Measured memory_bytes: 27408
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n;
      ll a[n];
      for(int i=0;i<n;i++){
        cin>>a[i];
      }
      ll ans=0;
      for(int i=2;i<n;i++){
        for(int j=1;j<i;j++){
          for(int k=0;k<j;k++){
            if(a[i]<a[j]+a[k] && a[j]<a[i]+a[k] && a[k]<a[j]+a[i]) 
              ans+=(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i]);
          }
        }
      }
      cout<<ans;
}

Measured memory_bytes: 3604
/**
 * @brief AtCoder Beginner Contest 088<br>
 * D - Grid Repainting
 *
 * BFSパターン
 * @see https://atcoder.jp/contests/abc088/tasks/abc088_d
 */
#include <iostream>
#include <queue>
using namespace std;

using P = pair<int, int>;
constexpr int MAX_H = 50;
constexpr int MAX_W = 50;

int H, W;
string maze[MAX_H];
int cnt[MAX_H][MAX_W];
int white_num;

int dh[]{-1, 0, 1, 0};
int dw[]{0, -1, 0, 1};

int bfs(int h, int w) {
  queue<P> que;
  cnt[h][w] = 1;
  que.push(P(h, w));

  while (!que.empty()) {
    P p = que.front();
    que.pop();
    int count = cnt[p.first][p.second];
    if (p.first == H - 1 && p.second == W - 1)
      return white_num - count;

    ++count;
    for (int i{}; i < 4; ++i) {
      int nh = p.first + dh[i];
      int nw = p.second + dw[i];
      if (nh < 0 || nh >= H ||
          nw < 0 || nw >= W ||
          cnt[nh][nw] >= 0 ||
          maze[nh][nw] == '#')
        continue;
      cnt[nh][nw] = count;
      que.push(P(nh, nw));
    }
  }

  return -1;
}

int main() {
  cin >> H >> W;
  for (int h{}; h < H; ++h) {
    cin >> maze[h];
    for (int w{}; w < W; ++w) {
      cnt[h][w] = -1;
      if (maze[h][w] == '.')
        ++white_num;
    }
  }

  cout << bfs(0, 0) << endl;
  return 0;
}


Measured memory_bytes: 256