akhauriyash/Code-Regression huggingface dataset:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
S = []
for _ in range(N):
    S.append(str(input()))

ans = 0
for b in range(N):
    flag = True
    for i in range(N):
        for j in range(i+1,N):
            if S[i][(j+b)%N] != S[j][(i+b)%N]:
                flag = False
                break
        else:
            continue
        break
    if flag:
        ans += N

print(ans)

Measured memory_bytes: 41708
// https://atcoder.jp/contests/abc133/tasks/abc133_c
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    constexpr ll mod= 2019;
    ll L, R;
    cin >> L >> R;
    ll d = R - L;
    if (d >= 2019)
    {
        printf("0\n");
        return 0;
    }

    ll ans = 2020;
    for (ll i = L; i < R; ++i)
    {
        for (ll j = L + 1; j <= R; ++j)
        {
            ll r = (i * j) % mod;
            if (r < 0) r = (r + mod) % mod;
            ans = min(ans, r);
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3724
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp38 {
    class Program {
        static void Main(string[] args) {
            string S = Console.ReadLine();

            int l = S.Length;  //文字数

            long ans = 0;

            for (int s = 0; s < (1 << (l - 1)); s++) {
                string now = "";
                now += S[0];

                for (int i = 0; i < (l - 1); i++) {
                    //上からi桁目のビットが立っているかどうか
                    if ((s & (1 << ((l - 1) - i - 1))) != 0) {
                        now += "+";
                    }
                    now += S[i + 1];
                }

                //Console.WriteLine(now);

                //文字列を解釈する
                var num = now.Split('+').Select(x => long.Parse(x)).ToArray();
                ans += num.Sum();

            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
using namespace std;
#define pi M_PI

int main(){
    int x, t;
    cin >> x >> t;
    int c=0;
    for(int i=0; i<t; i++){
        x--;
        if(x == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << x << endl;
    
    return 0;
}

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF LLONG_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int n;
  LL llmax = 0;
  LL a;

  scanf("%d",&n);

  LL arr[n];

  REP (i, n) {
    scanf("%lld",&a);
    arr[i] = a;
    llmax += a;
  }

  LL sunuke = 0;
  LL arai = llmax;
  LL ans = max(3 * llmax, INF);
  REP (i, n - 1) {
    sunuke += arr[i];
    arai -= arr[i];
    if (abs(sunuke - arai) < ans) ans = abs(sunuke - arai);
  }

  printf("%lld\n",ans);

}


Measured memory_bytes: 1792
class Graph():

    from collections import namedtuple
    __Pair = namedtuple("Pair", "cost point")

    def __init__(self, townCount):
        self.__townCount = townCount
        self.__adjacencyList = [[] for _ in range(townCount)]

    def GetPath(self, beginPoint, endPoint, cost):
        item = self.__Pair(cost, endPoint)
        self.__adjacencyList[beginPoint].append(item)

    def Dijkstra(self, beginPoint):

        from sys import maxsize as MaxValue
        from queue import PriorityQueue
        stateTable = {"NotVisited": 0, "Stay": 1, "Visited": 2}

        # 初期化
        pq = PriorityQueue()
        costTable = [MaxValue for _ in range(self.__townCount)]
        visitState = [stateTable["NotVisited"]
                      for _ in range(self.__townCount)]

        # 処理
        costTable[beginPoint] = 0
        pq.put_nowait(self.__Pair(0, beginPoint))

        while not pq.empty():

            minItem = pq.get_nowait()
            minPoint, minCost = minItem.point, minItem.cost

            visitState[minPoint] = stateTable["Visited"]

            if minCost <= costTable[minPoint]:

                for cost, point in self.__adjacencyList[minPoint]:
                    if visitState[point] != stateTable["Visited"]:

                        if costTable[minPoint] + cost < costTable[point]:
                            costTable[point] = costTable[minPoint] + cost
                            visitState[point] = stateTable["Stay"]
                            pq.put_nowait(self.__Pair(costTable[point], point))

        return costTable


# main process
townCount = int(input())
wayCount = int(input())

graph = Graph(townCount)

for lp in range(wayCount):
    begin, end, cost1, cost2 = [int(item) for item in input().split(",")]
    begin -= 1
    end -= 1
    graph.GetPath(begin, end, cost1)
    graph.GetPath(end, begin, cost2)


beginPoint, endPoint, budget, pillarCost = [
    int(item) for item in input().split(",")]

beginPoint -= 1
endPoint -= 1

leaveCost = graph.Dijkstra(beginPoint)
returnCost = graph.Dijkstra(endPoint)

result = budget - pillarCost - leaveCost[endPoint] - returnCost[beginPoint]

print(result)



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

int main()
{
	pair<int, string> s;
	s.first = 0;
	cin >> s.second;

	pair<int, string> s1;
	s1.first = 0;
	pair<int, string> s2;
	s2.first = 1;

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int q;
		cin >> q;
		if (q == 1) {
			s.first = s.first ^ 1;
			s1.first = s1.first ^ 1;
			s2.first = s2.first ^ 1;
		}
		else {
			int f;
			string c;
			cin >> f;
			cin >> c;

			if (s1.first == f - 1) {
				s1.second += c;
			}
			else {
				s2.second += c;
			}
		}
	}

	if (s1.first == 0) {
		reverse(s1.second.begin(), s1.second.end());
		cout << s1.second;
	}
	else {
		reverse(s2.second.begin(), s2.second.end());
		cout << s2.second;
	}
	
	if (s.first == 1) {
		reverse(s.second.begin(), s.second.end());
	}
	cout << s.second;

	if (s1.first == 1) {
		cout << s1.second;
	}
	else {
		cout << s2.second;
	}
	cout << endl;

	return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int d[60];
int main(){
	int n;cin>>n;
	int sum=0;
	int ans=0;
	rep(i,n){
		cin>>d[i];
		sum+=d[i];
	}
	rep(i,n){
		ans+=d[i]*(sum-d[i]);
	}
	cout<<ans/2<<endl;
}

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

int main() {
  int n;

  cin >> n;

  vector<int> a(n);

  long long sum = 0;
  int mod = 1e9 + 7;

  for(int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    sum %= mod;
  }

  // find the area of a large square
  long long ans = sum * sum % mod;

  //remove the central square
  for(int i = 0; i < n; i++) {
    ans -= (long long)a[i] * a[i] % mod;
    if(ans < 0)
      ans += mod;
  }

  // divide by 2
  // ans /= 2 with mod 1e9 + 7
  ans *= (mod + 1) / 2;
  ans %= mod;

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main{
	static ArrayList<Integer>[] g;
	static int N;
	static int[] B;
	static int[] C;
	static long[] sum;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			N = sc.nextInt();
			if (N == 0)
				break;
			String[] A = new String[N];
			B = new int[N];
			C = new int[N];
			String[][] D = new String[N][];
			HashMap<String, Integer> id = new HashMap<>();
			sum = new long[N];
			for (int i = 0; i < N; ++i) {
				A[i] = sc.next();
				B[i] = sc.nextInt();
				C[i] = sc.nextInt();
				D[i] = new String[C[i]];
				for (int j = 0; j < C[i]; ++j) {
					D[i][j] = sc.next();
				}
				id.put(A[i], i);
			}
			for (int i = N - 1; i >= 0; --i) {
				sum[i] = (i + 1 < N ? sum[i + 1] : 0) + B[i];
			}

			g = new ArrayList[N];
			for (int i = 0; i < N; ++i)
				g[i] = new ArrayList<>();

			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < C[i]; ++j) {
					int dst = id.get(D[i][j]);
					g[i].add(dst);
					g[dst].add(i);
				}
			}
			id.clear();
			D = null;
			A = null;
			opt = B[0];
			System.out.println(dfs(1, 1, B[0]) + B[0]);
			B = null;
			C = null;
			sum = null;
			 System.gc();
		}
	}

	static long opt;

	static long dfs(long used, int cur, long cursum) {
		if (cur >= N)
			return 0;
		if (sum[cur] + cursum < opt) {
			return 0;
		}
		long res = 0;
		boolean unadj = true;
		boolean unrestriected = true;
		for (int dst : g[cur]) {
			if (!(dst < cur && ((used >> dst) & 1) == 0)) {
				unadj = false;
			}
			if (((used >> dst) & 1) == 1) {
				unrestriected = false;
			}
		}
		if (unrestriected) {
			res = Math.max(res, dfs(used | (1L << cur), cur + 1, cursum + B[cur]) + B[cur]);
		}
		if (!unadj) {
			res = Math.max(res, dfs(used, cur + 1, cursum));
		}
		opt = Math.max(opt, cursum + res);
		return res;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 270092
a, b, c, d = [int(x) for x in input()]
ops = '+-'
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            tmp = a
            tmp = tmp + b if op1 == '+' else tmp - b
            tmp = tmp + c if op2 == '+' else tmp - c
            tmp = tmp + d if op3 == '+' else tmp - d
            if tmp == 7:
                print(str(a) + op1 + str(b) + op2 + str(c) + op3 + str(d) + "=7")
                exit()

Measured memory_bytes: 3064
h,w,a,b = map(int,input().split())
ans1 = [[0 for _ in range(a)] + [1 for _ in range(w-a)] for i in range(b)]
ans2 = [[1 for _ in range(a)] + [0 for _ in range(w-a)] for i in range(h-b)]

ans = ans1 + ans2
for i in ans:
    for x in i:
        print(x,end="")
    print()

Measured memory_bytes: 122048
#UnionFindクラス
class UnionFind:

  def __init__(self,n):
    self.par =  [i for i in range(n)]
    self.rank = [1 for _ in range(n)]

  # xの根を返す
  def find(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  
  # xとyの根を結合させる
  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x != y:
      if self.rank[x] < self.rank[y]:
        x, y = y, x
      self.rank[x] += self.rank[y]
      self.par[y] = x
  
  # x,yの根が同じかどうかを返す（根が同じ:True、根が異なる:False）
  def is_same(self, x, y):
    return self.find(x) == self.find(y)

  # xが含まれる木の要素数を返す
  def size(self, x):
    return self.rank[self.find(x)]
    
n,m = map(int,input().split())
info = [list(map(int,input().split())) for i in range(m)]
uf = UnionFind(n)
okisa = [1]*(n)
ans = [0]*(m)
ans_=0
for i in range(n):
  ans_ = ans_+i
  
ans[m-1]= ans_
for i in range(1,m)[::-1]:
  if uf.is_same(info[i][0]-1,info[i][1]-1):
    ans[i-1] = ans[i] 
  else:
    ans[i-1] = ans[i]-uf.size(info[i][0]-1)*uf.size(info[i][1]-1)
    uf.union(info[i][0]-1,info[i][1]-1)
for i in range(m):
  print(ans[i])

Measured memory_bytes: 36380
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
s = input().rstrip()
queries = [tuple(input().rstrip().split()) for _ in range(Q)]
lb, ub = 0, N
while ub - lb > 1:
    m = (lb + ub) // 2
    i = m
    ok = False
    for t, d in queries:
        if s[i] == t:
            i += [-1, 1][d == 'R']
        if i == -1:
            ok = True
            break
        if i == N:
            break
    if ok:
        lb = m
    else:
        ub = m
l = lb
lb, ub = 0, N
while ub - lb > 1:
    m = (lb + ub) // 2
    i = m
    ok = False
    for t, d in queries:
        if s[i] == t:
            i += [-1, 1][d == 'R']
        if i == -1:
            break
        if i == N:
            ok = True
            break
    if ok:
        ub = m
    else:
        lb = m
r = ub
print(r - l - 1)

Measured memory_bytes: 87116
### input test
"""
N, M = 10000, 10000
C = [[] for _ in range(N+1)]
for i in range(M):
    p, y = N-i, i*4+M
    C[p].append((y, i))

###
"""
N, M = map(int, input().split())
C = [[] for _ in range(N+1)]
for i in range(M):
    p, y = map(int, input().split())
    C[p].append((y, i))

###

R = [[] for _ in range(M)]
for p, P in enumerate(C):
    x = 1
    for y, i in sorted(P):
        R[i].append((p, x))
        x += 1

for px in R:
    print("{:06d}{:06d}".format(*px[0]))


Measured memory_bytes: 50148
//17
#include<iostream>
#include<utility>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>

using namespace std;

typedef pair<int,int> pii;

struct S{
  int t;
  pii p;
  vector<int> v;
  int l;
};

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    bool d[16][16]={{}};
    while(m--){
      int s,t;
      cin>>s>>t;
      d[s][t]=d[t][s]=true;
    }
    pii is(1,0);
    for(int i=1;i<=n;i++){
      int l;
      cin>>l;
      is.second|=l<<i;
    }
    bool l[16][16]={{}};
    for(int i=1;i<=n;i++){
      int k;
      cin>>k;
      while(k--){
	int r;
	cin>>r;
	l[i][r]=true;
      }
    }
    queue<S> que;
    S s;
    s.p=is;
    s.t=s.l=0;
    que.push(s);
    set<int> p;
    bool f=false;
    while(!que.empty()){
      S c=que.front();
      if(c.p.first==n){
	f=true;
	if(c.p.second==1<<n){
	  break;
	}
      }
      que.pop();
      if(!(c.p.second>>c.p.first&1)||!p.insert(((c.p.first*16)+c.l<<16)+c.p.second).second)continue;
      for(int i=c.l+1;i<=n;i++){
	if(l[c.p.first][i]){
	  S n=c;
	  n.l=i;
	  n.p.second^=1<<i;
	  n.v.push_back(i+(n.p.second>>i&1)*100);
	  n.t++;
	  que.push(n);
	}
      }
      for(int i=1;i<=n;i++){
	if(d[c.p.first][i]&&(c.p.second>>i&1)){
	  S n=c;
	  n.l=0;
	  n.v.push_back(-i);
	  n.p.first=i;
	  n.t++;
	  que.push(n);
	}
      }
    }
    if(que.empty()){
      cout<<(f?"You can not switch off all lights.":"Help me!")<<endl;
    }else{
      cout<<"You can go home in "<<que.front().t<<" steps."<<endl;
      vector<int> v=que.front().v;
      for(int i=0;i<v.size();i++){
	if(v[i]>0){
	  if(v[i]>100){
	    cout<<"Switch on room "<<v[i]-100<<'.'<<endl;
	  }else{
	    cout<<"Switch off room "<<v[i]<<'.'<<endl;
	  }
	}else{
	  cout<<"Move to room "<<-v[i]<<'.'<<endl;
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 29456
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,k;
    cin>>n>>k;
    long long sum=0;
    long long ar[n];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    sort(ar,ar+n);
    for(int i=0;i<(n-k);i++)
    {
        sum+=ar[i];
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 1792
package main

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

func main() {
	In := readLine()
	for _, v := range strings.Split(In, "") {
		if v == "9" {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

/////////////////////////////////////////

//func readLineInt() []int {
//	result := make([]int, 0)
//	for _, v := range strings.Split(readLine(), " ") {
//		i, _ := strconv.Atoi(v)
//		result = append(result, i)
//	}
//	return result
//}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}


Measured memory_bytes: 640
# coding: utf-8
# Your code here!
import math

while True:
    n=int(input())
    
    if n==0:
        break
    else:
        S=[int(s) for s in input().split()]
        a2=0
        
        m=sum(S)/n
        
        for i in range(n):
            a2+=(S[i]-m)**2
            a=math.sqrt(a2/n)

    print(f'{a:.5f}')


Measured memory_bytes: 5728
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	ll K, A, B;
	cin >> K >> A >> B;

	if ((A + 2 > B) || (K <= A - 1)) {
		cout << 1 + K << endl;
		return 0;
	}

	ll t = K - A + 1;
	ll res = A + (t / 2) * (B - A) + (t % 2);
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int x = 0;
  int y = 0;

  scanf("%d", &x);
  scanf("%d", &y);

  while (!((x == 0) && (y == 0))) {
    if (x < y) {
      printf("%d %d\n", x, y);
    } else {
      printf("%d %d\n", y, x);
    }
    
    scanf("%d", &x);
    scanf("%d", &y);    
  }
  
  return 0;
}

Measured memory_bytes: 600
import collections

ans = []
n = int(input())
s = [input() for _ in range(n)]
dic = collections.Counter(s).most_common()
max_num = dic[0][1]
for k, v in dic:
    if v == max_num:
        ans.append(k)
    else:
        break
ans.sort()
print("\n".join(ans))


Measured memory_bytes: 45084
#include <bits/stdc++.h>
using namespace std;
int main (){
  string s;
  cin>>s;
  char a,b;
  int i,c=0;
  for(i=0;i<s.length()/2;i++){
    a = s[s.length()-i-1];
    b = s[i];
    if(a !=b){
      //cout<<a<<b<<endl;
      c++;
    }
    
  }
  cout<<c;
  return 0;
}

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

int main()
{
	bool flag=false;
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!=t[i])
			flag=true;
	}
	if(flag)
		cout<<"No";
	else
		cout<<"Yes";

	return 0;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define ll long long

#ifndef ONLINE_JUDGE
#define debug(format, ...) fprintf(stderr, \
    "%s:%d: " format "\n", __func__, __LINE__,##__VA_ARGS__)
#else
#define debug(format, ...)
#define NDEBUG
#endif

int n, m;

bool vis[1005][1005];
char s[1005];
int dist[1005][1005];

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

int main()
{
    scanf("%d%d", &n, &m);
    queue<pair<int, int> > bfs;
    for (int i = 1; i <= n; i++) {
        scanf("%s", s + 1);
        for (int j = 1; j <= m; j++) {
            if (s[j] == '#') {
                bfs.push(make_pair(i, j));
                vis[i][j] = true;
            }
        }
    }
    while (!bfs.empty()) {
        pair<int, int> cur = bfs.front();
        bfs.pop();
        for (int i = 0; i < 4; i++) {
            pair<int, int> newpos = make_pair(cur.first
                + dx[i], cur.second + dy[i]);
            if (newpos.first < 1 || newpos.first > n ||
                newpos.second < 1 || newpos.second > m) continue;
            if (vis[newpos.first][newpos.second]) continue;
            bfs.push(newpos);
            dist[newpos.first][newpos.second] =
                dist[cur.first][cur.second] + 1;
            vis[newpos.first][newpos.second] = true;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            ans = max(ans, dist[i][j]);
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 12184
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1;
const int inf=(1ull<<31)-1;
bool a[10];
int n,k;

bool f(int b){
	for (;b;b/=10)
		if (a[b%10])
			return false;
	return true;
}

int main()
{
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(15);
	cin>>n>>k;
	for (int i=0,t;i<k;i++){
		cin>>t;
		a[t]=true;
	}
	for (;!f(n);n++);
	cout<<n;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
     	long a = sc.nextLong();
      	long b = sc.nextLong();
      	long x = sc.nextLong();
      	long aa = a/x;
      	long bb = b/x;
      	if(a%x==0) System.out.println(bb-aa+1);
    	else System.out.println(bb-aa);
    }
}

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

  const int MOD = 1000000000 + 7;

  struct UnionFind{
      private:
          vector<int> parent;
      public:
          UnionFind(int n) : parent(n, -1) {};

          int root(int x){
              if (parent[x] < 0) return x;
              return parent[x] = root(parent[x]);
          }

          int size(int n){
              return -parent[root(n)];
          }

          bool connect(int x, int y){
              x = root(x);
              y = root(y);
              if( x == y ) return false;
              if( size(x) < size(y)) swap(x ,y);
              parent[x] += parent[y];
              parent[y] = x;
              return true;
          }

          int min_rank(){
              int minimum = parent[0];
              for(auto p: parent){
                  if(minimum > p){
                      minimum = p;
                  }
              }
              return minimum;
          }
  };

  int main() {
      int N, M;
      cin >> N >> M;
      UnionFind uf(N);
      for (int i = 0; i < M; i++){
          int x, y;
          cin >> x >> y;
          uf.connect(x-1, y-1);

      }
      cout << -uf.min_rank() << endl;
  }

Measured memory_bytes: 3680
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

int N;

vector<tuple<int, int, int>> tp;

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

  cin >> N;
  vector<lint> L(N);
  rep(i, N) cin >> L[i];

  sort(L.begin(), L.end());

  lint ans = 0, b, c, tmp;
  for (int i = 0; i + 1 < N; i++) {
    for (int j = i + 1; j < N; j++) {
      b = L[i], c = L[j];
      tmp = c - b;
      auto it1 = upper_bound(all(L), tmp);
      auto it2 = lower_bound(all(L), b + c);
      auto x = it1 - L.begin();
      if (x <= j) x = j + 1;
      auto y = it2 - L.begin();
      y--;
      if (L[y] < b + c) y++;
      // cout << "x = " << x << endl;
      // cout << "y = " << y << endl;
      // cout << y - x << endl;
      if (y - x < 0) continue;

      ans += y - x;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
ans="No"
f=[a for a in A if a%4==0]
t=[a for a in A if a%4!=0 and a%2==0]
if len(f)*2+len(t)>=N:
  ans="Yes"
elif len(f)>=(N-1)//3+1 and N%2!=0:
  ans="Yes"
print(ans)

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


int main()
{
    while (true)
    {
        int ans=0;
        int H;cin >> H;if (H==0) break;
        vector<vector<int> > board(H,vector<int> (5,0));
        for (int i=0;i<H;i++)
        {
            for (int j=0;j<5;j++)
            {
                cin >> board[i][j];
            }
        }
        bool can=true;
        while (can)
        {
            can=false;
            for (int i=0;i<H;i++)
            {
                vector<int> check;
                for (int j=0;j<4;j++)
                {
                    if (board[i][j]==board[i][j+1] && board[i][j]!=0)
                    {
                        check.push_back(j);
                    }
                }
                int cnt=0;
                for (int j=0;j<(int)check.size()-1;j++)
                {
                    if (check[j+1]-check[j]==1)
                    {
                        cnt++;
                    }
                }
                if (cnt>=1)
                {
                    cnt++;
                    can=true;
                    for (int j=0;j<check.size()-1;j++)
                    {
                        if (check[j+1]-check[j]==1)
                        {
                            ans+=board[i][check[j]]*(cnt+1);
                            for (int k=0;k<=cnt;k++)
                            {
                                board[i][check[j]+k]=0;
                            }
                            break;
                        }
                    }
                }
            }
            for (int j=0;j<5;j++)
            {
                for (int i=H-1;i>=0;i--)
                {
                    if (board[i][j]==0)
                    {
                        int k=i;
                        while (k>=0 && board[k][j]==0)
                        {
                            k--;
                            if (k==-1) break;
                        }
                        if (k!=-1)
                        {
                            board[i][j]=board[k][j];
                            board[k][j]=0;
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
int A,B,K;
cin >> A >> B >> K;
int count=0,a;
for(int i=100;i>=1;i--){
  if(A%i==0 && B%i==0){
    count++;
  }
  if(count == K){
    a = i;
    break;
  }
}
cout << a << endl;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
typedef pair<li, li> PI;

double dp[3030][3030];
double p[3030];

int main(void)
{
	li n;
	cin >> n;
	rep(i, n) {
		rep(j, n) {
			dp[i][j] = 0;
		}
	}
	rep(i, n) {
		cin >> p[i];
	}
	dp[0][0] = 1.0;
	rep(i, n) {
		rep(j, i + 1) {
			dp[i + 1][j] += dp[i][j] * (1 - p[i]);
			dp[i + 1][j + 1] += dp[i][j] * p[i];
		}
	}
	double res = 0.0;
	rep(i, n + 1) {
		if (i > n - i) {
			res += dp[n][i];
		}
	}

	printf("%.12f\n", res);


	return 0;
}

Measured memory_bytes: 71936
def main():
    m,d = map(int,input().split())
    ans = 0
    for i in range(1,m+1):
        for j in range(1,d+1):
            d1 = j%10
            d10 = j//10
            if d1 >= 2 and d10 >= 2 and d1*d10 == i:
                ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 39536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			if("AAA".equals(s) || "BBB".equals(s)) {
				System.out.println("No");
			} else {
				System.out.println("Yes");
			}

		}

	}

}


Measured memory_bytes: 22868
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int,int>PII;

const int maxn = 2e5 + 10;

int t,n,k,len,value;

int dp[maxn];

int main(void) {
	cin >> n >> k;
	for(int i = 1; i <= k; i ++) {
		scanf("%d",&len);
		for(int j = 1; j <= len; j ++){
			scanf("%d",&value);
			dp[value] = value;
		}
		
	}
	int ans = 0;
	for(int i = 1; i <= n; i ++) {
		if(dp[i] != i) ans ++;
	}
	cout << ans << endl;
	return 0;	
} 

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

int main()
{
	register int n, m, a, b;
	scanf("%d %d %d %d", &n, &m, &a, &b);
	for (register int i = 0; i < n; ++i) {
		for (register int j = 0; j < m; ++j) {
			if (i < b && j < a) putchar('0');
			else if (i >= b && j >= a) putchar('0');
			else putchar('1');
		}
		puts("");
	}
	return 0;
}

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

int main() {
    int t;
    cin >>t;
    unsigned long long sum=0;
    while(t--){
        long long l,r;
        scanf("%lld%lld",&l,&r);
        sum+=(r-l+1);
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   string o,e;cin >>o>>e;
    for (int i = 0; i < e.size(); ++i) {
        cout <<o[i]<<e[i];
    }
    if(o.size()!=e.size())cout<<o.back()<<endl;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>
#include <stack>

using namespace std;

#define long long long
#define fi first
#define se second
typedef pair<int,int> ii;

const long MOD = 1e9+7;
int A[100003];

long pwr(long a, long b)
{
	if(b == 0) return 1;
	else if(b == 1) return a;
	else if(b == 2) return (a*a)%MOD;
	else if(b%2 == 0) return pwr(pwr(a, b/2),2);
	else return (pwr(a,b-1)*a)%MOD;
}

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	int n;
	long k;
	scanf("%d %lld", &n, &k);

	for(int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	
	long res = 0;
	for(int i = 0; i < n; i++)
	{
		long a = 0, b = 0;
		for(int j = 0; j < n; j++)
		{
			if(j < i && A[i] < A[j])
				a++;
			if(A[i] < A[j])
				b++;
		}
		// printf("%lld %lld\n", a, b);
		long aa = (2*a)%MOD;
		long kb = ((k-1)*b)%MOD;
		res += (((aa+kb)*k)%MOD*pwr(2,MOD-2))%MOD;
		res %= MOD;
	}
	printf("%lld\n", res);

}










Measured memory_bytes: 256
from itertools import product
from collections import defaultdict
N = int(input())
S = input()

ans = 0
D = defaultdict(int)
for pattern in product([0, 1], repeat=N):
    red = ''.join([s for s, p in zip(S[:N], pattern) if p == 0])
    blue = ''.join([s for s, p in zip(S[:N], pattern) if p == 1])
    D[(red, blue)] += 1

for pattern in product([0, 1], repeat=N):
    red = ''.join([s for s, p in zip(S[N:], pattern) if p == 0])
    blue = ''.join([s for s, p in zip(S[N:], pattern) if p == 1])
    ans += D[(blue[::-1], red[::-1])]
print(ans)


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

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

    int height = 0, ans = 0;
    for (int i = 0; i < N; i++) {
        if (H[i] > height) {
            ans += H[i] - height;
            height = H[i];
        } else {
            height = H[i];
        }
    }
    cout << ans << 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 s;
    cin >> s;
    map<char, int>count;
    for(char c : s)count[c]++;
    for(auto v : count) {
      if(v.second%2 != 0){
        puts("No");
        exit(0);
      }
    }
    puts("Yes");
    return 0;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int a,b,c,d,ans=1,count=0;
    cin >> a >> b;
    if(b == 1){
        cout << '0' << endl;
        return 0;
    }
    while(1){
        ans += a-1;
        count++;
        if(ans >= b){
            cout << count << endl;
            return 0;
        }
    }
}

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

const unsigned long long bigp=(1ULL<<61)-1ULL;
const unsigned long long smallp=(1ULL<<31)-1ULL;
const unsigned long long smallpplus=(1ULL<<31);
const unsigned long long smallpminus=(1ULL<<30)-1ULL;

unsigned long long b=313139;

class hash_mod{
    public:
    unsigned long long val;
    unsigned long long val_u, val_d;
    unsigned long long another_u, another_d;
    unsigned long long m, m_u, m_d;

    void remainder(){
        val_u=(val>>61);
        val_d=val&bigp;
        if(val_u + val_d <bigp) val= val_u + val_d;
        else val= (val_u + val_d) -bigp;
    }

    void update(unsigned long long v){
        val=v;
        remainder();
    }

    void addition(unsigned long long another){
        val+=another;
        remainder();
    }

    void subtraction(unsigned long long another){
        val+=bigp;
        val-=another;
        remainder();
    }

    void multiple(unsigned long long another){
        val_u=(val>>31);
        val_d=val&smallp;
        another_u=(another>>31);
        another_d=another&smallp;
        m=val_u*another_d + val_d*another_u;
        m_u=(m>>30);
        m_d=m&smallpminus;
        val=0;
        val+=val_u*another_u*(2ULL);
        val+=m_u + m_d*smallpplus;
        val+=val_d*another_d;
        remainder();
    }
};

int main(){
    //input
    unsigned long long N;
    cin >> N;
    unsigned long long a[N], bb[N];
    unsigned long long i;
    for(i=0; i<N; i++){
        cin >> a[i];
    }
    for(i=0; i<N; i++){
        cin >> bb[i];
    }

    //exception
    if(N==1){
        cout << 0 << " " << (a[0]^bb[0]) << endl;
        system("pause");
        return 0;
    }

    //calc
    hash_mod B_hash;
    B_hash.update(0ULL);
    for(i=0; i<N-1; i++){
        B_hash.multiple(b);
        B_hash.addition((bb[i]^bb[i+1])+1ULL);
    }

    hash_mod sub, b_pow;
    b_pow.update(1ULL);
    for(i=0; i<N-2; i++){
        b_pow.multiple(b);
    }
    
    hash_mod A_hash;
    A_hash.update(0ULL);
    for(i=0; i<N-1; i++){
        A_hash.multiple(b);
        A_hash.addition((a[i]^a[i+1])+1ULL);
    }
    if(A_hash.val==B_hash.val){
        cout << 0 << " " << (a[0]^bb[0]) <<endl;
    }
    sub.update((a[0]^a[1])+1ULL);
    sub.multiple(b_pow.val);
    A_hash.subtraction(sub.val);
    A_hash.multiple(b);
    A_hash.addition((a[N-1]^a[0])+1ULL);
    if(A_hash.val==B_hash.val){
        cout << 1 << " " << (a[1]^bb[0]) << endl;
    }
    for(i=2; i<N; i++){
        sub.update((a[i-1]^a[i])+1ULL);
        sub.multiple(b_pow.val);
        A_hash.subtraction(sub.val);
        A_hash.multiple(b);
        A_hash.addition((a[i-2]^a[i-1])+1ULL);
        if(A_hash.val==B_hash.val){
            cout << i << " " << (a[i]^bb[0]) << endl;
        }
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 7052
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;


ll H, W;

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

	cin >> H >> W;

	if (H % 3 == 0 || W % 3 == 0) {
		cout << 0 << endl;
	}
	else if(H%2==0 || W%2==0) {
		ll h = (H % 2 == 0) ? H / 2: 1e9;
		ll w = (W % 2 == 0) ? W / 2 : 1e9;
		h = min(H, h);
		w = min(W, w);

		cout << min(h, w) << endl;
	}
	else {
		ll one = abs((H + 3) / 3 * W - (W - 1) / 2 * (H - (H + 3) / 3));
		swap(H, W);
		ll two = abs((H + 3) / 3 * W - (W - 1) / 2 * (H - (H + 3) / 3));

		one = min(one, H);
		two = min(two, W);

		cout << min(one, two) << endl;
	}



	return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
int main(){
  int i ,c1 ,c2 ,c3 ,cnt=0 ,total=0 ,last[10]={1,2,3,4,5,6,7,8,9,10};
  while( scanf( "%d %d %d" ,&c1 ,&c2 ,&c3 ) != EOF ){
    total += c1 + c2;
    last[c1] = 0;
    last[c2] = 0;

    for( i=9 ; i>=0 ; i-- ){
      if( total + last[i] <= 20 && last[i] != 0 ){
	cnt++;
      }
      //   printf( "    %d\n" ,last[i] );
    }

    if( cnt >= 4 ){
      printf( "YES\n" );
    }
    else {
      printf( "NO\n" );
    }

    total = 0;
    cnt = 0;
    for( i=0 ; i<10 ; i++ ){
      last[i] = i;
    }
  }

  return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound 

int main()
{
  int x,y;cin>>x>>y;
  
  for (int a=0;a<100;a++)
  {
    for (int b=0;b<100;b++)
    {
      if (2*a+4*b==y && a+b==x){
        cout<<"Yes"<<endl;
        return (0);
      }
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<bits/stdc++.h>

using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pii;

class uf{
public:
  uf();
  uf(lli _n){
    init(_n);
  }
  void init(lli _n){
    n = _n;
    rank.resize(n);
    parent.resize(n);
    for (lli i = 0; i < n; i++) {
      rank[i] = 0;
      parent[i] = i;
    }
  }
  lli find(lli x){
    if(x == parent[x])return x;
    else return parent[x] = find(parent[x]);
  }
  
  void unite(lli x, lli y){
    x = find(x);
    y = find(y);
    if(x == y)return;
    if(rank[x] < rank[y]){
      parent[x] = y;
    }else{
      parent[y] = x;
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  bool same(lli x, lli y){
    return find(x) == find(y);
  }
private:
  lli n;
  vector<lli> rank, parent;
};


struct edge{
  lli from, to, cost;
  bool operator<(const edge &e)const{
    return cost < e.cost;
  }
};

lli V, E;

lli kruskal(vector<edge> &es, vector<bool> &used){
  sort(es.begin(), es.end());
  uf u(V);
  lli res = 0;
  for (lli i = 0; i < es.size(); i++) {
    edge &e = es[i];
    if(not u.same(e.from, e.to)){
      u.unite(e.from, e.to);
      used[i] = true;
      res += e.cost;
    }
  }
  return res;
}

void dfs(vector<vector<edge> > &g, vector<vector<lli> > &mat, vector<bool> &used, int s, int v){
  used[v] = true;
  for (int i = 0; i < g[v].size(); i++) {
    edge &e = g[v][i];
    if(used[e.to] == true)continue;
    mat[s][e.to] = max(mat[s][e.to], e.cost);
    mat[e.to][s] = max(mat[e.to][s], e.cost);
    dfs(g, mat, used, s, e.to);
  }
}
         

int main(){
  lli n, m, w, h, q;
  std::cin >> n >> m;
  //vector<vector<lli> > mat(n, vector<lli>(n, 0));
  V = n;
  vector<edge> e(m);
  vector<bool> used(m, false);
  for (lli i = 0; i < m; i++) {
    std::cin >> e[i].from >> e[i].to >> e[i].cost;
    //e[i].from--, e[i].to--;
  }
  lli cost = kruskal(e, used);
  vector<vector<edge> > g(n);
  for (lli i = 0; i < m; i++) {
    if(used[i] == true){
      edge te = (edge){e[i].to, e[i].from, e[i].cost};
      g[e[i].from].emplace_back(e[i]);
      g[e[i].to].emplace_back(te);
      // mat[e[i].from][e[i].to] = e[i].cost;
      // mat[e[i].to][e[i].from] = e[i].cost;
    }
  }
  // for (int i = 0; i < n; i++) {
  //   vector<bool> used(n, false);
  //   dfs(g, mat, used, i, i);
  // }
  std::cout << cost << std::endl;
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < n; j++) {
  //     std::cout << mat[i][j] << " ";
  //   }
  //   std::cout << std::endl;
  // }
  // std::cin >> q;
  // vector<lli> s(q), t(q);
  // for (lli i = 0; i < q; i++) {
  //   std::cin >> s[i] >> t[i];
  //   std::cout << cost - mat[--s[i]][--t[i]] << std::endl;
  // }
  return 0;
}

Measured memory_bytes: 6020
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define ll long long
#define endl "\n"
#define lu unsigned long long
#define mod 1000000007
#define ld long double
#define f(i, n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define v vector<ll>
#define vv vector<vector<ll> >
#define vs vector<string>
#define vpr vector<pair<ll,ll>>
#define fi first
#define se second
#define all(x)  x.begin(),x.end()
#define bg(x)  x.begin()
#define sz(x)  x.size()
#define in(x,n) f(i,n) cin>>x[i]
#define out(x,n) f(i,n) cout<<x[i]<<" "
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a)  *(min_element(a.begin(),a.end()))
#define mem(x,val) memset(x,val,sizeof(x))
#define tc    ll t;cin>>t;while(t--)
#define pi pair<int,int>
#define prfloat(val,precise) cout<<fixed<<setprecision(precise)<<val<<endl;
const ld PI = 2 * acos(0.0);
void yes(){ cout<<"YES\n";}
void no(){cout<<"NO\n";}
ll m(ll a){ return (a+mod)%mod;}
ll cel(ll x1,ll y1){ ;if((x1%y1)==0)return x1/y1;return x1/y1+1;}
ll power(ll a,ll b){ if(b==0)return 1;ll d=power(a,b/2);d=m(d*d);
if(b&1)d=m(d*a);return d;}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring hstr[x],... end of string
str.find(qtr) : returns the first ocoucurenece of qtr in str */

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h,n;cin>>h>>n;
	v arr(n);in(arr,n);
	int sum=0;
	f(i,n)sum+=arr[i];
	if(sum >=h)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
  int h[3];
  cin >> h[0] >> h[1] >> h[2];
  sort(h,h+3);

  int h0 = h[0];
  for(int i=0;i<3;i++){
  	h[i] -= h0;
  } 
  int remain = 2*h[2]-h[1];

  int ans = 0;
  if(h[1]%2==0){
  	ans = remain/2;
  }else{
  	ans = (remain+3)/2;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int datas[105];
LL wei[105];
LL memo[105][100005];
const LL INF=1e17;
LL solve(int ix, int val)
{
	if(val <=0) return 0;
	if(ix<0)
	{
		if(val<=0) return 0;
		else return INF;
	}
	if(memo[ix][val]!=-1) return memo[ix][val];
	return memo[ix][val]=min(solve(ix-1, val), wei[ix]+solve(ix-1, val-datas[ix]));
}

int main()
{
	int n;
	LL w;
	scanf("%d%lld", &n, &w);
	for(int a=0;a<n;a++)
	{
		scanf("%lld%d", &wei[a], &datas[a]);
	}
	memset(memo, -1, sizeof(memo));
	int hasil=0;
	for(int a=100000;a>=0;a--)
	{
		LL tmp=solve(n-1, a);
		if(tmp <= w)
		{
			hasil=a;
			break;
		}
	}
	printf("%d\n", hasil);
	return 0;
}

Measured memory_bytes: 82304
import sys
from collections import deque
from itertools import permutations
input = sys.stdin.readline

N, K = [int(x) for x in input().strip().split()]
l1 = deque([])
l2 = deque([])
ans = deque([])
c = K

while c <= N:
    l1.append(c)
    c += K
ans = len(l1) ** 3

if K % 2 == 0:
    c = K / 2
    while c <= N:
        l2.append(c)
        c += K
ans += len(l2) ** 3

print(ans)

Measured memory_bytes: 11252
#include<cstdio>
#include<map>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>

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

using namespace std;

int main(){
	int n[4];
	cin>>n[0]>>n[1]>>n[2]>>n[3];
	if(n[1]<=n[2]){
		cout<<0<<endl;
		return 0;
	}
	else if(n[3]<=n[0]){
		cout<<0<<endl;
		return 0;
	}
	else{
		sort(n,n+4);
		int ans = n[2]-n[1];
		cout<<ans<<endl;
		return 0;
	}
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        
        int n=sc.nextInt();
        int d[]=new int[n];
        int s=0;
        for (int i = 0; i < d.length; i++) {
			d[i]=sc.nextInt();
			s+=d[i];
		}
        int r=0;
        for (int i = 0; i < d.length; i++) {
            s-=d[i];
            r+=d[i]*s;
		}
        out.println(r);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}


class P {
	int x, y, d;
	P(int  x, int y, int d) {
	  this.x=x;
	  this.y=y;
	  this.d=d;
	}
}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return p.a-a;//des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 21204