akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>

int testcase_ends() {
  int n;
  scanf("%d", &n);

  if (n == 0)
    return 1;

  std::vector<int> total(1000);
  std::vector<int> prog(1000, -1);
  int lastday=0;
  bool blessed=false;

  for (int i=0; i<n; ++i) {
    int M, D, h, m, p;
    char e;
    scanf("%d/%d %d:%d %c %d", &M, &D, &h, &m, &e, &p);
    
    int today=100*M+D;
    if (lastday != today) {
      prog.assign(1000, -1);
      lastday = today;
    }

    int time=60*h+m;

    //fprintf(stderr, "%02d/%02d %02d:%02d\n", M, D, h, m);
    if (p == 0) {
      if (e == 'I') {
	blessed = true;
	for (int j=1; j<1000; ++j) {
	  if (prog[j] >= 0) {
	    prog[j] = time;
	  }
	}
      } else if (e == 'O') {
	blessed = false;
	for (int j=1; j<1000; ++j) {
	  if (prog[j] >= 0) {
	    total[j] += time - prog[j];
	    //fprintf(stderr, "0 %d: +%02d\n", j, time-prog[j]);
	    prog[j] = time;
	  }
	}
      }

      continue;
    }


    if (e == 'I') {
      prog[p] = time;
    } else if (e == 'O') {
      if (blessed) {
	total[p] += time - prog[p];
	//fprintf(stderr, "1 %d: +%02d\n", p, time-prog[p]);
      }
      prog[p] = -1;
    }
  }

  printf("%d\n", *std::max_element(total.begin()+1, total.end()));
  return 0;
}

int main() {
  while (!testcase_ends()) {}

  return 0;
}

Measured memory_bytes: 2708
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main()
{string s ;
 cin >> s ;
 
 bool c = false ;
 if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) c = true;
  if (s [0] == s[2] && s[1] == s[3] && s[1] != s[2]) c = true;
 if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) c = true;
  
  
  cout << ( c ? "Yes" : "No" ) << endl;
  
  
  
  
  
  
  
  
  
  
  
  
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F(a,b,c,d) for (register int a=b;a<=c;a+=d)
#define FD(a,b,c,d) for (register int a=b;a>=c;a-=d)
using namespace std;
struct node {
	int x,y;
}a[100000+10];
int n,m,ans;
bool cmp(node a,node b)
{
	if (a.x!=b.x) return a.x<b.x;
	return a.y>b.y;
}
int main(){
	cin>>n>>m;
	for (int i=1;i<=m;i++)
	{
		cin>>a[i].x>>a[i].y;
	}
	sort(a+1,a+m+1,cmp);
	int l=0,r=n;
	for (int i=1;i<=m;i++)
	{
		if (a[i].x<r)
		{
			l=max(a[i].x,l);
			r=min(r,a[i].y);
		}
		else 
		{
			ans++;
			l=a[i].x;
			r=a[i].y;
		}
	}
	cout<<ans+1<<endl;
	return 0;
}



Measured memory_bytes: 1024
def main():
    n_ansl = [0]*(2*(10**5))
    for i in range(1,2*(10**5)):
    # for i in range(1,20):
        cnt = 0
        one_cnt = bin(i).count("1")
        rem = i
        while rem != 0:
            one_cnt = bin(rem).count("1")
            rem = rem%one_cnt   
            cnt += 1
        n_ansl[i] = cnt
 
    n = int(input())
    x = input()
    one_cnt = x.count('1')

    if one_cnt == 0:
        for i in range(n):
            print(1)
        exit()
    
    curr_2b = 1
    curr_2b_p = 1
    curr_2b_m = 1
    curr_sum = 0
    curr_sum_p1 = 0
    curr_sum_m1 = 0
    for i in range(n-1, -1, -1):
        if x[i] == '1':
            curr_sum += curr_2b
            curr_sum_p1 += curr_2b_p
            curr_sum_m1 += curr_2b_m
            curr_sum%=one_cnt
            curr_sum_p1%=(one_cnt+1)
            if one_cnt > 1:
                curr_sum_m1%=(one_cnt-1)
        curr_2b*=2
        curr_2b_p*=2
        curr_2b_m*=2
        curr_2b%=one_cnt
        curr_2b_p%=(one_cnt+1)
        if one_cnt > 1:
            curr_2b_m%=(one_cnt-1)
 
        
 
    curr_2b = 1
    curr_2b_p = 1
    curr_2b_m = 1
    ansl = [0]*(n)
    for i in range(n-1, -1, -1):
        if x[i] == '1':
            diff = (-1)*curr_2b_m
            if one_cnt > 1:
                ans = (curr_sum_m1 + diff)%(one_cnt-1)
                ansl[i] = n_ansl[ans]+1
            else:
                ansl[i] = 0
        else:
            diff = curr_2b_p
            ans = (curr_sum_p1 + diff)%(one_cnt+1)
            ansl[i] = (n_ansl[ans]+1)
        # curr_2b *= 2
        curr_2b*=2
        curr_2b_p*=2
        curr_2b_m*=2
        curr_2b%=one_cnt
        curr_2b_p%=(one_cnt+1)
        if one_cnt > 1:
            curr_2b_m%=(one_cnt-1)
 
 
    # print(ansl)
    for a in ansl:
        print(a)
 
if __name__ == "__main__":
    main()

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

template<typename T>
T kiriage(T a, T b)
{
	return (a + b - 1) / b;
}

void Main()
{
	vector<int> vec(5);
	rep(i,5) cin >> vec[i];
	int mod_min = 10;
	int last_idx = - 1;
	rep(i,5) {
		if (vec[i] % 10 == 0) continue; 
		if (mod_min > vec[i] % 10) {
			mod_min = vec[i] % 10;
			last_idx = i;
		}
	}
	int res = 0;
	rep(i,5) {
		if (i == last_idx) res += vec[i];
		else res += kiriage(vec[i], 10) * 10;
	}
	cout << res << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};

function main(input) {
  const o = new I(input, String);

  var s = o.a();

  var s1 = "01".repeat(Math.floor(s.length / 2));
  s1 += (s.length % 2) === 0 ? "" : "0"; //01010
  var s2 = "10".repeat(Math.floor(s.length / 2)); //01010
  s2 += (s.length) % 2 === 0 ? "" : "1";

  var s1c = 0;
  var s2c = 0;
  for (var i = 0; i <s.length; i++) {
    if(s[i]!== s1[i]) s1c+=1;
    if(s[i]!== s2[i]) s2c+=1;
  }
  console.log(Math.min(s1c,s2c));
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;
using ll = long long;
using vec = vector<int>;

#define rep(i, n)  for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)

const int INF = 2147483647;
const ll  MOD = 1000000007;

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

    ll r = 0, g = 0, b = 0;
    for(auto i : s) {
        if(i == 'R') r++;
        else if(i == 'G') g++;
        else b++;
    }

    // 全パターンを計上
    ll ans = r * g * b;

    for(int i = 0; i < n; ++i) {
        // 同間隔で条件を満たすなら除く
        for(int d = 0; d < n; ++d) {
            int j = i+d;
            int k = j+d;

            if(k >= n) break;

            if((s[i] != s[j]) && (s[j] != s[k]) && (s[i] != s[k])) --ans;
        }
    }

    cout << ans;
}

Measured memory_bytes: 3640
#include<cstdio>
#define INF (2100000000)
#define NMAX 100
int path[NMAX][NMAX];
int n;

bool floyd(){
    for(char k=0;k<n;k++){
        for(char i=0;i<n;i++){
            if(path[i][k]==INF)
                continue;
            for(char j=0;j<n;j++){
                if(path[k][j]==INF)
                    continue;
                int temp = path[i][k]+path[k][j];
                path[i][j] = (path[i][j] < temp)? path[i][j]:temp;
                if(i==j&&temp<0)
                    return false;
            }
        }
    }
}

int main(){
    int i, j;
    int weight;
    short edge;
    scanf("%d%d", &n, &edge);
    for(i=0;i<n;i++)//initial
        for(j=0;j<n;j++)
            path[i][j] = (i==j) ? 0 : INF;
    while(edge--){
        scanf("%d%d%d", &i, &j, &weight);
        path[i][j] = weight;
    }
    if(floyd()){
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                if(j) printf(" ");
                if(path[i][j]==INF) printf("INF");
                else printf("%d", path[i][j]);
            }
            printf("\n");
        }
    }else{
        printf("NEGATIVE CYCLE\n");
    }
    return 0;
}



Measured memory_bytes: 2796
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit = {
    while (sc.hasNext) {
      val name = sc.next
      val a, b = sc.nextInt
      println(name + " " + (a + b) + " " + (a * 200 + b * 300))
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 45044
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> price(N);
  
  int sum=0;
  for(int i=0;i<N;i++){
  cin>>price.at(i);
  }
  sort(price.begin(),price.end());
  reverse(price.begin(),price.end());
  
  for(int i=0;i<N;i++){
    sum +=price.at(i);

  }
  cout<<sum-(price.at(0))/2<<endl;


   }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n=0;
  long long ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    if((i+1)%3!=0&&(i+1)%5!=0){
      ans=ans+i+1;
    }
  }
  cout<<ans;
}

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

#define NMIN 1
#define NMAX 36

struct Card{
char name;
char value;  
};


void bubble(struct Card A[],int N){
  int i,j;
  struct Card t;
  for(i=0;i<N;i++)
    for(j=N-1;j>=i;j--)
      if(A[j].value < A[j-1].value){
	t = A[j];
	A[j] = A[j-1];
	A[j-1] = t;
      } 
  
}

void selection(struct Card A[],int N){
  int i,j,minj;
  struct Card t;
  for(i=0;i<N;i++){
    minj=i; 
    for(j=i;j<N;j++){
      if(A[j].value<A[minj].value) minj=j;
    }
    t=A[i];
    A[i]=A[minj];
    A[minj]=t;
  }
}

void print(struct Card A[],int N){
  int i;
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%c%c",A[i].name,A[i].value);
  }
  printf("\n");
}

int isStable(struct Card C1[],struct Card C2[],int N){
  int i;
  for(i=0;i<N;i++){
    if(C1[i].name != C2[i].name) return 0;
  }
  return 1;
}



int main(){
  int N,i,j;
  struct Card C1[NMAX],C2[NMAX];
  char ch;
  
  scanf("%d",&N);
  
  if(N<NMIN||N>NMAX) exit(1);
  
  for(i=0;i<N;i++){
    scanf(" %c%c",&C1[i].name,&C1[i].value);
  }
  
  for(i=0;i<N;i++){
    C2[i]=C1[i];
  }
  
  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  printf("Stable\n");
  print(C2,N);
  if(isStable(C1,C2,N)==1){
    printf("Stable\n");
  }
  else{
    printf("Not stable\n");
  }
  
  return 0;
}



Measured memory_bytes: 2144
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class RectangleSum():
    def __init__(self, N, M):
        self.N = N
        self.M = M
        self.s = [[0] * (M+1) for _ in range(N+1)]

    def add(self, i, j, v):
        self.s[i+1][j+1] += v

    def build(self):
        for i in range(self.N+1):
            for j in range(self.M):
                self.s[i][j+1] += self.s[i][j]

        for i in range(self.N):
            for j in range(self.M+1):
                self.s[i+1][j] += self.s[i][j]

    def sum(self, i, j, h, w):
        ret = self.s[i][j]
        ret += self.s[i+h][j+w]
        ret -= self.s[i+h][j]
        ret -= self.s[i][j+w]

        return ret


@mt
def slv(N, M, Q, LR, PQ):
    rs = RectangleSum(N+1, N+1)
    for l, r in LR:
        rs.add(l, r, 1)

    rs.build()

    for p, q in PQ:
        print(rs.sum(p, p, q-p+1, q-p+1))


def main():
    N, M, Q = read_int_n()
    LR = [read_int_n() for _ in range(M)]
    PQ = [read_int_n() for _ in range(Q)]
    slv(N, M, Q, LR, PQ)


if __name__ == '__main__':
    main()


Measured memory_bytes: 79512
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=(b);i>=(a);i--)
typedef long long int lli;
typedef pair<int,int> mp;
typedef pair<int,mp> mmp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX

int n,m,fn,qn;

set<int> sets[100005];

struct unifo{
	int uni[100010];
	void init(int n){
		rep(i,n)uni[i]=i;
	}
	int find(int p){
		if(uni[p]==p)return p;
		else return (uni[p]=find(uni[p]));
	}
	void mer(int p,int q){
		if(!same(p,q))uni[find(p)]=find(q);
	}
	bool same(int p,int q){
		return find(p)==find(q);
	}
};

unifo uni;

vector<mp> vs[100005];
mmp es[200005];
int dist[100005];

priority_queue<mp,vector<mp>,greater<mp> > que;

void dijkstra(){
	reg(i,1,n)dist[i] = IINF;
	
	while(!que.empty()){
		mp pa = que.top();
		que.pop();
		int no = pa.sec,
			co = pa.fir;
		if(dist[no]<=co)continue;
		dist[no] = co;
		rep(i,vs[no].size()){
			mp pb = vs[no][i];
			int to = pb.fir,
				tc = co + pb.sec;
				if(dist[to]<=tc)continue;
			que.push(mp(tc,to));
		}
	}
}

int anss[100005];

int main(void){

	scanf("%d%d%d%d",&n,&m,&fn,&qn);
	uni.init(n+3);
	
	rep(i,m){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		vs[a].push_back(mp(b,c));
		vs[b].push_back(mp(a,c));
		es[i] = mmp(-1,mp(a,b));
	}
	
	rep(i,fn){
		int a;
		scanf("%d",&a);
		que.push(mp(0,a));
	}
	
	rep(i,qn){
		int a,b;
		scanf("%d%d",&a,&b);
		sets[a].insert(i);
		sets[b].insert(i);
	}
	
	dijkstra();
	
	/*
	reg(i,1,n){
		printf("dist .. %d\n",dist[i]);
	}*/
	
	rep(i,m){
		mmp& pa = es[i];
		pa.fir = min(dist[pa.sec.fir],dist[pa.sec.sec]);
		//printf("edgs .. %d %d %d\n",pa.sec.fir,pa.sec.sec,pa.fir);
	}
	
	sort(es,es+m,greater<mmp>());
	
	
	rep(i,m){
		mmp pa = es[i];
		int a = es[i].sec.fir,
			b = es[i].sec.sec,
			d = es[i].fir;
		//printf("edg .. %d %d %d\n",a,b,d);
		a = uni.find(a);
		b = uni.find(b);
		if(uni.same(a,b))continue;
		
		set<int> sa,sb;
		swap(sa,sets[uni.find(a)]);
		swap(sb,sets[uni.find(b)]);
		
		if(sa.size()>sb.size())swap(sa,sb);
		
		set<int>::iterator ite;
		
		for(ite = sa.begin(); ite != sa.end(); ite++){
			int no = *ite;
			//printf("set .. %d no .. %d\n",a,no);
			if(sb.find(no)!=sb.end()){
				//printf("merge %d %d %d\n",a,b,no);
				sb.erase(no);
				anss[no] = d;
			}
			else sb.insert(no);
		}
		
		uni.mer(a,b);
		swap(sb,sets[uni.find(a)]);
	}
	
	rep(i,qn){
		printf("%d\n",anss[i]);
	}
	
	return 0;
}

Measured memory_bytes: 27664
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long ll;
ll dp[21][1 << 21];
int must[21][21];
int mustbe[21][21];
int n, m, k;
ll ans;
int fix(int a, int b) // change first 1 after b to a 0
{
	for (int i = b+1; i <= 20; i++)
	{
		if (a & (1 << i))
		{
			a ^= (1 << i);
			return a;
		}
	}
	return a;
}
int main()
{
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < k; i++)
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		a--;
		b--;
		must[a][b] = 1;
		mustbe[a][b] = c;
	}
	dp[0][0] = 1;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			for (int k = 0; k < (1 << (n-1)); k++)
			{
				if (!dp[j][k]) continue;
				ll am = dp[j][k];
				dp[j][k] = 0;
				am %= mod;
				if (j == n-1)
				{
					if (i == m-1) ans += am;
					else
					{
						dp[0][k] += am;
					}
				}
				else
				{
					int prevmove = !!(k & (1 << j));
					if (must[i][j] && mustbe[i][j] < prevmove) continue;
					int newk = (k | (1 << j));
					if (newk != k) newk = fix(newk, j);
					if (!must[i][j] || mustbe[i][j])
					{
						dp[j+1][newk] += am;
					}
					if (!prevmove && (!must[i][j] || !mustbe[i][j]))
					{
						dp[j+1][k] += am;
					}
				}
			}
		}
	}
	ans %= mod;
	printf("%lld\n", ans);
}


Measured memory_bytes: 123136
#include <iostream>
#include <string>
#include <algorithm>

int main() {
  std::string a, b;
  std::cin >> a >> b;
  std::reverse(b.begin(), b.end());
  if (a == b) std::cout << "YES" << std::endl;
  else std::cout << "NO" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n,y;
    cin>>n>>y;
    y/=1000;
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n-i; j++){
            if((y-10*i-5*j)>=0){
                int k=y-10*i-5*j;
                //cout<<i<<" "<<j<<" "<<k<<endl;
                if(i+j+k!=n && k>=0){
                    continue;
                }
                //cout<<"answer"<<endl;
                cout<<i<<" "<<j<<" "<<k<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
 "fmt"
)

func main(){
	var n int
	fmt.Scanf("%d",&n)
	
	cnt := 0.0
	
	for i:=1; i <= n; i++ {
		if i % 2 != 0 {
			cnt++
		}
	}
		
	ans := float64(cnt) / float64(n)
	
	fmt.Printf("%v",ans)
}


Measured memory_bytes: 512
import sys

N,K,Q=(int(x) for x in input().split())
#Ai=[]
par=[]
for i in range(N):
	par.append(K)

par = [0] * N

for i in range(Q):
	a=int(input())
	par[a-1] += 1 	


#Ai.append(a)
#print(par)
for i in range(N):
	if par[i]+K > Q:
		print("Yes")
	else:
		print("No")
#print(par)

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll n,m,q,T,k;
const ll big = 1000000007ll;

ll F[200001] = {0};
vector<ll> A;

bool comp(ll i,ll j){return F[i] < F[j];}

int main() {
    ll a,b,c,d;

    cin >> n >> k;
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        if(F[a] == 0){
            A.push_back(a);
        }
        F[a]++;
    }

    ll k2 = sz(A);
    sort(all(A),comp);
    ll ans = 0;
    for(ll c1 = 0; c1 < k2-k; c1++){
        ans += F[A[c1]];
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int n,k,a[200],data[200],ans=0,sum=0;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int lim=min(n,k);
	for(int i=0;i<=lim;i++){
		for(int j=0;j<=lim-i;j++){
			int q=0;memset(data,0,sizeof(data)); 
			sum=0;
			for(int i1=0;i1<i;i1++){
				sum+=a[i1];
				data[q++]=a[i1];
			}
			for(int i1=n-1;i1>n-1-j;i1--){
				sum+=a[i1];
				data[q++]=a[i1];
			}
			sort(data,data+q);
			//int rest=lim-(i+j);
			int rest=k-(i+j);
			for(int i1=0;i1<=min(rest,q-1);i1++){
				if(i1!=0){sum-=data[i1-1];}
				if(sum>ans)
					ans=sum;
			}
		} 
	}
	printf("%d\n",ans);	
} 

Measured memory_bytes: 256
s = list(input())
t = input()
ans = False
for i in range(len(s)-len(t), -1, -1):
  temp = s[i:i+len(t)]
  count = 0
  for j in range(len(temp)):
    if temp[j] == t[j] or temp[j] == "?":
      count += 1
    else:
      break
  if count == len(t):
    ans = True
    s[i:i+len(t)] = t
    s = "".join(s).replace('?', 'a')
    print(s)
    break

if not ans:
  print('UNRESTORABLE')

Measured memory_bytes: 3064
import bisect

n=int(input())
a=list(map(int,input().split()))
a.sort()
k=bisect.bisect_left(a,a[-1]/2)

if k==n-1:
    print(a[-1],a[-2])
elif k==0:
    print(a[-1],a[0])
else:
    if a[-1]/2-a[k-1]<a[k]-a[-1]/2:
        k-=1
    print(a[-1],a[k])


Measured memory_bytes: 20136
#!/usr/bin/env python3
import sys


def solve(N: int):
    N = N % 10
    if N in {3}:
        return 'bon'
    elif N in {0, 1, 6, 8}:
        return 'pon'
    elif N in {2, 4, 5, 7, 9}:
        return 'hon'


def main():
    N = int(sys.stdin.readline())  # type: int
    print(solve(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9104
import java.lang.Math.*

fun main(args: Array<String>){
    val N = readLine()!!.toInt()
    val H = Array(N){ readLine()!!.split(" ").map { it.toLong() } }

    loop@ for(i in 0 until 101){
        for(j in 0 until 101){
            val hList = H.filter{ it[2] != 0L }.map { it[2] + abs(i - it[0]) + abs(j - it[1]) }.distinct()
            if(hList.size == 1){
                val h = hList[0]
                H.map { max(h - abs(i - it[0]) - abs(j - it[1]), 0) == it[2] }.all { it }.let {
                    if(it){
                        println("$i $j $h")
                        return
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 53832
import java.util.Scanner;

class Main{
      public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	String number;
    	char[] ca;
    	int num;
    	
    	for(;;){
    		number = scan.next();
    		ca =  number.toCharArray();
    		num = 0;
    		
    		if(ca[0] == '0'){
    			break;
    		}
	    	for(int i = 0; i < ca.length; i++){
	    		num += ca[i] - '0';
	    	}
	    	System.out.println(num);
    	}
     }
}

Measured memory_bytes: 26016
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, m) = input!(usize, usize);
    let mut broken = vec![];
    let mut mins = vec![0; n + 1];

    for i in 0..m {
        let (b,) = input!(usize);
        broken.push(b);
    }

    mins[0] = 1;
    if let Ok(i) = broken.binary_search(&1) {
        mins[1] = 0;
    } else {
        mins[1] = 1;
    }

    for i in 2..(n+1) {
        if let Ok(x) = broken.binary_search(&i) {
            mins[i] = 0;
        } else {
            mins[i] += (mins[i - 1] + mins[i - 2]) % 1_000_000_007;
        }
    }

    println!("{}", mins[n]);
}

fn main() {
    solve();
}


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

int main(){
  int N;
  cin >> N;
  
  if(N%3 == 0){
    cout << N/3 << endl;
  }
  
  else if(N%3 == 1){
    cout << N/3 << endl;
  }
  
  else {
    cout << N/3 << endl;
  }
  
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

bool chk(vll& arr) {
  bool ret = true;
  rep(i, 8) {
    ll y = i + 1;
    ll x = arr[i] + 1;
    // rd
    while(y < 8 && x < 8){
      if (arr[y] == x) ret = false;
      if (!ret) break;
      y++;
      x++;
    }
    // ld
    y = i + 1;
    x = arr[i] - 1;
    if (!ret) break;
    while (y < 8 && 0 <= x) {
      if (arr[y] == x) ret = false;
      if (!ret) break;
      y++;
      x--;
    }    
  } // i
  return ret;
}

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

  vll xs(n);
  vll ys(n);
  rep(i, n) {
    cin >> xs[i] >> ys[i];
  }

  vll arr(8);
  ll ans = 0;
  rep(i, 8) arr[i] = i;
  do {
    bool prec = true;
    rep(i, n) {
      if (arr[xs[i]] != ys[i]) {
        prec = false;
        break;
      }
    }
    if (!prec) continue;

    if (chk(arr)) {
      ans++;
      rep(i,8){
        string s = "........";
        s[arr[i]] = 'Q';
        cout << s << endl;
      }
      //cout << "----" << endl;
    }
  } while (next_permutation(arr.begin(), arr.end()));

  //cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3236
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))

if sum(c1)+sum(c2)+sum(c3) == 3*(c1[0]+c2[1]+c3[2]):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
int main(){
  int q;
  std::cin>>q;
  std::vector<std::string> str1,str2;
  std::string str;
  for(int i=0;i<q;i++){
    std::cin>>str;
    str1.push_back(str);
    std::cin>>str;
    str2.push_back(str);
    //std::cout<<str1[i][0]<<"\n";
    //std::cout<<str2[i][0]<<"\n";
  }
  
 
  for (int i = 0; i < q; i++) {
	  int ans[str1[i].length()+1][str2[i].length()+1];
	  for (int j = 0; j < str1[i].length() + 1; j++) {
		  for (int k = 0; k < str2[i].length() + 1; k++) {
			  
			  if (j == 0 || k == 0) {
				  ans[j][k] = 0;
			  }else {
				  //std::cout << " str1= " << str1[i][j-1] << " str2= " << str2[i][k-1] << " \n ";
				  if (str1[i][j-1] == str2[i][k-1]){
					  //std::cout << "ppp";
					  ans[j][k] = std::max({ ans[j - 1][k - 1] + 1,ans[j - 1][k],ans[j][k - 1] });
					  //ans[j][k] = std::max({ 1,2,3 });
				  }else {
					  ans[j][k] = std::max(ans[j - 1][k], ans[j][k - 1]);
				  }
			  }
			  //std::cout << ans[j][k] << " ";
			  
		  }
		  //std::cout << "\n";
	  }
	  std::cout << ans[str1[i].length()][str2[i].length()] << "\n";
  }
  

  return 0;
}



Measured memory_bytes: 7084
# aaaaabbbbb
# a_a_ab_b_b
# aaaaabbbbb
# a_a_ab_b_b
# aaaaabbbbb

# 51x41 → 25x20の_がくり抜ける
# 51x82

H = 24
W = 49
#H = 3
#W = 4
import numpy as np
X = np.full((W+W+1,2*(H+H+1)),'.',dtype='U1')
A,B = map(int,input().split())

# view
left = X[:,:H+H+1]
right = X[:,H+H+1:]
right[:] = '#'

for symbol,n,view in [['#',B-1,left],['.',A-1,right]]:
  q,r = n//H,n%H
  for i in range(q):
    view[2*i+1,1::2] = symbol
  view[2*q+1,1:1+2*r:2] = symbol

print(2*W+1,4*H+2)
for row in X:
  print(''.join(row))


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;

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

  std::cin >> S;

  std::string T;

  if(S[0] == 'S'){
      T = "Cloudy";
  }else if(S[0] == 'C'){
      T = "Rainy";
  }else{
      T = "Sunny";
  }

  std::cout << T << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast                          \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);

#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>

#define loop(l, r) for(int i = l;i <= r;++i)
#define loopj(l, r) for(int j = l;j <= r;++j)
#define loopStep(l, r, step) for(int i = l;(step >= 0 ? (i <= r) : (i >= r));i += step)
#define loopStepj(l, r, step) for(int j = l;(step >= 0 ? (j <= r) : (j >= r));j += step)
#define loopRange(el, container) for(auto &el : container)

#define test int t;cin >> t; while(t--)

#define ENDL << "\n"

using namespace std;

int main()
{
	fast;

	ull n;
	cin >> n;

	for(ull i = floor(sqrt(n));i >= 1;--i)
	{
		if(n % i == 0)
		{
			cout << i + (n/i) - 2 ENDL;
			return 0;
		}
	}

	cout << "Error\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
        int k[] = { 0, 300000, 200000, 100000 };
        int s=0;
        int x,y;

        cin >> x >> y;

        if ( x < 4 ) s += k[x];
        if ( y < 4 ) s += k[y];
        if ( x == 1 && y == 1 ) s += 400000;

        cout << s <<  endl;

        return 0;
}


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

int main(){
  int a, b, c = 0;
  int count5, count7 = 0; 
  cin >> a >> b >> c;
  
  if(a == 5){
    count5 += 1;
  }
  else if(a == 7){
    count7 += 1;
  }
  
  if(b == 5){
    count5 += 1;
  }
  else if(b == 7){
    count7 += 1;
  }
  
  if(c == 5){
    count5 += 1;
  }
  else if(c == 7){
    count7 += 1;
  }
  
  if(count5 == 2 && count7 == 1){
  	cout << "YES" << endl;
  }
  else{
  	cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1
 
typedef struct node{
  int parent,left,right;
}Node;
 
Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int, int);
int setHeight(int);
int getSibling(int);
void print(int);
 
int main(){
  int v,l,r,i,root=0;

  scanf("%d",&n);
 
  for(i=0;i<=n-1;i++){
    T[i].parent=NIL;
  }

  for(i=0;i<=n-1;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL){
      T[l].parent=v;
    }
    if(r!=NIL){
      T[r].parent=v;
    }
  }

  for(i=0;i<=n-1;i++){
    if(T[i].parent==NIL){
      root=i;
    }
  }

  setDepth(root,0);
  setHeight(root);
 
  for(i=0;i<=n-1;i++){
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].parent);
    printf("sibling = %d, ",getSibling(i));
    int deg = 0;
    if(T[i].left!=NIL){
      deg++;
    }
    if(T[i].right!=NIL){
      deg++;
    }
    printf("degree = %d, ",deg);
    printf("depth = %d, ",D[i]);
    printf("height = %d, ",H[i]);
 
    if(T[i].parent==NIL){
      printf("root\n");
    } 
    else if(T[i].left==NIL&&T[i].right==NIL){
      printf("leaf\n");
    } 
    else {
      printf("internal node\n");
    }
  }

  return 0;
}
 
void setDepth(int u,int d){
  if(u==NIL)
    return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}
 
int setHeight(int u) {
  int h1=0, h2=0;
  if(T[u].left!=NIL)
    h1=setHeight(T[u].left)+1;
  if(T[u].right!=NIL)
    h2=setHeight(T[u].right)+1;
  return H[u]=(h1>h2 ? h1:h2);
}
 
int getSibling(int u){
  if(T[u].parent==NIL){
    return NIL;
  }
  if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL){
    return T[T[u].parent].left;
  }
  if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL){
    return T[T[u].parent].right;
  }
  return NIL;
}

Measured memory_bytes: 624
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
    Q[tail]=x;
    tail=(tail+1)%LEN;
}

P dequeue(){
    P x=Q[head];
    head=(head+1)%LEN;
    return x;
}

int min(int a,int b){
   if( a<b ) return a;
   else return b;
}

int main()
{
    int elaps=0,c;
    int i,q;
    P u;

    scanf("%d%d",&n,&q);
    for( i=1 ; i<=n ; i++ ){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }

    head = 1;
    tail = n+1;

    while( head != tail ){
        u = dequeue();
        c = min(q,u.t);
        u.t -= c;
        elaps += c;
        if( u.t > 0 ) enqueue(u);
        else {
            printf("%s %d\n",u.name,elaps);
        }

    }

    return 0;
}


Measured memory_bytes: 11900
/*
	Name:
	Author: xiaruize
	Date:
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define sz(a) int((a).size())

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int x;
	cin>>x;
	cout<<360/__gcd(360,x)<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
char ans[2005][10005];
char s[2005][10005];
int len[2005],start[2005][10005];
int n,k;
bitset<10005>can[2005];
char Max='z'+1;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		len[i]=strlen(s[i]+1);
	}
	can[n].reset();can[n].set(0);
	for(int i=n-1;i>0;i--){
		can[i]=can[i+1]|(can[i+1]<<len[i+1]);
	}	
	for(int i=1;i<=k;i++)ans[0][i]=Max;
	start[0][1]=1;start[0][k+1]=1;
	for(int i=1;i<=n;i++){
		memcpy(ans[i],ans[i-1],sizeof ans[i]);
		memcpy(start[i],start[i-1],sizeof start[i-1]);
		for(int j=1;j<=k;j++){
			if(j+len[i]-1>k||!can[i][k-(j+len[i]-1)]||(!start[i-1][j]&&ans[i][j]!=Max))continue;
			if(j>1&&ans[i][j-1]==Max)break;
			int lcp=0;
			bool ok=true;
			while(1+lcp<=len[i]&&j+lcp<=k&&ans[i][j+lcp]==s[i][1+lcp])lcp++;
			int nxt=j+lcp;
			if(lcp==len[i]){
				start[i][nxt]=1;
				continue;
			}
			if(ans[i][nxt]>s[i][lcp+1]){
				for(int _=j;_<j+len[i];_++){
					if(_>nxt)start[i][_]=0;
					ans[i][_]=s[i][_-j+1];
				}
				for(int _=j+len[i];_<=k;_++)ans[i][_]=Max,start[i][j]=0;
				start[i][j]=1;
				break;
			}
		}
	}
	string _ans=""; 
	for(int i=1;i<=k;i++)_ans+=ans[n][i];
	can[n].reset();can[n].set(0);
	for(int i=n-1;i>0;i--){
		can[i]=can[i+1]|(can[i+1]<<len[i+1]);
	}	
	for(int i=1;i<=k;i++)ans[0][i]=Max;
	start[0][1]=1;start[0][k+1]=1;
	for(int i=1;i<=n;i++){
		memcpy(ans[i],ans[i-1],sizeof ans[i]);
		memcpy(start[i],start[i-1],sizeof start[i-1]);
		for(int j=1;j<=k;j++){
			if(j+len[i]-1>k||!can[i][k-(j+len[i]-1)]||(!start[i-1][j]&&ans[i][j]!=Max))continue;
			if(j>1&&ans[i][j-1]==Max)break;
			int lcp=0;
			bool ok=true;
			while(1+lcp<=len[i]&&j+lcp<=k&&ans[i][j+lcp]==s[i][1+lcp])lcp++;
			int nxt=j+lcp;
			if(lcp==len[i]){
				start[i][nxt]=1;
				continue;
			}
			if(ans[i][nxt]>s[i][lcp+1]){
				for(int _=j;_<j+len[i];_++){
					start[i][_]=0;
					ans[i][_]=s[i][_-j+1];
				}
				for(int _=j+len[i];_<=k;_++)ans[i][_]=Max,start[i][j]=0;
				start[i][j]=1;
				break;
			}
		}
	}
	string __ans=""; 
	for(int i=1;i<=k;i++)__ans+=ans[n][i];
	cout<<min(_ans,__ans)<<endl;
	return 0;
}

Measured memory_bytes: 120320
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>

using namespace std;
#define MAX 1000000000

int main(){
    int N, M;
    vector<pair<int, bool>> X;
    cin >> N >> M;
    for (int i = 0; i < M; i++){
        int temp;
        cin >> temp;
        X.push_back(make_pair(temp, false));
    }
    sort(begin(X), end(X));
    X[0].second = true;

    vector<pair<int, int>> dif;
    for (int i = 1; i < M; i++){
        dif.push_back(make_pair(abs(X[i].first - X[i - 1].first), i));
    }
    sort(begin(dif), end(dif), greater<pair<int, int>>());

    int limit = dif.size() < N - 1 ? dif.size() : N - 1;
    for (int i = 0; i < limit; i++){
        int idx = dif[i].second;
        X[idx].second = true;
    }

    int tempAns = 0;
    vector<int> ans;
    for (int i = 1; i < M; i++){
        if (X[i].second == true){
            ans.push_back(tempAns);
            tempAns = 0;
            continue;
        }
        tempAns += X[i].first - X[i - 1].first;
    }
    if (X[M - 1].second != true){
        ans.push_back(tempAns);
    }
    cout << accumulate(begin(ans), end(ans), 0)<< endl;
    return 0;

}

Measured memory_bytes: 2676
var
	N,ans,i,id:Longint;
	t:Array[1..50]of Longint;
	s:Array[1..50]of String;
	x,inp:String;
	flag:Boolean;
begin
	readln(N);
	for i:=1 to N do begin
		readln(inp);
		id:=1;
		while inp[id]<>' 'do inc(id);
		s[i]:=copy(inp,1,id-1);
		t[i]:=0;
		inc(id);
		while id<=length(inp)do begin
			t[i]:=t[i]*10+ord(inp[id])-48;
			inc(id);
		end;
	end;
	readln(x);
	for i:=1 to N do begin
		if flag then inc(ans,t[i]);
		if s[i]=x then flag:=True;
	end;
	writeln(ans);
end.

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
bool g[710][710],dp[710][710];
int col[710];
int n,cnt,cnt2;
bool dfs(int from){
	if(col[from]) cnt++;
	else cnt2++;
	for(int to=1;to<=n;to++){
		if(from==to) continue;
		if(g[from][to]){
			if(col[to]!=-1){
				if(col[to]!=(col[from]^1))
					puts("-1"),exit(0);
			}else{
				col[to]=col[from]^1;
				dfs(to);
			}
		} 
	}
	return true;
}
int main(){
	int m,a,b;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		g[a][b]=g[b][a]=true;
	}
	for(a=1;a<=n;a++)
		for(b=1;b<=n;b++)
			g[a][b]=!g[a][b];
	memset(col,-1,sizeof col);
	dp[0][0]=true;
	int num=0;
	for(int v=1;v<=n;v++){
		if(col[v]==-1){
			col[v]=0;
			++num;
			cnt=cnt2=0;
			if(!dfs(v)) puts("-1"),exit(0);
			else{
				for(int i=0;i<=n;i++){
					if(dp[num-1][i]){
						dp[num][i+cnt]=true;
						dp[num][i+cnt2]=true;
					}
				}
			}
		}
	}
	int ans=0x3f3f3f3f;
	for(int i=0;i<=n;i++){
		if(dp[num][i]){
			int s_size=i,t_size=n-i;
			ans=min(ans,s_size*(s_size-1)/2+t_size*(t_size-1)/2);
		}
	}
	if(ans==0x3f3f3f3f) ans=-1;
	printf("%d\n",ans);
	return 0;
}

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

////
int main(){
    // 入力
    LL N;cin >> N;
    vector<LL> A(N);
    rep(i,N)cin >> A[i];

    // 全体の降雨量
    LL sum = 0;
    rep(i,N)sum += A[i];

    // x0 以外の各 xi の和
    LL sum_2 = 0;
    rep(i,N){
        if(i % 2 == 0)continue;
        else sum_2 += A[i];
    }
    sum_2 *= 2;         // 全体の降雨量から x0 を除いたものにするために2倍

    // x0 生成
    vector<LL> x(N);    // 各山の降雨量vector生成
    x[0] = sum - sum_2;

    // 各 xi 生成
    rep(i,N){
        if(i == 0)continue;
        x[i] = 2*A[i-1] - x[i-1];
    }

    // 出力
    rep(i,N)cout << x[i] << " ";
    
}



Measured memory_bytes: 2816
n, a, b = map(int, input().split())

if a > b:
    print(0)
    exit(0)
if n == 1:
    if a == b:
        print(1)
        exit(0)
    else:
        print(0)
        exit(0)
print((n-2) * (b-a) + 1)

Measured memory_bytes: 3060
N, K = map(int, input().split())
h = [0] * N
for i in range(N):
  h[i] = int(input())

h.sort()

score = h[K - 1] - h[0]
for i in range(N - K + 1):
  tmp_score = h[i + K - 1] - h[i]
  score = min(score, tmp_score)

print(score)


Measured memory_bytes: 7472
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl

u64 gcd(u64 x, u64 y) {
  if(x < y) {
    return gcd(y, x);
  } else if(y == 0) {
    return x;
  } else {
    gcd(y, x % y);
  }
} 

int main(int argc, const char* argv[]) {
  u64 n, ix, x, d = 0;
  cin >> n >> ix;
  
  rep(i, n) {
    cin >> x;
    u64 diff = ix > x ? ix - x : x - ix;
    
    if(d == 0) {
      d = diff;
    } else {
      d = gcd(diff, d);
    }
  }
  
  cout << d << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]

comp = sorted(a, reverse = True)

Fmax = comp[0]
Smax = comp[1]

for i in range(n):
    if a[i] == Fmax:
        print(Smax)
    
    else:
        print(Fmax)

Measured memory_bytes: 14112
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>>a(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> a.at(i).at(j);//bingo受け取り
    }
  }
  int n;
  cin >> n;
  vector<int>b(n);
  for(int k=0;k<n;k++){
    cin >> b.at(k);//当選番号
  }
   for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<n;k++){
        if(a.at(i).at(j) == b.at(k)){//(i,j)=当選番号
          a.at(i).at(j)=0;//0にする（0はbingoカードに存在しないため）
        }
      }
    }
   }
  if(a.at(0).at(0)+a.at(0).at(1)+a.at(0).at(2)==0||
     a.at(1).at(0)+a.at(1).at(1)+a.at(1).at(2)==0||
     a.at(2).at(0)+a.at(2).at(1)+a.at(2).at(2)==0||
     a.at(0).at(0)+a.at(1).at(0)+a.at(2).at(0)==0||
     a.at(0).at(1)+a.at(1).at(1)+a.at(2).at(1)==0||
     a.at(0).at(2)+a.at(1).at(2)+a.at(2).at(2)==0||
     a.at(0).at(0)+a.at(1).at(1)+a.at(2).at(2)==0||
     a.at(0).at(2)+a.at(1).at(1)+a.at(2).at(0)==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }



int collatz(int n){
    int a=n;
    if(a%2 == 0)a/=2;
    else a = a*3+1;
    return a;
}

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

    int i = 0;
    vector<int>a(1000);
    while(true){
        a[s]+=1;
        i ++;
        if (a[s] == 2){
            cout << i << endl;
            return 0;
        }
        s =collatz(s);
    }


}



Measured memory_bytes: 3624
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  YesorNo(s < t);
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
N = int(input())

if N%2==1:
    L = [[N]]
    for i in range(1,N//2+1):
        L.append([i,N-i])
else:
    L = []
    for i in range(1,N//2+1):
        L.append([i,N-i+1])
LN = len(L)
M = []
for i in range(LN):
    A = L[i]
    for j in range(i+1,LN):
        B = L[j]
        for Ai in A:
            for Bi in B:
                M.append([Ai,Bi])

MN = len(M)
print(MN)
for i in range(MN):
    print(M[i][0],M[i][1])

Measured memory_bytes: 45808
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	long long a, b;
	cin >> a >> b;
	int ans = 0;
	for (long long i = a; i <= b; ++i) {
		string hoge = to_string(i);
		if (hoge[0] == hoge[4] && hoge[1] == hoge[3]) {
			ans++;
		}
	}
	cout << ans << endl;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define mod 1e9 +7;

typedef long long ll;
typedef vector<ll> vll;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

string to_bin_string(ll n){
    stringstream ss;
    ss << bitset<8>(n); //任意の桁数<m>
    string s = ss.str();
    return s;
}
int main()
{
    string s;
    cin >> s;
    if(s.size() > 5 && s[2] == s[3] && s[4] == s[5])cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
} 

Measured memory_bytes: 256