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

#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)


typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

template <class T>
using pqueue = priority_queue<T>;
template <class T>
using rpqueue = priority_queue<T, vector<T>, greater<T> >;


int sint() { int x; scanf("%d", &x); return x; }
ll sll() { ll x; scanf("%lld", &x); return x; }
double sdb() { double x; scanf("%lf", &x); return x; }


int arr[200];
bool memo[101000][5];

int main() {
	memset(memo, false, sizeof(memo));
	int n, k;
	n = sint();
	k = sint();
	
	for(int i = 0; i < n; i++) {
		arr[i] = sint();
	}
	
	for(int i = 1; i <= k; i++) {
		for(int j = 0; j < 2; j++) {
			bool check = false;
			for(int l = 0; l < n; l++) {
				if(i-arr[l] >= 0) {
					if(memo[i-arr[l]][1-j] == false) {
						check = true;
					}
				}
			}
			memo[i][j] = check;
		}
	}
	
//	for(int i = 1; i <= k; i++) {
//		printf("%d %d\n", memo[i][0], memo[i][1]);
//	}
	
	if(memo[k][0]) {
		printf("First\n");
	} else {
		printf("Second\n");
	}
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
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; }
ll mod = 1000000007;

void solve()
{
	int n; cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	vector<ll> s(n+1, 0);
	rep(i, n)s[i+1]=s[i]+a[i];
	map<ll,ll> m;
	rep(i, n+1)m[s[i]]++;
	ll ans = 0;
	for(auto e:m)
	{
		ll x = e.second;
		ans += (x-1)*x/2;
	}
	cout << ans << endl;
	return;	
}

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


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
        a[i] = a[i] - 1;
    }
    int light[N];
    for(int i = 0; i < N; i++){
        light[i] = false;
    }
    int now = 0, next = a[now];
    int count = 0;
    light[0] = true;


    while(!light[1]){
        light[next] = true;
        light[now] = false;
        int w = next;
        next = a[next];
        now = w;
        count++;
        if(count > N) {count = -1; break;}
    }
    cout << count << endl;

}

Measured memory_bytes: 1024
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL; 																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																							   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


///////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////

/////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int n;
	cin >> n;
	vector<int> v;
	int id;
	
	int maxi = 0;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		v.pb(x);
		if(x > maxi){
			maxi = x;
			id = i;
		}
	}
	
	nth_element(v.begin(), v.begin()+1, v.end(), std::greater<int>());
	int maxi2 = v[1];
	
	for(int i = 0; i < n; i++){
		if(i != id){
			cout << maxi << endl;
		}
		else cout << maxi2 << endl;
	}
	
	
	
	return 0;
}




Measured memory_bytes: 2548
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var x = sc.nextInt();
		var n = sc.nextInt();
		var set = new HashSet<Integer>();
		for (int i = 0; i < n; i++) {
			set.add(sc.nextInt());
		}
		sc.close();

		var result = x;
		var min = Integer.MAX_VALUE;
		for (int i = x - 50; i <= x + 50; i++) {
			if (set.contains(i)) {
				continue;
			}
			int dif = Math.abs(x - i);
			if (dif < min) {
				result = i;
				min = dif;
			}
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 35864
def main():
    A, B = map(int, input().split(' '))

    low = int(B /0.1)
    up = int((A+1) / 0.08)
    
    value = -1
    for i in range(low,up):
        if int(i*0.08)==A and int(i*0.1)==B:
            value = i
            break
    
    print(value)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
 
    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    ll k;
    ll w,x;
    cin>>n>>a;
    vector<ll> v(n);
    rep(i,n) v[i]=a+i;
    sum=accumulate(all(v),0);
    rep(i,n){
        if(v[i]==0){
            cout<<sum<<endl;
            return 0;
        }
    }
    if(sum>0){
        cout<<sum-v[0]<<endl;
    }else{
        cout<<sum-v[n-1]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3600
def printg():
	for i in range(H+2):
		print(G[i])

def p(s):
	if s == '#':
		return True
	else:
		return False

def isok(i,j):
	u = p(G[i][j-1])
	r = p(G[i+1][j])
	d = p(G[i][j+1])
	l = p(G[i-1][j])
	if u or r or d or l:
		return True
	else:
		return False

if __name__ == '__main__':
	H,W = map(int,input().split())
	G = [['B']*(W+2) for _ in range(H+2)]

	for i in range(H):
		l = input()
		for j in range(W):
			G[i+1][j+1] = l[j]

	for i in range(H+1):
		for j in range(W+1):
			if G[i][j] == '#':
				if not isok(i,j):
					print('No')
					exit()

	print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> d(n);
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    int sum=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            sum+=d[i]*d[j];
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#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;
}
//

struct lines {
  int m;
  int len[10];
  int dir[10];  // right = 1, straight = 0, left = -1
};

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

  int n;
  int x, y, d, px, py, pd;
  lines L[51];

  while (cin >> n, n) {
    for (int i = 0; i <= n; i++) {
      cin >> L[i].m;
      for (int j = 0; j < L[i].m; j++) {
        cin >> x >> y;
        if (j == 0) {  //最初はまっすぐ
        } else {
          d = (x == px ? y - py : x - px);
          L[i].len[j - 1] = abs(d);  //線の長さ

          if (j == 1) {
            L[i].dir[j - 1] = 0;
          } else {
            if (x == px) {
              L[i].dir[j - 1] = (pd * d > 0 ? 1 : -1);
            } else {
              L[i].dir[j - 1] = (pd * d > 0 ? -1 : 1);
            }
          }
        }
        px = x;
        py = y;
        pd = d;
      }
      L[i].m--;
      L[i].dir[L[i].m] = 0;  //最後はまっすぐ
    }

    for (int i = 1; i <= n; i++) {
      if (L[0].m != L[i].m) {
        continue;
      }

      bool same = true;
      for (int j = 0; j < L[i].m; j++) {
        if (L[0].len[j] != L[i].len[j]) {
          same = false;
          break;
        }
        if (L[0].dir[j] != L[i].dir[j]) {
          same = false;
          break;
        }
      }
      if (same) {
        cout << i << "\n";
        continue;
      }

      same = true;
      for (int j = 0; j < L[i].m; j++) {
        if (L[0].len[j] != L[i].len[L[i].m - 1 - j]) {
          same = false;
          break;
        }
        if (L[0].dir[j] != L[i].dir[L[i].m - j] * -1) {
          same = false;
          break;
        }
      }
      if (same) {
        cout << i << "\n";
      }
    }
    cout << "+++++\n";
  }

  return 0;
}


Measured memory_bytes: 3180
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

string s;

bool even_string(string s) {
  int d = s.length() / 2;
  rep(i, d) {
    if (s[i] != s[d + i]) return false;
  }
  return true;
}

int main() {
  cin >> s;

  s.pop_back();
  s.pop_back();
  while (!even_string(s)) {
    s.pop_back();
    s.pop_back();
  }
  cout << s.length();
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n,m;
    scanf ("%d %d", &n, &m);
    
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int a;
        scanf("%d", &a);
        sum += a;
    }
    
    int ret = -1;
    if (sum <= n) ret = n - sum;
    printf("%d\n", ret);
}


Measured memory_bytes: 1732
import sys
import numpy as np
import math
import collections
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
c_n = np.array([(k, v) for k, v in c.items()])
total = np.dot(c_n.T[0], c_n.T[1])
q = int(input())
for _ in range(q):
    cf, ca = map(int, input().split())
    num = c[cf]
    if ca in c:
        c[ca] += c[cf]
        c[cf] = 0
#         del sd[cf]
#         del c[cf]
    else:
#         sd[ca] = sd[cf]
        c[ca] = c[cf]
        c[cf] = 0
#         del sd[cf]
#         del c[cf]
    total += num * (ca - cf)
    print(total)


Measured memory_bytes: 41124
#include <cstdio>
#include <algorithm>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to

using namespace std;

const int N = 101;

char g[N][N];
short s[N][N];
short f[N][N][N][N];

void inc(short &a, short b) { if (b > a) a = b;}

short get(int x1, int y1, int x2, int y2)
{
	if (x1 > x2 || y1 > y2) return -10000;	
	x1 --, y1 --;
	return s[x2][y2] - s[x2][y1] - s[x1][y2] + s[x1][y1];
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	int ex, ey;
	Rep(i, n) {
		scanf("%s", g[i] + 1);
		Rep(j, m) {
			s[i][j] = s[i][j - 1];	
			if (g[i][j] == 'o') s[i][j] ++;
			else if (g[i][j] == 'E') ex = i, ey = j;
		}
	}
	Rep(i, n) Rep(j, m) s[i][j] += s[i - 1][j];
	short ans = 0;
	Rep0(i, ex - 1) Rep0(j, ey - 1) Rep0(k, n - ex) Rep0(h, m - ey){
		//printf("%d %d %d %d %d\n", i, j, k, h, (int)f[i][j][k][h]);
		int lx = max(1 + k, ex - i), rx = min(n - i, ex + k);
		int ly = max(1 + h, ey - j), ry = min(m - j, ey + h);
		short tmp = f[i][j][k][h];
		if (1 + k <= ex - i - 1 && ex - i - 1 <= n - i) 
			inc(f[i + 1][j][k][h], tmp + get(ex - i - 1, ly, ex - i - 1, ry));
		if (1 + h <= ey - j - 1 && ey - j - 1 <= m - j)
			inc(f[i][j + 1][k][h], tmp + get(lx, ey - j - 1, rx, ey - j - 1));
		if (1 + k <= ex + k + 1 && ex + k + 1 <= n - i) 
			inc(f[i][j][k + 1][h], tmp + get(ex + k + 1, ly, ex + k + 1, ry));
		if (1 + h <= ey + h + 1 && ey + h + 1 <= m - j) 
			inc(f[i][j][k][h + 1], tmp + get(lx, ey + h + 1, rx, ey + h + 1));
		inc(ans, tmp);
	}
	
	printf("%d\n", (int)ans);
	
	return 0;
}


Measured memory_bytes: 201344
n,a,b=map(int, input().split()) 


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


mod = 10**9+7



def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

sou = pow(2,n,mod) -1
ans = (sou - combination(n, a)-combination(n, b))
if (ans<0):
        ans += mod
if (ans<0):
        ans += mod
print(ans)

Measured memory_bytes: 3064
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];
		long step=0;
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		for(int i=1;i<N;i++){
			if(A[i-1]>A[i]){
				step+=A[i-1]-A[i];
				A[i]=A[i-1];
			}
		}
		System.out.println(step);
	}	
}

Measured memory_bytes: 60440
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int d=sc.nextInt();
    int a[][] = new int[n][d];
    for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
        a[i][j]=sc.nextInt();
      }
    }
    int count=0;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        int total=0;
        for(int k=0;k<d;k++){
          total+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
        }
        int dist = (int)(Math.sqrt((double)total));
        if( dist*dist==total ){
          count++;
        }
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21972
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {

        static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        public static void main(String[] args) throws Exception{

            int w = Integer.parseInt(reader.readLine());
            int n = Integer.parseInt(reader.readLine());

            int[] seq = new int[w];
            for (int i=0; i<w; i++)
                seq[i] = i+1;

            while (n-- > 0) {
                String[] s  = reader.readLine().split(",");
                int begin = Integer.parseInt(s[0]) - 1;
                int end = Integer.parseInt(s[1]) - 1;

                int tmp = seq[begin];
                seq[begin] = seq[end];
                seq[end] = tmp;
            }

            for (int i=0; i<w; i++)
                System.out.println(seq[i]);
        }

}

Measured memory_bytes: 17116
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int w = scanner.nextInt();
			int h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			int xs = scanner.nextInt();
			int ys = scanner.nextInt();
			xg = scanner.nextInt();
			yg = scanner.nextInt();
			int n = scanner.nextInt();
			map = new int[h + 2][w + 2];

			for (int i = 0; i < n; i++) {
				int c = scanner.nextInt();
				int d = scanner.nextInt();
				int x = scanner.nextInt();
				int y = scanner.nextInt();
				if (d == 0) {
					for (int j = 0; j < 2; j++) {
						for (int k = 0; k < 4; k++) {
							map[j + y][k + x] = c;

						}
					}
				} else {
					for (int j = 0; j < 4; j++) {
						for (int k = 0; k < 2; k++) {
							map[j + y][k + x] = c;
						}
					}
				}
			}
			color = map[ys][xs];
			b = new boolean[h + 2][w + 2];
			if (color == 0)
				System.out.println("NG");
			else
				System.out.println(slove(xs, ys) ? "OK" : "NG");
		}

	}

	private boolean slove(int x, int y) {
		PriorityQueue<Point> pq = new PriorityQueue<Point>();
		pq.add(new Point(y, x, getDis(x, y)));
		b[y][x] = true;
		while (!pq.isEmpty()) {
			Point point = pq.poll();
			x = point.x;
			y = point.y;

			if (point.dis == 0)
				return true;

			for (int[] a : dxy) {
				int dx = a[1] + x;
				int dy = a[0] + y;
				if (b[dy][dx])
					continue;
				if (map[dy][dx] != color)
					continue;
				pq.add(new Point(dy, dx, getDis(dx, dy)));
				b[dy][dx] = true;
			}
		}
		return false;
	}

	private int getDis(int x, int y) {
		return Math.abs(yg - y) + Math.abs(xg - x);
	}

	class Point implements Comparable<Point> {
		int y;
		int x;
		int dis;

		@Override
		public int compareTo(Point o) {
			return this.dis - o.dis;
		}

		public Point(int y, int x, int dis) {
			super();
			this.y = y;
			this.x = x;
			this.dis = dis;
		}
	}

	int[][] dxy = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
	boolean[][] b;
	int[][] map;
	int xg;
	int yg;
	int color;
}

Measured memory_bytes: 24116
use strict;
use warnings;
package ModInt;
sub MOD(){10**9+7}
use overload
	"+"=>\&modadd,
	"-"=>\&modsub,
	"*"=>\&modmul,
	"/"=>\&moddiv,
	"**"=>\&modpow,
	"=="=>\&modeq,
	"!="=>\&modne,
	"0+"=>sub{return${$_[0]}},
;
sub new{
	my$class=shift;
	return bless\($_[0]%MOD),$class;
}
sub modadd{
	my($x,$y)=@_;
	return bless\(($$x+(ref$y?$$y:$y))%MOD),ref$x;
}
sub modsub{
	my($x,$y)=@_;
	my$v=$$x;
	$v-=ref$y?$$y:$y;
	$v=-$v if$_[2];
	$v%=MOD;
	return bless\$v,ref$x;
}
sub modmul{
	my($x,$y)=@_;
	return bless\((ref$y?$$y:$y%MOD)*$$x%MOD),ref$x;
}
sub moddiv{
	my($x,$y)=@_;
	my$v=$$x;
	my$w=ref$y?$$y:$y%MOD;
	$v=$_[2]?$w*modinv($v)%MOD:$v*modinv($w)%MOD;
	return bless\$v,ref$x;
}
sub modpow{
	my($x,$y)=@_;
	my$r=1;
	my$v=$$x;
	my$w=$y;
	($v,$w)=($w,$v)if$_[2];
	$v%=MOD;
	while($w>0){
		$r=$r*$v%MOD if$w&1;
		$v=$v*$v%MOD;
		$w>>=1;
	}
	return bless\$r,ref$x;
}
sub modeq{
	my($x,$y)=@_;
	my$v=$$x;
	my$w=ref$y?$$y:$y%MOD;
	return$v==$w;
}
sub modne{
	my($x,$y)=@_;
	my$v=$$x;
	my$w=ref$y?$$y:$y%MOD;
	return$v!=$w;
}
sub modinv{
	my$r=1;
	my$a=shift;
	my$n=MOD-2;
	while($n>0){
		$r=$r*$a%MOD if$n&1;
		$a=$a*$a%MOD;
		$n>>=1;
	}
	return$r;
}
package main;
<>;
my$ans=ModInt->new(0);
my$cumsum=ModInt->new(0);
for(split$",<>){
	$ans+=$cumsum*$_;
	$cumsum+=$_;
}
print$ans,$/;


Measured memory_bytes: 24820
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=5e2+4;

int main()
{
	string s;

	cin>>s;

	if(s[0]=='7' or s[1]=='7' or s[2]=='7')
	cout<<"Yes";
	else
	cout<<"No";

    return 0;
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramA
    {
        static void Main()
        {
            if (Line == "ABC")
            {
                System.Console.WriteLine("ARC");
            }
            else
            {
                System.Console.WriteLine("ABC");
            }
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 25812
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 10005
 
#define PI   3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007



int main()
{
	FAST;
	ll n;
	cin >> n;
	ll a[n+6]; ll m = 0;
	for(ll i = 0; i< n; i ++){
		cin >> a[i];
		m += a[i];
		m --;
	}
	cout << m;
	return 0;
}

Measured memory_bytes: 3664
# 深さ優先探索
N = int(input())
links = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    links[a].append((b, c))
    links[b].append((a, c))

Q, K = map(int, input().split())

d = [float('inf')] * (N + 1)
d[K] = 0
q = [K]
while q:
    i = q.pop()
    for j, c in links[i]:
        if d[i] + c < d[j]:
            d[j] = d[i] + c
            q.append(j)

result = []
for _ in range(Q):
    x, y = map(int, input().split())
    result.append(d[x] + d[y])
#print('\n'.join(str(v) for v in result))
print(*result, sep='\n')


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

#define rc(x) return cout<<x<<endl,0

using namespace std;
 
// AtCoder 092 C: 
// const int N = 10e5 + 10;

int cnt[1000];

int main() {
	int n, x, y, ans=0;
	cin >> n;
	vector <pair<pair<int, int>,int> > v;
	for(int i=0; i<n; i++){
		cin >> x >> y;
		v.push_back(make_pair(make_pair(x, y), 0));
	}
	for(int i=0; i<n; i++){
		cin >> x >> y;
		v.push_back(make_pair(make_pair(x, y), 1));
	}
	memset(cnt, 0, sizeof(cnt));
	sort(v.begin(), v.end());
	for(int i=0; i<2*n; i++){
		if(v[i].second == 0){
			cnt[v[i].first.second]++;
		}else{
			for(int j=v[i].first.second; j>=0; j--){
				if(cnt[j] >= 1){
					cnt[j]--;
					ans++;
					break;
				}
			}
		}
	}
	rc(ans);
}


Measured memory_bytes: 256
let nil = -1

type tree = {
  mutable parent : int;
  mutable child : int;
  mutable bro : int;
  mutable depth : int;
}

let make () = { parent = nil; child = nil; bro = nil; depth = nil }

let set_depth t n =
  let rec root i =
    if i = n then nil
    else if t.(i).parent = nil then i
    else root (i + 1)
  in
  let rec doit i d =
    t.(i).depth <- d;
    if t.(i).bro <> nil then doit t.(i).bro d;
    if t.(i).child <> nil then doit t.(i).child (d + 1);
  in
  doit (root 0) 0

let print_tree t =
  let print i =
    print_string "node "; print_int i;
    print_string ": parent = "; print_int t.(i).parent;
    print_string ", depth = "; print_int t.(i).depth;
    print_string (if t.(i).parent = nil then ", root, [" else if t.(i).child = nil then ", leaf, [" else ", internal node, [");
    let rec print_children c =
      if c <> nil then begin
        if c <> t.(i).child then print_string ", ";
        print_int c;
        print_children t.(c).bro
      end
    in
    print_children t.(i).child;
    print_string "]\n";
  in
  Array.iteri (fun i _ -> print i) t

let () =
  let n = Scanf.scanf "%d " (fun i -> i) in
  let t = Array.init n (fun _ -> make ()) in
  let rec read i =
    if i < n then begin
      let id, k = Scanf.scanf "%d %d " (fun id k -> id, k) in
      let rec read_node j left_child =
        if j < k then begin
          let c = Scanf.scanf "%d " (fun i -> i) in
          t.(c).parent <- id;
          if j = 0 then t.(id).child <- c else t.(left_child).bro <- c;
          read_node (j + 1) c
        end
      in
      read_node 0 0;
      read (i + 1)
    end
  in
  read 0;
  set_depth t n;
  print_tree t

Measured memory_bytes: 13292
object Main extends App {
	val Array(p, q, r) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	val a1 = p + q
	val a2 = q + r
	val a3 = p + r

	println(math.min(a1, math.min(a2, a3)))
	

}

Measured memory_bytes: 27440
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;


int main() {
  int n;
  ll d;
  cin >> n >> d;
  
  ll a = 0,b = 0;
  
  int ans = 0;
  REP(i,n){
    cin >> a >> b;
    if(d*d >= a*a + b*b){
      ans++;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <array>
#include <map>
#include <set>

using namespace std;

int main()
{
    string s;
    cin >> s;

    sort(s.begin(), s.end());
    bool check = (s[0] == s[1]) && (s[2] == s[3]) && s[1] != s[2];

    cout << (check ? "Yes" : "No") << endl;

}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

double f(double x, int l, int r, int v){
    if(x <= l) return v+(l-x);
    else if(x <= r) return v;
    return v+(x-r);
}

int main(){
    int N; cin >> N;
    vector<int> t(N+2, 0), v(N+2, 0), l(N+2, 0), r(N+2, 0);

    for(int i=1; i<=N; i++) cin >> t[i];
    for(int i=1; i<=N; i++) cin >> v[i];

    for(int i=1; i<=N; i++){
        r[i] = r[i-1] + t[i];
        l[i] = r[i-1];
    }

    r[N+1] = r[N];
    l[N+1] = r[N];

    double h1 = 0.0;
    double h2;
    double ans = 0.0;

    for(double x=0.5; x<=r[N]; x+=0.5){
        h2 = 500.0;
        for(int i=0; i<N+2; i++) h2 = min(h2, f(x, l[i], r[i], v[i]));
        ans += 0.25*(h1 + h2);
        h1 = h2;
    }

    printf("%.5lf\n", ans);
}

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

using namespace std;
using ll=long long;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,a,b) for(int i=a;i<b;i++)

int main(){
    string s,t;
    cin>>s>>t;
    map<string,int> mp;
    cin>>mp[s]>>mp[t];
    
    string c;
    cin>>c;
    mp[c]--;
    cout<<mp[s]<<" "<<mp[t]<<endl;
}

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

int main() {
    int numItems;
    cin >> numItems;
    int maxWeight;
    cin >> maxWeight;

    int items[numItems][2];
    for(int i = 0; i < numItems; i++) {
        cin >> items[i][0]; //weight
        cin >> items[i][1]; //value
    }

    vector<vector<unsigned long int> > maxValue(numItems, vector<unsigned long int>(maxWeight+1, 0));
    
    for(int weight = items[0][0]; weight <= maxWeight; weight++) {
        maxValue[0][weight] = items[0][1];
    }

    for(unsigned int item = 1; item < numItems; item++) {
        for(unsigned int weight = 0; weight <= maxWeight; weight++) {
            if(items[item][0] > weight) {
                maxValue[item][weight] = maxValue[item-1][weight];
            } else {
                maxValue[item][weight] = max(maxValue[item-1][weight],  
                                             maxValue[item-1][weight - items[item][0]] + items[item][1]);
            }
        }
    }
    
    cout << maxValue[numItems-1][maxWeight];

    return 0;
}

Measured memory_bytes: 81944
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int rectangle, diamond;
	
	rectangle = diamond = 0;
	while (scanf("%d,%d,%d", &a, &b, &c) != EOF){
		if (a * a + b * b == c * c){
			rectangle++;
		}
		else if (a == b){
			diamond++;
		}
	}
	printf("%d\n%d\n", rectangle, diamond);
	
	return 0;
}

Measured memory_bytes: 596
import numpy as np

ans = 0
n, d = map(int, input().split())
for i in range(n):
    x1, x2 = map(int, input().split())
    arr1 = np.array([x1, x2])
    if  d >= np.linalg.norm(arr1):
        ans += 1

print(ans)


Measured memory_bytes: 27156
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ll r;
cin>>r;
cout<<r*r<<endl;
}



Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <tuple>
#include <stdbool.h>
#include <bitset>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
using namespace std;


int main(void) {
    int a,b,c;
    cin >> a;
    cin >> b;
    cin >> c;
    if (
        (a == b ) &&
        (b == c ) &&
        (c == a )
    ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;cin>>s>>t;
  int n=s.size(),m=t.size();
  vector<char> a(n); vector<char> b(m);
  
  for(int i=0;i<n;i++)a.at(i)=s.at(i);
  for(int i=0;i<m;i++)b.at(i)=t.at(i);
  sort(a.begin(),a.end());
  sort(b.begin(),b.end(),greater<int>());
  
  string c,d;
  for(int i=0;i<n;i++)c+=a.at(i);
  for(int i=0;i<m;i++)d+=b.at(i);
  
  if(c<d)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<double, null_type, less_equal<double>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
typedef long long ll;
typedef double dd;
typedef long double ldd;
typedef pair <int, int> pii;
typedef pair <pii , int> ppii;
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
#define mp make_pair
#define all(x) x.begin() , x.end()
#define debug(x) cerr<< #x << " = " << x << endl
#define ddebug(x, y) cerr<< #x << " = " << x  << ", " << #y << " = " << y << endl
#define uop(x, y) pii(min(x, y), max(x, y))
#define mem(a, b) memset(a, b, sizeof a)
#define sq(x) (x) * (x)
#define out return cout << "NO" << endl, 0
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, x;
	cin >> n >> x;
	cout << 3 * (n - __gcd(n , x)) << endl;
	return 0;
}



Measured memory_bytes: 3584
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        if (sc.next().equals("H") ^ sc.next().equals("H")) {
            System.out.println("D");
        } else {
            System.out.println("H");
        }
    }
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s; cin>>s;
	int cnt=0;
	for(auto&&i:s){
		if(i=='g')++cnt;
		else --cnt;
	}
	cout<<cnt/2<<"\n"s;
}


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

int main(){
    int N, max = 0, num = 0;
    cin >> N;
    int H[N];
    for(int i = 0; i < N; i++){
        cin >> H[i];
        if(max <= H[i]){
            max = H[i];
            num++;
        }
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N, M;

vector<pair<int,int>> solve(int lhs, int rhs){
  vector<pair<int,int>> ret;
  map<pair<int,int>,int> memo;
  while(lhs>=1){
    int a = abs(lhs-rhs);
    int b = N-a;
    if(a>b) swap(a,b);
    if(a == b || lhs == rhs){
      ;
    }else{
      if(memo.count(make_pair(a,b)) == 0){
        memo[make_pair(a,b)] = 1;
        ret.emplace_back(lhs,rhs);
      }else{
        rhs++;
        if(rhs>N) rhs -= N;
        continue;
      }
    }
    lhs--;
    rhs++;
    if(rhs>N) rhs -= N;
  }
  return ret;
}

int main(){
  cin >> N >> M;

  REP(i,1,N){
    int lhs = N/2;
    int rhs = lhs+i;
    if(rhs>N) rhs -= N;
    vector<pair<int,int>> ret = solve(lhs, rhs);
    
    if(ret.size() >= M){
      rep(i,M){
        cout << ret[i].first << " " << ret[i].second << endl;
      }
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 9460
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> X(N), Y(N), idx(N);
    REP(i,N) cin >> X[i] >> Y[i];
    iota(idx.begin(), idx.end(),0);
    double ans = 0;
    do{
        for(int i=1;i<N;i++) ans += hypot(X[idx[i]]-X[idx[i-1]], Y[idx[i]]-Y[idx[i-1]]);
    }while(next_permutation(idx.begin(),idx.end()));
    for(int i=N;i>1;i--) ans /= i;
    printf("%.12lf\n", ans);
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    for i in 1..10000000 {
        let x: u32 = sc.read();
        if x == 0 { break; }
        println!("Case {}: {}", i, x);
    }
}



Measured memory_bytes: 5052
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<bitset<64>> mask(n, 0);
    rep(i, n) {
        int k;
        cin >> k;
        rep(j, k) {
            int b;
            cin >> b;
            mask[i].set(b);
        }
    }
    bitset<64> b;
    int q;
    cin >> q;
    while (q--) {
        int com, i;
        cin >> com >> i;
        bitset<64> c;
        if (com != 0) c = (b & mask[i]);
        switch (com) {
        case 0:
            cout << b.test(i) << endl;
            break;
        case 1:
            b |= mask[i];
            break;
        case 2:
            b &= ~mask[i];
            break;
        case 3:
            b ^= mask[i];
            break;
        case 4:
            cout << (c == mask[i]) << endl;
            break;
        case 5:
            cout << c.any() << endl;
            break;
        case 6:
            cout << !c.any() << endl;
            break;
        case 7:
            cout << c.count() << endl;
            break;
        case 8:
            cout << c.to_ullong() << endl;
            break;
        }
    }
}



Measured memory_bytes: 3176
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm> 
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define y1 abcde
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 5e3 + 15;
int n, k, a[N];

int p[N][N];
bitset <N> dp[2][N];

// dp[prefix/suffix][i][sum]
int ans;

inline void precalc() {
	dp[0][0][0] = dp[1][n+1][0] = true;
	for(int i = 1; i <= n; ++i)
		dp[0][i] = dp[0][i-1] | (dp[0][i-1] << a[i]);
	for(int i = n; i; --i)
		dp[1][i] = dp[1][i+1] | (dp[1][i+1] << a[i]);
	for(int i = 1; i <= n; ++i) {
		p[i][0] = 1;
		for(int j = 1; j <= k; ++j)
			p[i][j] = p[i][j-1] + dp[0][i][j];
	}
}

inline int get(int i, int l, int r) {
	if(!l)
		return p[i][r];
	if(l > r)
		return 0;
	return p[i][r] - p[i][l-1];
}

main() {
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	precalc();
	for(int i = 1; i <= n; ++i) {
		bool flag = false;
		for(int j = 0; j < k; ++j) {
			if(dp[1][i+1][j] && (j + a[i] >= k || get(i - 1, max(0, k - j - a[i]), k - j - 1))) {
				flag = true;
				break;
			}
		}
		flag |= get(i - 1, max(0, k - a[i]), k - 1) != 0;
		ans += !flag;
	}
	printf("%d\n", ans);
    return 0;
}

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

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

    int maximum = 0;
    for(int i = 0; i < N; i++){
        maximum = max(L[i], maximum);
    }

    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += L[i];
    }

    if(maximum * 2 < sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }

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

  ld N,M; cin >> N >> M;
  vector<ll> A(N);
  ld total = 0;
  rep(i, N) {
    cin >> A[i];
    total += A[i];
  }

  ld need = ceil(total / ((long double)4 * M));
  ll cur = 0;

  rep(i, N) {
    if(A[i] >= need) ++cur;
  }

  if(cur >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int s;
	double w,h,bmi;

	while (scanf("%d,%lf,%lf", &s, &w, &h) != EOF) {
		bmi = w / (h*h);
		if (bmi >= 25) printf("%d\n", s);
	}
	return 0;
}

Measured memory_bytes: 628
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
struct fix_point: private T {
  explicit constexpr fix_point(T &&func): T(std::forward<T>(func)) { }
  template <class... Args>
  constexpr decltype(auto) operator () (Args &&... args) const {
    return T::operator()(*this, std::forward<Args>(args)...);
  }
};
 
template <class T>
constexpr decltype(auto) make_fix_point(T &&func) {
  return fix_point<T>{std::forward<T>(func)};
}

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (int &x: A) {
    std::cin >> x;
  }
  std::cout << (make_fix_point([](auto &&dfs, std::vector<int> &vec) -> bool {
    int sum = 0;
    for (int x: vec) {
      sum += x - 1;
    }
    if (sum & 1) {
      return true;
    }
    int idx = -1;
    for (int i: range(0, vec.size())) {
      if (vec[i] & 1) {
        if (vec[i] == 1) return false;
        if (idx != -1) return false;
        idx = i;
      } 
    }
    --vec[idx];
    int gcd = 0;
    for (int x: vec) {
      gcd = std::__gcd(gcd, x);
    }
    for (int &x: vec) {
      x /= gcd;
    }
    return !dfs(vec);
  })(A) ? "First" : "Second") << '\n'; 
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	if(n<=k){
		cout<<n*x;
	}
	else{
		cout<<k*x+(n-k)*y;
	}
	return 0;
}

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

signed main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n,x,k,d,i;
    cin>>x>>k>>d;

    x=abs(x);
    int y = x/d;
    if(y > k)
    {
        x-=k*d;
        cout<<x<<endl;
        return 0;
    }

    k-=y;
    int r = x%d;
    int l = d-x%d;

    if(k%2)
        cout<<l<<endl;
    else
        cout<<r<<endl;


    return 0;
}




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

int main(){
    int N, ans = 0;
    cin >> N;
    string s;
    cin >> s;
    int left = 0, right = N - 1;
    while(left < right){
        if(s[left] == 'R' && s[right] == 'W'){
            left++;
            right--;
        }
        else if(s[left] == 'R') left++;
        else if(s[right] == 'W') right--;
        else{
            ans++;
            left++;
            right--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3708
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

int main(){
  string S,T;
  cin >> S >> T;
  int ln = S.size();
  bool flag = false;
  for(int i = 0; i < ln; i++){
    char A = S[ln-1];
    S.pop_back();
    S = A + S;
    if(S == T){
      flag = true;
      break;
    }
  }

  if(flag) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 256
n = int(input())

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

alice = []

bob = []

for i in range(n):
	alice.append(max(card))
	del card[card.index(max(card))]
	if card == []:
		break
	bob.append(max(card))
	del card[card.index(max(card))]
	if card == []:
		break
        
print(sum(alice) - sum(bob))

Measured memory_bytes: 3064