akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;

vector<string> board;

int boardQuality(vector<string>& board) {
  int n = board.size();
  assert(n == board[0].size());
  set<int> s;
  rep(i, n) {
    set<char> t1, t2;
    rep(j, n) {
      if (board[i][j] != '.') t1.insert(board[i][j]);
      if (board[j][i] != '.') t2.insert(board[j][i]);
    }
    s.insert(t1.size());
    s.insert(t2.size());
    if (s.size() > 1) return -1;
  }
  return *(s.begin());
}

bool printBoard(int n) {
  assert(board.size() == n && board[0].size() == n);

  int q = boardQuality(board);
  if (q == -1) return false;

  printf("(n, k) = (%d, %d)\n", n, q);
  rep(i, n) {
    rep(j, n) cout << board[i][j];
    cout << endl;
  }
  return true;
}

bool searchBoard(int i, int n, int k, int v, int h) {
  if (v == 0 && h == 0) return printBoard(n);
  if (i == n * n) return false;

  int r = i / n;
  int c = i % n;
  if (v > 0 && r + 1 < n && board[r][c] == '.' && board[r + 1][c] == '.') {
    board[r][c] = 'a' + v + h;
    board[r + 1][c] = 'a' + v + h;
    if (searchBoard(i + 1, n, k, v - 1, h)) return true;
    board[r][c] = '.';
    board[r + 1][c] = '.';
  }
  if (h > 0 && c + 1 < n && board[r][c] == '.' && board[r][c + 1] == '.') {
    board[r][c] = 'a' + v + h;
    board[r][c + 1] = 'a' + v + h;
    if (searchBoard(i + 1, n, k, v, h - 1)) return true;
    board[r][c] = '.';
    board[r][c + 1] = '.';
  }
  return searchBoard(i + 1, n, k, v, h);
}

void search() {
  for (int n = 3; n < 7; ++n) {
    printf("searching n = %d...\n", n);
    for (int k = 1; k <= n; ++k) {
      for (int m = 1; 4 * m <= n * n; ++m) {
        if (k * n != 3 * m) continue;
        board = vector<string>(n, string(n, '.'));
        searchBoard(0, n, k, m, m);
      }
    }
  }
}

unordered_map<int, vector<string>> tile = {
    {3, {"c..", "c..", ".bb"}},
    {4, {"ihgg", "ihff", "eedc", "bbdc"}},
    {5,
     {
         "kji..",
         "kji..",
         "hggff",
         "h.edd",
         "ccebb",
     }},
    {6,
     {
         "mlk...",
         "mlk...",
         "j.iihh",
         "jgff..",
         ".g.edd",
         "cc.ebb",
     }},
    {7,
     {
         "aa..hi.",
         "....hin",
         "....jkn",
         "....jkl",
         "bbee..l",
         "ccff..m",
         "..ddggm",
     }}};

void validateTiles() {
  for (auto it = tile.begin(); it != tile.end(); it++) {
    if (boardQuality(it->second) == -1) {
      printf("Invalid: %d\n", it->first);
      exit(1);
    }
  }
}

int main() {
  cin >> N;

  if (N == 2) {
    cout << -1 << endl;
    return 0;
  }

  if (N == 3) {
    for (auto& line : tile[3]) cout << line << endl;
    return 0;
  }

  int y = (N % 4);
  if (y != 0) y += 4;
  int x = (N - y) / 4;

  rep(i, x) {
    rep(j, 4) {
      cout << string(i * 4, '.');
      cout << tile[4][j];
      cout << string(N - 4 * (i + 1), '.');
      cout << endl;
    }
  }
  rep(j, y) {
    cout << string(N - y, '.');
    cout << tile[y][j];
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <string.h>
int main(void) {
  int a, d[100], i, j, x = 0;
  scanf("%d", &a);
  for (i = 0; i < a; i++) {
    scanf("%d", &d[i]);
  }
  for (i = 0; i < a; i++) {
    for (j = 1; j < a - i; j++) {
      x += d[i] * d[j + i];
      // fflush(stdout);
      // printf("%d\n", x);
    }
  }
  printf("%d\n", x);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int ans,cnt,n,m;
int main(){
    scanf("%d%d",&n,&m);
    while(m--){
        int x;
        char s[5];
        scanf("%d%s",&x,s);
        if(a[x]==-1)continue;
        if(s[0]=='A'){
            cnt++;
            ans+=a[x];
            a[x]=-1;
        }
        else a[x]++;
    }
    printf("%d %d\n",cnt,ans);
    return 0;
}

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

int main(){
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    bool flag=false;
    if(x>=r&&x<=w-r){
        if(y>=r&&y<=h-r)flag=true;
    }

    if(flag)cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3060
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = zeros(Int,n)
	for i in 1:100
		for j in 1:100
			for k in 1:100
				x = i^2+j^2+k^2+i*j+j*k+k*i
				if x<=n
					a[x]+=1
				end
			end
		end
	end
	for i in 1:n
		println(a[i])
	end
end

main()

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

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

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> a2(2*n);
  for(int i = 0; i < n; ++i){
    a2[i] = a[i];
    a2[i + n] = a[i] + k;
  }

  ll ans = 1000000;
  for(int i = 0; i < n; ++i){
    ans = min((ll)(a2[i + n - 1] - a2[i]), ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  string s,t;cin>>s>>t;
  bool flag=false;
  for(char c='a';c<='z';++c){
    if(s+c==t)flag=true;
  }
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef long double td;
typedef vector<td> vd;
typedef pair<ll,ll> ii;
typedef vector<ii> vii; typedef vector<bool> vb;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(ll i = ll(a); i < (ll)(b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define show(v,n) cerr << #v << " = "; forn(i,n) cerr << v[i] << " "; cerr << endl;
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
int MAXN = 500005;

 
int main()
{ 	
	FIN;
	#ifdef input
		freopen("test1.txt", "r", stdin);
	#endif
	
	int n, k;
	cin >> n >> k;
	vector <ll> v(n);
	forn(i,n) cin >> v[i];
	
	vector <ll> dp(100005,0), aux(100005,0), prefix(100005,0);
	ll modu = (int)(1e9+7);
	forn(i,v[0]+1) dp[i]=1;
	prefix[0]=dp[0];
	forr(i,1,k+1) prefix[i]=prefix[i-1]+dp[i];
	forr(i,1,n)
	{
		forn(j,k+1)
		{
			aux[j]=prefix[j];
			aux[j]%=modu;
			if(j-v[i] > 0) aux[j]+=modu-prefix[j-v[i]-1];
			aux[j]%=modu;
		}
		forn(j,k+1)
		{
			dp[j]=aux[j];
			if(j==0)
			{
				prefix[j]=aux[j];
				aux[j]=0;
				continue;
			}
			prefix[j]=aux[j]+prefix[j-1];
			prefix[j]%=modu;
			aux[j]=0;
		}
	}
	
	cout << dp[k] << endl;
    return 0;
}


Measured memory_bytes: 5532
use strict;
use warnings;

sub main {
    chomp(my $nkq = <STDIN>);
    my ($N,$K,$Q) = split(/ /,$nkq);
    my @A;
    while(<STDIN>){
        chomp;
        push(@A,$_)
    }
    print solver($N,$K,$Q,\@A);
}
main() unless caller;

sub solver {
    my ($N,$K,$Q,$A) = @_;
    my @ans;
    my $n = $K - $Q;
    my %tmp;
    my %mem;
    if($n>0){
        @ans = map{$_='Yes'}(0..$N-1);
        return join("\n", @ans) . "\n";
    } else {
        for my $i(@$A) {
            $i--;
            unless (defined $mem{$i}) {
                $tmp{$i} = $n;
                $mem{$i} = 1;
            }
            $tmp{$i}++;
        }
    }
    for my $j(0..$N-1) {
        if(defined $tmp{$j} && $tmp{$j} > 0){
            $ans[$j] = 'Yes';
        } else {
            $ans[$j] = 'No';
        }
    }
    return join("\n", @ans) . "\n";
}

Measured memory_bytes: 33664
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 30000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long powering(long long now, long long now_go) {
	long long ans = 1;
	while (now_go != 0) {
		if (now_go % 2 == 1) {
			ans *= now;
			ans %= MAX_MOD;
		}
		now *= now;
		now %= MAX_MOD;
		now_go /= 2;
	}
	return ans;
}
vector<long long> calc(vector<long long> a, vector<long long> b) {
	long long k = sqrt(a.size());
	vector<long long> ans;
	for (int i = 0; i < k; ++i) {
		for (int q = 0; q < k; ++q) {
			long long geko = 0;
			for (int t = 0; t < k; ++t) {
				geko += a[i * k + t] * b[t * k + q];
				geko %= MAX_MOD;
			}
			ans.push_back(geko);
		}
	}
	return ans;
}
vector<long long> powered(vector<long long> a, long long n) {
	vector<long long> ans = a;
	n--;
	while (n != 0) {
		if (n % 2 == 1) {
			ans = calc(ans, a);
		}
		a = calc(a, a);
		n /= 2;
	}
	return ans;
}
long long inv(long long now) {
	return powering(now, MAX_MOD - 2LL);
}
long long dp[2000000] = {};
long long ans[2000000] = {};
int main(){
#define int long long
	int n,h,d;
	cin >> n >> h >> d;
	long long geko = 1;
	for (long long i = 1; i <= n; ++i) {
		dp[i] = dp[i - 1];
		dp[i] += geko;
		dp[i] %= MAX_MOD;
		geko *= (long long)(i + 1LL);
		geko %= MAX_MOD;
	}
	ans[0] = geko;
	ans[0] *= inv(n + 1);
	ans[0] %= MAX_MOD;
	long long tea = ans[0];
	for (long long i = 1; i < h; ++i) {
		long long geko = tea;
		geko *= dp[n];
		geko %= MAX_MOD;
		ans[i] = geko;
		tea += ans[i];
		tea %= MAX_MOD;
		if (i - d >= 0) {
			tea -= ans[i - d];
			tea += MAX_MOD;
			tea %= MAX_MOD;
		}
	}
	long long final_ans = 0;
	for (int i = max(h - d, 0LL); i < h; ++i) {
		final_ans += ans[i];
		final_ans %= MAX_MOD;
	}
	cout << final_ans << endl;
	return 0;
}

Measured memory_bytes: 18688
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a <= c && b >= c ? "Yes" : "No") << endl;
	return 0;
}

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

using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    long long int health[n];
    for (int i=0; i<n; i++){
        cin>>health[i];
    }
    sort(health, health+n);
    long long int attack = 0LL;
    if (n>k){
        attack = accumulate(health, health+(n-k),0LL);
    }
    cout<<attack;
    return 0;
}

Measured memory_bytes: 1792
N,M = [int(i) for i in input().split()]
ab = [0] * N
cd = [0] * M
index = [-1] * N
for i in range(N) :
    ab[i] = [int(j) for j in input().split()]
for i in range(M) :
    cd[i] = [int(j) for j in input().split()]
for i in range(N) :
    indexa = []
    min = 10000000000
    for j in range(M) :
        l = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if l < min :
            indexa.clear()
            indexa.append(j+1)
            min = l
        elif l == min :
            indexa.append(j+1)
    if len(indexa) == 1 :
        index[i] = indexa[0]
    else :
        indexa.sort()
        index[i] = indexa[0]
for i in range(N) :
    print(index[i])

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**9)
MOD = 10**9+7
TT = 10**5+3

N,K = map(int,input().split())
*A, = map(int,input().split())
# N, K = 10**5, 5*10**5
# A = [i for i in range(N)]

A = sorted(A)
*rA, = reversed(A)

# https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae


fac = [1]
ifac = [1]
for i in range(TT):
    fac.append((fac[i]*(i+1)) % MOD)
    ifac.append((ifac[i]*pow(i+1, MOD-2,MOD)) % MOD)

def comb(a,b):
    if(a == 0 and b == 0):
        return 1
    if(a < b or a < 0):
        return 0
    tmp = (ifac[a-b]* ifac[b]) % MOD
    return (tmp * fac[a]) % MOD


c = 0
for i,(a,r) in enumerate(zip(A,rA)):
    s,t = N-i-1,K-1
    # K=1のときはc=0
    if 0<s and s>=t and 0<t:
        c += (comb(s,t)*(r-a) )%MOD

print(c%MOD)

Measured memory_bytes: 76452
<?php
    $NM = explode(" ",trim(fgets(STDIN)));
    $N = $NM[0];
    $M = $NM[1];
    
    for ($i = 0; $i < $N; $i++) {
        $AB = explode(" ",trim(fgets(STDIN)));
        $price[] = $AB[0];
        $stock[$price[$i]] += $AB[1];
    }
    
    
    ksort($stock);
    $buy = 0;
    $ans = 0;
    foreach ($stock as $key => $val)
    {
        //この店で買う数
        $buy = min($M, $val);
        
        //金額をたす
        $ans += $buy * $key;
        
        //必要な個数を減らす
        $M -= $buy;
    }
    
    echo $ans;
    
?>

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  map<int,int> m;

  int N; cin >> N;
  int free = 0;

  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    tmp /= 400;
    if(tmp >= 8) {
      free++;
      continue;
    }

    m[tmp]++;
  }
  int color_num = m.size();

  cerr << color_num << " " << free << endl;
  int min_val = max(1, color_num);
  int max_val = color_num + free;

  cout << min_val << " " << max_val << endl;



}


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

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n);
        for (int i = 0; i < n; i ++) scanf("%d", &a[i]);
        sort(a.rbegin(), a.rend());
        int h = 0, w = 0;
        while (true) {
                if (a[w] <= h) break;
                h ++, w ++;
        }
        h --, w --;
        int res1 = a[w] - h - 1;
        int k = w;
        while (h < a[k]) k ++;
        int res2 = k - w - 1;
        puts((res1 & 1 || res2 & 1) ? "First" : "Second");
        return 0;
}


Measured memory_bytes: 640
/*

https://atcoder.jp/contests/code-festival-2016-qualc/tasks/codefestival_2016_qualC_d

隣り合った2列のみが関係する
隣り合った2列は実質的に自由な順番で解体できる
→あとは部分点問題を解くだけ

O(H**2)までは行ける
dp[l][r] = 左をl個、右をr個まで減らしたときのコスト最小値
→O(H**2)

推移のコストを前計算で高速に？
cost[z][t] = 左の数-右の数がzの時、右のtopからt個目までに同じ文字がいくつあるか
→O(H**2)で計算可能

*/

#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <bitset>

using namespace std;

#define rep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 998244353;

int wi(int ind,int H){
    if (ind < 0) return 2*H+2+ind;
    return ind;
}

int main(){

    int H,W;
    cin >> H >> W;

    vector<string> c(H);
    rep(i,0,H) cin >> c[i];
    int ans = 0;

    vector<vector<int>> cost(H*2+2,vector<int> (H+1));
    vector<vector<int>> dp(H+1,vector<int> (H+1));

    rep(ind,0,W-1){

        rep(i,0,H*2+2){
            rep(j,0,H+1){
                cost[i][j] = 0;
            }
        }
        rep(i,0,H+1){
            rep(j,0,H+1){
                dp[i][j] = INT_MAX;
            }
        }

        rep(z,-H,H+1){
            int now = 0;
            rep(t,1,H+1){
                if (0<t+z && t+z<=H && c[t-1][ind+1] == c[t+z-1][ind]){
                    now += 1;
                }
                cost[wi(z,H)][t] = now;
            }
        }

        dp[H][H] = 0;
        rrep(l,H,-1){
            rrep(r,H,-1){
                if (l > 0){
                    dp[l-1][r] = min(dp[l-1][r],dp[l][r]+cost[wi(l-r,H)][r]);
                }
                if (r > 0){
                    dp[l][r-1] = min(dp[l][r-1],dp[l][r]+cost[wi(l-r,H)][r]);
                }
            }
        }

        ans += dp[0][0];
    }

    cout << ans << endl;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
#define rep1(i,n) for(i=1;i<=n;i++)
int main(){
  int i;
  unsigned long long H;
  int N;
  int A[100001];
  unsigned long long sum = 0;
  bool beatFrag = false;
  
  cin >> H >> N;
  rep1(i,N) cin >> A[i];
  
  sort(A,A+N);
  
  rep1(i,N){
    sum += A[i];
    if(H<=sum){
      beatFrag = true; 
      break;
    }
  }
  
  if(beatFrag==true)
    cout << "Yes";
  else
    cout << "No";
 
}

Measured memory_bytes: 640
n, m = map(int, input().split())
a_array = [int(input()) for x in range(m)]
res = [1 for x in range(n + 1)]
res[1] = 1
for i in a_array:
    res[i] = -1

for i in range(2, n + 1):
    if res[i] == -1:
        continue
    if res[i - 1] != -1 and res[i - 2] != -1:
        res[i] = (res[i - 1] + res[i - 2])%1000000007
    elif res[i - 1] != -1 or res[i - 2] != -1:
        res[i] = max(res[i - 1], res[i - 2])%1000000007
    else:
        res[i] = 0
print(res[-1])


Measured memory_bytes: 7860
q=int(input())
#lr=[list(map(int,input().split())) for i in  range(q)]
MAX=10**5+1
l=[0]*MAX

def  is_prime(n):
	if n == 1:
		return  False

	for i in  range(2,int(n**0.5)+1):
		if n % i == 0:
			return  False
	return  True
cnt=0
for i in range(1, MAX, 2):
  if is_prime(i) and is_prime((i+1)/2):
    l[i]=1
    
l2=[0]*(MAX+1)
for i in range(0, MAX):
  l2[i+1]=l2[i]+l[i]
#print(l2)

for i in range(q):
  l,r=map(int, input().split())
  r+=1
  print(l2[r]-l2[l])

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

#define null               ""
#define all(dat)           dat.begin(), dat.end()
#define over(msg)          cout << msg << endl, exit(0);
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

int n, ans;
string a, b, c;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> a >> b >> c;
    loop (i, n) {
        int res = 3;
        for (char c = 'a'; c <= 'z'; ++c) {
            res = min(res, (a[i] != c) + (b[i] != c) + (::c[i] != c));
        }
        ans += res;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
  s.append(list(map(int,input().split())))
last=[0]*26

for day in range(1,d+1):
  co=[]
  dla=[]
  down=0
  for (i,j) in zip(last,c):
    down+=(day-i)*j
  for (i,j) in zip(last,c):
    dla.append(down-(j*(day-i)))
  for con in range(26):
    co.append(s[day-1][con]-dla[con]*c[con])
  choice=co.index(max(co))
  last[choice]=day
  print(choice+1)

Measured memory_bytes: 9272
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    int c=0;
    while(n--)
    {
        int l=nxt(),r=nxt();
        c+=(r-l+1);
    }
    cout<<c<<endl;
    
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {
	rapid_pleaseAC_fast;

	int a, b, c;
	cin >> a >> b >> c;
	Yes((a < c && c < b) || (b < c && c < a));

	please AC;
}
//参考：---

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	ll a,b,dim=0;
	cin>>a>>b;
	for(int i=1;i<=b-a;i++){
		dim+=i;
	}
	cout<<dim-b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {

	long long A, B, C, K;
	long long sum = 0;

	std::cin >> A >> B >> C >> K;

	if (A >= K) {
		sum = 1 * K;
	}
	else {
		if (B >= K - A) {
			sum = (1 * A) + (0 * (K - A));
		}
		else {
			sum = (1 * A) + (0 * (B)) + ((-1) * (K - A - B));
		}
	}

	std::cout << sum << std::endl;



}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MIN(x, y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))
#define ADDIF(ii) do { \
    if (i##ii) { \
      cc += c[ii]; \
      for (int j = 0; j < m; j++) { \
        aa[j] += a[ii][j]; \
      } \
    } \
} while(0);
int main()
{
  int n, m, x;
  int c[12];
  int a[12][12];
  scanf("%d%d%d", &n, &m, &x);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &c[i]);
    for (int j = 0; j < m; j++)
    {
      scanf("%d", &a[i][j]);
    }
  }
  int minc = 100000000;
  for (int i0 = 0; i0 < 2 - (n - 0 <= 0); i0++)
  for (int i1 = 0; i1 < 2 - (n - 1 <= 0); i1++)
  for (int i2 = 0; i2 < 2 - (n - 2 <= 0); i2++)
  for (int i3 = 0; i3 < 2 - (n - 3 <= 0); i3++)
  for (int i4 = 0; i4 < 2 - (n - 4 <= 0); i4++)
  for (int i5 = 0; i5 < 2 - (n - 5 <= 0); i5++)
  for (int i6 = 0; i6 < 2 - (n - 6 <= 0); i6++)
  for (int i7 = 0; i7 < 2 - (n - 7 <= 0); i7++)
  for (int i8 = 0; i8 < 2 - (n - 8 <= 0); i8++)
  for (int i9 = 0; i9 < 2 - (n - 9 <= 0); i9++)
  for (int i10 = 0; i10 < 2 - (n - 10 <= 0); i10++)
  for (int i11 = 0; i11 < 2 - (n - 11 <= 0); i11++) {
    int cc = 0;
    int aa[12] = {0};
    ADDIF(0);
    ADDIF(1);
    ADDIF(2);
    ADDIF(3);
    ADDIF(4);
    ADDIF(5);
    ADDIF(6);
    ADDIF(7);
    ADDIF(8);
    ADDIF(9);
    ADDIF(10);
    ADDIF(11);
    int pass = 1;
    for (int j = 0; j < m; j++) {
      if (aa[j] < x) {
        pass = 0;
        break;
      }
    }
    if (!pass) {
      continue;
    }
    minc = MIN(minc, cc);
  }
  if (minc == 100000000) {
    printf("-1");
  } else {
    printf("%d", minc);
  }
  return 0;
}

Measured memory_bytes: 2032
import math
N,M = map(int,input().split())

if(abs(N-M) > 1):
  ans = 0
elif(abs(N-M) == 0):
  a = math.factorial(N)
  ans = (2*a*a)%(10**9+7)
elif(abs(N-M) == 1):
  a = math.factorial(N)
  b = math.factorial(M)
  ans = (a*b)%(10**9+7)
print(ans)

Measured memory_bytes: 5180
n,m = map(int,input().split())
dp = [0 for i in range(n+1)]
is_Broken = [False for i in range(n+1)]
dp[0] = 1

for i in range(m):
    buf = int(input())
    is_Broken[buf] = True

for i in range(1,n+1):
    if is_Broken[i] == True:
        continue
    if i == 1:
        dp[i] = dp[i-1]
    else:
        tmp = dp[i-1] + dp[i-2]
        dp[i] = tmp%(10**9+7)

print(dp[n])


Measured memory_bytes: 7836
using System;
using System.Collections.Generic;
using System.Linq;

namespace debug
{
    public static partial class Program
    {
        public static void Main()
        {
            var ab = Console.ReadLine().ToLongArray();
            Console.WriteLine(new []
            {
                ab.Sum(), ab[0] * ab[1], ab[0] - ab[1]
            }.Max());
        }
    }

    public static partial class Program
    {
        //テンプレここから
        private static long Gcd(long aaa, long bbb) => bbb == 0 ? aaa : Gcd(bbb, aaa % bbb);
        private static long Lcm(long aaa, long bbb) => aaa * bbb / Gcd(aaa, bbb);
        private static long ToLong(this double ddd) => (long) ddd;
        private static long ToLong(this string str) => long.Parse(str);
        private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
        private static long[] ToLongArray(this string str, char opr = ' ') => str.Split(opr).ToLong();
        private static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb));
        private static long Sign(this long iii) => Math.Sign(iii);
        private static bool IsEven(this long iii) => iii % 2 == 0;
        private static bool IsEven(this int iii) => iii % 2 == 0;

        private static readonly int[] _Dx =
        {
            0, -1, 0, 1
        };

        private static readonly int[] _Dy =
        {
            -1, 0, 1, 0
        };

        public const int MOD = 1000000007;
        public const string UPPER_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const string LOWER_ALPHABET = "abcdefghijklmnopqrstuvwxyz";
        private static long ToLong(this char ccc) => ccc.ToString().ToLong();
        private static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
        private static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);

        private static string JoinToStr(this IEnumerable<long> array, string sep = "") =>
            array.Select(xxx => xxx.ToString()).Join(sep);

        public static string JoinToStr(this IEnumerable<int> array, string sep = "") =>
            array.Select(xxx => xxx.ToString()).Join(sep);

        //テンプレここまで
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int H,W; cin>>H>>W;
    vector<string> S(H);
    rep(h,0,H) cin>>S.at(h);

    string ans="Yes";
    vector<vector<bool>> reach(H,vector<bool>(W,false));
    vector<pair<int,int>> D{make_pair(0,-1),make_pair(-1,0),make_pair(1,0),make_pair(0,1)};
    rep(h,0,H)rep(w,0,W){
        if(reach.at(h).at(w)) continue;

        reach.at(h).at(w)=true;
        if(S.at(h).at(w)=='#'){
            bool canPaint=false;
            for(auto d:D){
                if(w+d.first>=0 && w+d.first<W && h+d.second>=0 && h+d.second<H){
                    if(S.at(h+d.second).at(w+d.first)=='#'){
                        canPaint=true;
                        reach.at(h+d.second).at(w+d.first)=true;
                    }
                }
            }
            if(!canPaint){ans="No"; break;}
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>

using namespace std;

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

int dfs(int x,int y)
{
	if(field[y][x] == 0)
		return 0;
	char c = field[y][x];
	field[y][x] = 0;
	for(int i=0;i<4;++i){
		if(c == field[y+dy[i]][x+dx[i]])
			dfs(x+dx[i],y+dy[i]);
	}
	return 1;
}

int main(void)
{
	while(1){
		int hei,wei;
		cin >> hei >> wei;
		if(hei == 0 && wei == 0)
			return 0;

		for(int y=1;y<=hei;++y){
			char str[101];
			cin >> str;
			for(int x=1;x<=wei;++x){
				field[y][x] = str[x-1];
			}
		}

		int ans=0;
		for(int y=1;y<=hei;++y){
			for(int x=1;x<=wei;++x){
				ans+=dfs(x,y);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int a = -1;
            int b = -1;
            bool judge = false;
            for (int i = 0; i < s.Length; i++)
            {
                for (int j = 1; j <= 2; j++)
                {
                    if (i - j >= 0) judge = unb(s.Substring(i - j, j + 1), s[i]);
                    if (judge)
                    {
                        a = i - j + 1;
                        b = i + 1;
                        break;
                    }
                }
            }
            Console.WriteLine("{0} {1}", a, b);
        }
        static bool unb(string s, char c)
        {
            return s.Count(x => x == c) > s.Length / 2 ? true : false;
        }
    }
}

Measured memory_bytes: 17468
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 3000;
const int MOD = 998244353;

inline int add(int x, int y) {x += y; return x >= MOD ? x - MOD : x;}
inline int sub(int x, int y) {x -= y; return x < 0 ? x + MOD : x;}
inline int mul(int x, int y) {return (int)(1LL * x * y % MOD);}

int pow_mod(int b, int p) {
	int ret = 1;
	for(int i=p;i;i>>=1,b=mul(b,b))
		if( i & 1 ) ret = mul(ret, b);
	return ret;
}

int f[MAXN + 5][MAXN + 5], A, B, C, D;

int main() {
	scanf("%d%d%d%d", &A, &B, &C, &D);
	
	for(int i=A;i<=C;i++) {
		int tmp = 0;
		for(int j=B;j<=D;j++) {
			if( i == A && j == B ) f[A][B] = 1;
			else {
				tmp = mul(add(tmp, f[i-1][j-1]), i - 1);
				f[i][j] = add(tmp, mul(f[i-1][j], j));
			}
		}
	}
		
	int ans = 0;
	for(int i=1;i<=D;i++)
		ans = add(ans, mul(f[C][i], pow_mod(C, D - i)));
	printf("%d\n", ans);
}

Measured memory_bytes: 36860
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
//エラトステネスの篩
int prime[MAX];
bool is_prime[MAX+1];

void sieve(int n){
	int p=0;
	for(int i=0;i<=n;i++) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2;i*j<=n;j++)	is_prime[i*j]=false;
		}
	}
}
int main(){
    int n;
    cin>>n;
    sieve(55555);
    vector<int>ans(n);
    int i=0;
    int w=0;
    while(prime[i]){
        int t=prime[i]%5;
        if(t==1){
            ans[w++]=prime[i];
        }
        i++;
        if(w>=n)break;
    }
    REP(i,n)OUT(ans[i]);
    return 0;
}

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

int main() {
	int r1, r2, r;
	char c;
	int cnt[2] = {0, 0};
	while (cin >> r1 >> c >> r2 >> c >> r) {
		if (r1==r2) cnt[1]++;
		else if (r1*r1+r2*r2==r*r) cnt[0]++;
	}
	cout << cnt[0] << endl << cnt[1] << endl;
	return 0;
}

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

typedef long long int ll;
using namespace std;
vector<int> as, bs, cs;

int main() {
    int N;
    ll ans = 0;
    cin >> N;

    for (int i = 0; i < N; i++) {
        ll tmp;
        cin >> tmp;
        as.push_back(tmp);
    }
    for (int i = 0; i < N; i++) {
        ll tmp;
        cin >> tmp;
        bs.push_back(tmp);
    }
    for (int i = 0; i < N; i++) {
        ll tmp;
        cin >> tmp;
        cs.push_back(tmp);
    }
    sort(as.begin(), as.end());
    sort(bs.begin(), bs.end());
    sort(cs.begin(), cs.end());

    for (int j = 0; j < N; j++) {
        ll cb_number = (cs.end() - upper_bound(cs.begin(), cs.end(), bs[j]));
        ll ba_number = (lower_bound(as.begin(), as.end(), bs[j]) - as.begin());
        ans += (cb_number * ba_number);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1784
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)

int next(char x) {
	if (x == 'a')return 1;
	else if (x == 'b')return 2;
	else return 3;
}

int main() {
	int turn,flag=0,a=1,b=0,c=0;
	char A[101], B[101], C[101];
	scanf("%s\n%s\n%s", A, B, C);
	turn = next(A[0]);
	while (flag == 0) {
		if (turn == 1) {
			if (A[a] == '\0')flag = 1;
			else {
				turn = next(A[a]);
				a++;
			}
		}
		else if (turn == 2) {
			if (B[b] == '\0')flag = 2;
			else {
				turn = next(B[b]);
				b++;
			}
		}
		else {
			if (C[c] == '\0')flag = 3;
			else {
				turn = next(C[c]);
				c++;
			}
		}
	}
	if (turn == 1)printf("A");
	else if (turn == 2)printf("B");
	else printf("C");
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <cfenv>
#include <cmath>

using namespace std;

vector <long long> a, f;
long long i, n, k, ans = 0, ub = -1, hb = 1e+12 + 1, mid;

bool search(long long x);
 
bool search(long long x){
  long long res = 0;
  for(i = 0; i < n; i++){
    long long ax = a[i], fx = f[i];
    if(ax * fx > x){
      res += (long long)ceil((double)(ax * fx - x) / fx);
    }
  }
  return res <= k;
}

int main(void){
  
  cin >> n >> k;
  
  for(i = 0; i < n; i++){
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  
  for(i = 0; i < n; i++){
    int tmp;
    cin >> tmp;
    f.push_back(tmp);
  }
  
  sort(a.begin(), a.end());
  sort(f.begin(), f.end(), greater<long long>());
  
  while(hb - ub > 1){
    mid = (ub + hb) / 2;
    if(search(mid))
      hb = mid;
    else
      ub = mid;
  }
  
  cout << hb << endl;
  
  return 0;
}


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

int main() {
  int N, total;
  cin >> N;
  total = N % 10;
  for(int i = 8; i > 0; i--) {
    int d1 = 10, d2 = 10;
    for(int j = 0; j < i; j++) {
      d1 *= 10;
      d2 *= 10;
    }
    d2 /= 10;
    total += (N % d1) / d2;
  }
  if (N % total) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cost;
  int c[501],s[501],f[501];
  cin>>n;
  for(int i=0;i<n-1;i++){
    cin>>c[i]>>s[i]>>f[i];
  }
  for(int i=0;i<n-1;i++){
    cost=s[i];
    for(int j=i;j<n-1;j++){
      int tmp=s[j];
      while(tmp<cost){
        tmp+=f[j];
      }
      cost=tmp;
      cost+=c[j];      
    }
    cout<<cost<<endl;
  }
  cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();

		double d = Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2));

		System.out.println(BigDecimal.valueOf(d).toPlainString());
	}

}

Measured memory_bytes: 28360
#include<stdio.h>
int main()
{
	int n,a,i,r;
	while(1){
		r=0;
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=0;i<n;i+=4){
			scanf("%d",&a);
			r+=a;
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 2616
def cmb(n, r):
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n
  numerator = [n - r + k + 1 for k in range(r)]
  denominator = [k + 1 for k in range(r)]
  for p in range(2,r+1):
    pivot = denominator[p - 1]
    if pivot > 1:
      offset = (n - r) % p
      for k in range(p-1,r,p):
        numerator[k - offset] /= pivot
        denominator[k] /= pivot
  result = 1
  for k in range(r):
    if numerator[k] > 1:
      result *= int(numerator[k])

  return result


a,s=map(int,input().split())
if (2*a-s)%3==0 and max(a,s)<=2*min(a,s):
  n=(a+s)//3
  r=(2*a-s)//3
  print((cmb(n,r))%(10**9+7))
else:print(0)

Measured memory_bytes: 44032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5;
int r[N],c[N];
vector<int>v1,v2;
int main(){
int h,w,m,x,y;
cin>>h>>w>>m;
map<pair<int,int>,int>mp;
while(m--){
    cin>>x>>y;
    r[x]++,c[y]++;
    mp[{x,y}]=1;
}
int mx1=0,mx2=0;
for(int i=1;i<=h;i++) mx1=max(mx1,r[i]);
for(int i=1;i<=h;i++) if(r[i]==mx1) v1.push_back(i);
for(int i=1;i<=w;i++) mx2=max(mx2,c[i]);
for(int i=1;i<=w;i++) if(c[i]==mx2) v2.push_back(i);
for(auto i:v1) for(auto j:v2) if(!mp[{i,j}]) {cout<<mx1+mx2;exit(0);}
cout<<mx1+mx2-1;
}
/*
4 4
1 1
4 4
....
..#.
.#..
....
*/


Measured memory_bytes: 28496
N = int(input())
A = [int(input()) for _ in range(N)]

if A[0] != 0:
    print(-1)
    exit()

ans = 0
for i in range(1, N):
    if A[i]-A[i-1] >= 2:
        print(-1)
        exit()
    elif A[i]-A[i-1] == 1:
        ans += 1
    else:
        ans += A[i]
print(ans)


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

int main(){
  int a,b,c,x,y;
  int ans=0;
  cin>>a>>b>>c>>x>>y;
  if(a+b<=2*c){
    ans=a*x+b*y;
  }else{
     
      int s=c*2*x+b*(y-x);
      int t=c*2*y+a*(x-y);
      int u=c*max(x,y)*2;
    if(x<=y){
        ans=min(u,s);
    }else{
        ans=min(u,t);
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
def dfs(v,N,visited):
    allvis=True
    for i in range(N):
        if visited[i]==False:
            allvis=False
    if allvis:
        return 1
    ret=0
    
    for i in range(N):
        if graph[v][i]==False:
            continue
        if visited[i]:
            continue
        visited[i]=True
        ret+=dfs(i,N,visited)
        visited[i]=False
    return ret



N,M = map(int, input().strip().split())
graph = [[False] * N for i in range(N)]
for i in range(M):
    a,b=map(int,input().strip().split())
    graph[a-1][b-1]=True
    graph[b-1][a-1]=True
    

visited=[False]*N
visited[0]=True

print(dfs(0,N,visited))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  double n,d;
  cin>>n>>d;
  long long c=0;
  for(int i=0;i<n;i++){
    double x,y;
    cin>>x>>y;
    if(d>=sqrt(x*x+y*y)){
	c++;
    }
    
  }
  cout<<c<<endl;
}

Measured memory_bytes: 3800
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

double abs1(double X);
int main()
{
	int N,T,A,hei,ans,i;
	double tem,dif=1000;
	cin>>N>>T>>A;
	for(i=0;i<N;i++){
		cin>>hei;
		tem=T-hei*0.006;
		if(abs1(A-tem)<dif){
			ans=i+1;
			dif=abs1(A-tem);
		}
	}
	cout<<ans;
	return 0;
}
double abs1(double X)
{
	if(X>=0){
		return X;
	}else{
		return (-1)*X;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
typedef struct {
	char direction[100];
	int num1,num2,num3,num4,num5,num6;
}DICE_t;
int main(){
	int n;
	scanf("%d",&n);
	DICE_t a[n];
	for(int x=0;x<n;x++){
	    scanf("%d %d %d %d %d %d",&a[x].num1,&a[x].num2,&a[x].num3,&a[x].num4,&a[x].num5,&a[x].num6);
	}
	int x,y;
	for(x=0;x<(n-1);x++){
		for(y=(x+1);y<n;y++){
	        int dummy,turn=0;
	        while(turn<24){
		        if(turn%4==0&&turn!=0){
		    	    strcpy(a[y].direction,(turn%8==4 ?"SSEN":"ESEN"));
	    	    }
    		    else{
        			strcpy(a[y].direction,"SEN");
    	    	}
    	        for(int i=0;a[y].direction[i]!=0;i++){
    	            if(a[y].direction[i]=='N'){
		                dummy=a[y].num5;
	            	    a[y].num5=a[y].num1;
	            	    a[y].num1=a[y].num2;
	            	    a[y].num2=a[y].num6;
	        	        a[y].num6=dummy;
	                }
	                else if(a[y].direction[i]=='S'){
		                dummy=a[y].num6;
	            	    a[y].num6=a[y].num2;
	            	    a[y].num2=a[y].num1;
	            	    a[y].num1=a[y].num5;
	            	    a[y].num5=dummy;
	                }
    	    	    else if(a[y].direction[i]=='E'){
		                dummy=a[y].num4;
	        	        a[y].num4=a[y].num6;
	        	        a[y].num6=a[y].num3;
	        	        a[y].num3=a[y].num1;
	        	        a[y].num1=dummy;
	                }
	                else if(a[y].direction[i]=='W'){
	                    dummy=a[y].num1;
    	            	a[y].num1=a[y].num3;
	                	a[y].num3=a[y].num6;
	                	a[y].num6=a[y].num4;
	                	a[y].num4=dummy;
	                }	
    	        }
	        	if(a[x].num1==a[y].num1&&a[x].num2==a[y].num2&&a[x].num3==a[y].num3&&a[x].num4==a[y].num4&&a[x].num5==a[y].num5&&a[x].num6==a[y].num6){
	        		printf("No\n");
	        		goto end;
	        	}
	    	    turn++;
	        }
		}
	}
	printf("Yes\n");
end:	
	
	return 0;
}

Measured memory_bytes: 2676
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 2e5 + 10;

PII t[MR];

bool g[MR];

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);

	REP(i, M)
	{
		scanf("%d%d", &t[i].first, &t[i].second);
		if (t[i].first == 1)
			g[t[i].second] = 1;
	}

	REP(i,M)
		if (g[t[i].first] && t[i].second == N)
		{
			printf("POSSIBLE\n");
			return 0;
		}

	printf("IMPOSSIBLE\n");

	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int n;
    cin>>n;
    vector<pair<long long,long long>> a(n,{0,0});
    for(int i=0;i<n;i++) cin>>a[i].first>>a[i].second;

    int aa,bb;
    auto ff = [&aa,&bb] (long long x,long long y) -> long long{ return aa*x+bb*y;};
    auto f = [&ff] (const pair<long long,long long>& a, const pair<long long,long long>& b) -> bool{
        return ff(a.first,a.second)<ff(b.first,b.second);
    };
    auto dist = [] (const pair<long long,long long>& a, const pair<long long,long long>& b) -> long long{
        return abs(a.first-b.first)+abs(a.second-b.second);
    };
    long long ans=0;
    for(aa=-1;aa<=1;aa++){
        for(bb=-1;bb<=1;bb++){
            sort(full(a),f);
            for(int i=0;i<n;i++){
                ans=max(ans,max(dist(a[i],a[0]),dist(a[i],a.back())));
            }
        }
    }
    cout<<ans<<"\n";

}

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

    solve();
    return 0;
}

Measured memory_bytes: 6356
#include<stdio.h>
int main()
{
	int x1,y1,x2,y2,a,b;

	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);

	a=x2-x1;
	b=y2-y1;
	printf("%d %d %d %d",x2-b,y2+a,x1-b,y1+a);
	return 0;
}

Measured memory_bytes: 128
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {			cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

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


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


const int mx = 1e5+123;
int lev[mx];
vi adj[mx];
int par[mx];

void bfs ( int s )
{
	mem ( lev, -1 );

	queue<int> q;
	q.push ( s );

	while ( !q.empty() ) {
		int u = q.front();
		q.pop();

		for ( auto v : adj[u] ) {
			if ( lev[v] == -1 ) {
				lev[v] = lev[u] + 1;
				par[v] = u;
				q.push( v );
			}
		}
	}
}


int main()
{
	optimize();

	int n, m;
	cin >> n >> m;
	for ( int i = 1; i <= m; i++ ) {
		int u, v;
		cin >> u >> v;
		adj[u].PB ( v );
		adj[v].PB ( u );
	}

	bfs ( 1 );

	for ( int i = 2; i <= n; i++ ) {
		if ( lev[i] == -1 ) return cout << "No", 0;
	}

	cout << "Yes\n";
	for ( int i = 2; i <= n; i++ ) cout << par[i] << endl;





	return 0;
}

















Measured memory_bytes: 10948