akhauriyash/Code-Regression huggingface dataset:
import Control.Monad ( replicateM )
import Data.Bits ( xor )

f  2 = (\a b -> [a, b]) <$> [0, 1] <*> [0, 1]
f  3 = (\a b c -> [a, b, c]) <$> [0, 1] <*> [0, 1] <*> [0, 1]
f  4 = (\a b c d -> [a, b, c, d]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f  5 = (\a b c d e -> [a, b, c, d, e]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f  6 = (\a b c d e f -> [a, b, c, d, e, f]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f  7 = (\a b c d e f g -> [a, b, c, d, e, f, g]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f  8 = (\a b c d e f g h -> [a, b, c, d, e, f, g, h]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f  9 = (\a b c d e f g h i -> [a, b, c, d, e, f, g, h, i]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]
f 10 = (\a b c d e f g h i j -> [a, b, c, d, e, f, g, h, i, j]) <$> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1] <*> [0, 1]

check :: [Int] -> Int -> [Int] -> Bool
check switches p ks = p == (foldl1 xor $ map (switches!!) ks)

checkAll :: [Int] -> [Int] -> [[Int]] -> Bool
checkAll switches ps kss = all (\(p, ks) -> check switches p ks) (zip ps kss)

main = do
    [n, m] <- map read . words <$> getLine
    kss <- replicateM m $ map read . words <$> getLine
    ps <- map read . words <$> getLine
    let switchess = f n

    print $ length $ filter (\switches -> checkAll switches ps (map (tail . map pred) kss)) switchess


Measured memory_bytes: 1020
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]

A = [i[0] for i in AB]
B = [i[1] for i in AB]
from statistics import median

a_med = median(A)
b_med = median(B)

if N%2==1:
  print(b_med - a_med + 1)
  
else:
  print(int((b_med - a_med) * 2) + 1)

Measured memory_bytes: 132172
var
 a:array[1..100001] of longint;
 n,i,s,sum:longint;
procedure kp(l,r:longint);
 var
  i,j,t,mid:longint;
 begin
  i:=l;j:=r;mid:=a[(i+j) div 2];
  repeat
   while a[i]<mid do inc(i);
   while a[j]>mid do dec(j);
   if i<=j then
    begin
     t:=a[i];a[i]:=a[j];a[j]:=t;
     inc(i);dec(j);
    end;
  until i>j;
  if i<r then kp(i,r);
  if j>l then kp(l,j);
 end;
begin
 readln(n);
 for i:=1 to n do readln(a[i]);
 kp(1,n);
 s:=1;
 for i:=2 to n+1 do
  if a[i]=a[i-1] then inc(s)
   else begin
          if odd(s) then inc(sum);
          s:=1;
        end;
  writeln(sum);
end.

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

int main() {
  while(1){
    int x,y;
    cin >> x >> y;
    if(x==0 && y==0)
      break;
    
    if(x>y){
      swap(x,y);
    }
    cout << x << ' ' << y << endl;    
  }
}



Measured memory_bytes: 3028
#include <cstdio>
#include <cassert>

using namespace std;

const int N = 309;

char a[N][N];
int ans[N][N];

int main() {
  int rows, cols, m;
  scanf("%d%d%d", &rows, &cols, &m);
  for (int i = 0; i < rows; ++i) {
    scanf("%s", a[i]);
  }
  for (int i = 0; i < rows; ++i) {
    for (int j = 0; j < cols; ++j) {
      ans[i][j] = 0;
    }
  }
  for (int i = 0; i < rows; ++i) {
    for (int j = 0; j < cols; ++j) {
      if (a[i][j] == '.') {
        continue;
      }
      int lj = j - 1;
      while (lj >= 0 && a[i][lj] == '.' && ans[i][lj] == 0) {
        --lj;
      }
      int hj = j + 1;
      while (hj < cols && a[i][hj] == '.' && ans[i][hj] == 0) {
        ++hj;
      }
      int li = i - 1;
      while (li >= 0) {
        bool ok = true;
        for (int nj = lj + 1; nj < hj; ++nj) {
          if (a[li][nj] == '#' || ans[li][nj] != 0) {
            ok = false;
          }
        }
        if (!ok) {
          break;
        }
        --li;
      }
      int hi = i + 1;
      while (hi < rows) {
        bool ok = true;
        for (int nj = lj + 1; nj < hj; ++nj) {
          if (a[hi][nj] == '#' || ans[hi][nj] != 0) {
            ok = false;
          }
        }
        if (!ok) {
          break;
        }
        ++hi;
      }
      for (int ni = li + 1; ni < hi; ++ni) {
        for (int nj = lj + 1; nj < hj; ++nj) {
          ans[ni][nj] = m;
        }
      }
      --m;
    }
  }
  for (int i = 0; i < rows; ++i) {
    for (int j = 0; j < cols; ++j) {
      assert(ans[i][j] != 0);
    }
  }
  for (int i = 0; i < rows; ++i) {
    for (int j = 0; j < cols; ++j) {
      if (j > 0) {
        putchar(' ');
      }
      printf("%d", ans[i][j]);
    }
    putchar('\n');
  }
}


Measured memory_bytes: 1152
import numpy as np

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

l = [int(i) for i in input().split()]
l.sort()
if n == 1 or m == 1:
    print(l[-1]-l[0])
elif n > m:
    print(0)
else:
    d = [0 for i in range(m - 1)]
    for i in range(m-1):
        d[i] = l[i+1] - l[i]
    d = np.array(d)
    dl = d.argsort()[::-1]
    count = 0
    for i in range(n):
        if i == 0:
            count += l[dl[i]] - l[0]
            index = dl[i]
        elif i == n - 1:
            count += l[-1] - l[index+1]
        else:
            count += l[dl[i]] - l[index+1]
            index = dl[i]
    print(count)


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

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

    vector<int> vec(n);

    int allpoint=0;
    int count=0;
    for(int i=0;i<n;i++){
        cin >> vec.at(i);
        allpoint += vec.at(i);
    }

    string s = "No";

    for(int i=0;i<n;i++){
        if((double)vec.at(i)/allpoint >= 1.0/(4*m)){
            count++;
        }
        if(count>=m){
            s = "Yes"; break;
        } 
    }
    
    cout << s << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ans = new int[4];
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            if(s.equals("AC")) ans[0]++;
            else if(s.equals("WA")) ans[1]++;
            else if(s.equals("TLE")) ans[2]++;
            else ans[3]++;
        }
        System.out.println("AC x " + ans[0]);
        System.out.println("WA x " + ans[1]);
        System.out.println("TLE x " + ans[2]);
        System.out.println("RE x " + ans[3]);
        sc.close();

    }

}


Measured memory_bytes: 58084
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <algorithm>
#include <map>

using namespace std;

int main(){
    int n;
    cin >> n;
    pair<int, int> p[n];

    for(int i = 0; i < n; i++){
        cin >> p[i].first;
    }

    for(int i = 0; i < n; i++){
        cin >> p[i].second;
    }

    int sum = 0;

    for(int i = 0; i < n; i++){
        if(p[i].first > p[i].second){
            sum += p[i].first - p[i].second;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define debug(x) cout<<x<<endl;
#define int ll
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;
 
int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("a.in","r",stdin);
	#endif
	ios::sync_with_stdio(false);
 
 	int n;
 	cin>>n;
 	vector<int> v(n);
 	for(int i=0;i<n;i++)
 		cin>>v[i];

 	vector<int> dp(n);
 	dp[0] = 0;
 	dp[1] = dp[0] + abs(v[1]-v[0]);

 	for(int i=2;i<n;i++)
		dp[i] = min(dp[i-1] + abs(v[i]-v[i-1]), dp[i-2] + abs(v[i]-v[i-2]));
 
	cout<<dp[n-1]<<endl;
 
	return 0;
}

Measured memory_bytes: 4832
#include <iostream>
#include <cstdlib>

using namespace std;


struct node {
    int id;
    node *next;
};


node hdrs[101];
int adj[101][101];


int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        hdrs[i].next = &hdrs[i];
        hdrs[i].id = i;
    }

    for (int i = 1; i <= n; i++) {
        int k;
        int id;
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;

            node *t = (node *)malloc(sizeof(node));
            t->id = v;
            t->next = hdrs[id].next;
            hdrs[id].next = t;
        }
    }

    for (int i = 1; i <= n; i++) {
        node *t = &hdrs[i];
        while (t->next != &hdrs[i]) {
            t = t->next;
            adj[i][t->id] = 1;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < n; j++) {
            cout << adj[i][j] << " ";
        }
        cout << adj[i][n] << endl;
    }

    return 0;
}


Measured memory_bytes: 3152
s = input()
q = int(input())

for i in range(q):
    opt, *args = input().split()
    a = int(args[0])
    b = int(args[1])
    if opt == "print":
        print(s[a:b+1])
    elif opt == "reverse":
        s = s[:a] + s[a:b+1][::-1] + s[b+1:]
    elif opt == "replace":
        p = args[2]
        s = s[:a] + p + s[b+1:]


Measured memory_bytes: 5616
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<functional>
using namespace std;

int main(){
    int N,K;
    int ans=0;
    int x[105];
    cin>>N>>K;

    for(int i=0;i<N;i++){
        cin>>x[i];
        if(x[i]>K/2){
            ans+=abs(x[i]-K);
        }else{
            ans+=x[i];
        }
    }
    cout<<2*ans<<endl;


}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int x,a,b;
	cin>>x;
	cin>>a;
	cin>>b;
	if(a>=b)
	cout<<"delicious"<<endl;
	else
	if(x>=b-a)
	cout<<"safe"<<endl;
	else
	cout<<"dangerous"<<endl;
	return 0;
} 

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

using namespace std;


typedef unsigned long long ll;

vector<vector<ll> > lines;

int n;
int field[9][9];

vector<ll> tmp;

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

bool ok=false;

ll fin;


void dfs(ll s,int idx){
	if(ok){
		return;
	}
	if(idx==lines.size()){
		if(fin==s)
			ok=true;
		return;
	}
	for(int i = 0; i < lines[idx].size(); i++){
		if((s&lines[idx][i])==0){
			dfs(s|lines[idx][i],idx+1);
		}
	}
}

void lineSearch(ll s,int curSum,int ret,int x,int y){
	if(curSum==ret){
		tmp.push_back(s);
	}
	for(int i= 0; i < 4; i++){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(nx>=0&&ny>=0&&nx<n&&ny<n&&field[ny][nx]>=1&&(curSum+field[ny][nx]<=ret)){
			if(!((s>>(ny*n+nx))&(1ull))){
				ll ns=s|(((1ull)<<(ny*n+nx)));
				lineSearch(ns,curSum+field[ny][nx],ret,nx,ny);
			}
		}
	}
}

int main(){


	while(cin>>n&&n!=0){
		fin=0;
		for(int i = 0; i < n*n; i++){
			fin|=(1ull<<i);
		}

		ok=false;
		lines.clear();
		vector<pair<int,pair<int,int> > > vpii;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin>>field[i][j];
				if(field[i][j]<0){
					vpii.push_back(make_pair(field[i][j],make_pair(i,j)));
				}
			}
		}
		for(int i = 0; i < vpii.size(); i++){
			tmp.clear();
			lineSearch(((1ull)<<(vpii[i].second.first*n+vpii[i].second.second)),0,-vpii[i].first,vpii[i].second.second,vpii[i].second.first);
			lines.push_back(tmp);
		}
		dfs(0ull,0);
		if(ok)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}

	return 0;
}

Measured memory_bytes: 968
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n = 3; 
  	vvi c(n, vector<int>(n));
  	rep(i,n){
      	rep(j,n) cin >> c[i][j];
    }
	vector<int> three(n);
  	iota(three.begin(),three.end(),0);
	int sum = c[0][0] + c[1][1] + c[2][2];
  	int temp;
  	do{
  		temp = c[0][three[0]] + c[1][three[1]] + c[2][three[2]];
      	if(sum != temp) {
        	puts("No");
          	return;
        }
    } while(next_permutation(three.begin(),three.end()));
	puts("Yes");
    return;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    ll h, w;
    cin >> h >> w;
    ll ans;
    if (h % 3 == 0 || w % 3 == 0) ans = 0;
    else {
        vector<ll> s(3);
        ll mn = LINF;

        rep(i, 2) {
            ll h_tmp = h / 2;
            srep(w_tmp, w, 1) {
                s[0] = w_tmp * h;
                s[1] = (w - w_tmp) * h_tmp;
                s[2] = (w - w_tmp) * (h - h_tmp);
                sort(all(s));
                mn = min(mn, s.back() - s.front());
            }
            srep(w_tmp, w, 1) {
                s[0] = w_tmp * h;
                s[1] = w_tmp * h;
                s[2] = (w - w_tmp*2) * h;
                sort(all(s));
                if (s[0] < 0) break;
                mn = min(mn, s.back() - s.front());
            }
            swap(w, h);
        }
        ans = mn;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>

using namespace std;

int main(){
  int a, b, c, d;
  
  cin >> a >> b >> c >> d;
  
  int left = a + b;
  int right = c + d;
  
  if(left > right){
    cout << "Left" << endl;
  }
  else if(left == right){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
  
  return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int H, W, D;
string sky[110];
int ts[110][110];

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

    std::cin >> H >> W >> D;

    for(int i=0;i<H;++i){
        std::cin >> sky[i];
    }

    int res = 0;
    
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            if(sky[i][j] == '#'){
                ts[i][j] = 0;
            }else{
                ts[i][j] = (j > 0 ? ts[i][j-1] : 0) + 1;
            }

            if(ts[i][j] >= D){
                ++res;
            }
        }
    }

    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            if(sky[i][j] == '#'){
                ts[i][j] = 0;
            }else{
                ts[i][j] = (i > 0 ? ts[i-1][j] : 0) + 1;
            }

            if(ts[i][j] >= D){
                ++res;
            }
        }
    }

    std::cout << res << std::endl;
}



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

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

    void Solve()
    {
        Scanner cin = new Scanner();
        int n = cin.NextInt();
        int k = cin.NextInt();


        Console.WriteLine(n - k + 1);
    }
}


class Scanner
{
    string[] s;
    int i;

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

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

    public string Next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public char[] ArrayChar()
    {
        return Next().ToCharArray();
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextInt() + add;
        }
        return Array;
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextLong() + add;
        }
        return Array;
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 1e8;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<int, int> P;

P operator -(P p, P q){
  return P(p.first - q.first, p.second - q.second);
}

inline int distP(P p, P q){
  if(p.first == q.first) return abs(p.second - q.second);
  else return abs(p.first - q.first);
  //return abs(p.first - q.first) + abs(p.second - q.second);
}

inline int inner(P p, P q){
  return p.first * q.first + p.second * q.second;
}
inline int cross(P p, P q){
  return p.first * q.second - p.second * q.first;
}

inline bool ok(P p, P q){
  //assert(p.first == 0 || p.second == 0);
  //assert(q.first == 0 || q.second == 0);
  return (inner(p, q) > 0 && cross(p, q) == 0) || (inner(p, q) == 0 && cross(p, q) > 0);
}

int main(){
  assert(P(3, 1) - P(2, 10) == P(1, -9));
  assert(!ok(P(2, 0), P(0, -2)));
  assert(!ok(P(2, 0), P(-2, 0)));
  assert(ok(P(2, 0), P(2, 0)));
  assert(ok(P(2, 0), P(0, 2)));
  int M, N;
  while(cin>>M>>N && M){
    map<string, int> id_inter;
    vector<P> inter_p(M);
    REP(i, M){
      string inter; int x, y;
      cin>>inter>>x>>y;
      int t = i;
      //int t = id_inter.size();
      id_inter[inter] = t;
      inter_p[t] = P(x, y);
    }
    vector<int> connect[1000];
    REP(i, N){
      string inter1, inter2;
      cin>>inter1>>inter2;
      int id1 = id_inter[inter1];
      int id2 = id_inter[inter2];
      connect[id1].push_back(id2);
      connect[id2].push_back(id1);
    }
    string src, dst; cin>>src>>dst;
    int from = id_inter[src];
    int to = id_inter[dst];
    P dist[1000][1000];
    REP(i, M)REP(j, M) dist[i][j] = P(-1, -1);
    queue<P> que;
    FORIT(it, connect[from]){
      que.push(P(from, *it));
      dist[from][*it] = P(distP(inter_p[from], inter_p[*it]), 2);
    }
    P ans = P(INF, INF);
    while(!que.empty()){
      P p = que.front(); que.pop();
      P state = dist[p.first][p.second];
      if(p.second == to){
        ans = min(ans, state);
      }
      FORIT(it, connect[p.second]){
        P p1 = inter_p[p.second] - inter_p[p.first];
        P p2 = inter_p[*it] - inter_p[p.second];
        if(ok(p1, p2)){
          P next = P(state.first + distP(P(0, 0), p2), state.second + 1);
          if(dist[p.second][*it] != P(-1, -1) && dist[p.second][*it] <= next){
            continue;
          }
          dist[p.second][*it] = next;
          que.push(P(p.second, *it));
        }
      }
    }
    if(ans != P(INF, INF)) cout<<ans.second<<endl;
    else cout<<"impossible"<<endl;
    assert(id_inter.size() == M);
  }
  return 0;
}

Measured memory_bytes: 9264
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b){
  while(b!=0){
    long long r;
    r=a%b;
    a=b;
    b=r;
  }
  return a;
}



int main(){
  long long a,b;
  cin>>a>>b;
  long long g=gcd(a,b);
  long long ans=0;
  long long n=g;
  for(long long i=2; i<=sqrt(g); i++){
    long long count=0;
    while(n%i==0){
      count++;
      n /=i;
    }
    if(count>0) {
      ans++;
    }
  }
  if(n>1) ans++;
  cout<<ans+1<<endl;
}
    

Measured memory_bytes: 256
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void q1(){
	int r;
	cin>>r;
	cout<<r*r;
}
void q2(){
	int n; cin>>n;
	if(n&1){
		cout<<"No\n";
		return ;
	}
	n/=2;
	string s;
	cin>>s;
	int fg=1;
	for(int i=0;i<n;++i)
	if(s[i]!=s[i+n])
	fg=0;
	fg==1 ? cout<<"Yes\n" : cout<<"No\n";
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t=1;
	while(t--)
	q2();
	return 0;
}
	


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

vector<vector<int64_t>> mul(const vector<vector<int64_t>>& lhs, const vector<vector<int64_t>>& rhs, int64_t mod, int64_t n) {
  vector<vector<int64_t>> result(n, vector<int64_t>(n));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      for (int k = 0; k < n; ++k) {
        result[i][j] += lhs[i][k] * rhs[k][j];
        result[i][j] %= mod;
      }
  return result;
}

vector<vector<int64_t>> pow(vector<vector<int64_t>>& mat, int64_t index, int64_t mod, int64_t n) {
  if (index == 1) {
    return mat;
  } else {
    auto half = pow(mat, index / 2, mod, n);
    if ((index % 2) == 0) {
      return mul(half, half, mod, n);
    } else {
      return mul(mat, mul(half, half, mod, n), mod, n);
    }
  }
}

int main() {
  while(1) {
    int64_t n,m;
    int64_t z;
    cin >> n >> m >> z;
    if (!n) break;
    vector<vector<int64_t>> t(2*m+1,vector<int64_t>(2*m+1));
    vector<vector<int64_t>> t1n(n);
    vector<pair<int64_t,int64_t>> r;
    r.emplace_back(0,0);
    for (int i = 0; i < m; ++i) {
      int64_t s,d;
      cin >> s >> d;
      --s;--d;
      t1n[s].push_back(2*i+1);
      t1n[d].push_back(2*i+2);
      r.emplace_back(s,d);
      r.emplace_back(d,s);
    }
    for (int i = 1; i <= 2*m; ++i) {
      int64_t s,d;
      std::tie(s,d) = r[i];
      for (int64_t to : t1n[d]) {
        if (r[to].second == s) continue;
        t[i][to] = 1;
      }
    }
    for (int64_t to : t1n[0]) {
      t[0][to] = 1;
    }
    auto res1 = pow(t, z, INT64_C(1000000007), 2*m+1);
    bool ok = false;
    for (int i = 1; i <= 2*m; ++i) {
      if(res1[0][i] == 0) continue;
      if(r[i].second == n-1){
        ok = true;
        break;
      }
    }
    if (ok) {
      cout <<"yes"<<endl;
    } else {
      cout <<"no"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1544
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
V = np.array(lr())
C = np.array(lr())
V -= C
V = V[V>0]
answer = V.sum()
print(answer)


Measured memory_bytes: 17848
#include <bits/stdc++.h>
#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)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  vector<int> x(5);
  rep(i, 5) cin >> x[i];

  rep(i, 5) {
    if (x[i] == 0) {
      cout << i + 1 << '\n';
      return 0;
    }
  }

  




  
  return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		double[][] a = {{35.5,71},{37.5,77},{40,83},{43,89},{50,105},{55,116},{70,148}};
		String[] b = {"AAA","AA","A","B","C","D","E","NA"};
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			double x = sc.nextDouble();
			double y = sc.nextDouble();
			int k = 0;
			while(k<7){
				if(x<a[k][0]&&y<a[k][1])break;
				k++;
			}
			System.out.println(b[k]);
		}
	}
}

Measured memory_bytes: 20560
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    vector<string> matrix(3);
    rep(i,3) cin >> matrix[i];
    rep(i,3) cout << matrix[i][i];
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  int k;
  cin>>s;
  cin>>k;
  int n=s.size();

  string t;
  for(int i=0;i<n;i++){
    if(('a'+26-s[i])%26<=k){
      k-=('a'+26-s[i])%26;
      t+='a';
    }else{
      t+=s[i];
    }
  }

  k%=26;
  while(k>0){
    if(t[n-1]=='z') t[n-1]='a';
    else t[n-1]++;
    k--;
  }
  cout<<t<<endl;

  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
static const int MAXN = 5e5 + 4;
static const int MAXQ = 5e5 + 2;
static const int INF = 0x7fffffff;

int n, D, Q;
int d[MAXN], q[MAXQ];

int sfx_unfeasible[MAXN];
bool feasible[MAXN] = { false };

int main()
{
    scanf("%d%d", &n, &D);
    for (int i = 0; i < n; ++i) scanf("%d", &d[i]);
    scanf("%d", &Q);
    for (int i = 0; i < Q; ++i) scanf("%d", &q[i]), --q[i];

    sfx_unfeasible[n] = 1;
    for (int i = n - 1; i >= 0; --i)
        if (sfx_unfeasible[i + 1] <= d[i] / 2) sfx_unfeasible[i] = sfx_unfeasible[i + 1];
        else sfx_unfeasible[i] = sfx_unfeasible[i + 1] + d[i];
    //for (int i = 0; i <= n; ++i) printf("%d%c", sfx_unfeasible[i], i == n ? '\n' : ' ');

    int pos = D;
    for (int i = 0; i < n; ++i) {
        //printf("%d: %d\n", i, pos);
        if (sfx_unfeasible[i + 1] <= pos) feasible[i] = true;
        int next = std::abs(pos - d[i]);
        if (next < pos) pos = next;
    }

    for (int i = 0; i < Q; ++i) puts(feasible[q[i]] ? "YES" : "NO");
    return 0;
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
// ll MOD = ll(1e9) + 7;

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

const ll MAX = 510000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
// long long COM(ll n, ll k){
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll rem(ll x, ll y) {
    if (x > 0) {
        return x % y;
    } else {
        return (y + x) % y;
    }
}

void solve(){
    COMinit();
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = (modpow(ll(2), n, MOD) - 1) % MOD;
    ll dn = 1;
    for (int i = 0; i < a; i++) {
        dn = (dn * (n - i)) % MOD;
    }
    ans = rem(ans - rem(dn * finv[a], MOD), MOD);
    dn = 1;
    for (int i = 0; i < b; i++) {
        dn = (dn * (n - i)) % MOD;
    }
    ans = rem(ans - rem(dn * finv[b], MOD), MOD);
    cout << ans << endl;


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

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

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

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

llong N, M, p;
vector<llong> d;

llong rdis(int a, int b){
	return (b-a+N)%N;
}
llong ldis(int a, int b){
	return (a-b+N)%N;
}

int main(){

	cin >> N >> M >> p;
	d.resize(M);
	for(auto &x : d)
		cin >> x;
	sort(ALL(d));

	llong maxiL = 0, maxiR = 0;
	for(int i = 0; i < M; i++)
		maxiL = max(maxiL, ldis(p,d[i])), maxiR = max(maxiR, rdis(p,d[i]));
	llong ans = min(maxiL, maxiR);
	for(int i = 0; i < M; i++){
		int rn = (i+1)%M, ln = (i-1+M)%M;
		// cerr << p << " " << d[i] << " : r" << rdis(p,d[i]) << " l" << ldis(p,d[i]) << endl;
		// cerr << d[i] << " " << d[rn] << " : " << ldis(d[i], d[rn]) << endl;
		// cerr << d[i] << " " << d[ln] << " : " << rdis(d[i], d[ln]) << endl;
		ans = min({ans, rdis(p,d[i])+ldis(d[i],d[rn]), ldis(p,d[i]) + rdis(d[i], d[ln])});
	}

	cout << ans*100 << endl;

	return 0;
}


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

#define f(i, a, b, c) for(int i = a ; i < b ; i += c)
#define fr(i, a, b, c) for(int i = a ; i >= b ; i -= c)
#define fit(it, v) for(auto it = v.begin() ; it != v.end() ; ++it)
#define frit(it, v) for(auto it = v.rbegin() ; it != v.rend() ; ++it)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define eb emplace_back
#define pb push_back
#define lli long long int
#define modn 998244353
#define NL '\n'

using namespace std;

typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< bool > vb;
typedef vector< string > vs;
typedef vector< lli > vli;
typedef vector< vector< char > > vvc;
typedef vector< vector< int > > vvi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef pair< lli, int> pli;
typedef pair< lli, lli> pll;
typedef set< int > si;
typedef set< ii > sii;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	#ifdef LOCAL_TEST
		clock_t z = clock();
    	ifstream h("in");
	    ofstream g("out");
	#else
	    #define h cin
	    #define g cout
	#endif // LOCAL_TEST

	int hr, n;
	h >> hr >> n;
	int sum = 0;
	f(i, 0, n ,1){
		int x;
		h >> x;
		sum += x;
	}
	g << (sum >= hr ? "Yes" : "No");

	#ifdef LOCAL_TEST
		cerr << "Time taken is: " << fixed << double(clock() - z) / CLOCKS_PER_SEC << NL;
		h.close();
		g.close();
	#endif // LOCAL_TEST
}




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

sumall = int(n * (n+1)/2)
sum3 = int(n//3 * (n//3 + 1) * 3/2)
sum5 = int(n//5 * (n//5 + 1) * 5/2)
sum15 = int(n//15 * (n//15 + 1) * 15/2)

print(sumall - sum3 - sum5 + sum15)

Measured memory_bytes: 9176
n, deadline =  list(map(int, input().split() ))

# 要素を入れる、popで最大のものを取り出す　優先度付きキューじゃん
# pythonでは最小のものが出てくるので注意

tasks = [list(map(int, input().split() )) for _ in range(n)]

from operator import itemgetter, attrgetter
tasks.sort(key = itemgetter(0))

idx_t = 0
ans = 0
import heapq

prio_queue = []
for today in range(deadline, -1, -1):

	span = deadline - today
	while(idx_t < n and tasks[idx_t][0] == span):
		heapq.heappush(prio_queue, -1 * tasks[idx_t][1])
		idx_t += 1
	
	if len(prio_queue) > 0:
		a = heapq.heappop(prio_queue)
		ans += -a

print(ans)



Measured memory_bytes: 32068
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;

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

long long int a[3][100001];

struct mise {
	int number;
	string name;
	int value;
};

bool biggerthan(mise a, mise b) {
	if (a.name != b.name)  return a.name < b.name;
	return a.value > b.value;
}

int main() {
	int n,a, max = 0, sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (max < a) {
			sum += max;
			max = a;
		}
		else {
			sum += a;
		}
	}
	if (max < sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
typedef long long s64;
typedef pair<int,int> pii;
void operator +=(pii &a,const pii &b)
{
	a=pii(a.first+b.first,a.second+b.second);
}
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=50+5,M=100+5,D=1e9+7;
s64 mi(s64 x,int y=D-2)
{
	s64 ans=1;
	while(y)
	{
		if(y&1)ans=ans*x%D;
		x=x*x%D;y>>=1;
	}
	return ans;
}
vector<int>lk[N];
int dfn[N],low[N],tot;
s64 jie[M*2];
int k;

s64 ans; 
void init_jie(int n)
{
	jie[0]=1;
	rep(i,1,n)jie[i]=jie[i-1]*i%D; 
}
s64 C(int n,int m)
{
	return jie[n]*mi(jie[m]*jie[n-m]%D)%D;
}
s64 calc(const pii &pr)
{
	if(!pr.second)return 1;
	if(pr.first<pr.second)return C(pr.second+k-1,k-1);
	s64 ans=0;
	rep(i,0,pr.second-1)ans+=mi(k,__gcd(i,pr.second));
	return ans%D*mi(pr.second)%D;
}
pii dfs(int x,int fr)
{
	dfn[x]=low[x]=++tot;
	pii pr=pii(1,0);
	for(auto y:lk[x])
	if(y!=fr)
	{
		if(dfn[y])
		{
			chmin(low[x],dfn[y]);
			if(dfn[y]>dfn[x])continue;
			++pr.second;
			continue;
		}
		pii now=dfs(y,x);
		chmin(low[x],low[y]);
		if(low[y]>dfn[x])
		{
			ans=ans*k%D*calc(now)%D;
			continue;
		}
		if(low[y]>=dfn[x])
		{
			now+=pii(1,1);
			ans=ans*calc(now)%D;
			continue;
		}
		pr+=now;++pr.second;
	}
	return pr;
}

int main()
{
	//freopen("1.in","r",stdin);
	int n,m;
	cin>>n>>m>>k;
	rep(i,1,m)
	{
		int x,y;
		cin>>x>>y;
		lk[x].push_back(y);
		lk[y].push_back(x);
	}
	
	init_jie(m+k);
	
	ans=1;
	rep(x,1,n)
	if(!dfn[x])dfs(x,0);
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    bool ans = 0;
    for (int i = 9; i > 0; i--) {
        if (N % i == 0 && N/i < 10) {
            ans = 1;
            break;
            }
    }
    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
# TLEするので、自前で用意せずに、ライブラリ使おう
# https://juppy.hatenablog.com/entry/2019/02/24/ABC119_-D_Lazy_Faith-_Python_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0_Atcoder

import bisect
A, B, Q = map(int, input().split())
S = sorted([int(input()) for i in range(A)])
T = sorted([int(input()) for i in range(B)])
X = [int(input()) for i in range(Q)]

s_size = A
t_size = B
inf = 99999999999999

for x in X:
  s_index = bisect.bisect_left(S, x)
  s_left = S[s_index - 1] if s_index > 0 else None
  s_right = S[s_index] if s_index < s_size else None
  t_index = bisect.bisect_left(T, x)
  t_left = T[t_index - 1] if t_index > 0 else None
  t_right = T[t_index] if t_index < t_size else None

  ans = inf

  sl = [s_left, s_right]
  tl = [t_left, t_right]

  for s in sl:
    if not s: continue
    c1 = abs(x - s)
    for t in tl:
      if not t: continue
      ans = min(ans, c1 + abs(s-t))


  for t in tl:
    if not t: continue
    c1 = abs(x - t)
    for s in sl:
      if not s: continue
      ans = min(ans, c1 + abs(s-t))

  print(ans)




Measured memory_bytes: 17920
from collections import deque

n, m = map(int,input().split())
ex = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    ex[a].append(b)
    ex[b].append(a)

d = deque()
d.append(1)
ans = [-1] * (n+1)
ans[1] = 1
while d:
    f = d.popleft()
    for t in ex[f]:
        if ans[t] == -1:
            ans[t] = f
            d.append(t)

for i in range(2, n+1):
    if ans[i] == -1:
        print('No')
        exit()

print('Yes')
for i in range(2,n+1):
    print(ans[i])

Measured memory_bytes: 34164
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<numeric>
#include<climits>
#include<queue>
#include<unordered_map>
 
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<vector<char>> s(n,vector<char>(n));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> s[i][j];
		}
	}
	long long ans = 0;
	for (int k = 0; k < n; ++k) {
		bool ok = true;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (s[(i + k) % n][j] != s[(j + k) % n][i]) {
					ok = false;
					break;
				}
			}
			if (!ok) break;
		}
		if (ok) ++ans;
	}

	cout << ans * n << endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
//#define rep(i, c) for(int i = 0; i < (int)c; i++)
//const int inf = 1000000000; // 10^9

int main() { 
int N;
cin >> N;
vector<int> X(N);
for (int i = 0; i < N; i++) cin >> X[i];
int ans = 10000000;
for(int i = 1; i <= 100; i++) { // L やR の計算が不要
  int cost = 0;
  for (int j = 0; j < N; j++) cost += pow((X[j] - i), 2);
  ans = min(ans, cost);
}
cout << ans << endl;
return 0;
}


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

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();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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; }

int main(void){
    int N; cin >> N;
    VS s(N); REP(i,N) cin >> s[i];

    int ans = 0;
    REP(i,N){
        REP(j,s[i].size()-1) if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
    }

    int na=0, nb=0, nab=0;
    REP(i,N){
        if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A') nab++;
        else if(s[i][0]=='B') nb++;
        else if(s[i][s[i].size()-1]=='A') na++;
    }

    if(nab) ans += nab-1;
    if(nab && na){
        ans++;
        na--;
    }
    if(nab && nb){
        ans++;
        nb--;
    }
    ans += min(na,nb);
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;

#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i,l,r) for(int i=(l);i<(r);i++)
#define forb(i,r,l) for(int i=(r);i>(l);i--)
#define log2i(x) 32 - __builtin_clz((x)) - 1
#define log2ll(x) 64 - __builtin_clzll((x)) - 1
#define Pi acos(-1.0)
#define sz(x) (int)x.size()
#define pw(x,y) trunc(exp(log((x))*(y)))
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int N = 31627;
const ll M = 1e9+7;
int n,k;
ll ans=0;
ll small[101][N], big[101][N];

int can(ll x) {
    int l=1, r=x;
    while(l<r) {
        int mid=(l+r+1)>>1;
        if(1ll*mid*mid<=x) l=mid;
        else r=mid-1;
    }
    return r;
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
#endif
    fastIO;
    cin >> n >> k;
    int m=can(1ll*n);
    small[0][1]=1;
    forw(i,0,k) {
        forw(j,0,m) small[i][j+1]=(small[i][j+1]+small[i][j])%M;
        forb(j,m-1,0) big[i][j]=(big[i][j]+big[i][j+1])%M;
        forw(j,0,m) {
            big[i+1][j+1]=((n/(j+1)-n/(j+2))*small[i][j+1])%M;
            if(j+1==n/(j+1)) big[i+1][j+1]=0;
            small[i+1][j+1]=(small[i][m]+big[i][j+1])%M;
        }
    }
    forw(i,0,m) ans=(ans+small[k][i+1]+big[k][i+1])%M;
    cout << ans;
    return 0;
}


Measured memory_bytes: 50176
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
using namespace std;
#define MOD          1000000007
#define PI           3.14159265358979
#define rep(i, n)    for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v)   for (auto i : v)
#define D(x)         cout << x << endl
#define d(x)         cout << x
#define all(x)       (x).begin(), (x).end()
#define rall(x)      (x).rbegin(), (x).rend()
#define pub(x)       push_back(x)
#define pob()        pop_back()
#define puf(x)       push_front(x)
#define pof()        pop_front()
#define mp(x, y)     make_pair((x), (y))
#define fi           first
#define se           second
#define setp(x)      setprecision(x)
#define mset(m, v)   memset(m, v, sizeof(m))

#define int        long long
//static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

static const int INF =        0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef long long             ll;
typedef vector<int>           vi;
typedef vector<double>        vd;
typedef vector<long long>     vll;
typedef vector<string>        vs;
typedef vector<bool>          vb;
typedef pair<int, int>        pii;
typedef pair<long, long>      pll;
typedef vector<pii>           vpii;
typedef vector<pll>           vpll;

template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

signed main() { 
        int n;
        cin >> n;
        vi a(n);
        rep(i, n) cin >> a[i];
        int i = 0;
        bool flag = false;
        int ans = 0;
        while (i < n) {
                if (a[i] >= 2) {
                        if (flag) a[i] ++;
                        ans += a[i] / 2;
                        if (a[i] % 2 == 1) {
                                flag = true;
                        } else {
                                flag = false;
                        }
                } else {
                        if (flag) a[i] ++;
                        if (a[i] == 1) {
                                flag = true;
                        }
                        if (a[i] == 2) {
                                ans ++;
                                flag = false;
                        }
                        else flag = false;
                }
                i++;
        }
        D(ans);
        return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int n, m, x, y;
vector<int> G[maxn];
queue<int> Q;
int ans = 0, in[maxn], dp[maxn];
int main()
{
    cin>>n>>m;
    for(int i = 1; i <= m; i++){
        cin>>x>>y;
        G[x].push_back(y);
        in[y]++;
    }
    for(int i = 1; i <= n; i++) if(in[i] == 0) Q.push(i);
    while(!Q.empty()){
        int x = Q.front(); Q.pop();
        for(auto y : G[x]){
            dp[y] = max(dp[y], dp[x] + 1);
            ans = max(ans, dp[y]);
            in[y]--;
            if(in[y] == 0) Q.push(y);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6528
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        char[] c = sc.next().toCharArray();
        boolean hasWhite = false;
        int ans = 0;
        int redCounter= N-1;

        for(int i=0;i<N;i++){
            if(c[i] == 'W'){
                boolean isFind = false;
                while(!isFind){
                    if(redCounter <= i){
                        break;

                    }
                    if(c[redCounter] == 'R'){
                        if(i < redCounter){
                            ans++;
                        }
                        isFind = true;
                    }
                    redCounter--;

                }

            }
        }

        System.out.println(ans);


    }

}




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

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }


int main(){
    ll R, G, B, N, ans = 0;
    cin >> R >> G >> B >> N;
    
    for(int i  = 0; i <= N; i++){
        for(int j = 0; j <= N - i * R; j++){
            if((N - (i * R + j * G)) / B >= 0 && (N - (i * R + j * G)) % B == 0){
                ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())

INF = 10 ** 9
dp = [INF] * (2 ** N)
dp[0] = 0
for i in range(M):
  a,b = map(int,readline().split())
  C = list(map(int,readline().split()))
  key = 0
  for c in C:
    key += (1 << (c - 1))
  for j in range(len(dp) - 1, -1, -1):
    if dp[j] == INF:
      continue
    if dp[j | key] > dp[j] + a:
      dp[j | key] = dp[j] + a

if dp[-1] == INF:
  print(-1)
else:
  print(dp[-1])


Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[m];
    int sum=0;

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

    if(sum>n)
        cout<<-1<<endl;
    else if(sum==n)
        cout<<0<<endl;
    else
        cout<<n-sum<<endl;

    exit(0);
}


Measured memory_bytes: 3612