akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int s = 0, t = 0;
		for (int i = 0; i < 4; i++)
		{
			s += sc.nextInt();
		}
		for (int i = 0; i < 4; i++)
		{
			t += sc.nextInt();
		}
		System.out.println(Math.max(s,t));
	}
}

Measured memory_bytes: 12000
def main():
    N, C = map(int, input().split())
    D = [[0] * (10 ** 5 + 5) for _ in range(C)]    
    for _ in range(N):
        s, t, c = map(int, input().split())
        c -= 1
        D[c][s] += 1
        D[c][t] -= 1
    
    for c in range(C):
        for i in range(1,10 ** 5 + 1):
            D[c][i] += D[c][i-1]

    for c in range(C):
        for i in range(1,10 ** 5 + 1):
            if D[c][i] == 1:
                D[c][i-1] = 1

    S = [0] * (10 ** 5 + 5)
    for c in range(C):
        for i in range(10 ** 5 + 1):
            S[i] += D[c][i]

    print(max(S))

if __name__ == "__main__":
    main()

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

int main(){
  int N;
  cin >> N;
  
  N = N % 10;
  
  if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9)
    cout << "hon" << endl;
  else if (N == 0 || N == 1 || N == 6 || N == 8)
    cout << "pon" << endl;
  else
    cout << "bon" << endl;
}

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

int32_t main()
{
    int n;
    cin>>n;
    int h[100000];
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    int dp[100000];
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]);
    }
    cout<<dp[n]<<"\n";
}

Measured memory_bytes: 1024
import Data.List
import Control.Monad

solve xs acc
  | null xs = acc
  | null zs = []  
  | otherwise = let (_,v) = maximum zs in solve (delete v xs) (v:acc)
  where
    l = length xs
    zs = filter (uncurry (==)) $ zip [1..l] xs
 
main = do 
  n <- readLn :: IO Int
  bs <- map read . words <$> getLine :: IO [Int]
  case solve bs [] of
    [] -> print (-1)
    xs -> mapM_ print xs


Measured memory_bytes: 1020
#include<iostream>
#include<string.h>
#include<stdio.h>

using namespace std;

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
	if(ch == 'A') return 1;
	else if(ch == 'C') return 2;
	else if(ch == 'G') return 3;
	else if(ch == 'T') return 4;
	else return 0;
}

long long getKey(char str[]){	//????????§??¬????????????????????¨??????????????????????????????
	long long sum=0, p=1;
	int i;
	for(i=0; i<strlen(str); i++){
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){	//h2??????????????????????????????????????¨???????????????????????????
	return key%M;
}
int h2(int key){
	return 1 + (key%(M-1));
}

int find(char str[]){
	long long key,h;
	int i;
	key = getKey(str);
	for(i=0; ; i++){
		h = (h1(key) + i*h2(key))%M;
		if(strcmp(H[h],str) == 0){
			return 1;
		}else if(strlen(H[h]) == 0){
			return 0;
		}
	}
}

int insert(char str[]){
	long long key,h;
	int i;
	key = getKey(str);
	for(i=0; ; i++){
		h = (h1(key) + i*h2(key))%M;
		if(strcmp(H[h],str) == 0){
			return 1;
		}else if(strlen(H[h]) == 0){
			strcpy(H[h], str);
			return 0;
		}
	}
}

int main(){
	int n, h, i;
	char str[L], com[9];

	for(i=0 ; i<M ; i++){
		H[i][0] = '\0';
	}

	scanf("%d",&n);
	for(i=0 ; i<n ; i++){
		scanf("%s %s",com, str);
		if(com[0] == 'i'){
			insert(str);
		}else{
			if(find(str)){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 15496
package main

import (
	"fmt"
	"math"
)

func main() {
	var N float64
	fmt.Scan(&N)
	X := math.Ceil(N * 100.0 / 108.0)
	P := int(X * 108.0 / 100.0)
	if int(N) != P {
		fmt.Println(":(")
	} else {
		fmt.Println(int(X))
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int>ii;
typedef vector<ii>vii;
#define forn(i,n) for(ll i=0;i<n;i++)
#define wez(n) ll (n); cin>>(n);
#define w(t) while(t--)
#define setmax(a,b) (a)=max((a),(b))
#define setmin(a,b) (a)=min((a),(b))
#define pb push_back
#define mp make_pair
#define pie 3.1415926535897;
#define inf 1000000000;
#define outa(a,e) forn(i,e) cout << a[i] << (i==e-1?'\n':' ')
#define oute(n) cout<<n<<"\n"
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,a,b;
    cin>>n>>a>>b;
    if(n*a<=b){
        cout<<n*a<<endl;
    }else{
        cout<<b<<endl;
    }
    return 0;
}

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

void struct_array(int a[], int W, int w)
{
  int s[501] = {0};
  for (int xt = W; xt > W - w; --xt) {
    if (xt % w == 0) {
      for (int x = w; x < W; x += w) {
        s[x] = s[x-w] - 1;
      }
    } else {
      s[xt] = 1;
      for (int x = xt - w; x > 0; x -= w) {
        s[x] = s[x+w] + 1;
      }
    }
  }

  for (int i = 0; i < W; ++i) {
    a[i] = s[i+1] - s[i];
  }
}

int main(int argc, char *argv[])
{
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  if (H % h == 0 && W % w == 0) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  int a[501] = {0};

  if (W % w == 0) {
    struct_array(a, H, h);
    for (int y = 0; y < H; ++y) {
      for (int x = 0; x < W; ++x) {
        cout << a[y];
        cout << ((x == W - 1)? "\n" : " ");
      }
    }
  } else {
    struct_array(a, W, w);
    for (int y = 0; y < H; ++y) {
      for (int x = 0; x < W; ++x) {
        cout << a[x];
        cout << ((x == W - 1)? "\n" : " ");
      }
    }
  }

  return 0;
}


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

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D(x)         cout << #x << " - " << x << endl;
  #define  D2(x)        cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  all(x)       (x).begin(), (x).end()
  #define  D2p(x)       cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
	ll n;
	cin >> n;
	vector<ll> v(n);
	vi bits(64);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	for(int i=0;i<n;i++){
		ll k = v[i];
		int j =0;
		while(k>0){
		   bits[j++] += (k%2);
		   k/=2;
		}
	}
	ll prod = 1;
	ll lst=0;
	ll finalans=0;
	for(int i=0;i<63;i++){
		ll k = bits[i]*(n-bits[i]);
		ll st = (lst+k)%2;
		lst = (lst+k)/2;
		finalans = (finalans + (st*prod))%MOD;
		prod = (prod%MOD*2%MOD)%MOD;
	}

	while(lst>0){
		ll st = (lst)%2;
		finalans = (finalans+(st)*prod)%MOD;
		lst=(lst)/2;
		prod = (prod%MOD*2%MOD)%MOD;
	}
	
	cout << finalans;
  }

  int main(){
    IOS
    solve();
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


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

int div(int x){
  int count = 0;
  while(x % 2 == 0 ){
      x /= 2;
      count++;
  }
  return count;
}

int main(){
  int N;
  cin  >> N;
  int a[N];
  int max = 0;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    max += div(a);
  }
  cout << max << endl;   
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream> 
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define ull unsigned long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define mod 10007
#define inf 0x3f3f3f3f
#define eps 1e-18
#define maxn 100010
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll ans=1; for(;b;b>>=1){if(b&1)ans=ans*a%mod; a=a*a%mod;} return ans;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void swap(int &a,int &b){int tmp=a; a=b; b=tmp;}
using namespace std;
char s[maxn];
int n;
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	if(s[1]=='0'||s[n]=='1'){
		printf("-1\n"); return 0;
	}
	for(int i=1;i<n;i++)
		if(s[i]!=s[n-i]){
			printf("-1\n"); return 0;
		}
	int last=1;
	s[n]='1';
	for(int i=2;i<=n;i++)
		if(s[i]=='1'){
			for(int j=last;j<i;j++)
				printf("%d %d\n",j,i);
			last=i;
		}
}

Measured memory_bytes: 1536
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
0 1 2
1 2 1
1 3 3

output:
5
"""

import sys
from collections import deque
from math import isinf


def generate_adj_table(v_table):
    for each in v_table:
        v_from, v_to, edge_weight = map(int, each)
        init_adj_table[v_from][v_to] = edge_weight
        init_adj_table[v_to][v_from] = edge_weight

    return init_adj_table


def graph_bfs(v_init):
    global distance
    distance = [float('inf')] * vertices
    distance[v_init] = 0
    queue.appendleft(v_init)

    while queue:
        current = queue.popleft()
        adj_weight = adj_table[current]
        for adj in adj_weight.keys():
            if isinf(distance[adj]):
                distance[adj] = distance[current] + adj_weight[adj]
                queue.append(adj)
    return None


def solve():
    graph_bfs(init_v)
    diameter, bridge_v = 0, 0
    for v in range(vertices):
        if isinf(distance[v]):
            continue
        if diameter < distance[v]:
            diameter = distance[v]
            bridge_v = v

    graph_bfs(bridge_v)
    diameter = 0
    for v in range(vertices):
        if isinf(distance[v]):
            continue
        diameter = max(diameter, distance[v])

    return diameter


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices = int(_input[0])
    v_info = map(lambda x: x.split(), _input[1:])

    queue = deque()
    distance = [float('inf')] * vertices

    init_adj_table = tuple(dict() for _ in range(vertices))
    adj_table = generate_adj_table(v_info)

    init_v = 0
    print(solve())

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

int returnHappiness(int x){
    int fivehundred=x/500;
    int happy1=500*fivehundred;
    x=x-happy1;
    int fives=x/5;
    int happy2=5*fives;
    happy1=happy1*2;
    return happy1+happy2;
}

int main(){
    int n;
    scanf("%d",&n);
    printf("%d",returnHappiness(n));
    return 0;
}

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

int solve(string a, string b)
{
  int n = a.length();
  int m = b.length();
  int dp[n+1][m+1];
  int mx = 0;
  int xid = 0, yid = 0;
  for(int i=0; i<n+1; i++)
    for(int j=0; j<m+1; j++)
    {
      if(i==0 || j==0)
        dp[i][j] = 0;
      
      if(a[i-1] == b[j-1])
      {
        dp[i][j] = dp[i-1][j-1] + 1;
        mx = max(mx, dp[i][j]);
        xid = i-1;
        yid = j-1;
      }
      else
        dp[i][j] = 0;
    }


    int d1 = xid+1 - mx;
  return m-mx;
}

int main()
{

    string a,b;
    cin >> a >> b ;
    int n = a.length();
    int m = b.length();
    int mn = INT_MAX;
    for(int i=0; i<=n-m; i++)
    {
        int diff = 0;
        for(int j=0; j<m; j++)
        {
            if(b[j] != a[j+i])
                diff++;
        }
        mn = min(diff, mn);
    }
    cout<< mn << endl;





  //cout << solve(a,b) << endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.rbegin(), a.rend()); // 降順ソート
    ll ans = 0;
    int t = n-1;
    rep(i,n) {
        int lim = 2;
        if (i == 0) lim = 1;
        rep(j,lim) {
            if(t > 0) {
                ans += a[i];
                t--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4004
#include <iostream>
#include <cmath>

using namespace std;

int n, d;
const int MAX_n = 10;
const int MAX_d = 10;
int x[MAX_n][MAX_d];

double distance(int i, int j){
    double rep = 0.0;
    for(int k = 0; k < d; k++){
        rep += pow(x[i][k] - x[j][k], 2);
    }

    return pow(rep, 1.0/ 2.0);
}

int main(){
    cin >> n >> d;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> x[i][j];
        }
    }

    int count = 0;
    double di;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            di = distance(i, j);
            if((int)di == di){
                count++;
            }
        }
    }

    cout << count << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n;
  cin >> n;
  vl a(n);
  ll cnt=0;
  ll sum=0;
  rep(i,n){
    cin >> a[i];
    if(a[i]<0){
      cnt++;
    }
    a[i]=abs(a[i]);
    sum+=a[i];
  }
  sort(a.begin(),a.end());
  if(cnt%2==0){
    cout << sum << endl;
  }
  else{
    cout << sum-2*a[0] << endl;
  }
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int sx,sy,tx,ty;
	while(~scanf("%d%d%d%d",&sx,&sy,&tx,&ty)){
		if(ty-sy>=0&&tx-sx>=0){
			for(int i=0;i<ty-sy;i++)
				printf("U");
			for(int i=0;i<tx-sx;i++)
				printf("R");
				
			for(int i=0;i<ty-sy;i++)
				printf("D");
			for(int i=0;i<tx-sx;i++)
				printf("L");
			
			printf("L");
			for(int i=0;i<ty-sy+1;i++)
				printf("U");
			for(int i=0;i<tx-sx+1;i++)
				printf("R");
			printf("D");
			
			printf("R");
			for(int i=0;i<ty-sy+1;i++)
				printf("D");
			for(int i=0;i<tx-sx+1;i++)
				printf("L");
			printf("U");
			printf("\n");
		}else if(ty-sy>=0&&tx-sx<=0){
			
			for(int i=0;i<abs(ty-sy);i++)
				printf("U");
			for(int i=0;i<abs(tx-sx);i++)
				printf("L");
				
			for(int i=0;i<abs(ty-sy);i++)
				printf("D");
			for(int i=0;i<abs(tx-sx);i++)
				printf("R");
			
			printf("R");
			for(int i=0;i<abs(ty-sy+1);i++)
				printf("U");
			for(int i=0;i<abs(tx-sx+1);i++)
				printf("L");
			printf("D");
			
			printf("L");
			for(int i=0;i<abs(ty-sy+1);i++)
				printf("D");
			for(int i=0;i<abs(tx-sx+1);i++)
				printf("R");
			printf("U");
			printf("\n");
			
		}else if(ty-sy<=0&&tx-sx<=0){
			
			for(int i=0;i<abs(ty-sy);i++)
				printf("D");
			for(int i=0;i<abs(tx-sx);i++)
				printf("L");
				
			for(int i=0;i<abs(ty-sy);i++)
				printf("U");
			for(int i=0;i<abs(tx-sx);i++)
				printf("R");
			
			printf("R");
			for(int i=0;i<abs(ty-sy+1);i++)
				printf("D");
			for(int i=0;i<abs(tx-sx+1);i++)
				printf("L");
			printf("U");
			
			printf("L");
			for(int i=0;i<abs(ty-sy+1);i++)
				printf("U");
			for(int i=0;i<abs(tx-sx+1);i++)
				printf("R");
			printf("D");
			printf("\n");
			
		}else if(ty-sy<=0&&tx-sx>=0){
			
			for(int i=0;i<abs(ty-sy);i++)
				printf("D");
			for(int i=0;i<abs(tx-sx);i++)
				printf("R");
				
			for(int i=0;i<abs(ty-sy);i++)
				printf("U");
			for(int i=0;i<abs(tx-sx);i++)
				printf("L");
			
			printf("L");
			for(int i=0;i<abs(ty-sy+1);i++)
				printf("D");
			for(int i=0;i<abs(tx-sx+1);i++)
				printf("R");
			printf("U");
			
			printf("R");
			for(int i=0;i<abs(ty-sy+1);i++)
				printf("U");
			for(int i=0;i<abs(tx-sx+1);i++)
				printf("L");
			printf("D");
			printf("\n");
			
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=0;
  std::cin >> x>>y;
  rep(i,x)z+=i;
  rep(i,y)z+=i;
  std::cout << z << '\n';
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B=  MAP()
print(A*B)


Measured memory_bytes: 9980
def is_kaibun(s):
    s1 = s[::-1]
    for i in range(len(s)):
        if s[i] != s1[i]:
            return False
    return True

s = input()
n = len(s)

s1 = s[::-1]
# print(s1)
# print(is_kaibun(s))

# S  は回文である。
# N を S の長さとするとき、S の 1 文字目から (N−1)/2 文字目まで(両端含む)からなる文字列は回文である。
a = int((n - 1) / 2 - 1)
# print(a)
s2 = s[0:a + 1]
# print(s2)
# print(is_kaibun(s2))

# S の (N+3)/2 文字目から N 文字目まで(両端含む)からなる文字列は回文である。
b = int((n + 3) / 2 - 1)
s3 = s[b:]
# print(s3)
# print(is_kaibun(s3))

if is_kaibun(s) and is_kaibun(s2) and is_kaibun(s3):
    print('Yes')
else:
    print('No')

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int EK_MAX = 1010;
const int EK_EDGE_MAX = 200010;
const int INF = 1e9;

template <class T> class EK{
	vector<int> V[EK_MAX];
	pair<int , int> edge[EK_EDGE_MAX];
	T f[EK_EDGE_MAX * 2];
	int d[EK_MAX];
	int n;
	
	int rev(int a){
		return a / 2 * 2 + (a + 1) % 2;
	}
	
	void bfs(int s){
		fill(d , d + EK_MAX , -1);
		d[s] = 0;
		queue<int> Q;
		Q.push(s);
		while(!Q.empty()){
			int x = Q.front(); Q.pop();
			for(vector<int>::iterator it = V[x].begin() ; it != V[x].end() ; ++it){
				if(f[*it] == 0) continue;
				int y = (*it) % 2 == 1 ? edge[(*it)/2].first : edge[(*it)/2].second;
				if(d[y] >= 0) continue;
				d[y] = d[x] + 1;
				Q.push(y);
			}
		}
	}
	
public:
	
	EK(){
		n = 0;
		fill(f , f + EK_EDGE_MAX * 2 , 0);
	}
	
	int put(int a , int b , T c){
		edge[n] = make_pair(a , b);
		V[a].push_back(2*n);
		V[b].push_back(2*n+1);
		f[2*n] = c;
		f[2*n+1] = 0;
		return n++;
	}
	
	T ans(int s , int t){
		while(1){
			bfs(s);
			if(d[t] < 0){
				T x = 0;
				for(vector<int>::iterator it = V[s].begin() ; it != V[s].end() ; ++it){
					x += f[(*it)/2*2+1] * ((*it) % 2 == 0 ? 1 : -1);
				}
				return x;
			}
			queue<int> Q;
			T y = INF;
			for(int i = t ; i != s ;){
				for(vector<int>::iterator it = V[i].begin() ; it != V[i].end() ; ++it){
					if(f[rev(*it)] == 0) continue;
					int z = (*it) % 2 == 1 ? edge[(*it)/2].first : edge[(*it)/2].second;
					if(d[z] == d[i] - 1){
						i = z;
						y = min(y , f[rev(*it)]);
						Q.push(*it);
						break;
					}
				}
			}
			while(!Q.empty()){
				int x = Q.front(); Q.pop();
				f[rev(x)] -= y;
				f[x] += y;
			}
		}
	}
};

const int Z = 100;
int H,W;
EK<int> solve;

int main(){
	scanf("%d%d" , &H , &W);
	repp(i,0,H){
		repp(j,0,W){
			char c;
			scanf(" %c" , &c);
			if(c == 'o'){
				solve.put(i,Z+j,1);
				solve.put(Z+j,i,1);
			} else if(c == 'S'){
				solve.put(2*Z,i,INF);
				solve.put(2*Z,Z+j,INF);
			} else if(c == 'T'){
				solve.put(i,2*Z+1,INF);
				solve.put(Z+j,2*Z+1,INF);
			}
		}
	}
	int d = solve.ans(2*Z,2*Z+1);
	printf("%d\n" , d < INF ? d : -1);
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)    cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"
//----------------------------------------------------------------
int main(void) {
  string s;
  cin >> s;

  bool ok=false;
  rep(i,3){
    if(s[i]=='7') ok=true;
  }

  if(ok){
    prt("Yes");
  } else {
    prt("No");
  }

}


Measured memory_bytes: 3628
n_m = list(map(lambda x: int(x), input().split(" ")))
N = n_m[0]
M = n_m[1]

result_dict = {}

for i in range(M):
    p_s = input().split(" ")
    P = int(p_s[0])
    S = p_s[1]
    if P in result_dict:
        if result_dict[P][0] == 1:
            continue
        elif S == "AC":
            result_dict[P][0] = 1
        else:
            result_dict[P][1] += 1
    else:
        if S == "AC":
            result_dict[P] = [1, 0]
        else:
            result_dict[P] = [0, 1]

ac_count = 0
wa_count = 0
for v in result_dict.values():
    if v[0] == 0:
        continue
    ac_count += 1
    wa_count += v[1]

result = "{} {}".format(ac_count, wa_count)
print(result)


Measured memory_bytes: 23204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

ll gcd(ll a, ll b) {
    ll r;
    if (!a || !b) return 0LL;
    if (a < b) {
        r = (b % a);
        if (!r) return a;
    } else {
        r = (a % b);
        if (!r) return b;
    }
    return gcd(b, r);
}
int gcd(int a, int b) {
    int r;
    if (!a || !b) return 0LL;
    if (a < b) {
        r = (b % a);
        if (!r) return a;
    } else {
        r = (a % b);
        if (!r) return b;
    }
    return gcd(b, r);
}

int main() {
    fast_io
    ll a, b;
    cin >> a >> b;
    ll x = gcd(a,b), x_copy = x;
    int ind;
    map<ll,int> mp;
    for (ll i = 2; i*i < x_copy; i++) {
        if (x % i) continue;
        ind = 0;
        while (x % i == 0) {
            x /= i;
            ind++;
            mp[i]++;
        }
        if (x == 1) break;
    }
    if (x != 1) mp[x]++;
    ll ans = 0;
    for (auto m: mp) ans++;
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long x;
  Solver() {
    S002 r;
    r >= x;
  }
  void solve() {
    puts(x < 1200 ? "ABC" : "ARC");
  }
};
 
int main() {
  for(;;) std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
cnt_max = 0
for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        if s[i+j] == t[j]:
            cnt += 1
    if cnt > cnt_max:
        cnt_max = cnt
print(len(t)-cnt_max)

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

int main(){
  long d;
  cin >> d;
  long n = 26, csum = 0, ccost = 0;
  vector<long> c(n),last(n);
  rep(i,n){
    cin >> c[i];
    csum += c[i];
    last[i] = 0;
  }
  vector<vector<long>> s(d,vector<long>(n));
  rep(i,d)rep(j,n)cin >> s[i][j];
  vector<vector<long>> cand;
  vector<long> score;
  random_device rd{};
  vector<long> yotei(d);
  vector<long> tmp(d);
  long final_ans = 0, final_index;

  rep(jj,20){

    long ans = 0;
    rep(i,n)last[i] = 0;
    rep(i,d)yotei[i] = rd()%n;
    rep(i,d){
      ccost += csum;
      ccost -= c[yotei[i]]*(i+1 - last[yotei[i]]);
      ans -= ccost;
      last[yotei[i]] = i+1;
      ans += s[i][yotei[i]];
    }
    int ii = 0;
    while(ii < 50000){
      long new_day = rd()%d, new_con;
      while(1){
        new_con = rd()%n;
        if(yotei[new_day] != new_con)break;
      }
      long pre_con = yotei[new_day];
      yotei[new_day] = new_con;
      long tmpans = 0;
      ccost = 0;
      rep(i,n)last[i] = 0;
      rep(i,d){
        tmp[i] = yotei[i];
        ccost += csum;
        ccost -= c[yotei[i]]*(i+1 - last[yotei[i]]);
        tmpans -= ccost;
        last[yotei[i]] = i+1;
        tmpans += s[i][yotei[i]];
      }
      if(tmpans < ans)yotei[new_day] = pre_con;
      else{
        ans = tmpans;
        cand.push_back(tmp);
      }
      ii++;
    }
    if(final_ans < ans){
      final_ans = ans;
      final_index = int(cand.size()-1);
    }
  }
  rep(i,d)cout << cand[final_index][i]+1 << endl;
  return 0;
}

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

using namespace std;

int n,m;
#define MAX 7368792
bool arr[MAX];
int _max = MAX-1;

int main() {
	while(true) {
		cin >> m >> n;
		if(n<=0) break;
		if(n==500000&&m==2) {
			cout << 7368791 << endl;
			continue;
		}
		for(int i = 0; i <= _max; i++) arr[i] = false;
		_max = MAX+n*2-500000*2;
		for(int i = m; i < MAX; i++) {
			if(!arr[i]) {
				if(n==0) {
					cout << i << endl;
					break;
				}
				for(int j = i*2; j < _max; j+=i) arr[j] = true;
				n--;
			}
		}
	}
}



Measured memory_bytes: 10304
#include<bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
#define cppio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;

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

const int maxn=1e5+5;
const ll inf=0x3f3f3f3f;
const ll mod=1e9+7;

int main(){
	ll a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	printf("%lld",max(a*c,max(a*d,max(b*c,b*d))));
	return 0;
}


Measured memory_bytes: 3804
<?php

$input = str_split(file_get_contents('php://stdin'));

$alphabet = array_fill_keys(range('a', 'z'), 0);
foreach ($input as $c) {
    if (! ctype_alpha($c)) { continue; }

    $alphabet[strtolower($c)]++;
}

foreach ($alphabet as $char => $count) {
    printf('%s : %d%s', $char, $count, PHP_EOL);
}

Measured memory_bytes: 6796
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; 
	cin >> N; 
	pair<int, int> A[100010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> A[i].first; 
		A[i].second = i; 
	}
	sort(A, A+N); 
	int count = 0; 
	for(int i = 0; i < N; i++){
		if(A[i].second % 2 != i % 2) count ++;
	}
	cout << count / 2 << endl; 
}

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

int main() {
	int h, w;
	cin >> h >> w;
	int c[10][10];
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> c[i][j];
		}
	}
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
	int a[h][w];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == -1) {
				continue;
			}
			ans += c[a[i][j]][1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int MaxN = 1e5;
int n, C, K;
int t[MaxN + 5];

int main()
{
	while (~scanf("%d%d%d", &n, &C, &K)) {
		for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
		sort(t + 1, t + n + 1);
		int first = t[1], cnt = 1, ans = 1;
		for (int i = 2; i <= n; i++) {
			first = min(t[i], first);
			if (t[i] > first + K) ans++, cnt = 1, first = t[i];
				else if (cnt + 1 > C) ans++, cnt = 1, first = t[i];
					else cnt++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 512
#include <cstdint>
#include <iostream>

using namespace std;

int32_t main()
{
  uint32_t r, g, b;
  cin >> r >> g >> b;

  uint32_t val = 100 * r + 10 * g + b;
  if (val % 4 == 0)
    cout << "YES";
  else
    cout << "NO";
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;

fn main() {
    input! {
        k: u64,
        x: u64,
    }

    //tabで移動
    if 500 * k >= x {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main() {
  int h[2], s[2];
  for (int i = 0; i < 2; i++)
    scanf("%d %d", &h[i], &s[i]);

  int now = 0;
  while (h[0] > 0 && h[1] > 0) {
    h[1 - now] -= s[now];
    now = 1 - now;
  }

  if (now)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    double sum_inverse = 0.0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum_inverse += 100000000 / a[i];
    }
    printf("%.6f\n",100000000 / sum_inverse);
}



Measured memory_bytes: 256
n,p = map(int,input().split())
s = list(map(int,(list(input()))))
def keychange(dic,x):
    newdic = {}
    for k in dic:
        b = (k*10 + x) % p
        newdic[b] = dic[k]
    return newdic
count = 0
if p == 2:
    for i in range(n):
        if s[i] % 2 == 0:
            count += i+1
    print(count)
    exit()
if p == 5:
    for i in range(n):
        if s[i] % 5 == 0:
            count += i+1
    print(count)
    exit()
inv_t = [0]+[1]
for i in range(2,p):
  inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
dic = {}
memory = [1,0]
for i in range(n):
    x = s[i] % p
    memory[0] = 10*memory[0] % p
    memory[1] = (10*memory[1] + x) % p
    xinv = inv_t[memory[0]]*(x-memory[1]+p) % p
    if xinv in dic:
        dic[xinv] += 1
    else:
        dic[xinv] = 1
    zeroinv = (p-memory[1])*inv_t[memory[0]] % p
    if zeroinv in dic:
        count += dic[zeroinv]
print(count)

Measured memory_bytes: 61680
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

const long long INF = 1LL << 60;

int N;
long long h[100010];

long long dp[100010];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> h[i];

    for (int i = 0; i < N; i++) dp[i] = INF;

    dp[0] = 0;

    for (int i = 1; i < N; i++) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 1e9+7,MAX = 1e6+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p,ll mod)
{
	if(p==0) return 1;
	ll z=powN(a,p/2,mod);
	z=(z*z)%mod;
	if(p%2) z=(z*a)%mod;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

int main()
{
	vi X(5);
	take(X,0,5);
	for(int i=0;i<5;i++)
	{
		if(X[i]!=i+1)
		{
			cout<<i+1<<endl;
			return 0;
		}
	}
}		

Measured memory_bytes: 6976
#include <bits/stdc++.h>
#if ONLINE_JUDGE
    #define DEBUG false
#else
    #define DEBUG true
#endif
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define rrep(i, n) rREP(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) std::sort(all(x))
#define REV(x) std::reverse(all(x))
#define UNIQUE(x) x.erase(std::unique(all(x)), x.end());
#define MAX(x) *std::max_element(all(x))
#define MIN(x) *std::min_element(all(x))
#define LOWitr(x, n) std::lower_bound(all(x), n)
#define UPRitr(x, n) std::upper_bound(all(x), n)
#define cii(x) int x; std::cin >> x
#define cill(x) signed long long int x; std::cin >> x
#define cis(x) std::string x; std::cin >> x
#define co(x) std::cout << x << "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) if(DEBUG) std::cout<<#x<<" : "<<(x)<<"\n"
template<class T>using V = std::vector<T>;
template<class T>using VV = std::vector<std::vector<T>>;
template<class T>using Q = std::queue<T>;
template<class T>using PQ = std::priority_queue<T>;
template<class T,class U>using P = std::pair<T, U>;
template<class T,class U>using M = std::map<T, U>;
template<class T,class U>using UM = std::unordered_map<T, U>;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T>inline void vcin(T &v){for(auto&& i : v) std::cin >> i;}
template<class T>inline void dumpv(const T& v, std::ostream& os = std::cout){
    if(DEBUG){
        os<<"{";
        std::for_each(all(v),[&os](typename T::value_type p){os<<p<<',';});
        os<<"}\n";
    }
}
using std::cin;
using std::cout;
using std::string;
using std::next_permutation;
using LL = signed long long int;
const int INF = INT_MAX, MOD = 1e9 + 7;
const LL LLINF = LLONG_MAX;
const double PI = M_PI;

void Main(){
    cill(n);
    cill(m);
    cill(x);
    VV<LL> vv(n, V<LL>(m, 0));
    V<LL> price(n);
    rep(i, n){
        cin >> price[i];
        vcin(vv[i]);
    }
    LL ans = INF;
    rep(bit, (1<<n)){
        V<LL> v(m);
        LL nowprice=0;
        rep(i, n){
            if (bit & (1<<i)){
                rep(j, m){
                    v[j]+=vv[i][j];
                }
                nowprice+=price[i];
            }
        }
        LL min = INF;
        rep(j, m){
            chmin(min, v[j]);
        }
        if (min >= x){
            chmin(ans, nowprice);
        }
    }
    if (ans==INF) ans=-1;
    co(ans);
}

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

Measured memory_bytes: 3660
N = int(input())
S = list(map(int, input().split()))

S.sort()

parent = [S.pop()]
rest = S
for _ in range(N):
	n_parent = []
	n_rest = []

	for p in parent[::-1]:
		while rest:
			x = rest.pop()
			if x < p:
				n_parent.append(x)
				break
			else:
				n_rest.append(x)
	parent += n_parent
	parent.sort()
	rest = rest + n_rest[::-1]

if len(parent) == (2**N):
	print("Yes")
else:
	print('No')



Measured memory_bytes: 34096
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <queue>
typedef long long ll;
using namespace std;

struct node{
  ll x,y,z;

  bool operator<(const node& r) const{
    return(x > r.x);
  }
};

int main(){
  ll i,j,h;
  priority_queue<ll> p_q;
  vector<ll> a,b,c;
  ll cnt=0,k,x,y,z;
  cin >> x >> y >> z >> k;
  a.resize(x),b.resize(y),c.resize(z);
  for(i=0;i<x;i++)cin >> a[i];
  for(i=0;i<y;i++)cin >> b[i];
  for(i=0;i<z;i++)cin >> c[i];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  ll p=0,q=0,r=0;
  priority_queue<pair<ll,node> > que;
  node t;
  map<pair<int,pair<int,int> >,int> mp; 
  t.x = t.y = t.z = 0;
  que.push(make_pair(a[0]+b[0]+c[0],t));
  while(cnt<k){
    pair<int,pair<int,int>> pt;
    cnt++;
    pair<ll,node> pr = que.top();
    que.pop();
    cout << pr.first << endl;
    t = pr.second;
    t.x++;
    pt.first = t.x;
    pt.second.first = t.y;
    pt.second.second = t.z;
    if(t.x<x && mp[pt]==0){
      que.push(make_pair(a[t.x]+b[t.y]+c[t.z],t));
      mp[pt]=1;
    }
    t.x--;
    t.y++;
    pt.first = t.x;
    pt.second.first = t.y;
    pt.second.second = t.z;
    if(t.y<y && mp[pt]==0){
      que.push(make_pair(a[t.x]+b[t.y]+c[t.z],t));
      mp[pt]=1;
    }
    t.y--;
    t.z++;
    pt.first = t.x;
    pt.second.first = t.y;
    pt.second.second = t.z;
    if(t.z<z && mp[pt]==0){
      que.push(make_pair(a[t.x]+b[t.y]+c[t.z],t));
      mp[pt]=1;
    }
    t.z--;
  }
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    ll k; cin >> k;
    VL a(n + 1);
    eFOR(i, 1, n)cin >> a[i];

    eFOR(i, 1, n) {
        --a[i];
        (a[i] += a[i - 1]) %= k;
    }

    ll ans = 0;
    map<ll, ll> m;
    int r = 0;
    FOR(l, 0, n) {
        --m[a[l]];
        while (r <= n && r < l + k) {
            ++m[a[r]];
            ++r;
        }
        ans += m[a[l]];
    }
    cout << ans << "\n";
}

Measured memory_bytes: 14336
//verma_ankit484

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const ll mod = (ll) 1e9+7;

using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>


int main() {
  IOS
  #ifdef AV
  freopen("int.txt", "r", stdin);
  #endif
  ll n;
  cin >> n;
  ll p = ceil((double)n/1.08);
  ll k = floor((double)p*1.08);
  if (k == n) {
    cout << p << endl;
  } else {
    cout << ":(\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<cassert>
#include<map>
#include<set>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define mp make_pair
#define pb push_back
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
////////////////////////

int const N = 8e3 + 41;

int n;
char s[N];
int a[2][N];
int dx, dy;
int na[N];
int su[2];
vector<pii> q;

void pushq(){
	int l = 0;
	fi(0, n){
		if(s[i] == 'T'){
			if(l) q.pb(mp(1, l));
			l = 0;
			q.pb(mp(0, 0));
		}else{
			++l;
		}
	}
	if(l) q.pb(mp(1, l));
}

void calca(){
	bool f = false;
	int d = 0;
	a[0][0] = a[1][0] = 1;

	fi(0, sz(q)){
		if(q[i].first == 0){
			d ^= 1;
			f = true;
		}else{
			int l = q[i].second;
			if(!f){
				fj(0, N){
					if(a[0][j]){
						a[0][j] = 0;
						a[0][j+l] = 1;
						break;
					}
				}
			}else{
				fdj(N, 0){
					if(a[d][j]) a[d][j+l] = 1;
				}
			}
		}
	}
}

void calcsu(){
	int d = 0;
	fi(0, sz(q)){
		if(q[i].first == 0){
			d ^= 1;
		}else{
			int l = q[i].second;
			su[d] += l;
		}
	}
}

void solve(){
	pushq();
	calca();	
	calcsu();

	bool okx = false, oky = false;
	fi(0, su[1]+1){
		if(!a[1][i]) continue;
		int r = su[1] - i;
		int y = i - r;
		if(y == dy) oky = 1;
	}
	fi(0, su[0]+1){
		if(!a[0][i]) continue;
		int r = su[0] - i;
		int x = i - r;
		if(x == dx) okx = 1;
	}
	
	bool ok = (okx & oky);
	if(ok) printf("Yes\n");
	else printf("No\n");
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%s",s);
	n = strlen(s);
	scanf("%d %d",&dx,&dy);

	solve();



	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
        int a, b;
        cin >> a >> b;

        FOR(i, 1, 1e5) {
                if ((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
                        cout << i << endl;
                        return 0;
                }
        }
        
        cout << -1 << endl;

        return 0;
}


Measured memory_bytes: 256