akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int N;
  cin >> N;
  
  int sum = 0;
  int max = 0;
  for(int i = 0; i < N; ++i)
  {
    int price;
    cin >> price;
    sum += price;
    if(price > max)
    {
      max = price;
    }
  }

  cout << sum - max / 2 << endl;
  
  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	s := make([]int, n)
	for i := range s {
		s[i] = nextInt()
	}

	c := 0
	for i := range s {
		min := i
		for j := i; j <= n-1; j++ {
			if s[j] < s[min] {
				min = j
			}
		}
		if s[i] != s[min] {
			s[i], s[min] = swap(s[i], s[min])
			c++
		}
	}
	fmt.Println(convertIntToString(s, " "))
	fmt.Println(c)
}

func swap(a, b int) (int, int) {
	return b, a
}

func convertIntToString(s []int, d string) string {
	b := make([]string, len(s))
	for i, v := range s {
		b[i] = strconv.Itoa(v)
	}

	return strings.Join(b, d)
}

// =================================
// I/O util
// =================================

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

// =================================



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

l = []
r = []

for _ in range(m):
    lr = list(map(int, input().split()))
    l.append(lr[0])
    r.append(lr[1])

a = min(r) - max(l) + 1

if a < 0:
    a = 0

print(a)

Measured memory_bytes: 11216
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Hello
{
    private const long INF = 1000000007;
    private struct Pair { public long x, y; public Pair(long xx, long yy) { x = xx; y = yy; } }
    public static void Main()
    {
        int N = NextInt();
        int K = NextInt();
        int[] V = LineInt();
        int[] reV = V.ToArray();
        Array.Reverse(reV);

        int ans = 0;
        for (int a = 0; a <= N; a++)
            for (int b = 0; b <= N; b++)
            {
                //吐き出しに使えるコスト
                int outcost = K - (a + b);
                if (outcost < 0 || a + b > N) continue;
                //含ませる
                List<int> list = new List<int>();
                for (int i = 0; i < a; i++) list.Add(V[i]);
                for (int i = 0; i < b; i++) list.Add(reV[i]);
                //吐けるだけ吐く
                var sorted = list.OrderBy(x => x);
                int minus = sorted.TakeWhile(x => x < 0).Take(outcost).Sum();
                ans = Math.Max(ans, list.Sum() - minus);
            }
        Console.WriteLine(ans);

    }
}
public class Input
{
    private static Queue<string> queue = new Queue<string>();
    private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); }
    public static string NextString() { Confirm(); return queue.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13652
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	 	int n = sc.nextInt();
		int[] a = new int[n];
    int all = 0;
		int prev_a = 0;
		for (int i = 0; i < n; i++) {
			int ai = sc.nextInt();
      all += Math.abs(ai - prev_a);
      a[i] = ai;
			prev_a = ai;
		}
		all += Math.abs(0 - prev_a);

    for (int i = 0; i < n; i++) {
      int prev = (i == 0) ? 0 : a[i - 1];
      int mid = a[i];
      int next = (i == n - 1) ? 0 : a[i + 1];

      int x = Math.abs(mid - prev);
      int y = Math.abs(next - mid);
      int z = Math.abs(next - prev);
      System.out.println(all - x - y + z);
    }
  }
}


Measured memory_bytes: 65900
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

    int  N,A,B,i;
    std::cin >> N;
    std::cin >> A;
    std::cin >> B;
    
    int max,min;

    if(A+B-N<=0){
        min=0;
    }else{
        min=A+B-N;
    }
    if(A>B){
        max=B;
    }else{
        max=A;
    }
    cout << max <<" "<< min << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=1e9+7;

signed main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  int ans=0;
  for(int j=0;j<60;j++){
    int cnt=0;
    for(int i=0;i<n;i++)cnt+=v[i]&1,v[i]>>=1;
    ans+=cnt*(n-cnt)%MOD*((1LL<<j)%MOD)%MOD;ans%=MOD;
  }
  cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;

int main(void) {
  int n, k;
  cin >> n >> k;
  ll ans = k;
  for (int i = 0; i < n - 1; i++) {
    ans *= (k - 1);
  }
  cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
n=int(input())
s=[int(input()) for i in range(n)]
s.sort()

x=sum(s)
if x%10!=0:
    print(x)
    exit()
    
for i in range(n):
    if s[i]%10!=0:
        x-=s[i]
        print(x)
        exit()
print(0)

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

int main() {
  int total,ninki;
  double totalNum = 0;
  double quarter = 0;
  
  cin >> total >> ninki;
  vector<int> vec(total);
  
  for(int i = 0; i < total; i++){
    cin >> vec.at(i);
    
    totalNum += vec.at(i);
  }
  
  if(totalNum < 4){
    cout << "No";
    return 0;
  }
  
  quarter = totalNum / (4 * ninki);
  sort(vec.begin(),vec.end(),greater<int>());

  if(vec.at(ninki-1) >= quarter) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define INF 1000000000
const int maxn = 1e5 + 5;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
    int n;
    cin >> n;
    int c_500 = n/500; // This let us how many 500 yens
    int remaning = n%500; 
    int c_5 = remaning/5;
    cout << c_500*1000+c_5*5 << endl;
}


Measured memory_bytes: 3640
package main

import (
	"fmt"
)

func main() {
	i := 1
	x := 0
	for {
		if _, err := fmt.Scan(&x); err != nil {
			panic(err)
		}
		if x == 0 {
			break
		}

		fmt.Printf("Case %d: %d\n", i, x)
		i++
	}
}



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

using namespace std;

int ctoi(const char c) {
  if ('0' <= c && c <= '9') return (c - '0');
  return -1;
}

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

  int d = 1;
  for (int i = 0; i < n; ++i) {
    if (d * 2 < d + k) {
      d *= 2;
    } else {
      d += k;
    }
  }
  cout << d<< endl;
}


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

using namespace std;

int main(){
	int H, W;
	scanf("%d%d", &H, &W);
	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			string str;
			char ch[100];
			scanf("%s", ch);
			str = ch;
			if(str == "snuke"){
				printf("%c%d\n", 'A' + j, i + 1);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n;
    cin>>n;
    int temp = n%10;
    if(temp == 3){
        cout<<"bon"<<endl;

    }
    else if(temp == 0 || temp == 1 || temp == 6 || temp ==8){
        cout<<"pon"<<endl;
    }
    else{
        cout<<"hon"<<endl;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define maxn 100005
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;cin>>n;
    cout<<setprecision(5)<<fixed;
    cout<<double(2)*n*3.141592;
    return 0;
}


Measured memory_bytes: 3760
#各操作でコストゼロになるボールは一意
n = int(input())
x = []
y = []
for i in range(n):
    xi,yi =map(int, input().split( ))
    x.append(xi)
    y.append(yi)

cnt = {}

for i in range(n):
    for j in range(i):
        d1 = x[i]-x[j]
        d2 = y[i]-y[j]
        if (d1,d2) in cnt:
            cnt[(d1,d2)] += 1
        else:
            cnt[(d1,d2)] = 1
        if (-d1,-d2) in cnt:#こっちもいる
            cnt[(-d1,-d2)] += 1
        else:
            cnt[(-d1,-d2)] = 1

tmp = 0

for k in cnt:
    tmp = max(tmp, cnt[k])

print(n-tmp)

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0;i < n;i++) {
        cin >> p[i];
    }
    int ans = 0;
    for (int i = 1;i < n - 1;i++) {
        if(p[i] < p[i+1]&& p[i] > p[i-1]){
          ans++;
        }
        if(p[i] > p[i+1] && p[i] < p[i-1]){
            ans++;
        }
    }
    cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto hw = readln.split.to!(int[]);
    auto H = hw[0];
    auto W = hw[1];
    int[][] AS, BS;
    AS.length = H;
    BS.length = H;
    foreach (i; 0..H) {
        AS[i] = readln.split.to!(int[]);
    }
    foreach (i; 0..H) {
        BS[i] = readln.split.to!(int[]);
    }
    auto DP = new int[][][](H, W, 80*80+1);
    foreach_reverse (h; 0..H) {
        foreach_reverse (w; 0..W) {
            foreach (d; 0..80*80+1) {
                auto e = abs(AS[h][w] - BS[h][w]);
                auto dpe = d + e;
                auto dme = abs(d - e);
                if (h+1 == H && w+1 == W) {
                    DP[h][w][d] = dme;
                    continue;
                }
                auto r = int.max;
                if (h+1 < H) {
                    if (dpe <= 80*80) r = min(r, DP[h+1][w][dpe]);
                    if (dme <= 80*80) r = min(r, DP[h+1][w][dme]);
                }
                if (w+1 < W) {
                    if (dpe <= 80*80) r = min(r, DP[h][w+1][dpe]);
                    if (dme <= 80*80) r = min(r, DP[h][w+1][dme]);
                }
                DP[h][w][d] = r;
            }
        }
    }
    writeln(DP[0][0][0]);
}

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

using namespace std;

int main() {
    int n, k;   cin >> n >> k;
    int *h = new int[n];
    for (int i = 0; i < n; i++)
        cin >> h[i];

    int *dp = new int[n];   //dp[i]はi番目の足場までの最小コスト
    dp[0] = 0;

    for (int i = 0; i < n-1; i++) {
        dp[i+1] = dp[i] + abs(h[i]-h[i+1]);
        for (int j = 2; j <= min(k, i+1); j++) {
            dp[i+1] = min(dp[i+1], dp[i+1-j] + abs(h[i+1] - h[i+1-j]));
        }
    }

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

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <random>
#include <stdio.h>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef string ST;


#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl

bool isPrime(LL N)
{
  if (N < 2) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else if (N % 2 == 0) {
    return false;
  }

  LD sqrtNum = sqrt(N);
  for (LL i = 3; i <= sqrtNum; i += 2)
  {
    if (N % i == 0)
    {
      return false;
    }
  }
  return true;
}


void func() {
  LL N;
  cin >> N;
  //N = 2000;
  vector<LL> L(N);
  REP(i, N) {
    cin >> L[i];
    //L[i]=1;
  }


  sort(ALL(L));
#if 0
  PRINTSP(L);
  LL cnt = 0;
  for (LL i1 = 0; i1 < N-2; i1++) {
    for (LL i2 = i1 + 1; i2 < N-1; i2++) {
      for (LL i3 = i2 + 1; i3 < N; i3++) {
        if (L[i1] >= L[i2] + L[i3]) {
          break;
        }
        if ((L[i2] < L[i1] + L[i3]) && (L[i3] < L[i1] + L[i2])) {
          cnt++;
        }
      }
    }
  }
  cout << cnt;
#endif
  LL c = 0;
  for (LL i1 = 0; i1 < N - 2; i1++) {
    for (LL i2 = i1 + 1; i2 < N - 1; i2++) {
      LL a = L[i1] + L[i2];
      LL b = lower_bound(L.begin() + i2 + 1, L.end(), a)- L.begin();
      //fprintf(stderr, "%lld %lld %lld\n",a, b,b-i2-1);
      c += b - i2 - 1;
    }
  }
  cout << c;

}

#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "\n%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
const int COMMAX = 2000;
const int MOD = 1000000007;
vector<long long> fac, finv, inv;
 
void InitializeCombination(void){
    fac.push_back(1LL);
    fac.push_back(1LL);
    finv.push_back(1LL);
    finv.push_back(1LL);
    inv.push_back(0LL); //Though 0^(-1) cannot be defined, there should be some number in inv[0]
    inv.push_back(1LL);
    for (int i = 2; i < COMMAX; i++){
        fac.push_back(fac[i-1] * (long long)i % (long long)MOD);
        inv.push_back((long long)MOD - inv[MOD%i] * (long long)(MOD/i) % (long long)MOD);
        finv.push_back(finv[i-1] * inv[i] % (long long)MOD);
    }
}
 
long long Combination(int n, int r){
    if (n < r) return 0LL;
    if (n < 0 || r < 0) return 0LL;
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD;
}


int main(void){
    int S;
    long long res = 0;
    cin >> S;

    InitializeCombination();

    for(int length = 1; length <= S/3; length++){
        int sumbuf = S - 3*length;
        res += Combination(sumbuf + length - 1, sumbuf);
        res %= MOD;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3688
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int Max = 100000;
typedef pair<int, int> count_s;

int main(){
  bool judge = true;
  int N;
  cin >> N;
  string str[N];

  for(int i=0;i<N;i++) cin >> str[i];

  for(int i=1;i<N;i++){
    for(int j=0;j<i;j++){
      if(str[j]==str[i]){
        judge = false;
        break;
      }
    }
    int l = str[i-1].size();
    if(str[i-1][l-1] !=str[i][0]){
      judge = false;
    }
    if(!judge) break;
  }

  if(judge) cout << "Yes" <<endl;
  else cout << "No" <<endl;

  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <functional>
#include <bitset>
#include <queue>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using string_view = boost::string_ref;

#include <boost/function_output_iterator.hpp>

using namespace std;

int main()
{
    int N,M,C;
    cin >> N >> M >> C;
    vector<int> B(M);
    vector<vector<int>> A(N, vector<int>(M));
    for(auto& b : B) cin >> b;
    for(auto& row : A) for(auto& a : row) cin >> a;
    cout << std::count_if(A.begin(), A.end(), [&](const auto& row){ return std::inner_product(B.begin(), B.end(), row.begin(), C) > 0; }) << '\n';
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return  [list(map(int, input().split())) for _ in range(n)]

k = I()
a,b = MI()
c = 0
for i in range(a,b+1):
    if i%k == 0:
        c = 1
if c == 1:
    print("OK")
else:
    print("NG")


Measured memory_bytes: 10088
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  s <- getLine :: IO String
  print $ solve s

white = '.'
black = '#'

solve :: String -> Int
solve s = minimum . map count $ scanl' (\(nwi, nbi) a -> if a == white then (nwi+1, nbi) else (nwi, nbi+1)) (0, 0) s
  where
    nw = length $ filter (==white) s
    -- nb = length $ filter (==black) s
    count (nwi, nbi) = nbi + nw - nwi


Measured memory_bytes: 14204
import java.util.*;
public class Main {

	/*
	 * 122D
	 * 
	 * This problem might be hard for students
	 *
	 * General Idea:
	 * This is a DP Problem and they should know how to MOD 1e9+7
	 * We note that only substrings with length 4 of
	 * ?AGC, ?ACG, ?GAC, A?GC, AG?C are not good (? means any character)
	 * So we can build our dp solution based on that
	 * DP[n][4th last character][3rd last character][2nd last character][last character]
	 * = number of good strings of length n and ends with those 4 characters
	 * The transition will be what happens when we append either character A G C T to it
	 * 
	 * Implementation Specific:
	 * This problem might be confusing to code because it has a lot of information
	 * Assume we are adding TTTT to the start of the string (This will not change our answer)
	 * So our initial case or base case is dp[0][T][T][T][T] = 1
	 * Also because storing character will use a lot of memory, we will compress it 
	 * A = 0, G = 1, C = 2, T = 3, ? = -1
	 * We will also store all the bad substrings encoded this way
	 * 
	 * Questions that might come up:
	 * Q: If ?AGC is bad then isn't AGC? also bad?
	 * A: Yes but this case is already covered by ?AGC
	 * Q: Do we have store the last 4 characters why not last 3 characters
	 * A: Yes you can also do it by storing last 3 characters.
	 *
	 * Time Complexity O(N * 4^4 * C) C is some large constant, Memory Complexity O(N * 4^4)
	 * 
	 */

	static char AGCT[] = {'A', 'G', 'C', 'T'};
	static int bad[][] = {{-1,0,1,2},{-1,0,2,1},{-1,1,0,2},{0,-1,1,2},{0,1,-1,2}};
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long DP[][][][][] = new long[N+1][4][4][4][4];
		DP[0][3][3][3][3] = 1;
		for(int i = 0; i<N; i++) {
			for(int a = 0; a<4; a++) {
				for(int b = 0; b<4; b++) {
					for(int c = 0; c<4; c++) {
						for(int d = 0; d<4; d++) {
							//Those for loops above me control the state
							for(int e = 0; e<4; e++) {
								boolean good = true;
								for(int k = 0; k<5; k++) {
									boolean tempgood = true;
									tempgood &= (bad[k][0] == -1 ? true : bad[k][0] == b);
									tempgood &= (bad[k][1] == -1 ? true : bad[k][1] == c);
									tempgood &= (bad[k][2] == -1 ? true : bad[k][2] == d);
									tempgood &= (bad[k][3] == -1 ? true : bad[k][3] == e);
									if(tempgood) {
										good = false;
									}
								}
								if(good) {
									DP[i+1][b][c][d][e] += DP[i][a][b][c][d];
									DP[i+1][b][c][d][e] %= 1000000007;
								}
							}
						}
					}
				}
			}
		}
		long ans = 0;
		for(int a = 0; a<4; a++) {
			for(int b = 0; b<4; b++) {
				for(int c = 0; c<4; c++) {
					for(int d = 0; d<4; d++) {
						ans += DP[N][a][b][c][d];
						ans %= 1000000007;
					}
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 38840
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<int>> d(M);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    vector<int> s_k(k);
    for (int j = 0; j < k; j++) {
      cin >> s_k[j];
      s_k[j]--;
    }
    d[i] = s_k;
  }
  vector<int> p(M);
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }
  int ans = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    int on_num = 0;
    for (int j = 0; j < M; j++) {
      int on_cnt = 0;
      for (int k = 0; k < d[j].size(); k++) {
        for (int i = 0; i < N; i++) {
          if (d[j][k] == i && bit & (1 << i)) {
            on_cnt++;
            // cout << bitset<8>(bit) << " " << j << " " << i << endl;
          }
        }
      }
      if (on_cnt % 2 == p[j]) on_num++;
    }
    if (on_num == M) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int n,m,c[20],a[20][20],b[20],s,ans=99999999,now,ok;
int main()
{
    int i,j,k;
    cin>>n>>m>>s;
    for(i=1;i<=n;i++)
    {
        cin>>c[i];
        for(j=1;j<=m;j++) cin>>a[i][j];
    }
    for(k=1;k<(1<<n);k++)
    {
        memset(b,0,sizeof(b));
        now=0;
        ok=1;
        for(i=1;i<=n;i++)
        {
            if(k&(1<<i-1))
            {
                now+=c[i];
                for(j=1;j<=m;j++) b[j]+=a[i][j];
            }
        }
        for(i=1;i<=m;i++) if(b[i]<s) ok=0;
        if(ok==1) 
         if(now<ans) ans=now;
    }
    if(ans==99999999) cout<<-1;
    else cout<<ans;
    cin>>i;
}
                
            
         


Measured memory_bytes: 3616
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
 
 
public class Main {


	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//int Q = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		//char[] c = sc.next().toCharArray();
		int INF = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		long MOD = 1_000_000_007;
		
		//素因数分解
		List<int[]> primes = new ArrayList<>();
		
		
		int now_prime = 2;
		int now_M = M;
		int MAX = Math.max(N*2, 1000000);
		while(now_prime*now_prime<=M){
			if(now_M%now_prime == 0){
				now_M /= now_prime;
				int[] prime = new int[2];
				prime[0] = now_prime;
				prime[1] = 1;
				while(now_M%now_prime == 0){
					now_M /= now_prime;
					prime[1]++;
				}
				primes.add(prime);
				
			}
			now_prime++;
		}
		if (now_M>1){
			int[] prime = new int[2];
			prime[0] = now_M;
			prime[1] = 1;
			primes.add(prime);
		}
		
		long ans = 1L;
		
		//二項係数演算用前処理
		long[] fac = new long[MAX+1];
		fac[0] = 1L;
		fac[1] = 1L;
		long[] inv = new long[MAX+1];
		inv[1] = 1L;
		long[] finv = new long[MAX+1];
		finv[0] = 1L;
		finv[1] = 1L;
		for(long i=2;i<MAX;i++){
			fac[(int) i] = (fac[(int) (i-1)]*i)%MOD;
			inv[(int) i] = MOD - inv[(int) (MOD%i)]*(MOD/i)%MOD;
			finv[(int) i] = (finv[(int) (i-1)] * inv[(int) i]) % MOD;
		}
		
		
		
		for(int[] prime : primes){
			//因数K個のN分割を求める
			int K = prime[1];
			ans *= fac[N+K-1] * finv[K]%MOD * finv[N-1]%MOD;
			ans %= MOD;
		}
		ans %= MOD;
		System.out.println(ans);
		
	}
}



Measured memory_bytes: 48852
//https://atcoder.jp/contests/abc153/tasks/abc153_a

#include <iostream>
#include <cmath>

using namespace std;

// first approach
// int main(void)  {
//     int H, A;
//     cin >> H >> A;
//     int t = 0;

//     while (H > 0) {
//         H -= A;
//         t++;
//     }

//     cout << t << endl;
// }

//second approach
int main(void) {
    float H, A;
    cin >> H >> A;
    cout << ceil(H/A) << endl;
}

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

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

int main()
{
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N){
        cin >> P.at(i);
    }
    rep(i, N){
        cin >> Q.at(i);
    }
    int a = 0, b = 0;
    vector<int> num(N);
    int count = 1;
    iota(num.begin(), num.end(), 1);
    do {
        if(equal(num.cbegin(), num.cend(), P.cbegin())){
            a = count;
        }
        if(equal(num.cbegin(), num.cend(), Q.cbegin())){
            b = count;
        }
        count++;
    } while (next_permutation(num.begin(), num.end()));
    cout << abs(a - b) << endl;
}

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

int dp[5010][5010];

signed main(){
  int n,l,p=1000000007;
  cin>>n>>l;
  vector<int> x(n),a(n);
  for(int i=0;i<n;i++)cin>>x[n-1-i];
  for(int i=0;i<n;i++)cin>>a[n-1-i];
  if(a[0]==0)dp[0][x[0]]=1;
  else for(int i=x[0];i<l;i+=a[0])dp[0][i]=1;
  for(int i=1;i<n;i++){
    int sum=0;
    for(int j=l-1;j>=x[i];j--){
      if((a[i]>0&&(j-x[i])%a[i]==0)||x[i]==j){
	  dp[i][j]+=sum;
	  dp[i][j]%=p;
	}
      sum+=dp[i-1][j];
      sum%=p;
    }
  }
  int ans=0;
  for(int i=0;i<l;i++){
    ans+=dp[n-1][i];
    ans%=p;
  }
  cout<<ans<<endl;
  return 0;
}



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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int a,b,c,x,y;
	std::cin >> a >> b >> c >> x >> y;
	if (a + b < c * 2) {
		std::cout << x * a + y * b << '\n';
		return 0;
	}
	// a,b1枚ずつよりab2枚買った方がいい
	if (x < y) {
		if (b < c * 2) {
			std::cout << x * c * 2 + (y-x) * b << '\n';
			return 0;
		}
		else {
			std::cout << y * c * 2 << '\n';
			return 0;
		}
	}
	else {
		if (a < c * 2) {
			std::cout << y * c * 2 + (x-y) * a << '\n';
			return 0;
		}
		else {
			std::cout << x * c * 2 << '\n';
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
(a, b, c) = input().split(' ')
a = int(a)
b = int(b)
c = int(c)
 
if a < b < c:
    print(a, b, c)
elif a < c < b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
else:
    print(c, b, a)

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n  ; 
  cin >> n  ;
  vector<intll> d(n) ; 
  rep(i,n) cin >> d.at(i) ;
  intll money = 1000 ;
  intll stock = 0;
  
  rep(i,n-1){
    if(d.at(i) < d.at(i+1) ){
      stock = money / d.at(i) ;
      money %= d.at(i) ; 
      money += stock * d.at(i+1) ;
      
    }
  }
    
    cout << money ;
                       
      
 
}


Measured memory_bytes: 3548
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
count0=0; countN=0;
for i in range(X,0,-1) :
  for j in range(M) :
    if i==A[j] :
      count0+=1
for i in range(X,N+1) :
  for j in range(M) :
    if i==A[j] :
      countN+=1
print(min(count0,countN))

Measured memory_bytes: 9224
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
	if(a >= k) cout << k << endl;
	else if(a+b >= k) cout << a << endl;
	else cout << a - (k-a-b) << endl;
    return;
}

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


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

#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()  
{ 
    FAST_INP;
    int a;
    cin >> a;
    cout << ((a) + (a*a) + (a*a*a)) << "\n";
    return 0;
} 

Measured memory_bytes: 3608
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
  int H, i, A[MAX+1];

  cin >> H;
  for (i = 1; i <= H; i++) cin >> A[i];

  for (i = 1; i <= H; i++) {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if (parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
    if (left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
    if (right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t;
  cin >> s >> t;
  vector<vector<int>> dp(s.size()+1,vector<int>(t.size()+1,0));
  for(int i=0; i<s.size(); i++){
    for(int j=0; j<t.size(); j++){
      if(s[i]==t[j]){
        dp[i+1][j+1]=dp[i][j]+1;
      }
      else{
        dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
      }
    }
  }
  int i=s.size(),j=t.size();
  string res="";
  while(i>0&&j>0){
    if(dp[i][j]==dp[i-1][j]) i--;
    else if(dp[i][j]==dp[i][j-1]) j--;
    else{
      res = s[i-1]+res;
      i--;j--;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 35584
// C - Synthetic Kadomatsu
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int main(){
	int N; cin>>N;
	vi A(4); for(int i=0; i<3; ++i) cin>>A[i];
	vi L(N); for(int i=0; i<N; ++i) cin>>L[i];

	int ans = INT_MAX, E = 1<<16;
	for(int i=0; i<E; ++i){

		vi B(4), C(4);
		for(int j=0; j<N; ++j){
			int b = (i>>(j*2))&3;
			++C[b];
			B[b] += L[j];
		}

		if(min({B[0],B[1],B[2]})!=0){
			int sum = 0;
			for(int j=0; j<3; ++j){
				sum += abs(A[j]-B[j]);
				if(C[j]>=2) sum += (C[j]-1)*10;
			}
			ans = min(ans, sum);
		}

	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
s=input()
even = ["L","U","D"]
odd = ["R", "U", "D"]
f = False
for i in range(len(s)):
  if i%2:
    if s[i] not in even:
      f = True
  else:
    if s[i] not in odd:
      f = True
if f:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	int n;
	cin>>n;
	vector<pair<ll, ll> > mp;
	ll x, y, sum = 0;
	for(int i = 0; i<n; i++){
		cin>>x>>y;
		mp.push_back({y,x});
	}
	sort(mp.begin(), mp.end());
	vector<pair<ll, ll> >::iterator it;
	for(it = mp.begin(); it != mp.end(); it++){
		sum += it->second;
		if(sum > it->first){
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}

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

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll K;
    cin >> n >> K;
    vector<ll> a(n), f(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());

    ll ok = 1e12, ng = -1;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        ll cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt += max(a[i] - min(a[i], mid / f[i]), 0LL);
        }
        (cnt <= K ? ok : ng) = mid;
    }
    cout << ok << "\n";
    return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
struct node
{
    int sz,bh;
}a[200005];
int ans[200005];
int cmp(node x,node y)
{
    return x.sz<y.sz;
}
int main()
{
    int n,i,j,r,l;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i].sz;
        a[i].bh=i;
    }
    sort(a+1,a+n+1,cmp);
    r=n;l=n+2;
    for(i=1;i<=n;i++)
    {

       if(i<=n/2)
       {
           ans[a[i].bh]=a[l/2].sz;
       }else
       {
           ans[a[i].bh]=a[r/2].sz;
       }
    }
    for(i=1;i<=n;i++)cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 4480
#include <vector>
#include <cstdio>
using namespace std;
typedef pair<int,int>pii;
main(){
	int n,x,i,q;
	for(;scanf("%d%d",&n,&x),n;printf("%d\n",x)){
		vector<pii>v;
		v.push_back(make_pair(x,1));
		for(i=1;i<n;i++){
			pii p=v.back();v.pop_back();
			scanf("%d",&x);
			if(x==p.first)v.push_back(make_pair(x,p.second+1));
			else if(i&1){
				if(q=0,v.size())q=v.back().second,v.pop_back();
				v.push_back(make_pair(x,q+p.second+1));
			}else{
				v.push_back(p),v.push_back(make_pair(x,1));
			}
		}
		for(x=i=0;i<v.size();i++)if(!v[i].first)x+=v[i].second;
	}
}

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

int main(){
  int A, B, C, X;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;

  int result = 0;
  for (int i = 0; i <= A; i++){
      for (int j = 0; j <= B; j++){
          for (int k = 0; k <=C; k++){
            if (500 * i + 100 * j + 50 * k == X && i + j + k >= 1) result++;
          }
      }

  }
  cout<< result <<endl;

  return 0;
}


Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() { 
  int n,m;
  cin>>n>>m;

  if(m>=n) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;


}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    std::vector<long long> t(2), a(2), b(2);
    for (int i = 0; i < 2; i++) std::cin >> t[i];
    for (int i = 0; i < 2; i++) std::cin >> a[i];
    for (int i = 0; i < 2; i++) std::cin >> b[i];
    std::vector<long long> d(2);
    for (int i = 0; i < 2; i++) d[i] = t[i]*(a[i] - b[i]);
    d[1] += d[0];
    if (d[1] == 0) {
        std::cout << "infinity" << std::endl;
        return 0;
    }
    if ((d[0] > 0) ^ (d[1] < 0)) {
        std::cout << 0 << std::endl;
        return 0;
    }
    long long sa = t[0] * a[0] + t[1] * a[1];
    long long sb = t[0] * b[0] + t[1] * b[1];
    if (sa < sb) {
        std::swap(sa, sb);
        std::swap(a, b);
    }
    long long k = t[1] * (a[1] - b[1]) / (sa - sb);
    std::cout << 2 * k - 1 - ((t[1] * (a[1] - b[1])) % (sa - sb) == 0) << std::endl;
    return 0;
}

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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> s(n,k-q);
  rep(i,q) {
    int a;
    cin >> a;
    s[a-1]++;
  }
  rep(i,n) {
    if (s[i] > 0) puts("Yes");
    else puts("No");
  }
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
ll gyaku(ll x){
  return pow(x,mod-2);
}
vector<ll> frac,gfrac;
void set_frac(ll n){
  frac.push_back(1);
  gfrac.push_back(1);
  for(ll i=1;i<=n;i++){
    frac.push_back(frac[i-1]*i%mod);
    gfrac.push_back(gyaku(frac[i]));
  }
}
ll nCr(ll n,ll r){
  ll res=frac[n]*gfrac[r]%mod;
  res*=gfrac[n-r];
  return res%mod;
}
int main(){
  vector<ll> gv;
  gv.push_back(0);
  ll n;
  cin>>n;
  for(ll i=1;i<=n;i++) gv.push_back((gv[i-1]+pow(i,mod-2))%mod);
  ll ans=0;
  for(int i=1;i<=n;i++){
    ll a;
    cin>>a;
    ans+=(a*(gv[i]+gv[n-i+1]-1))%mod;
  }
  for(ll i=1;i<=n;i++){
    ans*=i;
    ans%=mod;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1400
using System;
using System.Collections.Generic;

namespace cswork
{

    class Program
    {
        public Program() { }

        Scanner cin;

        void Omame()
        {
            cin = new Scanner();

            int a = cin.nextInt();
            int b = cin.nextInt();
            int k = cin.nextInt();

            int tmp = 0;
            for (int i = 100; i >= 1; i--)
            {
                if (a % i == 0 && b % i == 0)
                {
                    tmp++;
                }

                if (tmp == k)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    sort(s.begin(), s.end());

    string t;
    cin >> t;
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if (s < t)  cout << "Yes" << endl;
    else        cout << "No" << endl;    
}

Measured memory_bytes: 256
import heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
while t > 0:
	t -= 1
	# n = map(int,input().split())
	n = int(input())
	v = list(map(int,input().strip().split()))[0:n]
	m = 1000
	i = 0
	while i < n:
		j = i
		# print(i)
		while j+1 < n and v[j+1] >= v[j]:
			j += 1
		x = m//v[i]
		m = m%v[i]
		temp = x*v[j]
		m += temp
		# print(m,i)
		i = j+1
		# m -= x*a[i]
	print(m)
			# for i in range(q):
	# 	p = int(input().strip())
	# 	v.append(p)
	# for i in range(n):
	# 	l.append(0)
	# for i in v:
	# 	l[i-1] += 1
	# for i in range(n):
	# 	if(l[i] <= q-k):
	# 		print("No")
	# 	else:
	# 		print("Yes")


Measured memory_bytes: 62392
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

bool in(ll y, ll x, ll h, ll w){
	return 0 <= y && y < h && 0 <= x && x < w;
}

int main(){
	while(1){
		ll w,h; cin >> w >> h;
		if(!w && !h) break;
		vector<vc> a(h,vc(w));
		ll sy,sx;
		rep(i,h) rep(j,w) cin >> a[i][j];
		rep(i,h) rep(j,w) if(a[i][j]=='@') sy = i, sx = j;
		vvl d(h,vl(w,-1));
		d[sy][sx] = 1;
		queue<P> q;
		q.emplace(sy,sx);
		while(!q.empty()){
			P p = q.front(); q.pop();
			rep(i,4){
				ll ny = p.first + dy[i];
				ll nx = p.second + dx[i];
				if(!in(ny,nx,h,w) || d[ny][nx] > -1) continue;
				d[ny][nx] = a[ny][nx]=='.' ? 1 : 0;
				if(d[ny][nx]) q.emplace(ny,nx);
			}
		}
		ll ans = 0;
		rep(i,h) rep(j,w) if(d[i][j]!=-1) ans += d[i][j];
		cout << ans << endl;
	}
}


Measured memory_bytes: 3180
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n && n) {
    VI a(n);
    REP(i, 0, n) cin >> a[i];
    int st = -1;
    int len = 0;
    vector<PI> cont;
    REP(i, 0, n) {
      if (a[i] == st + len) {
        len += 1;
      } else {
        if (st >= 0)
          cont.push_back(PI(st, len));
        st = a[i];
        len = 1;
      }
    }
    cont.push_back(PI(st, len));
    REP(i, 0, cont.size()) {
      if (cont[i].second == 1) {
        cout << cont[i].first;
      } else {
        cout << cont[i].first << "-" << cont[i].first + cont[i].second - 1;
      }
      cout << (i + 1 == cont.size() ? "\n" : " ");
    }
  }
}



Measured memory_bytes: 3120
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int> > G(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	if (M % 2 == 1) {
		cout << -1 << endl;
	}
	else {
		vector<bool> vis(N, false);
		vector<int> out(N), depth(N);
		function<void(int, int)> dfs = [&](int pos, int pre) {
			vis[pos] = true;
			for (int i : G[pos]) {
				if (vis[i]) {
					if (depth[i] < depth[pos] - 1) {
						cout << i + 1 << ' ' << pos + 1 << endl;
						++out[i];
					}
				}
				else {
					depth[i] = depth[pos] + 1;
					dfs(i, pos);
				}
			}
			if (pre != -1) {
				if (out[pos] % 2 == 1) {
					cout << pos + 1 << ' ' << pre + 1 << endl;
					++out[pos];
				}
				else {
					cout << pre + 1 << ' ' << pos + 1 << endl;
					++out[pre];
				}
			}
		};
		dfs(0, -1);
	}
	return 0;
}

Measured memory_bytes: 18560
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int a, b, c, d, e, f;
int wat[1000000];
int sug[1000000];
int cntw = 0;
int cnts = 0;

int main() {
    cin >> a >> b >> c >> d >> e >> f;
    for (int i = 0; i <= f; i += (100 * a)) {
        for (int j = 0; j <= f; j += (100 * b)) {
            if (i + j > f) {
                continue;
            }
            wat[cntw] = i + j;
            cntw += 1;
        }
    }
    for (int i = 0; i <= f; i += c) {
        for (int j = 0; j <= f; j += d) {
            if (i + j > f) {
                continue;
            }
            sug[cnts] = i + j;
            cnts += 1;
        }
    }
    double maxc = -1.0;
    double answ = 0, anss = 0;
    for (int i = 0; i < cntw; i++) {
        for (int j = 0; j < cnts; j++) {
            if (wat[i] + sug[j] > f) {
                continue;
            }
            if (wat[i] * e < 100 * sug[j]) {
                continue;
            }
            double ii = (double)wat[i];
            double jj = (double)sug[j];
            if ((100.0 * jj) / (ii + jj) > maxc) {
                maxc = (100.0 * jj) / (ii + jj);
                answ = wat[i] + sug[j];
                anss = sug[j];
            }
        }
    }
    cout << answ << " " << anss << endl;
}

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

int n[1000];

int main()
{
	string n;
	cin >> n;
	int k = n.size();
	for (int i = 0; i < k; ++i)
		cin >> n[i];
	for (int i = 0; i < k; ++i)
	{
		if (n[i] == '7')
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 3588
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int a, b;
  cin >> a >> b;
  cout << max(0, a - b) << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    n, m = [int(i) for i in input().split()]
    # digits = [(int(i) for i in input().split()) for _ in range(m)]
    digits = [-1] * n
    for i in range(m):
        s, c = [int(i) for i in input().split()]
        if not digits[s-1] in (-1, c):
            print(-1)
            return

        digits[s-1] = c

    top = True
    for i in range(n):
        d = digits[i]
        if top:
            if d == 0:
                if i+1 < n:
                    print(-1)
                    return
                top = False
            if d == -1:
                digits[i] = 0
            else:
                top = False
        else:
            if d == -1:
                digits[i] = 0

    t = str(int("".join([str(i) for i in digits])))
    if len(t) == n:
        print(t)
    else:
        s = [str(i) for i in digits]
        s[0] = "1" if n > 1 else "0"
        print("".join(s))

main()


Measured memory_bytes: 3064