akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
9
1 1 1 2 2 1 2 3 2
)");
#define cin input
#endif

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

	vector<int> b(n);
	for (auto& i : b)
		cin >> i;
	vector<int> r;
	
	for (int i = n; i > 0; --i)
	{
		for (int j = i; j > 0; --j)
			if (b[j - 1] == j)
			{
				b.erase(b.begin() + j - 1);
				r.push_back(j);
				break;
			}
		if (b.size() == i)
			break;
	}

	if (b.size())
		cout << -1 << endl;
	else
		REP (i, n)
			cout << r[n - i - 1] << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    String S = sc.next();
    
    int zeroSeqCount = 0;
    int tail = 0;
    // set initial tail
    while (tail < N) {
      char c = S.charAt(tail);
      if (c == '0') {
        zeroSeqCount++;
        if (zeroSeqCount == K+1) {
          break;
        }
        tail++;
        while (tail < N && S.charAt(tail) == '0') {
          tail++;
        }
      } else {
        tail++;
      }
    }
    if (tail == N) {
      System.out.println(N);
      return;
    }

    int head = 0;
    int max = tail - head;
    while (tail < N) {

      //
      // move tail
      //

      // skip seq 0
      while (tail < N && S.charAt(tail) == '0') {
        tail++;
      }
      // move to head of next 0 seq
      while (tail < N && S.charAt(tail) != '0') {
        tail++;
      }
      
      //
      // move head
      //
      while (head < tail && S.charAt(head) != '0') {
        head++;
      }
      while (head < tail && S.charAt(head) == '0') {
        head++;
      }
      
      max = Math.max(max, tail-head);
    }
    
    System.out.println(max);
  }  
}

Measured memory_bytes: 23892
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int k = in.nextInt();
		Set<String> set = new HashSet<>();
		for (int i = 0; i < s.length(); i++) {
			for (int j = i + 1; j < i + 1 + k && j <= s.length(); j++) {
				set.add(s.substring(i, j));
			}
		}
		List<String> list = new ArrayList<>(set);
		Collections.sort(list);
		System.out.println(list.get(k - 1));
		in.close();
	}
}

Measured memory_bytes: 25156
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll x;
  cin >> x;
  
  cout << 1 - x << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
using namespace std;
long r,i;
string s,t;
int main() {
    cin >> s >> t;
    r = 0;
    for(i = 0; i < s.length(); i++) {
        if(s[i] != t[i]) r++;
    }
    cout << r;
    return 0;
}

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


int main() {
    int X;
    cin >>X;
    for(int i =X;1<=i;i--){
       for(int j=1;j<=X;j++){
          for(int k=2;k<=10;k++){
            if(i==pow(j,k)){
              cout <<i<<endl;
              return 0;
            }
          }
        }
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<string, int> pa;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> P(N);
  REP(i, N)
  cin >> S[i] >> P[i];
  pair<pa, int> vc[N];
  REP(i, N)
  vc[i] = make_pair(make_pair(S[i], -1 * P[i]), i + 1);
  sort(vc, vc + N);
  REP(i, N)
  cout << vc[i].second << endl;
  return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    int count = 0;
    while(t--){
        int l, r;
        cin >> l >> r;
        for(int i = l; i <= r; i++){
            count++;
        }
    }
   cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#  --*-coding:utf-8-*--

INF = float('inf');

def fulkerson(graph, src, sink):
    n = len(graph)

    matrix = [[0]*n for i in range(n)]
    bothDirGraph = [[] for i in range(n)]

    for nodeId, edges in enumerate(graph):
        for nodeId2, flowLimit in edges:
            matrix[nodeId][nodeId2] = flowLimit
            bothDirGraph[nodeId].append(nodeId2)
            bothDirGraph[nodeId2].append(nodeId)

    while True:
        path = findPath(bothDirGraph, matrix, src, sink)

        if path == None:
            break

        v = min(matrix[path[i]][path[i+1]] 
                for i in range(len(path)-1))

        for i in range(len(path)-1):
            node1 = path[i]
            node2 = path[i+1]
            
            matrix[node1][node2] -= v
            matrix[node2][node1] += v

    return (sum(c for _, c in graph[src]) - 
            sum(c for c in matrix[src]))


def findPath(bothDirGraph, matrix, src, sink):
    prevs = [None]*len(matrix)
    q = set([src])
    prevs[src] = src

    while len(q) > 0:
        node = q.pop()

        for nextNode in bothDirGraph[node]:
            if prevs[nextNode] == None and matrix[node][nextNode] > 0:
                prevs[nextNode] = node
                
                if nextNode == sink:
                    path = []
                    pathNode = sink

                    while pathNode != src:
                        path.append(pathNode)
                        pathNode = prevs[pathNode]

                    path.append(src)
                    return list(reversed(path))

                q.add(nextNode)

    return None
                    
def f(N, A):
    graph = [[] for i in range(N+2)]
    srcId = 0
    dstId = N+1

    for nodeId, a in enumerate(A, 1):
        if a < 0:
            graph[0].append((nodeId, -a))
        else:
            graph[nodeId].append((N+1, a))

        for k in range(2, N//nodeId+1):
            graph[nodeId].append((nodeId*k, INF))

    return (sum(filter(lambda a: a>0, A)) - 
            fulkerson(graph, 0, N+1))

def main():
    N = int(input())
    A = list(map(int, input().split()))

    print(f(N, A))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import Data.Bool (bool)

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  ds <- map (uncurry (==) . unsafeListToPair . map unsafeTextToInt . T.words) . T.lines <$> T.getContents :: IO [Bool]
  putStrLn . bool "No" "Yes" . any ((True, True, True) ==) . (zip3 <$> id <*> tail <*> tail . tail) $ ds

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair = (,) <$> head <*> head . tail
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 3920
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;

int main(){
	int k,n;
	cin >> k >> n;
	vector<int> a;
	int ima, mae=0;
	REP(i,n){
		cin >> ima;
		a.push_back(ima-mae);
		mae = ima;
	}
	a[0] += k-ima; 
	sort(a.begin(),a.end());
	int ans=0;
	REP(i,n-1){
		ans+=a[i];
	}
	
	cout << ans << "\n";
	
}

Measured memory_bytes: 1400
from sys import stdin
input = stdin.readline

N = int(input())
a = list(map(int, input().split()))

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

for i in range(N):
    dp[i][i + 1] = a[i] if N & 1 == 1 else -a[i]

for j in range(2, N + 1):
    for i in range(0, N + 1 - j):
        # j is the length of the interval + 1
        if (N - j) & 1 == 0:
            dp[i][i + j] = max(a[i] + dp[i + 1][i + j],
                               a[i + j - 1] + dp[i][i + j - 1])
        else:
            dp[i][i + j] = min(dp[i + 1][i + j] - a[i],
                               dp[i][i + j - 1] - a[i + j - 1])

print(dp[0][N])


Measured memory_bytes: 113628
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<int> l(n);
    for(int i=0; i<n; i++) cin>>l[i];

    if(2**max_element(l.begin(), l.end())<accumulate(l.begin(), l.end(), 0)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main()
{
  IOS;
  int n;
  cin>>n;
  int ac =0 ;
  int tle = 0;
  int re = 0;
  int wa = 0;
  while(n--)
  {
   string a;
   cin>>a;
   if(a=="WA")
   wa++;
   else if(a=="TLE")
   tle++;
   else if(a=="RE")
   re++;
   else if(a=="AC")
   ac++;
  }
  cout<<"AC x "<<ac<<endl<<"WA x "<<wa<<endl<<"TLE x "<<tle<<endl<<"RE x "<<re<<endl;
  return 0;
}



Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main()
{
    int a[3];
    for(int i=0;i<3;i++)
        cin>>a[i];
    sort(a,a+3);
    cout <<a[2]-a[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

struct Point{
    int x, y, i;

    bool operator<(const Point &that)const {
        return i < that.i;
    }
    void print(){
//        cout << i << endl;
        printf("%d\n", i);
    }
};
bool lessX(const Point &p1, const Point &p2){ return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2){ return p1.y < p2.y; }

struct Node{
    int ld_id, ru_id;
    int p_id;
};

// kd tree DST
static const int MAX_N = 500000;
Point pts[MAX_N];
Node ns[MAX_N]; // nodes of ketree
int tindex;
int makeKdTreeNode(int i, int n, int i1);

void queryRect(int sx, int sy, int tx, int ty, int nodeId, int depth, vector<Point> &inPts);

int main(){
    int n;
//    cin >> n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        Point &p = pts[i];
        p.i = i;
//        cin >> p.x >> p.y;
        scanf("%d %d",&p.x,&p.y);
    }


    tindex = 0;
    int rootNodeId = makeKdTreeNode(0, n, 0);

    int q;
//    cin >> q;
    scanf("%d", &q);
    vector<Point> inPts;
    for (int i = 0; i < q; i++) {
        int sx, tx, sy, ty;
//        cin >> sx >> tx >> sy >> ty;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);

        inPts.clear();
        queryRect(sx, sy, tx, ty, rootNodeId, 0, inPts);

        sort(inPts.begin(), inPts.end());
        for (Point p : inPts) {
            p.print();
        }
        printf("\n");
    }

    return 0;


}

int makeKdTreeNode(int left, int right, int depth) {
    if (left >= right) {
        return -1;
    }

    int curNodeIndex = tindex++;

//    bool (*c)(const Point &p1, const Point &p2) =  depth % 2 == 0 ? lessX : lessY;
//    sort(pts + left, pts + right, c);
    if(depth%2 == 0){
        sort(pts+left,pts+right,lessX);
    }else{
        sort(pts+left,pts+right,lessY);
    }

    int mid = (left + right) / 2;
    ns[curNodeIndex].p_id = mid;

    ns[curNodeIndex].ld_id = makeKdTreeNode(left, mid, depth + 1);
    ns[curNodeIndex].ru_id = makeKdTreeNode(mid + 1, right, depth + 1);

    return curNodeIndex;
}

void queryRect(int sx, int sy, int tx, int ty, int nodeId, int depth, vector<Point> &inPts){

    Point &p = pts[ns[nodeId].p_id];
    int x = p.x, y = p.y;

    if ((sx <= x && tx >= x && sy <= y && ty >= y)) {
        inPts.push_back(p);
    }

    if (depth % 2 == 0) {
        if (ns[nodeId].ru_id !=-1 && tx >= x)
            queryRect(sx, sy, tx, ty, ns[nodeId].ru_id, depth + 1, inPts);
        if (ns[nodeId].ld_id !=-1 && sx <= x)
            queryRect(sx, sy, tx, ty, ns[nodeId].ld_id, depth + 1, inPts);
    }
    else{
        if (ns[nodeId].ru_id !=-1 && ty >= y)
            queryRect(sx, sy, tx, ty, ns[nodeId].ru_id, depth + 1, inPts);
        if (ns[nodeId].ld_id !=-1 && sy <= y)
            queryRect(sx, sy, tx, ty, ns[nodeId].ld_id, depth + 1, inPts);
    }
}



Measured memory_bytes: 14504
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-01-19 20:50:05
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

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

    return 0;
}


Measured memory_bytes: 256
n = 3
num_list = [list(map(int, input().split())) for _ in range(n)]
N = (sum(num_list, []))
N1 = N.count(1)
N2 = N.count(2)
N3 = N.count(3)
N4= N.count(4)
if N1 > 2 or N2 > 2 or N3 > 2 or N3 > 2 or N4 > 2:
    print('NO')
else:
    print('YES')


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define en "\n"
#define eps 1e-9
#define VECT(v)  vector<int>v
#define SCAN(v)  int temp; for(int i=0; i<n; i++) {cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << en;
#define SORT(v)  sort(v.begin(), v.end());
#define CASEP(v) cout<<"Case "<<c<<": "<<v<<"\n"
#define DEBUG(v) cout << v << " "; cout << en;

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

	fast_io
	
	int n, x, t;
	cin >> n >> x >> t;

	double ans = (double)n/(double)x;
	int ans2 = ceil(ans) * t;
	cout << ans2 << en;

	return 0;
}

Measured memory_bytes: 3644
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007



int main(int argc, char const *argv[]) {
  int n;
  std::cin >> n;
  std::cout << 48-n << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define NUM_MAX 1000000

int hamming_num[NUM_MAX];

void make_hamming_num(void) {
	int i;
	int now,now2,now3;
	for(now=1;now<=NUM_MAX;now*=2) {
		for(now2=now;now2<=NUM_MAX;now2*=3) {
			for(now3=now2;now3<=NUM_MAX;now3*=5) {
				hamming_num[now3-1]=1;
			}
		}
	}
	for(i=1;i<NUM_MAX;i++) {
		hamming_num[i]+=hamming_num[i-1];
	}
}

int main(void) {
	int start,end;
	make_hamming_num();
	while(1) {
		scanf("%d",&start);
		if(start==0)break;
		scanf("%d",&end);
		printf("%d\n",hamming_num[end-1]-hamming_num[(start-1)-1]);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer p[] = new Integer[n];
        Integer max = 0;
        Integer maxPos = 0;
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            if (max < p[i]) {
                max = p[i];
                maxPos = i;
            }
        }

        int sum = 0;
        for (int i = 0; i < n; i++) {
            if (maxPos == i) {
                p[i] /= 2;
            }
            sum += p[i];
        }
        System.out.println(sum);
    }
}



Measured memory_bytes: 23252
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int i=0;
        int num = 1;
        while(num <= N){
            i++;
            num*=2;
        }
        i--;
        System.out.println((1<<i));
    }
}


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

using namespace std;

int solve(std::vector<char>& ss) {
  if (ss.size() <= 1) {
    return 0;
  }
  int ret = 0;
  int firstRemoved = 0;
  int lastRemoved = ss.size();
  do {
    int const begin = std::max(0, firstRemoved - 1);
    int const end = std::min(int(ss.size()), lastRemoved + 1);
    firstRemoved = -1;
    lastRemoved = 10000000;
    for (int i = begin; i + 1 < std::min(int(ss.size()), end);) {
      if (ss[i] != ss[i + 1]) {
        ss.erase(ss.begin() + i, ss.begin() + i + 2);
        if (firstRemoved < 0) {
          firstRemoved = i;
        }
        lastRemoved = i;
        ret += 2;
      } else {
        ++i;
      }
    }
  } while (firstRemoved >= 0 && ss.size() > 1);
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::string s;
  std::cin >> s;
  std::vector<char> ss;
  for (auto ch : s) {
    ss.push_back(char(ch == '1'));
  }
  std::cout << solve(ss) << std::endl;
  return 0;
}


Measured memory_bytes: 640
var
i:longint;
s:string;
b:boolean;
begin
readln(s);
if (s[1]<>'A') or (s[2]='C') or (s[length(s)]='C') then
begin
writeln('WA');
halt;
end;
b:=false;
for i:=2 to length(s) do
 if s[i]='C' then
 begin
  if b then
  begin
  writeln('WA');
  halt;
  end;
 b:=true;
 end
 else
  if s[i] in ['A'..'Z'] then
  begin
  writeln('WA');
  halt;
  end;
if b then
writeln('AC')
else
writeln('WA');
end.

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
  double w,h,x,y;
  cin>>w>>h>>x>>y;
  int b=0;

  if(2*x==w&&2*y==h){
    b=1;
  }

  cout<<w*h/2<<" ";
  cout<<b;
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

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

	if(a%2 == 0 || b%2 == 0 || c%2 == 0)
		cout << 0 << endl;
	else
		cout << min({a*b,b*c,a*c}) << endl;

	return 0;
}

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

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

  string a, b;
  cin >> a >> b;
  int n = stoi(a + b);
  string ans = (n == pow(floor(sqrt(n)), 2)) ? "Yes" : "No";
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int HMAX = 410, WMAX = 410;
int H,W;
vector<vector<char> > maze(WMAX,vector<char>(HMAX));
vector<bool> reach(WMAX*HMAX,false);
vector<vector<int> > G(HMAX*WMAX);


bool isArea(int x,int y){
  return x>=0 && x<W && y>=0 && y<H;
}

PLL dfs(int n){
  if(reach[n]) return PLL(0,0);
  reach[n] = true;
  ll n_Black = 0;
  ll n_White = 0;
  int x = n%W, y = n/W;
  if(maze[x][y] == '#') ++n_Black;
  else ++n_White;
  for(const int &u : G[n]){
    PLL p = dfs(u);
    n_Black += p.first;
    n_White += p.second;
  }
  return PLL(n_Black,n_White);
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> H >> W;
  rep(y,H) rep(x,W)cin >> maze[x][y];
  rep(y,H) rep(x,W){
    if(y<H-1 && maze[x][y] != maze[x][y+1]){
      G[y*W+x].push_back((y+1)*W+x);
      G[(y+1)*W+x].push_back(y*W+x);
    }
    if(x<W-1 && maze[x][y] != maze[x+1][y]){
      G[y*W+x].push_back(y*W+x+1);
      G[y*W+x+1].push_back(y*W+x);
    }
  }

  ll ans = 0;
  rep(y,H) rep(x,W){
    PLL p = dfs(y*W+x);
    ans += p.first*p.second;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 16896
/*
 * main.c
 *
 *  Created on: 2019/07/21
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int main()
{
	int A = 0, B = 0, C = 0, X = 0;
	int ans = 0, ia = 0, ib = 0, ic = 0;
	scanf("%d", &A); // 500
	scanf("%d", &B); // 100
	scanf("%d", &C); // 50
	scanf("%d", &X);
	for (ia = 0; ia <= A; ia++) {
		for (ib = 0; ib <= B; ib++) {
			for (ic = 0; ic <= C; ic++) {
				if (((ia*500) + (ib*100) + (ic*50)) == X) {
					ans++;
				}
			}
		}
	}
	printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;
const int mod = 1000000007;

ll mpow(ll x, ll n, ll mod){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % mod;
        x = x * x % mod;
        n  = n >> 1;
    }
    return ans;
}


int main(){
    ll N; cin >> N;
    ll ans = mpow(10, N, mod);
    ll tmp = mpow(9, N, mod);
    ans -= tmp;
    ans += mod;
    ans %= mod;
    ans -= tmp;
    ans += mod;
    ans %= mod;
    tmp = mpow(8, N, mod);
    ans += tmp;
    ans += mod;
    ans %= mod;
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int i,j,n,k;
    cin>>n>>k;
    if(k==1)
        cout<<0<<endl;
    else
        cout<<n-k<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
#define N 100
enum {
    WHITE,
    GRAY,
    DARK
};
 
int M[N][N] = {0};
int color[N] = {0};
int dt[N] = {0};
int ft[N] = {0}; 
int tt = 0, n = 0;
 
void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    dt[u] = ++tt;
    for(v = 0; v < n; v++){
        if(M[u][v] == 0) continue;
        if(color[v] == WHITE){
            dfs_visit(v);
        }
    }
        color[u] = DARK;
        ft[u] = ++tt;
}
 
void dfs(){
    int i;
    for(i = 0; i < n; i++){
        if(color[i] == WHITE){
            dfs_visit(i);
        }
    }
 
    for(i = 0; i < n; i++){
        printf("%d %d %d\n", i+1, dt[i], ft[i]);
    }
}
 
int main(void){
     
    int u, k, v, i, j;
    u = k = v = 0;
 
 
    scanf("%d", &n);
 
    for(i = 0; i < n; i++){
            scanf("%d", &u);
            scanf("%d", &k);
            for(j = 0; j < k; j++){
                scanf("%d", &v);
                v--;
                M[i][v] = 1;
            }   
    }
      
    dfs();
 
}


Measured memory_bytes: 2088
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,n,q,j,dp[21][2001],a[20],m;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	for(i=0;i<=n;i++)	{
		for(j=0;j<=2000;j++)	dp[i][j]=0;
	}
	dp[0][0]=1;
	for(i=0;i<n;i++)	{
		for(j=0;j<=2000;j++)	{
			if(dp[i][j]==1)	dp[i+1][j]=1;
			if(dp[i][j]==1 && j+a[i]<=2000)	dp[i+1][j+a[i]]=1;
		}
	}
	scanf("%d",&q);
	for(i=0;i<q;i++)	{
		scanf("%d",&m);
		if(dp[n][m]==1)	printf("yes\n");
		else printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2748
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];
        for(int i=0;i<n;i++){a[i]=sc.nextInt();}
        for(int i=n-1;i>=0;i--){
            if(i==n-1){System.out.print(a[i]);continue;}
            System.out.printf(" %d",a[i]);
        }
        System.out.println();
    }
}



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

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define nfor(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int i = int(l); i < int(r); i++)
#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define mp(x, y) make_pair((x), (y))
#define x first
#define y second

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<li, li> ptl;

template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

template<typename A, typename B> inline ostream& operator<< (ostream& out, const pair<A, B>& p) { return out << "(" << p.x << ", " << p.y << ")"; }
template<typename T> inline ostream& operator<< (ostream& out, const vector<T>& a) { out << "["; forn(i, sz(a)) { if (i) out << ','; out << ' ' << a[i]; } return out << " ]"; }
template<typename T> inline ostream& operator<< (ostream& out, const set<T>& a) { return out << vector<T>(all(a)); }
template<typename X, typename Y> inline ostream& operator<< (ostream& out, const map<X, Y>& a) { return out << vector<pair<X, Y>>(all(a)); }
template<typename T> inline ostream& operator<< (ostream& out, const pair<T*, int>& a) { return out << vector<T>(a.x, a.x + a.y); }

inline ld gett() { return ld(clock()) / CLOCKS_PER_SEC; }

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;

#ifdef SU1
#define LOG
#endif

int n;
li a, b, c, d;

bool read() {
	return !!(cin >> n >> a >> b >> c >> d);
}

void solve() {
  forn(t, 2) {
    ptl g(a, a);
    ptl q(b + (n - 1) * c, b + (n - 1) * d);

    forn(i, n - 1) {
      if (max(g.x, q.x) <= min(g.y, q.y)) {
        clog << "t: " << t << " i: " << i << " g: " << g << " q: " << q << endl;
        puts("YES");
        return;
      }
      g.x += c, g.y += d;
      q.x -= c, q.y -= d;
    }
    assert(g.x == a + (n - 1) * c && g.y == a + (n - 1) * d);
    assert(q.x == b && q.y == b);

    swap(a, b);
  }
  puts("NO");
}

int main() {
#ifdef SU1
    assert(freopen("input.txt", "rt", stdin));
    //assert(freopen("output.txt", "wt", stdout));
#endif

    cout << setprecision(10) << fixed;
    cerr << setprecision(5) << fixed;

    while (read()) {
			ld stime = gett();
			solve();
			cerr << "Time: " << gett() - stime << endl;
			//break;
		}

    return 0;
}


Measured memory_bytes: 256
x1, y1, x2, y2 = gets.split.map(&:to_i)
dx = x2 - x1
dy = y2 - y1
x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy
puts [x3, y3, x4, y4].join(' ')

Measured memory_bytes: 1788
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int n;
  int u[1000],d[1000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u[i];
  }
  for(int j=0;j<n;j++){
    cin>>d[j];
  }
  int ans=0,x=0;
  for(int k=0;k<n;k++){
    for(int l=0;l<n;l++){
      if(k>=l)
        ans+=u[l];
      if(k<=l)
        ans+=d[l];
    }
    x=max(ans,x);
    ans=0;
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define lp(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,tp=0,hp=0;
  string tc,hc;
  cin>>n;
  lp(i,n){
    cin>>tc>>hc;
    if(tc>hc)tp+=3;
    else if(tc<hc)hp+=3;
    else {
      tp++;
      hp++;
    }
    
  }
  cout<<tp<<" "<<hp<<endl;
  return 0;
  
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
const int N=505;
int a[N*N],b[N*N];
int n,m,ans,wei[N];
bitset<N> f[N],tmp;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
		scanf("%d%d",&a[i],&b[i]);
	for (int i=1;i<=n;i++){
		tmp.reset(); tmp[i]=1;
		for (int j=m;j;j--)
			if (tmp[a[j]]&tmp[b[j]]){
				wei[i]=1; break;
			}
			else if (tmp[a[j]]|tmp[b[j]])
				tmp[a[j]]=tmp[b[j]]=1;
		f[i]=tmp;
	}
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			if (!wei[i]&&!wei[j])
				if (!(f[i]&f[j]).count()) ans++;
	printf("%d",ans);
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String []args) throws Exception {
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        // int n = Integer.parseInt(br.readLine());
        // long [][] dp = new long[n+1][n+1];
        // ArrayList<String> list = new ArrayList<>();
        int n = sc.nextInt();
        if(n >= 30){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}

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

#define rep(i, from, to) for (int i = from; i < to; ++i)
#define REP(i, from, to) for (int i = from; i <= to; ++i)
#define dbp(x) cout<<#x<<": "<<x<<endl;
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl;
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl;
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl;

using namespace std;
struct team {
	int total, p, id;
	int miss[11], isOk[11], time[11];
	team() {
		fill(miss, miss + 11, 0);
		fill(isOk, isOk + 11, 0);
		fill(time, time + 11, 0);
		total = 0;
		p = 0;
		id = 0;
	}
};

bool cmp(const team &t1, const team &t2) {
	if (t1.p > t2.p)
		return true;
	if (t1.p < t2.p)
		return false;
	if (t1.total > t2.total)
		return true;
	if (t1.total < t2.total)
		return false;
	if (t1.id > t2.id)
		return true;
	return false;
}

bool cmp2(const team &t1, const team &t2) {
	if (t1.p == t2.p) {
		if (t1.total == t2.total) {
			return t1.id < t2.id;
		} else {
			return t1.total > t2.total;
		}
	} else {
		return t1.p < t2.p;
	}
}

bool eq(team t1, team t2) {
	return t1.p == t2.p && t1.total == t2.total;
}
team data[51];

void solve() {
	int M, T, P, R, m, t, p, j;

	while (cin >> M >> T >> P >> R, M || T || P || R) {
		fill(data, data + 51, team());
		rep(i, 0, R)
		{
			cin >> m >> t >> p >> j;
			if (j == 0) {
				data[t].isOk[p] = 1;
				data[t].time[p] = m;
				data[t].p++;
			} else {
				data[t].miss[p]++;
			}
		}

		REP(i, 1, T)
		{
			data[i].id = i;
			REP(j, 1, P)
			{
				data[i].total += data[i].isOk[j] * data[i].time[j]
						+ data[i].isOk[j] * data[i].miss[j] * 20;

			}
			team di = data[i];
//			dbp3(di.id, di.p, di.total);
		}
		sort(data + 1, data + T + 1, cmp2);
		reverse(data + 1, data + T + 1);
		team before = data[1];
		cout << data[1].id;
		REP(i, 2, T)
		{
			team now = data[i];
			if (eq(before, now))
				cout << "=" << now.id;
			else
				cout << "," << now.id;
			before = now;
		}
		cout << endl;
	}
}

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

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

map<char, int> mp;
string s; cin >> s; int n = s.size();for(int i=0; i<n; i++) mp[s[i]]++; for(auto e: mp) if(e.second & 1) { cout << "No\n"; return 0; } cout << "Yes\n";
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

bool solve(string S){
    int n=S.size();
    if(n%2==1){
        string x;
        rep(i,n/2)x.pb(S[i]);
        string y;
        REP(i,n/2+1,n)y.pb(S[i]);
        reverse(ALL(y));
        if(x==y)return true;
        return false;
    }else{
        string x,y;
        rep(i,n/2)x.pb(S[i]);
        REP(i,n/2,n)y.pb(S[i]);
        reverse(ALL(y));
        if(x==y)return true;
        return false;
    }
}

int main(){
    string S;
    cin>>S;
    if(!solve(S)){
        cout<<"No"<<endl;
        return 0;
    }
    int N=S.size();
    string a;
    rep(i,(N-1)/2){
        a+=S[i];
    }
    if(!solve(a)){
        cout<<"No"<<endl;
        return 0;
    }
    //cout<<a<<endl;
    a="";
    REP(i,(N+3)/2-1,N){
        a+=S[i];
    }
    if(!solve(a)){
        cout<<"No"<<endl;
        return 0;
    }
    //cout<<a<<endl;
    cout<<"Yes"<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
from itertools import combinations
n, k = map(int, input().split())
if k*2 > (n-1)*(n-2):
	print(-1)
else:
	ans = [[1, i] for i in range(2, n+1)]
	if k*2 < (n-1)*(n-2):
		cnt = 0
		for c in combinations(range(2, n+1), r=2):
			ans.append([c[0], c[1]])
			cnt += 1
			if cnt == ((n-1)*(n-2))//2 - k:
				break
	print(len(ans))
	for a in ans:
		print(a[0], a[1])

Measured memory_bytes: 4120
/*
	 
	                              Jai Shree Krishna !!
	                                 Radhe Radhe !!
	                                 
	             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
	             
	*/
	   
	   
	#include <bits/stdc++.h>
	using namespace std;
	 
	#define int long long
	typedef long long ll;
	#define loop(i,n)  for(int i=0;i<n;i++)
	#define read(a) int a; cin >>a;
	#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
	#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
	#define pb push_back
	#define ff first
	#define ss second
	#define vi vector<int>
	#define pi pair<int,int>
	#define vvi vector<vector<int>>
	#define sti set<int>
	#define vpi vector<pair<int,int>>
	#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
	#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
	#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
	#define endl "\n"
	#define mp make_pair
	#define ins insert
	#define rep(i,s,e)   for(int i=s;i<=e;i++)
	#define repd(i,s,e)  for(int i=e;i>=s;i--)
	#define vb vector<bool>
	#define read2(n,m) int n,m; cin >> n >> m;
	#define range(v) v.begin(),v.end()
	#define sortd(v) sort(v.begin(),v.end(),greater<int>())
	#define sorti(v) sort(v.begin(),v.end())
	 
	const ll inf = 1e18;
	const ll mod = 1e9 + 7;


    void subsetsUtil(vector<int>& A, vector<vector<int> >& res, 
                 vector<int>& subset, int index) 
{ 
    res.push_back(subset); 
    for (int i = index; i < A.size(); i++) { 
  
        // include the A[i] in subset. 
        subset.push_back(A[i]); 
  
        // move onto the next element. 
        subsetsUtil(A, res, subset, i + 1); 
  
        // exclude the A[i] from subset and triggers 
        // backtracking. 
        subset.pop_back(); 
    } 
  
    return; 
} 
  
// below function returns the subsets of vector A. 
vector<vector<int> > subsets(vector<int>& A) 
{ 
    vector<int> subset; 
    vector<vector<int> > res; 
  
    // keeps track of current element in vector A; 
    int index = 0; 
    subsetsUtil(A, res, subset, index); 
  
    return res; 
} 

	signed main()
	{
	 
	    fast;
		read2(n,m);
		read(k);
		string s[n];
		rep(i,0,n-1) cin >> s[i];
		vi a(n) , b(m);
		rep(i,0,n-1) a[i]=i;
		rep(i,0,m-1) b[i]=i;
		
		vector<vector<int> > s1 = subsets(a);
		vector<vector<int> > s2 = subsets(b);
		
		int c=0,ans=0;
	
		
		for(int i=0;i<s1.size();i++){
			for(int j=0;j<s2.size();j++){
				string t[n];
				c=0;
				rep(i,0,n-1){
				t[i]=s[i];	
				}
				
				for(auto x:s2[j]){
					rep(l,0,n-1) t[l][x] = 'r';
				}
				for(auto x:s1[i]){
					rep(l,0,m-1) t[x][l]='r';
				}
				
				rep(i,0,n-1){
				rep(j,0,m-1){
					if(t[i][j]=='#') c++;
				}
			   }
			   if(c==k) ans++;
				
			}
		}
		cout<<ans<<endl;
	    return 0;
	}
	 
	/* Pooja Yadav */

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int t,data[100000];;
	for(cin>>t;t>0;t--){
		int n,k,before,tmp,sum=0;
		cin>>n>>k;
		
		cin>>before;
		for(int i=1;i<n;i++){
			cin>>tmp;
			data[i-1]=tmp-before;
			before=tmp;
		}
		sort(data,data+n-1);
		for(int i=0;i+k<n;i++)sum+=data[i];
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 1564
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

vector<int> g[2010];
int main() {
  int n,x,y;
  cin >> n >> x >> y;
  --x;--y;
  rep(i,n-1) {
    g[i].push_back(i+1);
    g[i+1].push_back(i);
  }
  g[x].push_back(y);
  g[y].push_back(x);

  vector<vector<int>> d(n,vector<int>(n, 3000));
  rep(i,n) {
    d[i][i] = 0;
    stack<P> q;
    auto push = [&](int j, int nd){
      for (int x : g[j]) {
        if (d[i][x] >= nd || d[x][i]>=nd) {
          q.emplace(x,nd);
        }
      }
    };
    push(i,1);
    while ( !q.empty()) {
      P p = q.top(); q.pop();
      int m = min(d[i][p.first],d[p.first][i]);
      d[i][p.first] = d[p.first][i] = min(m,p.second);
      push( p.first, p.second + 1 );
    }
  }
  map<int,int> ans;
  rep(i,n)rep(j,n) ans[d[i][j]]++;
  rep(i,n-1) cout << (ans[i+1]/2) << endl;
}
  


Measured memory_bytes: 16128
import sys
from operator import itemgetter
input = sys.stdin.readline


def main():
    N = int(input())
    AB = [None] * N
    for i in range(N):
        A, B = map(int, input().split())
        AB[i] = (A, B, A + B)

    AB.sort(reverse=True, key=itemgetter(2))
    sum_A = 0
    sum_B = 0
    for i in range(N):
        if i % 2 == 0:
            sum_A += AB[i][0]
        else:
            sum_B += AB[i][1]

    ans = sum_A - sum_B
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22132
# define _CRT_SECUREj_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

typedef pair<double, vi> P;
struct food
{
	string name;
	int w;
	int s;
};
int n;
vector<food> a;

P calc(int bit, int s, double g, double d)
{
	if (s < 0)return P(-1, {});
	int _n = __builtin_popcount(bit);
	if (_n == n)
		return P(g / d, {});

	P ans = P(9999999999.0, {});
	FOR(i, n)
	{
		if (bit & 1 << i)continue;
		int nbit = bit | 1 << i;
		int ns = min(s - a[i].w, a[i].s);
		double ng = g + (_n + 1)*a[i].w;
		double nd = d + a[i].w;
		P x = calc(nbit, ns, ng, nd);
		if (x.first < 0)continue;
		if (ans.first > x.first)
		{
			ans = x;
			ans.second.insert(ans.second.begin(), i);
		}
	}
	return ans;
}

int main()
{
	while (cin >> n&&n)
	{
		a.clear();
		FOR(i, n)
		{
			food f;
			cin >> f.name >> f.w >> f.s;
			a.push_back(f);
		}
		P ans = calc(0, INT_MAX, 0, 0);
		FOR(i, n)
		{
			cout << a[ans.second[i]].name << endl;
		}
	}
}

Measured memory_bytes: 3032
#https://atcoder.jp/contests/abc071/tasks/arc081_a
N = int(input())
A = list(map(int, input().split()))
A.sort()
tmp = [0,0]
for i in range(len(A)-1):
    if A[i] == A[i+1] and not A[i] in tmp:
        tmp.append(A[i])
ans = tmp[-1]*tmp[-2]
if A.count(tmp[-1]) >=4:
        ans = tmp[-1]*tmp[-1]
print(ans)

Measured memory_bytes: 62832
import sys

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

bucket = [0 for i in range(max(a) + 1)]

for i in range(n):
    bucket[a[i]] += 1


sum_three_num = []

if len(bucket) == 1:
    sum_three_num.append(bucket[0])
elif len(bucket) == 2:
    sum_three_num.append(bucket[0] + bucket[1])
else:
    for i in range(1, len(bucket) - 1):
        sum_three_num.append(bucket[i-1] + bucket[i] + bucket[i+1])

print(max(sum_three_num))

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int W,H,N;
    cin >> W >> H >> N;
    vector<int> x(N),y(N),a(N);
    int xl = 0,xr = W,yb = 0,yt = H;
    for (int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> a[i];
        if (a[i] == 1){
            xl = max(xl,x[i]);
        } else if (a[i] == 2){
            xr = min(xr,x[i]);
        } else if (a[i] == 3){
            yb = max(yb,y[i]);
        } else if (a[i] == 4){
            yt = min(yt,y[i]);
        }
    }
    int w = max(xr - xl,0),h = max(yt - yb,0);
    cout << h * w << endl;



    return 0;
}


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

int main(){
    int H,W,N;
    int ans = 0;
    int buf = 0;
    cin >> H >> W >> N;
    if(H>W){
        while(buf<N){
            buf += H;
            ans++;
        }
    }else{
        while(buf<N){
            buf += W;
            ans++;
        }
    }
    cout << ans << endl;
    // cout << H << W << N << endl;
    return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int g(int B, int ub) {
    int i;
    for (i = 60; i >= 0; i--) {
        if (B & bit(i)) { break; }
    }
    return min(ub, bit(i + 1));
}

int f(int A, int B) {
    if (B - A <= 1) {
        set<int> s = {A, B, A | B};
        return s.size();
    }
    int ret = B - A + 1;
    int i;
    for (i = 60; i >= 0; i--) {
        if ((A & bit(i)) != (B & bit(i))) { break; }
        A &= ~bit(i), B &= ~bit(i);
    }
    A &= ~bit(i), B &= ~bit(i);
    ret += g(B, A) - (B + 1) + bit(i) - A;
    return ret;
}
int A, B;
signed main() {
    cin >> A >> B;
    cout << f(A, B) << endl;
}


Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
    int a,b,c;
    int sum;
    // 整数の入力
    scanf("%d %d %d", &a, &b, &c);

  sum = a+b+c;
  
  if (sum <= 21)
  {
    printf("win");
  }
  else
  {
      printf("bust");
  }
    return 0;
}

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

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

X, Y = map(int, readline().split())

for i in range(X + 1):
    acc = i * 2 + (X - i) * 4
    if acc == Y:
        print("Yes")
        sys.exit()
print("No")

Measured memory_bytes: 26956
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

int v, e, num = 1;
vector<vector<int> > a(100000);
vector<int> c(100000, 0), pn(100000), lw(100000), p(100000);
stack<int> s;
void dfs(){
  if(s.size() == 0) return;
  int x = s.top();
  s.pop();
  c[x] = 1;
  pn[x] = lw[x] = num++;
  for(int i = 0; i < a[x].size(); i++){
    int next = a[x][i];
    if(c[next] == 0){
      s.push(next);
      p[next] = x;
      dfs();
      lw[x] = min(lw[next], lw[x]);
    }
    else if(next != p[x]) lw[x] = min(lw[x], pn[next]);
  }
  return;
}

void solve(){
  cin >> v >> e;
  for(int i = 0; i < e; i++){
    long long s, t; cin >> s >> t;
    a[s].push_back(t);
    a[t].push_back(s);
  }
  s.push(0);
  dfs();
  /*for(int i = 0; i < v; i++){
    cout << pn[i] << " " << lw[i] << endl;
  }*/
  set<int> ans;
  int np = 0;
  for(int i = 1; i < v; i++){
    if(p[i] == 0) np++;
    else if(pn[p[i]] <= lw[i]) ans.insert(p[i]);
  }
  if(np >= 2) ans.insert(0);
  for(auto it = ans.begin(); it != ans.end(); it++){
    cout << *it << endl;
  }
  return;
}

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



Measured memory_bytes: 7988