akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>   
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, t;
pii a[N];

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i].S >> a[i].F;
   sort (a + 1, a + n + 1);
   for (int i = 1; i <= n; i ++) {
      t += a[i].S;
      if (t > a[i].F) cout << "No", exit (0);
   }
   cout << "Yes";

}                                     

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
// cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <math.h>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll k,x=2,y=2;
ll a[1000005];
int main(void){
    cin>>k;
    for(ll i=k;i>=1;i--)cin>>a[i];
    for(ll i=1;i<=k;i++){
        ll b=a[i];
        
        ll c=b*((y+b-1)/b);
        ll d=(x-x%b)+(b-1);
        if(d<y||c>x){
            cout<<-1<<endl;
            return 0;
        }
        y=c;
        x=d;
    }
    cout<<y<<' '<<x<<endl;
}

Measured memory_bytes: 1024
let () =
  let s = read_line () in
  let ls = String.length s in
  let rec iter l =
    if String.sub s 0 (l/2) = String.sub s (l/2) (l/2) then l
    else iter (l-2) in
  iter (ls-2) |> string_of_int |> print_endline


Measured memory_bytes: 384
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.ascii, std.typecons;

void main()
{
    char c;
    readf("%s", &c);
    readln;

    if (isUpper(c)) { writeln('A'); }
    else { writeln('a'); }
}

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

int main(){
	char c[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	vector<int> ans(26,0);
	string str;
	char ch;
	while(cin>>ch){
	//getline(cin,str);
	//for(int i=0; i<(int)str.size(); i++){
		//cout<<(str[i]-'0')<<endl;//-49
		//int n=str[i]-'0';
		int n=ch-'0';
		if(49<=n && n<= 74){
			ans[n-49]+=1;
		}else if(17<=n && n<=42){
			ans[n-17]+=1;
		}
	}
	for(int i=0; i<ans.size(); i++){
		cout<<c[i]<<" : "<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>
  
int G[100][100], d[100], v[100];
int getMST(int);
  
int main(){
    int n, i, j;
    
    scanf("%d", &n);
    for(i=0; i < n; i++){
        for(j=0; j < n; j++){
            scanf("%d", &G[i][j]);
        }
    }
    printf("%d\n", getMST(n));
  
    return 0;
}
  
int getMST(int n){
    int i, j, min, minp;
    int k = 1;
    int sum = 0;
    
    d[0] = 0;
    v[0] = 1;
  
    for(i = 1; i < n; i++) v[i]=0;
  
    while(1){
        min = 2001;
        for(i = 0; i < k; i++){
            for(j = 0; j < n; j++){
                if(G[d[i]][j]<min && G[d[i]][j] != -1 && v[j] != 1){
                    min = G[d[i]][j];
                    minp = j;
                }
            }
        }
      
        if(k == n) break;
        d[k] = minp;
        v[minp] = 1;
        sum += min;
        k++;
    }
  
    return sum;
}

Measured memory_bytes: 640
#include<stdio.h>
 
int a[8],b[8],c[15],d[15];
char t[8][8];

int Hira(int y){
  if(y==8)return 1;
  if(a[y])return Hira(y+1);
  int x;
  for(x=0;x<8;x++){
    if(b[x])continue;
    if(c[7-x+y])continue;
    if(d[y+x])continue;
    a[y]=1;
    b[x]=1;
    c[7-x+y]=1;
    d[y+x]=1;
    t[y][x]='Q';
    if(Hira(y+1))return 1;
    a[y]=0;
    b[x]=0;
    c[7-x+y]=0;
    d[y+x]=0;
    t[y][x]='.';
  }
  return 0;
}
 
int main(){
  int n,x,y,i,j;
  for(i=0;i<8;i++)
    for(j=0;j<8;j++)
      t[i][j]='.';
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&y,&x);
    a[y]=1;
    b[x]=1;
    c[7-x+y]=1;
    d[y+x]=1;
    t[y][x]='Q';
  }
 
  Hira(0);
 
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      printf("%c",t[i][j]);
    }
    printf("\n");
  }
 
  return 0;
}

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

int main(){
    unsigned long long N;
    cin >> N;
    cout << (N * (N - 2) + 1) / 2 << endl;
    for(unsigned long long i = 1; i <= N; ++i)
        for(unsigned long long j = 1; j < i; ++j)
            if(j + i != N + !(N & 1))cout << j << " " << i << endl;
}

Measured memory_bytes: 256
def gcd(a, b):
  if a < b:
    a_init = a
    a = b
    b = a_init
  while b != 0:
    r = a % b
    a = b
    b = r
  return a
	
K = int(input())
count = 0
temp = []
for a in range(1, K+1):
	for b in range(1, a):
		temp.append(gcd(a, b))
for c in range(1, K+1):
	for j in range(len(temp)):
		count += gcd(c, temp[j]) * 2
	for k in range(1, K+1):
		count += gcd(c, k)
print(count)


Measured memory_bytes: 9304
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>

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

using namespace std;
typedef long long ll;
const double INF = 1e12;

class BinaryIndexedTree
{
public:
  int n;
  vector<int> tree;

  BinaryIndexedTree(int N)
    : n(N), tree(vector<int>(n + 1, 0))
  {}

  void add(int a, int w) {
    for (int x = a; x <= n; x += (x & -x)) {
      tree[x] += w;
    }
  }

  int sum(int a) {
    int s = 0;
    for (int x = a; x > 0; x -= (x & -x)) {
      s += tree[x];
    }
    return s;
  }
};


int count_inv(int N, int * l) {
  BinaryIndexedTree bit(N);
  int ans = 0;
  REP(j, N) {
    ans += j - bit.sum(l[j]);
    bit.add(l[j], 1);
  }
  return ans;
}


int count_crossed_lines(int N, int * A, int * B, int * C, int * s, double x) {
  vector< pair<double, int> > Y;
  int li;
  REP(i, N) {
    li = s[i];
    Y.push_back(make_pair((-A[li] * x + C[li]) / B[li], i+1));
  }
  sort(Y.begin(), Y.end());
  int y_argsort[N];
  REP(i, N) {
    y_argsort[i] = Y.at(i).second;
  }
  return count_inv(N, y_argsort);
}


void sort_lines(int N, int * A, int * B, int * C, int * s) {
  vector< pair<double, int> > angles;
  REP(i, N) {
    angles.push_back(make_pair(double(A[i]) / B[i], i));
  }
  sort(angles.begin(), angles.end());
  REP(i, N) {
    s[i] = angles.at(i).second;
  }
}


bool check(double * rg, double m) {
  double d = rg[1] - rg[0];
  if (d < 1e-9) return true;
  if ( (m - rg[0]) / min(abs(rg[0]), abs(rg[1])) < 1e-10 ) return true;
  return false;
}


double find_coord(int N, int * A, int * B, int * C) {
  int med_v = ceil(N * (N-1) / 4.0);
  int lines_sorted[N];
  sort_lines(N, A, B, C, lines_sorted);
  // bin-search
  double rg[2] = {-INF, INF};
  double d, m = (rg[0] + rg[1]) / 2;
  do {
    int cl = count_crossed_lines(N, A, B, C, lines_sorted, m);
    if (cl < med_v) rg[0] = m;
    else rg[1] = m;
    d = rg[1] - rg[0];
    m = (rg[0] + rg[1]) / 2;
  } while (!check(rg, m));

  return m;
}

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

  int N;
  cin >> N;
  int A[N], B[N], C[N];
  REP(i, N) {
    cin >> A[i] >> B[i] >> C[i];
  }
  cout << setprecision(12) << find_coord(N, A, B, C) << " " << find_coord(N, B, A, C) << "\n";
  return 0;
}


Measured memory_bytes: 2808
while line = gets
  a,b,c,d,e,f=line.chomp!.split(" ").map(&:to_f)

  x = (b*f-c*e)/(b*d-a*e).round(3) + 0
  y = (a*f-c*d)/(a*e-b*d).round(3) + 0

  puts sprintf("%.3f %.3f", x, y)
end

Measured memory_bytes: 8876
import numpy as np
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A = np.array(A)
B = np.array(B)
A_org = A.copy()

for i in range(N):
    if A[i] - B[i] < 0:
        B[i] -= A[i]
        A[i] = 0
        
        if A[i+1] - B[i] < 0:
            A[i+1] = 0
        else:
            A[i+1] -= B[i]
    else:
        A[i] -= B[i]
        B[i] = 0

ans = A_org-A
print(ans.sum())

Measured memory_bytes: 27316
import java.util.Scanner;

public class Main{
  public static void main(String [] args){

    //nextLine():1行分の入力を取得する
    //length():文字列の長さを取得する
    //substring(a,b):aからb-1までのインデントに対応する文字を切り取る

    Scanner scanner = new Scanner(System.in);
    String s = scanner.nextLine();

    int[] save = new int[s.length()];
    int min = 1000;

    for(int i = 0; i < s.length()-2; i++){
      save[i] =  Integer.parseInt( s.substring(i,i+3) );
    }

    for(int i = 0; i < s.length()-2; i++){

      save[i] = 753 - save[i];
      if(save[i] < 0){
        save[i] = -save[i];
      }
      if(save[i] < min){
        min = save[i];
      }
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 22996
from collections import deque

k = int(input())
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for i in range(k):
    a = q.popleft()
    b = a % 10
    if b == 0:
        q.append(a * 10)
        q.append(a * 10 + b + 1)
    elif b == 9:
        q.append(a * 10 + b - 1)
        q.append(a * 10 + b)
    else:
        q.append(a * 10 + b - 1)
        q.append(a * 10 + b)
        q.append(a * 10 + b + 1)

print(a)

Measured memory_bytes: 18684
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 2019;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll L, R;

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

  cin >> L >> R;

  int ln = L/MOD;
  int rn = R/MOD;
  if (ln != rn) {
    cout << 0 << endl;
    return 0;
  }

  int lr = L%MOD;
  int rr = R%MOD;
  ll ans = MOD-1;
  for (ll i = lr; i <= rr; ++i) {
    for (ll j = i+1; j <= rr; ++j) {
      ans = min(ans, mod(i*j, MOD));
    }
  }

  cout << ans << endl;

  return 0;
}


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

using ll = long long int;

ll n;

int main(void){
  // Here your code !
  scanf("%lld", &n);

  if (n % 2 == 0) printf("%lld\n", n);
  else printf("%lld\n", 2 * n);

  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();
		for(int i=0;i<n;i++){
			char[] c=sc.next().toCharArray();
			Arrays.sort(c);
			int min=Integer.parseInt(String.valueOf(c));
			char[] d=new char[c.length];
			for(int j=0;j<c.length;j++){
				d[j]=c[c.length-j-1];
			}
			int max=Integer.parseInt(String.valueOf(d));
			System.out.println(max-min);
		}
	}
}

Measured memory_bytes: 17164
package main
 
import (
  "fmt"
  "math"
)

func max(nums ...int) int {
    if len(nums) == 0 {
        panic("funciton max() requires at least one argument.")
    }
    res := nums[0]
    for i := 0; i < len(nums); i++ {
        res = int(math.Max(float64(res), float64(nums[i])))
    }
    return res
}

func main() {
  var n int
  fmt.Scan(&n)
  sea := make([]int, n)
  mountain := make([]int, n)
  house := make([]int, n)
  dp_a := make([]int, n)
  dp_b := make([]int, n)
  dp_c := make([]int, n)
  
  for i := 0; i < n; i++ {
    fmt.Scan(&sea[i])
    fmt.Scan(&mountain[i])
    fmt.Scan(&house[i])
  }
  
  //1日目の幸福度を初期値とする
  dp_a[0] = sea[0]
  dp_b[0] = mountain[0]
  dp_c[0] = house[0]
  
  //2日目以降の幸福度は0で初期化
  for i := 1; i < n; i++ {
     dp_a[i] = 0
     dp_b[i] = 0
     dp_c[i] = 0
  }
  
  //1日ずつ、活動毎に幸福度の最大値を求める
  for i := 1; i < n; i++ {
    dp_a[i] = max(dp_b[i-1] + sea[i], dp_c[i-1] + sea[i])
    dp_b[i] = max(dp_a[i-1] + mountain[i], dp_c[i-1] + mountain[i])
    dp_c[i] = max(dp_a[i-1] + house[i], dp_b[i-1] + house[i])
  }
  
  fmt.Println(max(dp_a[n-1],dp_b[n-1],dp_c[n-1]))
}

Measured memory_bytes: 10880
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cassert>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<int> graph[200005];
vector<bool> used(200005);
vector<int> len(200005);

void dfs(int p, int l) {
  if (used[p]) return;
  used[p] = true;
  len[p] = l;
  for(auto e: graph[p]) {
    dfs(e, l+1);
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  rep(i, n-1) {
    int a, b; cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  dfs(1, 1);

  int pos = -1;
  int now = 0;
  for(int i=1; i<=n; i++) {
    if (len[i] > now) {
      now = len[i];
      pos = i;
    }
  }

  for(int i=1; i<=n; i++) {
    used[i] = false;
  }

  dfs(pos, 1);

  int ma = 0;
  for(int i=1; i<=n; i++) {
    chmax(ma, len[i]);
  }
  ma--;
  if (ma%3==1) {
    cout << "Second" << endl;
  } else {
    cout << "First" << endl;
  }

}

Measured memory_bytes: 18304
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int F[][][] = new int[N][5][2];
		int P[][] = new int[N][11];
		for (int i= 0;i<N;i++) {
			for (int j=0;j<5;j++) {
				for (int k=0;k<2;k++) {
					F[i][j][k] = sc.nextInt();
				}
			}
		}
		for (int i= 0;i<N;i++) {
			for (int j=0;j<11;j++) {
				P[i][j] = sc.nextInt();
			}
		}
		int sum =Integer.MIN_VALUE;
		for (int i=1;i<1024;i++) {
			int temp=0;
			int pattern[] = Main.intToArray(i);
			for (int j=0;j<N;j++) {
				int count=0;
				for (int k=0;k<10;k++) {
					if (pattern[k]== F[j][k/2][k%2]&& F[j][k/2][k%2]==1) {
						count++;
					}
				}
				temp +=P[j][count];
			}
			if (temp>sum) {
				sum =temp;
			}
		}
		System.out.println(sum);
	}

	public static int[] intToArray(int a) {
		int result[] = new int[10];
		int i =0;
		while (a>0) {
			result[i] = a%2;
			a/=2;
			i++;
		}
		return result;
	}
}

Measured memory_bytes: 28260
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

template<typename T>
constexpr T binaryPow_mod(T radix, T index, T mod) noexcept {
	radix %= mod;
	T rtv = 1;
	while (index > 0) {
		if (index & 1) {
			rtv *= radix;
			rtv %= mod;
		}

		radix *= radix;
		radix %= mod;

		index = index >> 1;
	}

	return rtv;
}

template<typename T>
constexpr T inv(T a, T mod) noexcept {
	return binaryPow_mod(a, mod - 2, mod);
}

template<typename T>
constexpr T c(T n, T r, T mod) noexcept {
	T nCr = 1;
	for (T i = 0; i < r; ++i) {
		nCr *= n - i;
		nCr %= mod;
		nCr *= inv(1 + i, mod);
		nCr %= mod;
	}

	return nCr;
}

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

	ll x, y;
	cin >> x >> y;
	ll z = x + y;
	
	if (z % 3 != 0 || min(x, y) < (z / 3)) {
		cout << 0 << "\n";
	}
	else {
		ll a, b;
		a = z / 3;
		b = 2 * (z / 3) - x;

		cout << c(a, b, _MOD) << "\n";
	}

	return 0; 
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<string>
#include<stack>
#include<set>
#define int long long
using namespace std;
signed main() {
    string s;
    cin>>s;
    int count=0,max=-1;
    for(int i=0;i<s.size();i++) {
        if(s[i]=='R') count++;
        if(s[i]=='S') count=0;
        if(count>max) max=count;
    }
    cout<<max<<endl;
    return 0;
}


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

using namespace std;

int gcd(int a, int b)
{
    while(b)
    {
        a %= b;
        swap(a, b);
    }
    return a;
}

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

    int n, x;
    cin >> n >> x;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        ans = gcd(ans, abs(a - x));
    }

    cout << ans;

    return 0;
}


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

int main() {
    int x, y;
    cin >> x >> y;
    int code = 0;
    int mac = 0;
    if(x == 3){
        code = 100000;
    } else if(x == 2){
        code = 200000;
    } else if(x == 1){
        code = 300000;
    }
    if(y == 3){
        mac = 100000;
    } else if(y == 2){
        mac = 200000;
    } else if(y == 1){
        mac = 300000;
    }
    if(code + mac == 600000){
        cout << 1000000 << endl;
    } else {
        cout << code + mac << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define pb push_back
#define fi first
#define se second



ll c1=0;
ll c2=0;

ll h,w;

ll a[410][410],b[410][410];

void dfs(ll s,ll t){
    if(b[s][t]==0){
        b[s][t]=1;
        if(a[s][t]==0) c1++;
        else c2++;

        ll s1,s2,t1,t2;

        s1=s-1;
        s2=s+1;
        t1=t-1;
        t2=t+1;


        if(s1>=0&&a[s][t]!=a[s1][t]) dfs(s1,t);
        if(t2<w&&a[s][t]!=a[s][t2]) dfs(s,t2);
        if(s2<h&&a[s][t]!=a[s2][t]) dfs(s2,t);
        if(t1>=0&&a[s][t]!=a[s][t1]) dfs(s,t1);
        
    
    }
    
}



int main(){
    ll i,j;

    cin>>h>>w;

    for(i=0;i<h;i++){
        string p;
        cin>>p;
        for(j=0;j<w;j++){
            if(p[j]=='#') a[i][j]=0;
            else a[i][j]=1;
        }
    }
    for(i=0;i<h;i++){
        for(j=0;j<w;j++) b[i][j]=0;
    }

    ll ans=0;
    ll po=0;

    while(po<h*w){
        ll x=po/w;
        ll y=po-x*w;

        dfs(x,y);
        ans+=c1*c2;

        
        po++;
        c1=0;
        c2=0;
    }
    cout<<ans<<endl;
    return 0;
}

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


int main() {
  
  int N;
  cin  >> N;
  
  vector<string> blue(N);
  
  rep(i,N){
    cin >> blue.at(i);
  }
  
  
  int M;
  cin  >> M;
  
  vector<string> red(M);
  
  rep(i,M){
    cin >> red.at(i);
  }
  
  
  int num,max=0;
  
  for(int i=0; i< N; i++){
    
    num = 1;
    
    for( int j=i+1; j< N; j++){
      if(blue.at(i)==blue.at(j))
        num++;
    }
    for(int j=0; j<M; j++){
      if(blue.at(i)==red.at(j))
        num--;
    }
    
    if(num>max)
      max=num;
  }
  
  cout << max << endl;
  
  
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a.at(i);
    for(int i = k; i < n; i++) {
        if(a.at(i) > a.at(i - k)) {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 4044
N, M, C = map(int, input().split())
bl = list(map(int, input().split()))
ans = 0
for i in range(N):
  l = list(map(int, input().split()))
  tmp = 0
  for j in range(M):
    tmp += bl[j] * l[j]
  if tmp + C > 0:
    ans += 1
print(ans)

Measured memory_bytes: 3060
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
a=lnii()

l1=[i+a[i] for i in range(n)]
l2=[i-a[i] for i in range(n)]

c1=Counter(l1)
c2=Counter(l2)

ans=0
for i in c1:
  ans+=c1[i]*c2[i]

print(ans)

Measured memory_bytes: 63552
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}



int main(void) {
    FAST_IO;
    
    int n, k;
    int cnt = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x >= k) cnt++;
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
hn =list(map(int, input().split()))
ls= [0]*(n-1)
ans = 0
count = 0
for i in range(n-1):
    if hn[i+1] <= hn[i]:
        ls[i] = 1
        count += 1
    else:
        ans = max(ans, count)
        count=0

ans = max(ans, count)

print(ans)

Measured memory_bytes: 20416
import java.util.*;

public class Main {
	public static void printArray(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + ", ");
		}
		System.out.println();
	}

	public static<T> void printArrayT(T[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + ", ");
		}
		System.out.println();
	}

	public static class Triple implements Comparable<Triple> {
		public int S, T, X;
		Triple(int S, int T, int X) {
			this.S = S;
			this.T = T;
			this.X = X;
		}

		@Override
		public String toString() {
			return String.format("(%d, %d, %d)", S, T, X);
		}

		@Override
		public int compareTo(Triple o) {
			return this.X - o.X;
		}
	}

	public static class Pair implements Comparable<Pair> {
		public int D, index;
		Pair(int D, int index) {
			this.D = D;
			this.index = index;
		}

		@Override
		public String toString() {
			return String.format("(%d, %d)", D, index);
		}

		@Override
		public int compareTo(Pair o) {
			return this.D - o.D;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); // 2 * 10^5
		int Q = sc.nextInt(); // 2 * 10^5
		Triple[] STX = new Triple[N];
		TreeSet<Pair> DSET = new TreeSet<Pair>();
		int[] D = new int[Q];
		for (int i = 0; i < N; i++) {
			int s = sc.nextInt(); // 10^9
			int t = sc.nextInt(); // 10^9
			int x = sc.nextInt(); // 10^9
			STX[i] = new Triple(s, t, x);
		}
		for (int i = 0; i < Q; i++) {
			int d = sc.nextInt(); // 10^9
			DSET.add(new Pair(d, i));
			D[i] = -1;
		}

		Arrays.sort(STX, 0, N);
		for (Triple stx : STX) {
			int startTime = stx.S - stx.X;
			int endTime = stx.T - stx.X;
			Iterator<Pair> it = DSET.subSet(new Pair(startTime, -1), new Pair(endTime, -1)).iterator();
			while (it.hasNext()) {
				Pair pair = it.next();
				D[pair.index] = stx.X;
				it.remove();
			}
		}
		StringBuilder sb = new StringBuilder();
		for (int len : D) {
			sb.append(len);
			sb.append("\n");
		}
		System.out.print(sb);
	}
}


Measured memory_bytes: 198164
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
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;
}
vector<int> nums;
void dfs(Graph &g, vector<bool> &visit, vector<bool> &seen, vector<int> &p, int v){
    visit[v]=true;
    seen[v]=true;
    nums.push_back(p[v]);
    for(int u:g[v]){
        if(visit[u]) continue;
        dfs(g,visit,seen,p,u);
    }
}
int main(){
    int N,M;
    cin>>N>>M;
    vector<int> p(N);
    Graph g(N);
    rep(i,N){
        int a;
        cin>>a;
        a--;
        p[i]=a;
    }
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);g[b].push_back(a);
    }
    //swapの範囲が互いに行き来可能であればその範囲pにおいて最大化できる個数はp-1個
    //範囲においてi=piとなるpiが存在するかをdfsで調べられそう？
    
    //全体についての訪問管理
    vector<bool> visit(N);
    vector<bool> correct(N,false);
    int ans=0;
    rep(i,N){
        if(visit[i]) continue;
        if(g[i].size()){
            //ある範囲についての訪問管理
            vector<bool> seen(N);
            //ある範囲に含まれるpiの値
            nums.resize(0);
            dfs(g,visit,seen,p,i);
            for(auto j=nums.begin(); j!=nums.end(); j++){
                if(seen[*j]) {ans++;correct[*j]=true;}
            }
        }
    }
    rep(i,N){
        if(!correct[i]&&p[i]==i) ans++;
    }
    cout<<ans<<endl;
}

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

int main() {
  int K,S; cin >> K >> S;
  
  long ans =0;
  for (int i =0; i<=K; i++) {
    for (int j =i; j<=K; j++) {
      int k = S - i - j;
      if (k < j || k > K) continue;
      if (i == j && j == k) {
        ans++; continue;
      } else if (i == j && i != k) {
        ans += 3; continue;
      } else if (j == k && i != j) {
        ans += 3; continue;
      } else {
        ans += 6;
      }
    }
  }
  cout << ans << endl;
}

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

namespace atcorder_BeginnerContest_125
{
    class Program
    {

        static void Main(string[] args)
        {

            string[] dataRow = Console.ReadLine().Split(' ');

            double len = double.Parse(dataRow[0]);
            int cnt = int.Parse(dataRow[1]);
            double end = double.Parse(dataRow[2]) + 0.5;

            int ret = 0;

            for (double d = len; d <= end; d += len)
            {
                ret += cnt;
            }

            Console.WriteLine(ret);

        }

    }
}



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

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int N = Integer.parseInt(s[0]);
        int K = Integer.parseInt(s[1]);
        String str = stdR.readLine();
        System.out.println(str.substring(0, K - 1)+(char)(str.charAt(K - 1) + 32) +str.substring(K, N));
    }
}


Measured memory_bytes: 22100
n = int(input())
cAC, cWA, cTLE, cRE = 0, 0, 0, 0
for i in range(n):
  s = str(input())
  if s == 'AC':
    cAC += 1
  elif s == 'WA':
    cWA += 1
  elif s == 'TLE':
    cTLE += 1
  else:
    cRE += 1
print("AC x", cAC)
print("WA x", cWA)
print("TLE x", cTLE)
print("RE x", cRE)


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

int main(){
    int k;
    cin >> k;
    queue<ll> q;
    for (int i = 1; i < 10;i++){
        q.push(i);
    }

    for (int i = 0; i < k-1;i++){
        ll s = q.front();
        q.pop();
        int ama = s % 10;
        s *= 10;
        if(ama!=0){
            q.push(s+ama-1);
        }
        q.push(s + ama );
        if(ama!=9){
            q.push(s + ama +1);
        }
    }
    cout << q.front() << endl;

    return 0;
}

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

int main()
{
    cout.precision(20);
    vector< double > fact(11);
    fact[0] = 1;
    for (int i = 1; i <= 10; i++) {
        fact[i] = i * fact[i - 1];
    }
    int n;
    cin >> n;
    vector< double > x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    double ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2)) * 2 * fact[n - 1];
        }
    }
    for (double i = 1; i <= n; i++) {
        ans /= i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M, X = MAP()
CA = [LIST() for _ in range(N)]
ans = 10**7

for i in range(1<<N):
	i = list("{:b}".format(i).zfill(N))
	cost = 0
	skill = [0]*M
	for j in range(N):
		if i[j] == "1":
			cost += CA[j][0]
			for k in range(M):
				skill[k] += CA[j][k+1]
	if all(x >= X for x in skill):
		ans = min(ans, cost)

print(-1 if ans == 10**7 else ans)

Measured memory_bytes: 9980
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	long long n;
	register int i, t, l, s;
	cin >> n;
	for (i = sqrt(n); i >= 1; --i){
		if (n%i == 0){
			t = i;
			l = n / i;
			s = 1;
			while (l >= 10){
				++s;
				l /= 10;
			}
			cout << s;
			goto endapp;
		}
	}
endapp:
	//system("pause > nul");
	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++)
typedef pair<int, int> P;
typedef long long ll;
ll dp[2][2020];
int main()
{
    string s;
    cin >> s;
    ll ans = 0;
    for (auto i = 0; i < s.length(); i++)
    {
        int val = s[i] - '0';
        for (int j = 0; j < 2019; j++)
        {
            dp[(i + 1) % 2][j] = 0;
        }
        dp[(i + 1) % 2][val] = 1;
        for (int j = 0; j < 2019; j++)
        {
            dp[(i + 1) % 2][(j * 10 + val) % 2019] += dp[i % 2][j];
        }
        ans += dp[i % 2][0];
    }
    ans += dp[s.length() % 2][0];
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

struct dat{int r, c, cnt;};
vector<int> dr = {1, 0, -1, 0};
vector<int> dc = {0, 1, 0, -1};

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

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

	vector<string> A(H);
	rep(i, H) cin >> A[i];

	queue<dat> qu;
	vector<vector<int>> grid(H, vector<int>(W, -1));
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(A[i][j] == '#'){
				qu.push((dat){i, j, 0});
				grid[i][j] = 0;
			}
		}
	}

	int ans = 0;
	while(qu.size() > 0){
		dat d = qu.front();
		qu.pop();

		ans = max(ans, d.cnt);

		for(int i = 0; i < 4; i++){
			int nr = d.r + dr[i];
			int nc = d.c + dc[i];

			if(0 <= nr && nr < H && 0 <= nc && nc < W & grid[nr][nc] == -1){
				grid[nr][nc] = d.cnt + 1;
				qu.push((dat){nr, nc, d.cnt + 1});
			}
		}
	}

	cout << ans << endl;
}


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

int main_()
{
    int N, M;
    cin >> N >> M;

    vector<vector<int>> Ass(N);
    for (auto &&as : Ass)
    {
        int K;
        cin >> K;
        copy_n(istream_iterator<int>(cin), K, back_inserter(as));
        sort(as.begin(), as.end());
    }

    auto ans = accumulate(
        Ass.begin() + 1, Ass.end(),
        Ass.front(),
        [](auto &&acc, auto &&as) {
            std::vector<int> result;
            set_intersection(
                acc.begin(), acc.end(),
                as.begin(), as.end(),
                back_inserter(result));
            return result;
        });

    cout << ans.size() << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

      if(N == 0){
        break;
      }

      int temp,sum;
      for(int i = 1;i<= N/2;++i){
        temp = i;
        sum = i;

        while(1){
          ++temp;
          sum += temp;

          if(sum == N){
            ++ans;
            break;
          }
          else if(sum > N){
            break;
          }
          else{
            continue;
          }
        }
      }
      cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3080
import java.util.*;

// first get the dist matrix by floyd algo
// then get the permutation of the route
// then cal the minimum
//

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int R = sc.nextInt();

        int[][] g = new int[N][N];
        int[][] dist = new int[N][N];
        List<Integer> r = new ArrayList<>();
        for (int i = 0; i < R; i++) r.add(sc.nextInt());

        // this is just to store the edges, so as to initialize the dist matrix
        List<List<Integer>> edges = new ArrayList<>();
        for (int i = 0; i < M; i++) {
            edges.add(Arrays.asList(sc.nextInt(), sc.nextInt(),sc.nextInt()));
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (i != j) {
                    dist[i][j] = Integer.MAX_VALUE;
                }
            }
        }

        for (List<Integer> edge : edges) {
            dist[edge.get(0) - 1][edge.get(1) - 1] = edge.get(2);
            dist[edge.get(1) - 1][edge.get(0) - 1] = edge.get(2);
        }

        List<List<Integer>> routes = new ArrayList<>();

        /* interesting sp algo */
        for (int k = 0; k < N; k++) {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    // if any of the ik and kj is infinite, then i just doesn't make sense, continue
                    if (dist[i][k] != Integer.MAX_VALUE
                        && dist[k][j] != Integer.MAX_VALUE
                        && dist[i][j] > dist[i][k] + dist[k][j])

                        dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }

        permutation(routes, r, 0);

        int ans = Integer.MAX_VALUE;
        for (List<Integer> route : routes) {
            int tmp = dist(route, dist);
            if (tmp < ans)
                ans = tmp;
        }

        System.out.println(ans);

    }

    public static int dist(List<Integer> route, int[][] dist) {
        int ans = 0;
        for (int i = 1; i < route.size(); i++) {
            ans += dist[route.get(i - 1) - 1][route.get(i) - 1];
        }

        return ans;
    }

    public static void permutation(List<List<Integer>> routes, List<Integer> perm, int cnt) {
        if (cnt == perm.size()) {
            routes.add(new ArrayList<>(perm));
            return;
        }

        for (int i = cnt; i < perm.size(); i++) {
            Collections.swap(perm, i, cnt);
            permutation(routes, perm, cnt + 1);
            Collections.swap(perm, i, cnt);
        }
    }

}


Measured memory_bytes: 48500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll _() {
	ll x=0,f=1; char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())
		if(ch=='-')f=-f;
	for(;ch>='0'&&ch<='9';ch=getchar())
		x=x*10+ch-'0';
	return x*f;
}
#define _ _()
int main() {
	int n=_; int a=_; int b=_;
	int A=0,B=0,C=0; 
	for( int i=1;i<=n;i++ ) {
		int x=_; 
		if(x<=a) A++;
		else 
		if(x<=b) B++;
		else C++;
	}
	cout<<min(min(A,B),C);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main(){
	long long i,n,ans=0;
	cin >> n;
	long long a[10010];
	
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	
	for(i=0;i<n;i++){
		while(a[i]%2==0){
			ans++;
			a[i] = a[i]/2;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;using ull=unsigned ll;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPARR(i,v) for(int i=0;i<v.size();++i)
#define all(v) (v).begin(),(v).end()
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
#define cut(n, Min, Max) max(min(n,Max),Min)
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"":"im")<<"possible"<<endl
#define Poss(n) cout<<((n)?"P":"Imp")<<"ossible"<<endl
template<typename T>ostream&operator<<(ostream&o,const vector<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<typename T>ostream&operator<<(ostream&o,const set<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T,typename U>ostream&operator<<(ostream&o,const pair<T,U>&v){o<<v.first<<' '<<v.second;return o;}

int main(){
    int cnt[4]={};
    REP(i,6){
        int a;
        cin>>a;
        cnt[a-1]++;
    }
    REP(i,4){
        if(cnt[i]==3){
            YES(0);
            return 0;
        }
    }
    YES(1);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int M = 1000;
VI e[M];
int x[M];
bool ok = true;

const int INF = 1e9;

int dfs(int now, int past){
    VI dp(x[now]+1, INF);
    dp[0] = 0;
    for (int next : e[now]){
        if (next == past) continue;
        int d = dfs(next, now);
        VI dpn(x[now]+1, INF);
        REP(i,x[now]+1){
            if (dp[i] == INF)continue;
            if (i + x[next] <= x[now]) dpn[i + x[next]] = min(dpn[i + x[next]], dp[i] + d);
            if (i + d <= x[now]) dpn[i + d] = min(dpn[i + d], dp[i] + x[next]);
        }
        REP(i,x[now]+1) dp[i] = dpn[i];
    }
    int ret = INF;
    REP(i,x[now]+1) ret = min(ret, dp[i]);

    // cout << now << endl;
    // REP(i,x[now]+1) cout << dp[i] << " ";
    // cout << endl;

    if (ret == INF) ok = false;
    return ret;
}

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

    FOR(i,1,n-1){
        int p;
        scanf("%d", &p);
        p--;
        e[p].push_back(i);
        e[i].push_back(p);
    }

    REP(i,n) cin >> x[i];

    dfs(0, -1);

    cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;

    return 0;
}





Measured memory_bytes: 5756
#include <bits/stdc++.h>
#define rep(i,n) for(long long i = 0; i < (long long)(n); ++i)

using namespace std;
using ll = long long;

int main() {
	ll n, x, y;
	cin >> n >> x >> y;
	x--; y--;
	vector<int> dis(n);
	rep(i, n) rep(j, i) {
		ll ans = i - j;
		ans = min(ans, abs(i - y) + abs(j - x) + 1);
		dis[ans]++;
	}
	rep(i, n - 1) cout << dis[i + 1] << endl;
	return 0;
}
//1-2-3-4-5-6-7
//  +---------+


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
    long long n,x,m,l[100005]={},sum[100005]={},ans=0,c=1000000,d;
    cin>>n>>x>>m;
    for(int i=0;i<m && i<n ;i++){
        if(i!=0)
            sum[i]+=x+sum[i-1];
        else
            sum[i]=x;
        l[i]=x;
        ans+=x;
        x*=x;
        x%=m;
        if(i!=n-1){
        for(int j=0;j<i;j++){
            if(x==l[j]){
                c=j;
                d=i;
                n-=d;
                n--;
                break;
            }
        }
        }
        if(c!=1000000)
            break;
    }
    if(c!=1000000){
        long long a=n/(d-c+1),b=sum[d]-sum[c-1];
        ans+=a*b;
        n%=(d-c+1);
        for(int i=c;i<n+c;i++){
            ans+=l[i];
        }
    }
    cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 5192
#include "iostream"
using namespace std;
int main(){
  int a,b,x;
  cin>>a>>b>>x;
  if((x<a)||(x>(a+b))||((x==(a+b))&&(x!=a))){
    cout<<"NO"<<endl;
  }
  else{
    cout<<"YES"<<endl;
  }
}


Measured memory_bytes: 3608
#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>;

struct Edge {
    int to, id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
    int k = 1;
    rep(i,g[v].size()) {
        int u = g[v][i].to, ei = g[v][i].id;
        if (u == p) continue;
        if (k == c) k++;
        ans[ei] = k; k++;
        dfs(u,ans[ei],v);
    }
}

int main() {
    int n;
    cin >> n;
    g.resize(n);
    ans.resize(n-1);
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back((Edge){b,i});
        g[b].push_back((Edge){a,i});
    }
    dfs(0);
    int mx = 0;
    rep(i,n) mx = max(mx, int(g[i].size()));
    cout << mx << endl;
    rep(i,n-1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 11112
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long K, ans =0;
  cin >> K;

  long long vec[K];
  map<long long, long long> m;
   
  for(int i = 0; i < K; i++){
    cin >> vec[i];
    //cout << "ak";
    m[vec[i]]++;
  }

  long long sum =0;
  for(int j =0; j < m.size(); j++){
    sum += m[j]*(m[j]-1)/2;
  }

  for(int i = 0; i < K; i++){
    /*m[vec[i]]--;
    
    for(int j =0; j < m.size(); j++){
      ans += (m[j]*(m[j]-1))/2;
    }
    m[vec[i]]++;
    
    cout << ans << endl;
    ans = 0;
  }*/
  //ans = (sum - (m[vec[i]] -1));
  ans = sum - m[vec[i]]*(m[vec[i]]-1)/2 + (m[vec[i]]-1)*(m[vec[i]]-2)/2;
  cout << ans << endl; 
  ans = 0;

}

}


Measured memory_bytes: 16256
#include <iostream>
#include <math.h>
using namespace std;
int main() {
	int N, D, n, x, y;
	double r;
	n = 0; N = 0; D = 0;
	cin >> N >> D;

	for (int i = 0; i < N; i++) {
		x = 0; y = 0;
		cin >> x >> y;
		r = 0;
		r = sqrt(pow(x,2) + pow(y,2));
		if (r <= D) {
			n += 1;
		}
		else {
			n += 0;
		}
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 3632
def main():
    X = int(input())
    Y = 2*int(X**(1/5))+1
    for A in range(-Y,Y):
        for B in range(-Y,Y):
            if A**5 - B**5==X:
                return A,B

if __name__ == "__main__":
    A,B=main()
    print("{} {}".format(A,B))

Measured memory_bytes: 9376
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

struct UnionFind {
    vector<int> par;
    int n, cnt;
    UnionFind(const int& x = 0) {init(x);}
    void init(const int& x) {par.assign(cnt=n=x, -1);}
    inline int find(const int& x) {return par[x] < 0 ? x : par[x] = find(par[x]);}
    inline bool same(const int& x, const int& y) {return find(x) == find(y);}
    inline bool unite(int x, int y) {
        if ((x = find(x)) == (y = find(y))) return false;
        --cnt;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    inline int count() const {return cnt;}
    inline int count(int x) {return -par[find(x)];}
};

struct Edge {
    int u;
    int v;
    double cost;
    Edge() {}
    Edge(int u, int v, double cost) : u(u), v(v), cost(cost) {}
    bool operator<(const Edge& rhs) const {return cost < rhs.cost;}
};

int square(int x) {return x*x;}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++)
        cin >> X[i] >> Y[i];
    vector<Edge> es;
    double sum = 0;
    for (int i = 0; i < M; i++) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        es.emplace_back(p, q, sqrt(square(X[p]-X[q])+square(Y[p]-Y[q])));
        sum += es.back().cost;
    }
    sort(es.rbegin(), es.rend());
    double minus = 0;
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        Edge e = es[i];
        if (uf.same(e.u, e.v)) continue;
        uf.unite(e.u, e.v);
        minus += e.cost;
    }
    printf("%.10lf\n", sum-minus);
    return 0;
}

Measured memory_bytes: 3480
#include<iostream>
#include<vector>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> d(n);

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

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

  int ans;

  ans=(d[n/2]-d[n/2-1]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640