akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())
edges = [[None for i in range(W)] for i in range(H)]

for i in range(H):
  s = list(map(str, input()))
  for j in range(W):
    edges[i][j] = s[j] 


def find_next(i, j):
  next = []
  if i > 0 and edges[i-1][j] == ".":
    next.append((i-1, j))
  if i < H - 1 and edges[i+1][j] == ".":
    next.append((i+1, j))
  if j > 0 and edges[i][j-1] == ".":
    next.append((i, j-1))
  if j < W - 1 and edges[i][j+1] == ".":
    next.append((i, j+1))
  return next

inf = 9999999999999999999

from collections import deque

def dfs(i, j):
  colors = [["white" for i in range(W)] for j in range(H)]
  queue = deque()
  queue.append((i, j))
  distance = [[inf for i in range(W)] for j in range(H)]
  distance[i][j] = 0

  result = -1
  while queue:
    i, j = map(int, queue.popleft())
    colors[i][j] = "black"
    for (x, y) in find_next(i, j):
      if colors[x][y] == "white":
        colors[x][y] = "gray"
        d = min(distance[i][j] + 1, distance[x][y])
        distance[x][y] = d
        result = max(result, d)
        queue.append((x, y))
  return result


ans = -1
for i in range(H):
  for j in range(W):
    if edges[i][j] == "#": 
      continue
    
    ans = max(ans, dfs(i, j))

print(ans)

Measured memory_bytes: 3316
while(True):
    input_line = input().split()
    op = input_line[1]
    a = int(input_line[0])
    b = int(input_line[2])
    if op == '+':
        print(a + b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)
    elif op == '-':
        print(a - b)
    else:
        break


Measured memory_bytes: 5592
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 100000, MAX_M = 100000;
int N, M;
int a[MAX_N];
ll dp[MAX_M+1];

// nを初期化するのを忘れずに
int BIT[MAX_M+10], n;

int sum(int i) {
  int res = 0;
  while (i > 0) {
    res += BIT[i];
    i -= i & (-i);
  }
  return res;
}


void add(int i, int x) {
  while (i <= n) {
    BIT[i] += x;
    i += i & (-i);
  }
}

int main() {
  cin >> N >> M;
  rep(i,N) cin >> a[i];
  n = M+10;

  for (int i = 0; i+1 < N; ++i) {
    if (a[i] < a[i+1]) {
      add(a[i]+1, 1);
      add(a[i+1], -1);
    } else {
       add(1, 1);
       add(a[i+1], -1);
       add(a[i]+1, 1);
    }
  }


  vector<pii> vp;
  for (int i = 1; i < N; ++i) {
    vp.push_back(pii(a[i], i));
  }

  sort(all(vp));

  for (int i = 0; i+1 < N; ++i) {
    if (a[i] < a[i+1]) dp[1] += a[i+1]-a[i];
    else dp[1] += a[i+1];
  }

  for (int m = 1; m < M; ++m) {
    dp[m+1] = dp[m]-sum(m);
    for (int i = lower_bound(all(vp), pii(m, 0)) - vp.begin(); i < vp.size() && vp[i].fi == m ; ++i) {
      dp[m+1] += (a[vp[i].sc]+M-a[vp[i].sc - 1])%M - 1;
    }
  }

  ll ans = 1e18;
  for (int m = 1; m <= M; ++m) {
    ans = min(ans, dp[m]);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 2676
#include <iostream>
#include <iomanip>
#include <string>
#include <map>

using namespace std;
 
int main()
{
    string S;
    cin >> S;

    bool fumi = true;

    for (int i=0; i<S.size(); i++) {
        if (i%2 == 0) {
            if (S[i] != 'R' && S[i] != 'U' && S[i] != 'D') {
                fumi = false;
                break;
            }
        } else {
            if (S[i] != 'L' && S[i] != 'U' && S[i] != 'D') {
                fumi = false;
                break;
            }
        }
    }

    if (fumi == false) {
        cout << "No";
    } else {
        cout << "Yes";
    }

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var (
	sc     scanner
	writer *bufio.Writer
)

func solve() {
	_, t := sc.nextInt(), sc.nextInt()
	a := sc.nextInts()

	x := t
	for i := 0; i < len(a)-1; i++ {
		x += _min(t, a[i+1]-a[i])
	}

	ans := strconv.Itoa(x)
	writer.WriteString(ans + "\n")
}

/* template functions */

func main() {
	defer writer.Flush()
	solve()
}

func init() {
	sc = scanner{
		buf: make([]string, 0, 64),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
	writer = bufio.NewWriter(os.Stdout)
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	line, err := s.r.ReadString('\n')
	if err != nil {
		panic(err)
	}

	drop := 1
	if len(line) > 1 && line[len(line)-2] == '\r' {
		drop = 2
	}
	line = line[:len(line)-drop]

	s.cur = 0
	s.buf = strings.Split(line, " ")
}

func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}

func (s *scanner) resetCur() {
	s.cur = 0
}

func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}

func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}

func (s *scanner) nextByte() byte {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur][0]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}

func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}

func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i, _ := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}

func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur], 64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}

func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i, _ := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i], 64)
	}
	s.resetCur()
	return res
}

func _max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func _min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func _abs(x int) int {
	return int(math.Abs(float64(x)))
}

// Searchable
// idx := lower_bound([]int{-199, -1, 0, 2, 4, 67, 100, 8435}, 60)
// => idx = 5
//
// No present
// idx := lower_bound([]int{-199, -1, 0, 2, 4, 67, 100, 8435}, 10000)
// => idx = 8
func lower_bound(a []int, x int) int {
	return sort.SearchInts(a, x)
}

func dump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}

func yes() {
	writer.WriteString("Yes\n")
}

func no() {
	writer.WriteString("No\n")
}


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

int main() {
  int N;
  cin >> N ;
  int count = 3;
  for(int i = 0; i < N; i++){
    string S;
    cin >> S;
    if(S == "Y"){
      count = 4;
      break;
    }
  }
  if(count == 3)
    cout << "Three" << endl;
  if(count == 4)
    cout << "Four" << endl;
}

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

public class Main {
	static long[] dp;
	static int mod = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		sc.close();

		dp = new long[s + 1];
		Arrays.fill(dp, -1);
		dp[0] = 1;
		System.out.println(dfs(s));
	}

	static long dfs(int s) {
		if (dp[s] != -1) {
			return dp[s];
		}

		long ret = 0;
		for (int i = s - 3; i >= 0; i--) {
			ret += dfs(i);
			ret %= mod;
		}
		return dp[s] = ret;
	}
}


Measured memory_bytes: 35724
n = gets.chomp.to_i
d = gets.chomp.split(" ").map(&:to_i)
m = gets.chomp.to_i
t = gets.chomp.split(" ").map(&:to_i)
d = d.sort
t = t.sort
count = 1
ookisa = t.size
hash = Hash.new(0)
d.each do |i|
    hash[i] += 1
end
t.each do |j|
    hash[j] -= 1
    if hash[j] < 0
        count -= 1
    end
end
if count >= 1
    puts "YES"
else
    puts "NO"
end

Measured memory_bytes: 58364
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner  sc = new Scanner(System.in);
        int i = sc.nextInt();
        
        int ss = 0;
        int mm = 0;
        int hh = 0;

        if(i != 0){
            ss = i%60;
            mm = i/60%60;
            hh = i/60/60;
        }

        System.out.println(hh + ":" + mm + ":" + ss);

        sc.close();
    }
}

Measured memory_bytes: 26332
from collections import Counter as counter

ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,m,k):
    res = []
    a = []
    for i in k:
        a.extend(i[1:])
    c = counter(a)
    for i in range(1,m+1):
        if c[i] == n : res.append(i)
    return len(res)
    
n,m = mi()
k = mix(n)
print(main(n,m,k))

Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int ans = 0, n = 0;

  cin >> n;

  string s;

  cin >> s;

  string t = s;

  sort(all(t));

  for(int i = 0; i < n; i++)
    ans += t[i] != s[i];

  cout << ans / 2;

  return 0;
}
/*

*/


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

using namespace std;

typedef long long int ll;

int dp[3005][3005];


int main()
{
    string s , t;
    cin >> s >> t;
    int sl = s.size();
    int tl = t.size();

    for (int i=1; i<=sl; i++)
    {
        for(int j=1; j<=tl; j++)
        {
            if(s[i-1]==t[j-1]) 
            {
                dp[i][j] = 1+ dp[i-1][j-1];

            }

            else dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
        }
    }

    // cout << dp[sl][tl]<<endl;

    int i=sl , j=tl;

    string ret ="";
    while(i>0 && j >0)
    {
        if(s[i-1]==t[j-1])
        {
            ret +=s[i-1];
            i--;
            j--;
        }
        else if(dp[i][j-1]> dp[i-1][j]) j--;
        else i--;
    }
    reverse(ret.begin() , ret.end());

    cout << ret <<endl;
    return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
int pow_i(int a,int n){
    int ans=1;
    for (int i = 0; i < n; ++i) {
        ans=ans*a;
    }
    return ans;
}

int main(){
    int n;
    cin>>n;
    stack<int> ans;
    if(n%2==1||n%2==-1){ans.push(1);n-=1;}
    else ans.push(0);
    n=n/2;
    int cnt=0;
    while(n!=0){
        if(n%2==0){ans.push(0);n=n/2;}
        else {ans.push(1);n+=cnt%2!=0?-1:1;n=n/2;}
        ++cnt;
    }
    while(!ans.empty()){
        cout<<ans.top();
        ans.pop();
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 256
# include<stdio.h>
# include<string.h>
char s[25];
int main(){
	while(scanf("%s",s)!=EOF){
		int l=strlen(s);
		for(int i=0;i<l-1;i++){
			if(s[i]==','){
				printf(" ");
				i++;
			}
			printf("%c",s[i]);
		}
		printf("%c\n",s[l-1]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>       // printf,scanf
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>  //sort,binarySearch
#include <functional> 
#include <iomanip> // setprecision
#include <utility>    // c+11 Array
#include <set>
#include <sstream>
#include <bits/stdc++.h>
#define PI 3.141592653589793238462643383279
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define pb(x) push_back(x)
#define debug(x) cout << #x << " = " << x << endl;
#define debret(x) debug(x) ; return 0;

using namespace std;

int main(void){

    string str;
    cin >> str;

    int cnt = 0;

    REP(i,str.size()){
        
        if(str[i] == 'C') cnt = 1;
        
        if(cnt == 1 && str[i] == 'F'){
            cout << "Yes"<< endl;
            return 0;
        }else if(str[i] == 'F'){
            cnt = 0;
        }
        
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  
  int a,b,c,d;
   cin>>a>>b>>c>>d;
 if(a>=1&&a<=100&&b>=1&&b<=100&&c>=1&&c<=100&&d<=100&&d>=1)
  {
  while(a>0&&c>0)
  {
    if(c-b>0)
    {
      c=c-b;
      if(a-d>0)
      {
       a=a-d;
	  }
	  else
	  {
	   cout<<"No"<<"\n";
	   break;
	  }
	}
	else
	{
	 cout<<"Yes"<<"\n";
	 break;
	}
 }
  }
 
 
 return 0;
}

Measured memory_bytes: 3636
N,A = map(int,input().split())
X = list(map(int,input().split()))

L = sum(X)

dp = [[[0]*(N+1) for _ in range(L+10)] for _ in range(N+1)]
dp[0][0][0] = 1

for i in range(N):
    for j in range(L+10):
        for k in range(N):
            dp[i+1][j][k] += dp[i][j][k]
            if j >= X[i]:
                dp[i+1][j][k+1] += dp[i][j-X[i]][k]
            
ans = 0
for k in range(1,N+1):
    if A*k > L:break
    ans += dp[N][A*k][k]
                
print(ans)
                
                

Measured memory_bytes: 103772
import numpy as np
n, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

dp = np.zeros((n+1, W+1), dtype=int)

for i in range(n):
    dp[i+1][:wv[i][0]] = dp[i][:wv[i][0]]
    dp[i+1][wv[i][0]:] = np.maximum(dp[i][:-wv[i][0]] + wv[i][1], dp[i][wv[i][0]:])
print(dp[n][W])

Measured memory_bytes: 92484
a,b = map(int,input().split())
while not(a==b==0):
    ans = 0
    import itertools
    c = itertools.combinations([i for i in range(1,a+1)], 3)
    for i in c:
        if sum(i)==b: ans+=1
    print(ans)
    a,b = map(int,input().split())


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, long long A, long long B){
    if((A-B) % 2 == 0) {
        cout << ((B-A)/2) << endl;
    } else {
        cout << min(A + (B-A) / 2, N-B+1 + (B-A) / 2 ) << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    int L[50];
    for (int i = 0; i < N; ++i) cin >> L[i];

    sort(L, L + N, greater<int>());
    int total =0;
    for (int i = 0; i < K; ++i){
        total += L[i];
    }
    cout << total;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool myfun(int a,int b){
    return a > b;
}
int main()
{
    int n;
    vector<int>vec;
    vector<int>::iterator it;
    for(int i=1;i<=10;i++){
        cin>>n;
        vec.push_back(n);
    }
    sort(vec.begin(),vec.end(),myfun);
    for(int i=0;i<3;i++){
        cout<<vec[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 3140
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;
 int main()
 {
 	int x,n,i,res;
 	int a[110];
 	while(scanf("%d%d",&n,&x)==2)
 	{
 		for(i=0;i<n;i++)
 		{
 			scanf("%d",&a[i]);
 			x-=a[i];
		 }
 		sort(a,a+n);
 		res=n;
 		res+=(int)(x/a[0]);
 		printf("%d\n",res);
	 }
 	return 0;
  } 

Measured memory_bytes: 128
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// #define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%MOD,e/2);
    return e%2==0 ? temp : (temp*n)%MOD;
}

ll inverse(ll n)
{
	return exp(n,MOD-2);
}
int LIM=6010;
v64 factorial(LIM,1);

void solve()
{
//Read Comments below main
	ll k,n;
	cin>>k>>n;
	ll ans=-1e9;
	v64 arr(n+1);
	for (int i=1; i<=n; i++)
	{
		cin>>arr[i];
	}
	for (int i=2; i<=n; i++)
		ans=max(ans,arr[i]-arr[i-1]);
	ans=max(ans,arr[1]+k-arr[n]);
	cout<<k-ans<<endl;
}
 
int main() {
    fast_cin();
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}
// BITMASK:
// 1)When some constraint is of the order of 15-20, think of bitmask DP.
// 2)When some constraint is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algo

Measured memory_bytes: 1920
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTA(a,n) sort(a,a+n)
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
  int x,a,b;
  cin >> x >> a >> b;
    //処理
  
    //出力
    if(abs(x-a)<abs(x-b)) cout << "A" << ENT;
    else cout << "B" << ENT;
    return 0;
}

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


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

int main(){
	int x;
	cin >> x;
  	bool ans = false;
  	if(x==5 || x==3 || x==7){
    	ans = true;
    }
  	if(ans) cout << "YES";
  	else cout << "NO";
  	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,pm,pe,pj,s,i;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%d%d%d",&pm,&pe,&pj);
			s=(pm+pe+pj)/3;
			if(pm==100||pe==100||pj==100) printf("A\n");
			else if((pm+pe)/2>=90) printf("A\n");
			else if(s>=80) printf("A\n");
			else if(s>=70) printf("B\n");
			else if(s>=50&&(pm>=80||pe>=80)) printf("B\n");
			else printf("C\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2508
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int n, m, p[100010], ac = 0, wa2[100010] = {0}, a[100010] = { 0 }, wa = 0;
	string s[100010];
	cin >> n >> m; 
	for (int i = 1; i <= m;i++) {
		cin >> p[i] >> s[i];
		if (a[p[i]]==0&&s[i]=="AC") {
			a[p[i]]++;
			ac++;
			if (wa2[p[i]]>0) {
				wa += wa2[p[i]];
			}
		}
		else if(a[p[i]] == 0 && s[i] == "WA"){
			wa2[p[i]]++;
		}
	}
	cout << ac <<" " <<wa << endl;
}

Measured memory_bytes: 6912
#include <stdio.h>
int main(void)
{
int X, a, b, c, d;
scanf ("%d", &X);
a= X/1000;
b= (X -a *1000)/100;
c= (X -a *1000 -b *100)/10;
d= X -a *1000 -b *100 -c*10;
if ( (a==2) && (b==2) &&(c==2) &&(d==2) ) {
printf ("4");
}
else if ( (a==2) && (b==2) && (c==2) ) {
printf("3");
}
else if ( (a==2) && (b==2) &&(d==2)  ) {
printf("3");
}
else if ( (a==2) && (c==2) &&(d==2)  ) {
printf("3");
}
else if ( (d==2) && (b==2) &&(c==2)  ) {
printf("3");
}
else if ( (a==2) && (c==2) ) {
printf("2");
}
else if ( (a==2) && (d==2) ) {
printf("2");
}
else if ( (c==2) && (b==2) ) {
printf("2");
}
else if ( (d==2) && (b==2) ) {
printf("2");
}
else if ( (c==2) && (d==2) ) {
printf("2");
}
else if(a == 2){
printf("1");
}
else if ( b== 2){
printf("1");
}
else if( c== 2){
printf("1");
}
else if( d== 2){
printf("1");
}
else{
printf("0");
}
return 0;
}

Measured memory_bytes: 128
program main
  implicit none
  integer :: n, i, res
  integer, allocatable :: p(:)
  read (*, *) n
  allocate (p(n))
  read (*, *) p(:)
  res = 0
  do i = 1, n - 2
    if ((p(i) < p(i + 1) .and. p(i + 1) < p(i + 2)) .or. (p(i) > p(i + 1) .and. p(i + 1) > p(i + 2))) res = res + 1
  end do
  write (*, "(i0)") res
end program main


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
	int A,B;
	char S[12];
	char T[12];
	char temp[12];
	scanf ("%s %s %d %d %s",S,T,&A,&B,temp);
	if (strcmp(S,temp)==0) {
		printf ("%d %d\n",A-1,B);
	}
	else if (strcmp(T,temp)==0) {
		printf ("%d %d\n",A,B-1);
	}
	return 0;
}

Measured memory_bytes: 2060
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = arrayInt(sc, n);
		sc.close();
		int max = 0;
		int pos = 0;
		for (int i = 0; i < n; i++) {
			if (max < a[i]) {
				max = a[i];
				pos = i;
			}
		}
		Arrays.sort(a);
		for (int i = 0; i < n; i++) {
			if (i == pos) {
				System.out.println(a[a.length - 2]);
			} else {
				System.out.println(max);
			}
		}
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 108292
import sys
input = sys.stdin.readline
n = int(input().strip())
s = input().strip()
cnt = 0
pre = ''
for ss in s:
    if ss == '(':
        cnt += 1
    elif ss == ')':
        cnt -= 1
        if cnt < 0:
            pre += '('
            cnt += 1
else:
    post = ')' * cnt
print(pre + s + post)

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

int main(){
    int a, b;
    cin >> a >> b;
    int sum=0;
    if(a!=b){
        cout << max(a,b)*2-1 << endl;
    }else{
        cout << 2*a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/detail/standard_policies.hpp>

// common
#define endl     "\n"
#define M_PI     3.14159265358979323846

// fast input output
#define fast_io  ios_base::sync_with_stdio(false); cin.tie(NULL);  cout.tie(NULL)

// fixed float field
#define fix_prec cout.setf( std::ios::fixed, std:: ios::floatfield ); cout.precision(9);

// vector
#define vi       vector<int>
#define vvi      vector<vector<int>>
#define vpii     vector<pair<int,int>>
#define pb(v,x)  v.push_back(x)

// pair
#define pii      pair<int,int>
#define mp(a,b)  make_pair(a,b)
#define F        first
#define S        second

// sort
#define all(x)   x.begin(),x.end()
#define rall(x)  x.rbegin(),x.rend()

// bound
#define lb(v,x)  lower_bound(v.begin(),v.end(),x)
#define ub(v,x)  upper_bound(v.begin(),v.end(),x)

using namespace std;
//using namespace __gnu_pbds;

//typedef tree < int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update > ordered_set;
typedef long long int lli;
typedef unsigned long long int ulli;

// constants
lli const mod  = 1e9+7;
lli const modl = 1e18;

// helper functions
// calculate gcd
lli gcd(lli x, lli y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

// calculate fibonacci number
lli fib(int n)
{
    lli a,b,c,i;
    a=0,b=1;
    if(n == 0)
        return a;
    for(i=2;i<=n;i++)
    {
    	c=a+b;
    	a=b;
    	b=c;
    }
    return b;
}

// check if number if prime
bool isprime(lli n)
{
	if(n<=1)
		return false;
	else if(n==2)
		return true;
	else if(n%2==0)
		return false;
	else
	{
		int i;
		for(i=3;i*i<=n;i++)
		{
			if(n%i==0)
				return false;
		}
		return true;
	}
}

// read from and write to text file
void readwrite()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
} 

// seive
vector<lli>prime(100000+7,1);
void buildprime(lli n)
{
	lli i,j;
	prime[0]=prime[1]=0;
	for(i=2;i*i<=n;i++)
	{
		if(prime[i])
		{
			for(j=i*i;j<=n;j+=i)
				prime[j]=0;
		}
	}
}

// nCr
lli dp[1005][1005];
lli comb[1005][1005];
lli ncr(lli n,lli r)
{
	if(n==r)
		return 1;
	if(r==0)
		return 1;
	if(r==1)
		return n;
	if(dp[n][r]!=0)
		return dp[n][r];
	return dp[n][r] = (ncr(n-1,r)%mod+ncr(n-1,r-1)%mod)%mod;
}

void ncrm()
{
	comb[0][0]=1;
	for(int i=1;i<1001;i++)
	{
		comb[i][0]=1;
		for(int j=1;j<=i;j++)
		{
			comb[i][j]=(comb[i-1][j]%mod+comb[i-1][j-1]%mod)%mod;
		}
	}
}

// binary exponentiation
lli binpowm(lli a,lli b)
{
	lli res=1;
	a%=mod;
	while(b)
	{
		if(b&1)
			res=((res%mod)*(a%mod))%mod;
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return res%mod;
}
 
// factorial
lli fact(lli n)
{
	lli i,res=1;
	for(i=1;i<=n;i++)
		res=((res%mod)*(i%mod))%mod;
	return res%mod;
}

// driver code
void solve()
{
	int n,x;
	cin>>n;
	x=ceil(1.0*n/1000);
	cout<<abs(1000*x-n);
}

int main()
{
  fast_io;
  fix_prec;
  //readwrite();
  int t=1;
  //cin>>t;
  while(t--)
  {
    solve();
    cout<<endl;     
  }
  return 0;	
}

/*
Kab Khoon khaulega tera jab sabka internship lag jayega tab
Shame on you if you do not get internship
*/

Measured memory_bytes: 3916
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int H, W, h, w;
i64 ans[550][550];

int main()
{
	scanf("%d%d%d%d", &H, &W, &h, &w);
	if (H % h == 0 && W % w == 0) {
		puts("No");
		return 0;
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if ((i + 1) % h == 0 && (j + 1) % w == 0) {
				ans[i][j] = -((h * w - 1) * 600 + 1);
			} else {
				ans[i][j] = 600;
			}
		}
	}
	puts("Yes");
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			printf("%lld%c", ans[i][j], j == W - 1 ? '\n' : ' ');
		}
	}
	return 0;
}


Measured memory_bytes: 3456
import math

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

A=n[0]
B=n[1]
H=n[2]
M=n[3]

A_rad=H*math.pi/6+M*math.pi/360
B_rad=M*math.pi/30


A_pos=[A*math.cos(A_rad),A*math.sin(A_rad)]
B_pos=[B*math.cos(B_rad),B*math.sin(B_rad)]

print(math.sqrt((A_pos[0]-B_pos[0])**2+(A_pos[1]-B_pos[1])**2))

Measured memory_bytes: 9596
from fractions import gcd
N=int(input())
A=list(map(int,input().split()))

L=[0]*N
R=[0]*N
L[0]=A[0]
R[0]=A[N-1]

for n in range(1,N):
  L[n]=gcd(A[n],L[n-1])
  R[n]=gcd(A[N-n-1],R[n-1])
  
  ans=max(L[N-2],R[N-2])

for i in range(1,N-1):
  ans=max(ans,gcd(L[i-1],R[N-i-2]))

print(ans)

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

int main(){
    int n;
    ll x;
    cin>>n>>x;
    vector<ll>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    int ans=0;
    int i=0;
    while(x>0 && i<n){
        x-=a[i];
        if(x>=0)ans++;
        i++;
    }
    if(x>0)ans--;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3544
#!/usr/bin/env python3

def solve(a, b):
    if a <= b:
        return a
    else:
        return a - 1

def readQuestion():
    import sys
    line = sys.stdin.readline()
    sline = line.rstrip()
    str_a, str_b = sline.split(' ')
    a = int(str_a)
    b = int(str_b)
    return a, b

def main():
    a, b = readQuestion()
    ans = solve(a, b)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// CPP program to print prime factors and their 
// powers. 
#include <bits/stdc++.h> 
using namespace std; 

// function to calculate all the prime factors and 
// count of every prime factor 
long long factorize(long long n) 
{ 
	int count = 0; 

	long long res=0;
	// count the number of times 2 divides 
	while (!(n % 2)) { 
		n >>= 1; // equivalent to n=n/2; 
		count++; 
	} 
	// if 2 divides it 
	if (count) 
		res+=1;

	// check for all the possible numbers that can 
	// divide it 
	for (long long i = 3; i <= sqrt(n); i += 2) { 
		count = 0; 
		while (n % i == 0) { 
			count++; 
			n = n / i; 
		} 
		if (count) 
			res+=1; 
	} 

	// if n at the end is a prime number. 
	if (n > 2) 
		res+=2;
	else 
		res+=1; 
	return res;
} 

// driver program to test the above function 
int main() 
{ 
	long long a,b;
	cin >> a >> b;
	long long n=__gcd(a,b); 
	long long ans=factorize(n);
	cout << ans; 
	return 0; 
} 


Measured memory_bytes: 256
r,g,b,n = list(map(int, input().split()))
r,g,b = sorted([r,g,b])

ans = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        if i*r + j*g > n:
            break
        if (n- (i*r + j*g))%b==0:
            ans += 1
print(ans)

Measured memory_bytes: 40556
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n,k;
    cin >> n >> k;

    vector<ll> v(n);
    ll sum = 0;
    REP(i,n) {
        cin >> v[i];
        sum += v[i];
    }

    ll ans = 0;
    vector<ll> v2;
    for(auto i = 1; i < sqrt(sum) ; i++) {
        if (sum % i == 0) {
            v2.emplace_back(i);
            v2.emplace_back(sum / i);
        }
    }
    sort(RALL(v));
    sort(RALL(v2));

    int pos = 0;
    while(ans == 0 && pos < v2.size()) {
        ll k2 = k*2;
        ll kp = 0;
        ll km = 0;

        vector<ll> ka(n);
        REP(i,n) ka[i] = v[i] % v2[pos];
        sort(ALL(ka));
        kp = accumulate(ALL(ka),0LL, [&](ll acc, ll i){return acc + v2[pos] - i;});
        // for (auto i : ka) {
        //    cerr << i << endl;
        // }
        REP(i,n) {
            kp -= v2[pos] - ka[i];
            km += ka[i];
            //cerr<< kp << " " << km << endl;
            if (kp < km) break;
            //cerr << (kp == km) << endl;
            if ((kp == km) && (kp + km <= k2) ){
                ans = v2[pos];
                break;
            }
        }
        pos++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    if (a+b+c!=17) {
      System.out.println("NO");
      return;
    }
    
    if (a==5) {
      if (b==5 || b==7) {
        System.out.println("YES");
        return;
      }
      
      System.out.println("NO");
      return;
    }
    
    if (a==7) {
      if (b==5) {
        System.out.println("YES");
        return;
      }
      
      System.out.println("NO");
      return;
    }
    
    System.out.println("NO");
  }
}

Measured memory_bytes: 23764
/*************************************************************************
    > File Name: solve.cpp
    > Author: XeroxAuto
    > Mail: lanzongwei@gmail.com
    > Created Time: 2020-08-29 20:14:55
 ************************************************************************/

#define GOODOJ
#define SYNC 0

#ifdef GOODOJ
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#include <chrono>
#include <random>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#else
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
#include <limits>
#include <cassert>
#include <sstream>
#include <iterator>
#include <functional>
#endif
using namespace std;

#define endl '\n'
#define fep(i,b,e) for(int i=(b);i<(e);++i)
#define rep(i,x) for(int i=0;i<(x);++i)
#define rap(i,x) for(auto& i : (x))
#define seg(t) (t).begin(), (t).end()
#define ep emplace_back
#define mkp make_pair
#define qxx(i,x) for(int i = head[x]; ~i; i = node[i].nex)
#define F first
#define S second
#define lowbit(x) ((-(x))&(x))
#define RE register
#define getchar() getchar_unlocked()
#ifdef DEBUG
void err(istream_iterator<string>){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ' ';
	err(++it, args...);
}
#define debug(args...) {string _s=#args;replace(seg(_s),',',' ');\
cerr<<"DEBUG:";istringstream it(_s);\
err(istream_iterator<string>(it), args);cerr<<endl;}
#else
#define debug(...)
#endif

template<typename T> inline bool cmax(T& a,const T& b) {return a<b?a=b,1:0;}
template<typename T> inline bool cmin(T& a,const T& b) {return a>b?a=b,1:0;}

#ifdef GOODOJ
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
typedef __gnu_pbds::priority_queue<int> pq;
#endif
typedef std::string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pa;

const double P = acos(-1.0), eps = 1e-9;
struct point { db x ,y;};
inline int sign(db a) {return a < -eps ? -1 : a > eps;}
#define dot(p1,p2,p3) ((p2.x-p1.x)*(p3.x-p1.x)+(p2.y-p1.y)*(p3.y-p1.y))
#define cross(p1,p2,p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))
#define crossOp(p1,p2,p3) sign(cross(p1,p2,p3))

const int Ma = 1e6, inf = 0x3f3f3f3f, mod = 1e9 + 7;

int fa[Ma];
int siz[Ma];
void init() {
	rep (i, Ma) fa[i] = i, siz[i] = 1;
}
int find(int x) {return fa[x] = fa[x] == x ? x : find(fa[x]);}
void unio(int a, int b) {
	a = find(a), b = find(b);
	if (a == b) return ;
	siz[a] += siz[b];
	fa[b] = a;
}

signed main() {
	#if SYNC==0
    ios::sync_with_stdio(false);
    cin.tie(0);
    #endif
	int n, m; cin >> n >> m;
	init();
	rep (i, m)  {
		int a, b; cin >> a >> b;
		unio(a, b);
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (find(i) == i) cmax(cnt, siz[i]);
	}
	cout << cnt << endl;
    
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int solution(int N, int H, vector<int>& A, vector<int>& B)
{
    vector<vector<int>> dp(N+1, vector<int>(H+1, 1e+9));
    dp[0][H] = 0;
    for(int i = 0; i < N; ++i){
        for(int h = 0; h <= H; ++h) dp[i+1][h] = dp[i][h];
        for(int h = H; h >= 0; --h){
            dp[i+1][h] = min(dp[i+1][h], dp[i+1][min(H, h+A[i])]+B[i]);
        }
    }
    return dp[N][0];
}

int main()
{
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];

    // dp[i][j] = i まで見て体力を j にするのに必要な最小のコスト
    vector<vector<int>> dp(N+1, vector<int>(H+1, 1e+9));
    dp[0][0] = 0;
    REP(i, N){
        REP(h, H+1) dp[i+1][h] = dp[i][h];
        REP(h, H+1){
            dp[i+1][h] = min(dp[i+1][h], dp[i+1][max(0, h-A[i])]+B[i]);
        }
    }
    // cout << dp[N][H] << endl;
    cout << solution(N, H, A, B) << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 20;
const int MASK = (1 << 16) + 5;

int n;
bool vis[MASK];
ll a[N][N], group[MASK], dp[MASK];

int Check(int mask, int pos) {
  return mask & (1 << pos);
}

ll fun(int mask) {
  if (mask == (1 << n) - 1) {
    return 0;
  }
  ll &tmp = dp[mask];
  if (vis[mask]) {
    return tmp;
  }
  vis[mask] = 1, tmp = -1e18;
  int cur = mask ^ ((1 << n) - 1);
  for (int i = cur; i > 0; i = (i - 1) & cur) {
    tmp = max(tmp, fun(mask | i) + group[i]);
  }
  return tmp;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%lld", &a[i][j]);
    }
  }
  int mask = 1 << n;
  for (int i = 0; i < mask; i++) {
    for (int j = 0; j < n; j++) {
      if (Check(i, j)) {
        for (int k = 0; k < n; k++) {
          if (Check(i, k)) {
            group[i] += a[j][k];
          }
        }
      }
    }
    group[i] /= 2;
  }
  /** Iterative **/
  for (int mask = 0; mask < (1 << n); mask++) {
    dp[mask] = group[mask];
    for (int sub = mask; sub > 0; sub = (sub - 1) & mask) {
      int comp = mask - sub;
      dp[mask] = max(dp[mask], dp[sub] + dp[comp]);
    }
  }
  printf("%lld", dp[(1 << n) - 1]);
  //printf("%lld", fun(0));
  return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <math.h>

int main(void){

	double a,b,h,m;
  scanf("%lf %lf %lf %lf", &a, &b, &h, &m);
	double a_deg = 2.0*M_PI*(h/12.0)+(1.0/6.0)*M_PI*(m/60.0);
	a_deg = (1.0/2.0)*M_PI-a_deg;
	double b_deg = 2.0*M_PI*(m/60.0);
	b_deg = (1.0/2.0)*M_PI-b_deg;
	double a_sin = a*sin(a_deg);
	double a_cos = a*cos(a_deg);
	double b_sin = b*sin(b_deg);
	double b_cos = b*cos(b_deg);
	double length = sqrt(pow(a_sin-b_sin,2)+pow(a_cos-b_cos,2));
	printf("%.12lf\n", length);

  return 0;
}

Measured memory_bytes: 2540
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

ll ma(ll x, ll y){
    if(x>y)return x;
    return y;
}

ll gcd(ll a, ll b){
    if(a < b){
        ll t = a;
        a = b;
        b = t;
    }
    if(a % b == 0)return b;
    else return gcd(b, a%b);
}
ll lcm(ll a, ll b){
    ll l = gcd(a, b);
    return a/l*b;
}
struct hoge
{
    char s[101];
};
struct hoge a[100];
int compare_int(const void *a, const void *b){
	struct hoge *A = (struct hoge *)a;
	struct hoge *B = (struct hoge *)b;
	int sc = strcmp(A->s,B->s);
	return sc;
}
int main(void){
    int n, l;
    scanf("%d %d", &n, &l);
    for(int i = 0;i < n;i++){
        scanf("%s", &a[i].s);
    }
    qsort(a, n, sizeof(struct hoge), compare_int);
    for(int i = 0;i < n;i++){
        for(int j = 0;j < l;j++){
            printf("%c", a[i].s[j]);
        }
    }
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>

#define FOR(VAR,ST,END) for(int VAR=ST; VAR<END; ++VAR)
#define FORI(VAR,ST,END) for(int VAR=ST; VAR<=END; ++VAR)
#define ROF(VAR,ST,END) for(int VAR=ST; VAR>END; --VAR)
#define ROFI(VAR,ST,END) for(int VAR=ST; VAR>=END; --VAR)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define MAXI(a,b) (a=(a>b?a:b))
#define MINI(a,b) (a=(a<b?a:b))
#define ABS(a) (a>0?a:-a)
#define MINI_NZ(a,b) {if(a==0) a = b; else a = a<b?a:b;}
#define SWAP_IF(type,x,y,cond) if(cond) {type tmp=x; x=y; y=tmp;}
#define SWAP(type,x,y) {type tmp=x; x=y; y=tmp;}
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
#define MAX_NP1 (MAX_N+1)

using namespace std;

int a[100];

int main()
{
    int n, d, result;
    cin >> n >> d >> result;

    FOR(i, 0, n)
    {
        int a;
        cin >> a;
        result += 1 + (d - 1) / a;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
# import time
# t1=time.time()
def LI():return list(map(int,input().split()))
def I(): return int(input())
# from collections import deque, Counter, defaultdict
# from heapq import heappop, heappush
# from pprint import pprint
# import numpy as np
# import itertools

n=I()
a=LI()
a.sort(reverse=True)
# print(a)

if n%2==0:
    ans=sum(a[:n//2])*2-a[0]
else:
    ans=sum(a[:n//2])*2-a[0]+a[n//2]
print(ans)

Measured memory_bytes: 94124
#include <iostream>
#include <string>
using namespace std;
int main(){
  int i,count=0;
  string s,p;

  cin>>s>>p;
  s=s+s;
  
  for(i=0; i<s.size()-p.size(); i++)if(p==s.substr(i,p.size())){
      cout<<"Yes\n";
      count++;
      break;
    }
  
  if(count==0)cout<<"No\n";
  
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,0,n)cin>>v[i];
    Sort(v);
    
    int a=0,b=0;
    rep(i,0,n){
        if(i%2==0)a+=v[n-i-1];
        else b+=v[n-i-1];
    }
    cout<<a-b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int N;
ll A[305][305];
bool graph[305][305];

void init(){
  for(int i = 0; i < 305; i++){
    for(int j = 0; j < 305; j++){
      A[i][j] = LLONG_MAX / 100;
      graph[i][j] = true;
    }
  }
}

int main(){
  init();
  cin >> N;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cin >> A[i][j];
    }
  }

  bool ok = true;
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
	if(i == j || j == k || k == i) continue;
	if(A[i][j] == A[i][k] + A[k][j]){
	  graph[i][j] = 0;
	}else if(A[i][j] > A[i][k] + A[k][j]){
	  ok = false;
	}
      }
    }
  }

  ll ans = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(graph[i][j]) ans += A[i][j];
    }
  }

  if(ok) cout << ans / 2 << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 1152
# from sys import exit
# A, B, C = [int(n) for n in input().split()]
# a = [int(input()) for _ in range(N)]
S = str(input())
# L = len(S)
# T = str(input())
# exit()
win = S.count("o")
win += 15 - len(S)
print("YES" if win >= 8 else "NO")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll maxi = 0;

void solve(ll* a,ll prev,ll m,ll n,ll ind,vector<ll>* arr,ll q){
	if(ind == n){
		ll ct = 0;
		REP(i,0,q){
			if(a[arr[i][1] - 1] - a[arr[i][0] - 1] == arr[i][2]){
				ct += arr[i][3];
			}
		}
		// REP(i,0,n) cout<<a[i]<<" ";
		// cout<<ct<<endl;
		if(ct > maxi) maxi = ct;
		return;
	}

	REP(i,prev,m){
		a[ind] = i;
		solve(a,i,m,n,ind+1,arr,q);
	}
}
int main() 
{
	ll n,m,q;
	cin>>n>>m>>q;
	vector<ll> arr[q];
	REP(i,0,q){
		ll x;
		REP(j,0,4){
			cin>>x;
			arr[i].push_back(x);
		}
	}
	// REP(i,0,q){
	// 	cout<<arr[i][0]<<" "<<arr[i][1]<<" "<<arr[i][2]<<" "<<arr[i][3]<<endl;
	// }
	ll* a = new ll[n]();
	REP(i,0,m){
		a[0] = i;
		solve(a,i,m,n,1,arr,q);
	}
	cout<<maxi<<endl;
	return 0;
}  


Measured memory_bytes: 3640
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

m,k = map(int,readline().split())

if (k > 2**m-1):
    print(-1)
    exit()

if (k == 0):
    ans = [i//2 for i in range(2**(m+1))]
    print(" ".join(map(str,ans)))
    exit()

if m == 1 and k == 1:
    print(-1)
    exit()

ans = []

for i in range(2**m):
    if i != k:
        ans.append(i)
anss = [k] + ans + [k] + ans[::-1]
print(" ".join(map(str,anss)))


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

int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	double mx = -1.0;
	int mx_water = a, mx_sugar = 0;
	for(int ia = 1; (a * ia) * 100 <= f; ia++) {
		for(int ib = 0; (a * ia + b * ib) * 100 <= f; ib++) {
			int water = (a * ia + b * ib) * 100;
			for(int ic = 0; water + c * ic <= f; ic++) {
				for(int id = 0; water + c * ic + d * id <= f; id++) {
					int sugar = c * ic + d * id;
					if(water + sugar > f) break;
					if(water/100 * e < sugar) break;
					double now = 100.0 * (double) sugar / (water + sugar);
					if(mx < now) {
						mx = now;
						mx_water = water;
						mx_sugar = sugar;
					}
				}
			}
		}
	}
	printf("%d %d\n", mx_water + mx_sugar, mx_sugar);
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		Map<Integer,List<Integer>> s = new HashMap<>();
		for(int i=0;i<m;i++) {
			List<Integer> list = new ArrayList<>();
			int k = in.nextInt();
			for(int j=0;j<k;j++) {
				list.add(in.nextInt()-1);
			}
			s.put(i, list);
		}
		int[] p = new int[m];
		for(int i=0;i<m;i++) {
			p[i] = in.nextInt();
		}
		int ans = 0;
		int max = 1<<n;
		for(int i=0;i<max;i++) {
			int[] s_tmp = new int[n];
			for(int j=0;j<n;j++) {
				s_tmp[j] = (i>>j)&1;
			}
			boolean fail = false;
			for(int idx : s.keySet()) {
				int count = 0;
				for(int idx2 : s.get(idx)) {
					count += s_tmp[idx2];
				}
				if(count%2!=p[idx]) {
					fail = true;
					break;
				}
			}
			if(fail) continue;
			else ans++;
		}
		System.out.println(ans);
		in.close();
	}

}


Measured memory_bytes: 23764