akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;

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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
  ll N;
  cin >> N;
  cout<<(N*(N-1))/2<<endl;






return 0;
}

Measured memory_bytes: 256
n=int(input())
g=[int(i) for i in input().split()]
h=[i for i in reversed(g)]
a=h[0]
for i in range(n):
    if a-h[i]>=0:
        a=h[i]
    elif a-h[i]==-1:
        a=h[i]-1
    else:
        a=-10
print("Yes" if a!=-10 else "No") 

Measured memory_bytes: 14224
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define EPS 1e-10
using namespace std;
typedef long long ll;
struct Point{
	double x,y;
	Point(double x = 0.0,double y = 0.0): x(x),y(y) {}
	Point operator + (Point p){
		return Point(x + p.x,y + p.y);
	}
	Point operator - (Point p){
		return Point(x - p.x,y - p.y);
	}
	Point operator * (double lambda){
		return Point(x * lambda,y * lambda);
	}
	Point operator / (double lambda){
		return Point(x / lambda,y / lambda);
	}
	Point neg(){
		return Point(-x,-y);
	}
	double norm(){
		return x * x + y * y;
	}
	double abs_(){
		return sqrt(norm());
	}
	bool operator == (const Point &p)const
	{
		return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
	}
	bool operator < (const Point &p)const
	{
		if(abs(x - p.x) < EPS) return y < p.y;
		else return x < p.x;
	}
};
typedef Point Vector;
struct Segment{
	Point p1,p2;
	Segment(Point p1 = Point(),Point p2 = Point()): p1(p1),p2(p2) {}
};
typedef Segment Line;
struct Circle{
	Point c;
	double r;
	Circle(Point c = Point(),double r = 0.0): c(c),r(r) {}
};
typedef vector<Point> Polygon;
double dot(Vector a,Vector b){
	return a.x * b.x + a.y * b.y;
}
double det(Vector a,Vector b){
	return a.x * b.y - b.x * a.y;
}
bool vertical(Line l1,Line l2){
	return abs(dot(l1.p2 - l1.p1,l2.p2 - l2.p1)) < EPS;
}
bool parallel(Line l1,Line l2){
	return abs(det(l1.p2 - l1.p1,l2.p2 - l2.p1)) < EPS;
}
Point proj(Point p,Line l){
	Vector a = l.p2 - l.p1;
	double r = dot(a,p - l.p1) / a.norm();
	return l.p1 + a * r;
}
Point ref(Point p,Line l){
	Point A = proj(p,l);
	return A + (A - p);
}
int ccw(Segment/*Directed Segment*/ s,Point p){//
	Vector a = s.p2 - s.p1,b = p - s.p1;
	if(det(a,b) > EPS) return 1;//COUNTER_CLOCKWISE
	else if(det(a,b) < -EPS) return -1;//CLOCKWISE
	else if(dot(a,b) < -EPS) return 2;//ONLINE_BACK
	else if(a.norm() < b.norm() - EPS) return -2;//ONLINE_FRONT
	else return 0;//ON_SEGMENT
}
bool intersect(Segment s1,Segment s2){
	return ccw(s1,s2.p1) * ccw(s1,s2.p2) <= 0 && ccw(s2,s1.p1) * ccw(s2,s1.p2) <= 0;
}
double disSP(Segment s,Point p){
	Vector a = s.p2 - s.p1;
	if(dot(a,p - s.p1) < EPS) return (p - s.p1).abs_();
	if(dot(a.neg(),p - s.p2) < EPS) return (p - s.p2).abs_();
	return abs(det(a,p - s.p1) / a.abs_());
}
double disSS(Segment s1,Segment s2){
	if(intersect(s1,s2)) return 0;
	return min(min(disSP(s1,s2.p1),disSP(s1,s2.p2)),min(disSP(s2,s1.p1),disSP(s2,s1.p2)));
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		Segment s1,s2;
		scanf("%lf%lf%lf%lf",&s1.p1.x,&s1.p1.y,&s1.p2.x,&s1.p2.y);
		scanf("%lf%lf%lf%lf",&s2.p1.x,&s2.p1.y,&s2.p2.x,&s2.p2.y);
		printf("%.10f\n",disSS(s1,s2));
	}
	return 0;
}



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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  int n; cin >> n;
  string s; cin >> s;

  int ans = 0;
  for(int i=0; i<n; ++i) {
    if(s[i] == 'A') {
      if(s[i+1] == 'B') {
        if(s[i+2] == 'C') {
          ans++;
        }
      }
    }
  }
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	for(long long ans=a;ans<=(long long)a*b;ans+=a){
		if(ans%b==0){
			cout<<ans<<endl;
			return 0; 
		}
	}
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
 
 int a,b,c;
 cin >> a >> b >> c;

 if(a+b==c||a==b+c||a+c==b){
   cout << "Yes" << endl;
 }
 else{
     cout << "No" << endl;
 }
 
}

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

const int INF = 1e9 + 10;

int main() {
  int N; cin >> N;
  vector<int> h(N + 2); rep(i, N) cin >> h[i];
  vector<int> dp(N + 2, INF);

  dp[0] = 0;
  rep(i, N) {
    for (int k = 1; k <= 2; k++) {
      int cost = abs(h[i + k] - h[i]);
      dp[i + k] = min(dp[i + k], dp[i] + cost);
    }
  }

  cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1024
h,n = map(int,input().split())

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

amax = max(a for a,b in ls)

dp = [0]*(h+amax)

for i in range(1,h+amax):
  p = max(1,2)
  dp[i] = min(dp[i-a]+b for a,b in ls)

print(min(dp[h:]))

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

struct Card {char suit, value;};

void bubbleSort(struct Card A[], int N) {
  for (int i=0; i<N; i++) {
    for (int j=N-1; j>=i+1; j--) {
      if (A[j-1].value > A[j].value) {
        Card t = A[j-1]; A[j-1] = A[j]; A[j] = t;
      }
    }
  }
}

void selectionSort(struct Card A[], int N) {
  for (int i=0; i<N; i++) {
    int minj = i;
    for (int j=i; j<N; j++) {
      if (A[j].value < A[minj].value) minj = j;
    }
    Card t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(struct Card A[], int N) {
  for (int i=0; i<N; i++) {
    if (i) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

// compare the resulting array of selection sort with always-stable resulting array of bubble sort.
bool isStable(struct Card C1[], struct Card C2[], int N) {
  for (int i=0; i<N; i++) {
    if (C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main() {
  Card C1[100], C2[100];
  int N;
  char ch;

  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }
  for (int i=0; i<N; i++) C2[i] = C1[i];

  bubbleSort(C1, N);
  selectionSort(C2, N);

  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if (isStable(C1, C2, N)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}



Measured memory_bytes: 3096
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	int cnt[9] = {0},n,a,memo = 0;
	cin >> n;
	
	rep(i,0,9){
		cnt[i] = 0;
	}
	
	rep(i,0,n){
		cin >> a;
		
		if(a/400 >= 8){
			cnt[8]++;
		}
		else{
			cnt[a/400]++;
		}
	}
	rep(i,0,9){
		if(i < 8 && cnt[i]){
			memo++;
		}
	}
	
	cout << max(1,memo) << " " << memo+cnt[8] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG



signed main() {
  int N; cin >> N;
  vector<pair<int,int>> A(N, pair<int,int>());
  rep(i, N) {
    int a; cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(all(A));
  reverse(all(A));
  
  vector<vector<int>> dp(N+1, vector<int>(N+1, 0));
  
  
  rep(i, N) {
    rep(j, i+2) {
      if(j == 0) dp[j][i+1-j] = dp[j][i-j] + A[i].first*abs(A[i].second-(N-1-(i-j)));
      else if(j == i+1) dp[j][i+1-j] = dp[j-1][i+1-j] + A[i].first*abs(A[i].second-j+1);
      else {
        dp[j][i+1-j] = max(dp[j-1][i+1-j] + A[i].first*abs(A[i].second-j+1),
                           dp[j][i-j] + A[i].first*abs(A[i].second-(N-1-(i-j))));
      }
    }
  }
  
  int ans = 0;
  rep(i, N+1) ans = max(ans, dp[i][N-i]);
  
  cout << ans << endl;
  
}


Measured memory_bytes: 34668
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

a, b = [0], [0]
for i in range(N):
    a.append(A[i]+a[i])
for i in range(M):
    b.append(B[i]+b[i])

j = M

for i in range(N+1):
    if a[i]>K:
        break
    while b[j]>K-a[i]:
        j-=1
    ans = max(ans, i+j)
print(ans)

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

#define debug(x) cout << #x << ": " << (x) << endl

int main(int argc, char *argv[]) {
  string S;
  cin >> S;
  int cnt = 0;
  int pos = 0;
  for (int i = 1; i < S.size(); ++i) {
    if (S[pos] == S[i]) continue;
    pos = i;
    ++cnt;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 512
use std::io::Read;
use std::cmp::Ordering;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let temp: Vec<i64> = iter.map(|d| d.parse::<i64>().unwrap()).collect();
    let mut dishes: Vec<&[i64]> = temp.chunks(2).collect();
    
    dishes.sort_by(|x, y| {
        let t1 = x[0] + x[1];
        let t2 = y[0] + y[1];
        t2.cmp(&t1)
    });
    
    let mut result = 0;
    
    for i in 0..n {
        if i % 2 == 0 {
            result += dishes[i][0];
        } else {
            result -= dishes[i][1];
        }
    }
    
    println!("{}", result);
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;


int main(void){
    int a;
    vector<int> v;

    rep(i,3){
        cin >> a;
        v.push_back(a);
    }
    int count=0;
    sort(v.begin(),v.end());
    int m = v.at(2)*3;
    int diff = m-v.at(0)-v.at(1)-v.at(2);
    if (diff%2==1){
        cout << (diff+3)/2 << endl;
    }else{
        cout << diff/2 << endl;
    }
}

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

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if(a > b || (n == 1 && a < b)){
        cout << 0 << "\n";
        return 0;
    }else if (n <= 2){
        cout << 1 << "\n";
        return 0;
    }
    cout << ((ll)b-a)*(n-2)+1 << "\n";
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
r = 0
g = 0
b = 0
for x in s:
  if x == 'R':
    r += 1
  elif x == 'G':
    g += 1
  else:
    b += 1
all = r*g*b
ex = 0
i = 0
for i in range(n-2):
  for j in range(i+1,(n+i-1)//2+1):
    if s[i] != s[j] and s[j] != s[2*j-i] and s[2*j-i] != s[i]:
      ex += 1
      
print(all-ex)      
      

Measured memory_bytes: 81292
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner stdIn = new Scanner(System.in);
        boolean[] N = new boolean[101];
        int a=stdIn.nextInt();
        for(int i=0;i<101;i++){
            N[i]=false;
        }
        for(int i=0;i<21;i++){
            for(int j=0;j<15;j++){
                if((i*4+j*7)<101)N[i*4+j*7]=true;
            }
        }
        if(N[a])System.out.println("Yes");
          else System.out.println("No");
    }
}

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

int main(void){
    // Your code here!
    int N;
    cin >> N;
    int A[101];
    for(int i = 0; i < N; i++)cin >> A[i];
    sort(A, A + N, greater<int>());
    int alice = 0;
    int bob = 0;
    int plus = 0;
    for(int i=0; i<N; i++){
        if(i % 2 == 0){
            alice += A[i];
        }else{
            bob += A[i];
        }
    }
    cout << alice - bob << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in();
	ll ans = 0;
	REP(i, n) {
		ll l = in(), r = in();
		ans += r - l + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int cnt = 0;
    while(n){
        cnt++;
        n /= k;
    }
    cout<<cnt<<endl;
    return 0;
    
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	solve()
}

func solve() {
	sc.Split(bufio.ScanWords)

	a := []int{nextInt(), nextInt(), nextInt()}
	sort.Ints(a)
	ans := a[0] + a[1]
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func anser(b bool, y string, n string) string {
	if b {
		return y
	}
	return n
}

Measured memory_bytes: 640
N = int(input())
A = [int(i) for i in input().split()] 
mod = 10**9 + 7

b = [0]*N 
b[0] = A[0]
for n in range(1,N):
    b[n] = A[n] ^ b[n-1]
#print('累積論理和',b)
m = max(b)
dp = [[0]*(m+1) for j in range(2)]
dp[0] = [1]*(m+1)
cnt = [0]*(m+1)
z = 0

for i in range(N):
    if b[i] == 0:
        z +=1
    dp[0][b[i]] += dp[1][b[i]]*(z-cnt[b[i]])
    dp[0][b[i]] %= mod
    dp[1][b[i]] += dp[0][b[i]]
    dp[1][b[i]] %= mod
    cnt[b[i]] = z


if b[N-1]:
    print(dp[0][b[N-1]])
else:
    ans = pow(2, z-1, mod)
    for i in range(1,m+1):
        ans += dp[1][i]
        ans %= mod
    print(ans)

Measured memory_bytes: 69340
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

int SS, W;

int main() {
	S2(SS, W);
	if (SS <= W) printf("unsafe");
	else printf("safe");
}
	

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

const int mod = 1000000007;
int dp[100005][2];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  dp[0][0] = 1;
  dp[0][1] = 0;
  rep(i,n) {
    dp[i+1][0] = dp[i+1][0] = 0;
    { // a+b = 0
      if (s[i] == '0') {
        dp[i+1][0] += dp[i][0];
        dp[i+1][1] += dp[i][1];
      } else {
        dp[i+1][1] += (dp[i][0] + dp[i][1]) % mod;
      }
    }
    { // a+b = 1
      if (s[i] == '0') {
        (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
      } else {
        (dp[i+1][0] += dp[i][0]*2 % mod) %= mod;
        (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
      }
    }
  }
  int ans = (dp[n][0]+dp[n][1]) % mod;
  cout << ans << endl;
  // rep(i,n)cout<<dp[i+1][0];
  // cout << endl;
  // rep(i,n)cout << dp[i+1][1];
  // cout << endl;
  // cout << dp[0][1] << endl;
  return 0;
}


Measured memory_bytes: 1280
import Control.Monad
import Control.Monad.State

type Stat = ([[Int]], Int, Int, Int)

main :: IO ()
main = do
  n <- readLn
  ass <- replicateM n readInts
  putStr $ solve ass

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: [[Int]] -> String
solve ass = evalState solve' (ass, 0, 0, 0)

solve' :: State Stat String
solve' = do
  (ass, s, u, v) <- get
  case ass of
    [] -> return "Yes"
    ([t, x, y]:bss)
      | d <= t - s && even (t - s - d) -> do
        put (bss, t, x, y)
        solve'
      | otherwise -> return "No"
      where  d = (abs (x - u)) + (abs (y - v))





Measured memory_bytes: 81276
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<pair<int, int>>;
using VTIII = vector<tuple<int, int, int>>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int a, b, c, d;


signed main(){
    cin >> a >> b >> c >> d;

    int i = 0;
    while(a > 0 and c > 0){
        if(i%2 == 0) c -= b;
        else a -= d;
        i++;
    }

    if(i%2 == 1) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define int long long
//O(V+E)

class SCC {
private:
  int V;
  vector<vector<int>> G;
  vector<vector<int>> rG;
  vector<int> vs, cmp;
  vector<bool> used;

  void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }
  void dfs(int v) {
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
      if (!used[G[v][i]]) dfs(G[v][i]);
    }
    vs.push_back(v);
  }
  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (int i = 0; i < rG[v].size(); i++) {
      if (!used[rG[v][i]]) rdfs(rG[v][i], k);
    }
  }
  vector<int> do_scc() {
    fill(used.begin(), used.end(), 0);
    vs.clear();
    for (int v = 0; v < V; v++) {
      if (!used[v]) dfs(v);
    }
    fill(used.begin(), used.end(), 0);
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--) {
      if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return cmp;
  }

public:
  SCC(int V) : V(V), G(V, vector<int>()), rG(V, vector<int>()), vs(V), cmp(V), used(V) {}

  void addEdge(int from, int to) { return add_edge(from, to); }
  vector<int> scc() { return do_scc(); }
};

signed main() {
  int V, E;
  cin >> V >> E;

  SCC sc(V);

  for (int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    sc.addEdge(s, t);
  }

  vector<int> cmp = sc.scc();

  int Q;
  cin >> Q;

  while (Q--) {
    int u, v;
    cin >> u >> v;
    if (cmp[u] == cmp[v]) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 4560
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), c
  cout << fixed << setprecision(15);

  ll n, m, l;
  cin >> n >> m >> l;

  vvll dist(n, vll(n, INF));
  rep(i, n) dist[i][i] = 0;

  rep(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    dist[a][b] = c;
    dist[b][a] = c;
  }

  rep(k, n) rep(i, n) rep(j, n) chmin(dist[i][j], dist[i][k] + dist[k][j]);

  vvll dist2(n, vll(n, INF));
  rep(i, n) dist2[i][i] = 0;

  rep(i, n - 1) {
    repLRE(j, i + 1, n - 1) {
      if (dist[i][j] <= l) {
        dist2[i][j] = 1;
        dist2[j][i] = 1;
      }
    }
  }


  rep(k, n) rep(i, n) rep(j, n) chmin(dist2[i][j], dist2[i][k] + dist2[k][j]);

  ll q;
  cin >> q;
  rep(i, q) {
    ll s, t;
    cin >> s >> t;
    s--, t--;
    ll ans = -1;
    if(dist2[s][t] != INF) ans = dist2[s][t]-1;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 5032
import sys
import math
from functools import reduce


def input():
    return sys.stdin.readline().strip()


def gcd_list(A):
    return reduce(math.gcd, A)


def main():
    K = int(input())
    diff = 0
    diff1 = 0
    same = 0

    for a in range(1, K + 1):
        for b in range(a + 1, K + 1):
            for c in range(b + 1, K + 1):
                diff += gcd_list([a, b, c])

    for a in range(1, K + 1):
        for c in range(a + 1, K + 1):
            diff1 += math.gcd(a, c)

    for a in range(1, K + 1):
        same += a

    print(diff * 6 + diff1 * 6 + same)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9636
//
// Created on 2020/05/31.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    long double a;
    long double b;
    cin>>a>>b;


    long double ans = a * b;

    cout<<(ll)ans<<endl;

    return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
#define pb  push_back
using namespace std;
typedef long long ll;
const int nax = 2e5+10;
vector<int> v[nax];
bool vis[nax];
int d1[nax], d2[nax];
int n;
void dfs(int s, int p, int dist, int d[]){
	d[s] = dist;
	for(auto i : v[s]){
		if(i != p){
			dfs(i,s,dist+1,d);
		}
	}
}
int main(){
	
   cin >> n;
   int m = n-1;
   
   for(int i=0;i<=n;i++) v[i].clear();
   
   for(int i=0;i<m;i++){
   	 int a,b;
     cin >> a >> b;
     a--,b--;
	 v[a].pb(b);
	 v[b].pb(a);   	
   }
   
    dfs(0,-1,0,d1);
    dfs(n-1,-1,0,d2);
    
    int ans = 0;

    // why ?
    for(int i=0;i<n;i++){
    	if(d1[i] <= d2[i]) ans++;
    	else ans--;
    }
    
    if(ans > 0) cout <<"Fennec" << endl;
    else cout <<"Snuke" << endl;
    
	return 0;
}

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

#define int long long 
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pi> 
#define vvpii vector<vpii>
#define all(V) V.begin(),V.end()
#define mpii map<int,int> 
#define mpci map<char,int> 
#define fi first
#define si second
#define pb(V) push_back(V)
#define mp(a,b) make_pair(a,b)
#define mt(a,b,c) make_tuple(a,b,c)
#define forn(i,n) for (int i = 0; i < int(n); ++i)


const int N = 1e5+10;
const int mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	
	sort(a.begin(),a.end());
	
	//~ for(auto z:a)
	//~ {
		//~ cout << z << " ";
	//~ }
	
	int ans = 0;
	
	//~ cout << a[n/2 - 1] << " " << a[n/2] << " ";
	if(a[n/2-1] != a[n/2])
	{
		for(int i = a[n/2 - 1] + 1; i <= a[n/2]; ++i)
		{
			ans ++;
		}
	}
	
	cout << ans;
}



Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#define MAXN 100006
using namespace std;
int ans,n,a[MAXN],anss;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=0;i<=n;i++)
		ans+=abs(a[i]-a[i+1]);
	for(int i=1;i<=n;i++)
	{
		anss=ans;
		anss-=abs(a[i]-a[i-1])+abs(a[i]-a[i+1]);
		anss+=abs(a[i-1]-a[i+1]);
		printf("%d\n",anss);
	}
}

Measured memory_bytes: 1536
import java.util.Scanner;

class Main{
        public static void main(String args[]){
                Scanner scan =new Scanner(System.in);
                int val[]=new int[3];
                val[0]=scan.nextInt();
                val[1]=scan.nextInt();
                val[2]=scan.nextInt();
                for(int i=0;i<3;i++){
                        for(int j=0;j<2;j++){
                                if(val[j]>val[j+1]){
                                        int temp=val[j];
                                        val[j]=val[j+1];
                                        val[j+1]=temp;
                                }
                        }
                }
                System.out.println(val[0]+" "+val[1]+" "+val[2]);
        }
}

Measured memory_bytes: 26140
program EDPCD
    implicit none
    integer(8)::N,W,i,j
    integer(8),dimension(100)::wi,vi
    integer(8),dimension(100000,100)::dp
    read(5,*)N,W
    read(5,*)(wi(i),vi(i),i=1,N)
    dp=0

    do i=1,N
        do j=1,W
            if(i==1)then
                if(j>=wi(i))then
                    dp(j,i)=vi(i)
                end if
            else if(j<wi(i))then
                dp(j,i)=dp(j,i-1)
            else if(j==wi(i))then
                dp(j,i)=max(dp(j,i-1),vi(i))
            else
                dp(j,i)=max(dp(j,i-1),dp(j-wi(i),i-1)+vi(i))
            end if
        end do
    end do

    print'(i0)',dp(W,N)
end program EDPCD

Measured memory_bytes: 78720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

class Main {
	public static void main(String[] args) throws IOException {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb = new StringBuffer();
 
        Map<Character, Integer> map = new HashMap<Character, Integer>();
        char[] mojiList = "abcdefghijklmnopqrstuvwxyz".toCharArray();
        
        for(char key : mojiList) {
           map.put(key, 0);
        }
        
        String input;
        
        while((input = br.readLine()) != null) {
            char[] strList = input.toLowerCase().toCharArray();
            for(char moji : strList) {
                if(map.containsKey(moji)) {
                    map.put(moji, map.get(moji) + 1);
                }
            }
        }
 
        for(char moji : mojiList) {
            System.out.println(moji + " : " + map.get(moji));
        }
    }
}

Measured memory_bytes: 24576
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;

int main(){
    ll n,k=0,a=0;
    string s;
    cin>>s;
    ll f=0,g=s.length()-1;
    while(f<g){
      if(s[f]==s[g])f++,g--;
      else if(s[f]=='x'&&s[g]!='x') a++,f++;
      else if(s[f]!='x'&&s[g]=='x') a++,g--;
      k++;
      if(k>100000){a=-1;break;}
    }
  cout<<a;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    string s,t; cin >> s >> t; REVERSE(t);
    YN(s==t);

    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

int main() {
    ll A;
    ld B;
    cin >> A >> B;
    ll ans = A * B;
    cout << ans << endl;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#include<iostream>
#include<boost/range/irange.hpp>
#include<boost/multiprecision/cpp_int.hpp>
#include<boost/algorithm/string/classification.hpp>
#include<boost/algorithm/string/split.hpp>
#include<boost/algorithm/string/join.hpp>
#include<boost/algorithm/string/replace.hpp>
#include<boost/math/tools/minima.hpp>
#include<boost/pending/disjoint_sets.hpp>
using namespace std;
using boost::irange;
using boost::multiprecision::cpp_int;
using boost::algorithm::split;
using boost::is_any_of;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::math::tools::brent_find_minima;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}
int main(){
	ll n, x;
	cin >> n >> x;
	ll a[n] = {0};
	ll before_sum = 0, after_sum = 0;
	for(ll i = 0; i < n; i++){
		cin >> a[i];
		before_sum += a[i];
	}
	for(ll i = 0; i < n-1; i++){
		if(a[i] + a[i+1] > x){
			a[i+1] = max(0, a[i+1] - (a[i] + a[i+1] - x));
		}
		if(a[i] + a[i+1] > x){
			a[i] = max(0, a[i] - (a[i] + a[i+1] - x));
		}
	}
	for(ll i = 0; i < n; i++){
		//cout << a[i] << " ";
		after_sum += a[i];
	}//cout << endl;
	ll ans = before_sum - after_sum;
	cout << ans << endl;
}   



Measured memory_bytes: 1024
#include <iostream>

using namespace std;

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

    if(N == 1){
        cout << "Hello World" << endl;
        return 0;
    }
    else{
        int A,B;
        cin >> A >> B;

        cout << A+B << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;



/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    map<ll, ll> m;
    rep(i,n) {
        cin >> a[i];
        m[a[i]]++;
    }
    ll sum = 0;
    for(auto i : m){
        ll n = i.second;
        sum += n*(n-1)/2;
    }
    
    rep(i,n){
        if (m[a[i]] == 1) {
            cout << sum << endl;
            continue;
        }
        cout << sum - (m[a[i]]-1) << endl;
    }
    
    
}


Measured memory_bytes: 12672
s=input()
t=input()

ans=len(t)
for i in range(len(s)-len(t)+1):
    cnt = len(t)
    for j in range(len(t)):
      if s[i:i+len(t)][j] == t[j]:
      	cnt -= 1
    ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 9016
# すぬけ君の人数N
# お菓子の種類K
N,K = map(int, input().split())

# すぬけ君の人数分要素のリストを作る
Sunuke_List = [0] * N

# お菓子iを持っているすぬけ君を取得してリストに格納
for i in range(K):
    d_i = int(input())
    A_i = list(map(int, input().split()))
    for j in range(d_i):
        Sunuke_List[A_i[j]-1] = Sunuke_List[A_i[j]-1] + 1

# お菓子が0このすぬけ君の人数を出力
print(Sunuke_List.count(0))

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

int main()
{
  int n;cin>>n;
  vector<int> a(n);
  int i;
  for(i=0;i<n;i++)cin>>a.at(i);
  int oddc=0;
  for(i=0;i<n;i++)
  {
    if(a.at(i)%2!=0)oddc++;
  }
  if(oddc%2==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 640
//Mohamed Galal
#define _CRT_SECURE_NO_WARNINGS
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <cstdlib>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#define PI 3.14159265359
#define all(v)  ((v).begin()), ((v).end())
#define all(s)  ((s).begin()), ((s).end())
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
void file()
{
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}
void Mohamed_Galal()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);
}
int main()
{
	Mohamed_Galal();
	int sum = 0;
	string s, t;
	cin >> s;
	t = s;
	for (size_t i = 0; i < s.size(); i++)
		s[i] -= '0';
	if (s[0] + s[1] + s[2] + s[3] == 7)
		cout << t[0] << "+" << t[1] << "+" << t[2] << "+" << t[3] << "=7" << endl;
	else if (s[0] + s[1] + s[2] - s[3] == 7)
		cout << t[0] << "+" << t[1] << "+" << t[2] << "-" << t[3] << "=7" << endl;
	else if (s[0] + s[1] - s[2] + s[3] == 7)
		cout << t[0] << "+" << t[1] << "-" << t[2] << "+" << t[3] << "=7" << endl;
	else if (s[0] - s[1] - s[2] + s[3] == 7)
		cout << t[0] << "-" << t[1] << "-" << t[2] << "+" << t[3] << "=7" << endl;
	else if (s[0] - s[1] + s[2] + s[3] == 7)
		cout << t[0] << "-" << t[1] << "+" << t[2] << "+" << t[3] << "=7" << endl;
	else if (s[0] + s[1] - s[2] - s[3] == 7)
		cout << t[0] << "+" << t[1] << "-" << t[2] << "-" << t[3] << "=7" << endl;
	else if (s[0] - s[1] + s[2] - s[3] == 7)
		cout << t[0] << "-" << t[1] << "+" << t[2] << "-" << t[3] << "=7" << endl;
	else if (s[0] - s[1] - s[2] + s[3] == 7)
		cout << t[0] << "-" << t[1] << "-" << t[2] << "+" << t[3] << "=7" << endl;
	else if (s[0] - s[1] - s[2] - s[3] == 7)
		cout << t[0] << "-" << t[1] << "-" << t[2] << "-" << t[3] << "=7" << endl;
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>

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

using namespace std;

int main(){
	for(int T=0,h,w;scanf("%d%d",&h,&w),h;T++){
		if(T>0) puts("");

		int a[100][10],type[100][10],rsum[10],csum[100];
		int rcnt[10]={},ccnt[100]={};
		rep(i,h){
			rep(j,w){
				char s[8]; scanf("%s",s);
				if(s[0]=='?'){
					type[i][j]=0;
				}
				else{
					sscanf(s,"%d",a[i]+j);
					type[i][j]=1;
					rcnt[j]++;
					ccnt[i]++;
				}
			}
			scanf("%d",csum+i);
		}
		rep(j,w) scanf("%d",rsum+j);
		scanf("%*d");

		while(1){
			bool change=false;
			rep(i,h) if(ccnt[i]==w-1) {
				int val=csum[i],jq;
				rep(j,w){
					if(type[i][j]==0) jq=j;
					else              val-=a[i][j];
				}
				a[i][jq]=val;
				type[i][jq]=2;
				rcnt[jq]++;
				ccnt[i]++;
				change=true;
			}

			rep(j,w) if(rcnt[j]==h-1) {
				int val=rsum[j],iq;
				rep(i,h){
					if(type[i][j]==0) iq=i;
					else              val-=a[i][j];
				}
				a[iq][j]=val;
				type[iq][j]=2;
				rcnt[j]++;
				ccnt[iq]++;
				change=true;
			}

			if(!change) break;
		}

		bool ok=true;
		rep(i,h) rep(j,w) if(type[i][j]==0) ok=false;
		if(!ok) puts("NO");
		else{
			rep(i,h) rep(j,w) if(type[i][j]==2) printf("%d\n",a[i][j]);
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long int


ll fac(ll n)
{
    if(n == 1) return 1;
    else{
        return n * fac(n - 1);
    }
}

int main()
{
    ll n;
    cin >> n;
    vector<pair<ll, ll>> xy(n);
    vector<ll> parmitation(n);
    for(ll i = 0; i < n; i++){
        cin >> xy[i].first >> xy[i].second;
        parmitation[i] = i;
    }
    double totaldis = 0;

    do{
        for(ll i = 1; i < n; i++){
            totaldis += sqrt(pow(xy[parmitation[i]].first - xy[parmitation[i - 1]].first, 2) + pow(xy[parmitation[i]].second - xy[parmitation[i - 1]].second, 2));
        }

    }while(next_permutation(parmitation.begin(), parmitation.end()));

    totaldis /= fac(n);

    printf("%.10f\n", totaldis);




}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    int cnt=0;
    cin>>n;
    int arr[n];
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);

    for(i=0; i<=n-3; i++)
    {
        for(int j=i+1; j<=n-2; j++)
        {
            for(int k=j+1; k<=n-1; k++)
            {
                //arr i arr j arr k

                if(arr[i]<(arr[j]+arr[k]))
                {

                    if (arr[j]<(arr[i]+arr[k]) )
                    {
                        if(arr[k]<(arr[j]+arr[i]))
                        {
                            cnt++;

                        }
                    }
                }
            }
        }

    }


    cout<<cnt<<endl;

    return 0;
}




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

int main()
{
  int N;
  string S;
  cin >> N >> S;
  string ans = "Yes";
  if (S.size() % 2 == 1)
    ans = "No";
  else
  {
    int n = S.size() / 2;
    rep(i, n)
    {
      if (S[i] != S[i + n])
        ans = "No";
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	bool prime[1000000];
	bool near2017[1000000];
	int ans[1000000];
	for(int i=2;i<1000000;i++){
		prime[i] = true;
		near2017[i] = false;
	}
	prime[0] = false;
	prime[1] = false;
	prime[2] = true;
	for(int i=2;i<1000000;i++){
		if(prime[i]==true){
			for(int j=i*2;j<1000000;j+=i){
				prime[j]=false;
			}
		}
	}

	for(int i=0;i<1000000;i++){
		if(i%2==0){
			near2017[i] = false;
		}else{
			if(prime[i] && prime[(i+1)/2]) near2017[i] = true;
		}
	}

	for(int i=1;i<1000000;i++){
		if(near2017[i]) ans[i] = ans[i-1] + 1;
		else ans[i] = ans[i-1];
	}

	int q;
	int l,r;
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		int a = 0;
		scanf("%d %d",&l,&r);
		a = ans[r] - ans[l-1];
		printf("%d\n",a);
	}

	return 0;
}


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

int main()
{
   string S,T;
   cin >> S >> T;

   // 文字列の入力
   int A,B;
   cin >> A >> B;

   string U;
   cin >> U;

   // cout << S << " " << T << " " << A << " " << B << " " << U << endl;
  
   // 出力
   if(S==U){
      cout << (A-1) << " " << B << endl;
   } else {
      cout << A << " " << (B-1) << endl;
   }

   return 0;
}




Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++) arr[i] = sc.nextInt();
        Arrays.sort(arr);
        int mid = N/2;
        int res = 0;
        if(arr[mid] == arr[mid-1]) {
            res = 0;
        } else {
            res = arr[mid] - arr[mid-1];
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 59216
fn main() {
    let v = read_vec::<i32>();
    let k = v[0];
    let s = v[1];

    let mut count = 0;
    for i in 0..k + 1 {
        for j in 0..k + 1 {
            let z = s - i - j;
            if 0 <= z && z <= k {
                count += 1;
            }
        }
    }
    println!("{}", count);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
n = int(input())
a = list(map(int,input().split()))
q = int(input())
bc = [list(map(int,input().split())) for i in range(q)]

l = [0 for i in range(10**5+1)]
for i in range(n):
    l[a[i]] += 1

ans = 0
for i in range(1,10**5+1):
    ans += l[i]*i

for i in range(q):
    b = bc[i][0]
    c = bc[i][1]
    before = 0
    after = 0
    if l[b] != 0:
        before = l[b]*b + l[c]*c
        l[c] += l[b]
        l[b] = 0
        after = l[b]*b + l[c]*c
    ans = ans-(before-after)
    print(ans)

Measured memory_bytes: 32192
//If you can think it, you should implement it
#include<bits/stdc++.h>
using namespace std;
 
#define xlr8 ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int
#define ld long double
#define mod 1000000007
#define eb emplace_back
#define mp make_pair
#define nl "\n"
#define ignore cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

int power(int a,int b,int m=mod){ int ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1LL*a*ans)%m; b>>=1;a=(1LL*a*a)%m;}return ans;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
int gcd(int a,int b){  if(b==0) return a;  return gcd(b,a%b);}
int lcm(int a,int b){return (a* b)/gcd(a,b);}

//__builtin_popcount()
//memset(a,0,sizeof(a))
//bool next_permutation(a.begin(),a.end())

int sum(int a)
{
    int cnt=0;
    while(a!=0)
    {
        cnt+=a%10;
        a/=10;
    }
    return cnt;
}

signed main(){
    xlr8;
    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        string a,b;
        cin>>a>>b;
        if(a==b.substr(0,a.size()))
            cout<<"Yes\n";
        else
            cout<<"No\n";



    }

 return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());

    ll prev = 0, count = 0;
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        if(prev != a.at(i)){
            if(count >= prev){
                ans += count - prev;
            }else{
                ans += count;
            }
            prev = a.at(i);
            count = 1;
        }else{
            count++;
        }
    }
    if(count >= prev){
        ans += count - prev;
    }else{
        ans += count;
    }

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

Measured memory_bytes: 1152
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

if N % 10 == 7 or N // 10 % 10 == 7 or N // 100 % 10 == 7:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9656