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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 507;

int n;
int x[MAXN];
int a[MAXN*MAXN];
int cc[MAXN];
int ord[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d", &x[i] );
}

void work ()
{
	// main work
	
	lpi ( i, 1, n ) ord[i] = i;
	sort ( ord+1, ord+1+n, [] ( int i, int j ) { return x[i] < x[j]; } );
	
	bool flag = false;
	lpi ( i, 1, n ) cc[i] = i - 1;
	
	int nk = 0, ni = 1;
	lpi ( i, 1, n ){
		while ( nk < x[ord[i]] - 1 ){
			while ( !cc[ord[ni]] ){
				++ni;
				if ( ni > n ){
					if ( !flag ) flag = true, ni = 1;
					else{
						printf ( "No\n" );
						return;
					}
				}
			}
			a[++nk] = ord[ni];
			--cc[ord[ni]];
		}
		if ( cc[ord[i]] ){
			printf ( "No\n" );
			return;
		}
		a[++nk] = ord[i];
		cc[ord[i]] = n - ord[i];
		if ( ni == i ) ++ni;
	}
	
	lpi ( i, 1, n ) while ( cc[i] ) a[++nk] = i, --cc[i];
	
	printf ( "Yes\n" );
	lpi ( i, 1, n*n ) printf ( "%d ", a[i] );
	putchar ( '\n' );
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(){
	/*string str,str2;
	cin>>str>>str2;
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	(str==s)?cout<<a-1<<" "<<b:cout<<a<<" "<<b-1;*/
	
	/*string str;
	cin>>str;
	int n = str.size();
	for(int i = 0;i<n;i++)
		cout<<'x';*/
		
	/*int n;
	cin>>n;
	set<int> s;
	for(int i = 0;i<n;i++){
		int a;
		cin>>a;
		if(s.find(a)==s.end()){
			s.insert(a);
		}else{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";*/
	
	int n,m;
	cin>>n>>m;
	float arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	
	double ans = 0,k = 0;
	for(int i =0;i<m;i++){
		ans = ans + (arr[i]+1)/2;
	}
	//cout<<ans<<endl;
	k = ans;
	for(int i=m;i<n;i++){
		k = k - (arr[i-m]+1)/2 + (arr[i]+1)/2;
		ans = max(k,ans);
		//cout<<k<<endl;
	}
	printf("%.7f",ans);
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{   int n,m,i,j,s=0;
    char a[105][105];
    cin>>n>>m;
    for(i=1;i<=n;i++)
      for(j=1;j<=m;j++)cin>>a[i][j];
    for(i=1;i<=n;i++)
    {  for(j=1;j<=m;j++)
      {  if(a[i][j]=='#')cout<<a[i][j];
           else {  if(a[i-1][j-1]=='#')s++;
                   if(a[i-1][j]=='#')s++;
                   if(a[i-1][j+1]=='#')s++;
                   if(a[i][j+1]=='#')s++;
                   if(a[i+1][j+1]=='#')s++;
                   if(a[i+1][j]=='#')s++;
                   if(a[i+1][j-1]=='#')s++;
                   if(a[i][j-1]=='#')s++;
                   cout<<s;
                   s=0;
                }
      }
      cout<<endl;
    }
    return 0;
}	

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N, K;
    int sum = 0;
    cin >> N >> K;
    int l[N];
    for (int i = 0; i < N; i++) {
        cin >> l[i];
    }

    sort(l, l + N, greater<int>());

    for (int i = 0; i < K; i++) {
        sum += l[i];
    }

    cout << sum << endl;
    return 0;
}
         

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			int[][] a = new int[1000][2];
			int count=0;
			int max = 0;
			while(true){
				a[count][0]=cin.nextInt();
				a[count][1]=cin.nextInt();
				if(a[count][0]+a[count][1]==0){
					break;
				}
				max = Math.max(Math.max(max, a[count][0]),a[count][1]);
				count++;
			}
			max++;
			int edgeCount=count;
			int[][] field = new int[max][max];
			for(int i = 0; i < count;i++){
				field[a[i][0]][a[i][1]]++;
				field[a[i][1]][a[i][0]]++;
				//System.out.println(a[i][0]+" " + a[i][1]);
			}
			int i;
			for(i = 1; i < field.length;i++){
				int edge=0;
				for(int j = 1; j < field.length;j++){
					//System.out.print(field[i][j]);
					edge+=field[i][j];
				}
				
				//System.out.println(edge);
				if(i==1||i==2){
					if(edge%2==0){
						System.out.println("NG");
						break;
					}
				}
				else{
					if(edge%2==1){
						System.out.println("NG");
						break;
					}
				}
			}
			if(i==field.length)
				System.out.println("OK");
			
		}
	}

}

Measured memory_bytes: 12000
# 3 つの整数 A, B, Cが与えられます。
# A, B, C のうち 2つは 同じ整数であり、
# 残りの 1つだけ異なる整数です。
# 例えば、A = 5, B = 7, C = 5の場合、
# A, C の 2つは同じ整数であり、
# B は 1つだけ異なる整数です。
# 3つの整数のうち、1つだけ異なる整数を求めてください。

# 制約
# -100 ≦ A, B, C ≦ 100
# A, B, C は整数
# 入力は問題文の条件を満たす

# 標準入力から A, B, C の値を取得する
a, b, c = map(int, input().split())

# 異なる整数を探して出力する
result = 0

if a == b:
    result = c
elif b == c:
    result = a
elif a == c:
    result = b
else:
    result = "Error"

print(result)


Measured memory_bytes: 9060
package main

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

func main() {
	scanner := Scanner()
	l := ReadInt(scanner)
	r := ReadInt(scanner)
	d := ReadInt(scanner)

	count := 0
	for i := l; i <= r; i++ {
		if i%d == 0 {
			count++
		}
	}
	fmt.Println(count)
}

func Scanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func ReadInt(scanner *bufio.Scanner) int {
	var t string

	if scanner.Scan() {
		t = scanner.Text()
	}

	n, err := strconv.Atoi(t)
	if err != nil {
		log.Fatal(err)
	}

	return n

}


Measured memory_bytes: 1832
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<ll, pair<ll,ll>>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define MOD 1000000007
//           123456789

ll x;

int main() {
    cin >> x;
    (x == 0) ? cout << 1 << endl : cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main() {
	int r, c, k; cin >> r >> c >> k;
	vector< vector < char > >  v(r, vector < char >(c));
	for (int i = 0; i < r; ++i)
		for (int j = 0; j < c; ++j)
			cin >> v[i][j];
	
	int ans = 0;
	for (int i = 0; i < (1 << r); ++i) {
		auto v2 = v;
		for (int j = 0; j < r; ++j) {
			if ((1 << j) & i) {
				for (int z = 0; z < c; z++)
					v2[j][z] = 'r';
			}
		}
		for (int i1 = 0; i1 < (1 << c); ++i1) {
			auto v3 = v2;
			for (int j = 0; j < c; ++j) {
				if ((1 << j) & i1) {
					for (int z = 0; z < r; z++)
						v3[z][j] = 'r';
				}
			}
		int cnt = 0;
		for (auto it : v3)
			for (char ch : it)
				if (ch == '#') ++cnt;
		if (cnt == k) ++ans;
		}
	}
	cout << ans;
		return 0;
}



Measured memory_bytes: 3568
N = int(input())
M,A,R,C,H = ([] for i in range(5))
for i in range(N):
    s = input()
    if s[0] == "M":
        M.append(s)
    if s[0] == "A":
        A.append(s)
    if s[0] == "R":
        R.append(s)
    if s[0] == "C":
        C.append(s)
    if s[0] == "H":
        H.append(s)
x = [len(M),len(A),len(R),len(C),len(H)]
ans = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += x[i]*x[j]*x[k]
print(ans)

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

using namespace std;

#define IOS ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);

#define endl "\n";


#define mod 1000000007
#define loop(i,s,n)  for(ll i=s;i<n;i++)
#define test  ll t; cin>>t; while(t--)
#define p push_back
typedef long long ll;
int main()
{IOS

ll n;
cin>>n;
if(n>=30)
{cout<<"Yes";}
else{cout<<"No";}


return 0;
}


Measured memory_bytes: 3608
void main() {
	auto ip = readAs!(int[]), N = ip[0], M = ip[1];
	auto A = readMatrix!char(N, N);
	auto B = readMatrix!char(M, M);
	bool ok = false;

	foreach(ly; 0..N-M+1) {
		foreach(lx; 0..N-M+1) {
			bool match = true;
			foreach(y; 0..M) foreach(x; 0..M) {
				if(A[ly+y][lx+x] != B[y][x]) match = false;
			}
			if(match) ok = true;
		}
	}
	(ok ? "Yes" : "No").writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
def gen_d_prim(n):
    D = [0] * (n+1)
    for i in range(2, n+1, 2): D[i] = 2
    for i in range(3, n+1, 2):
        if D[i] > 0: continue
        for j in range(i, n+1, i): D[j] = i
    return D

def is_pairwise(A):
    D = gen_d_prim(10**6)
    past = set()
    for a in A:
        now = set()
        while a != 1:
            # 素数 D[a]: 今回は未済 & 過去で済
            if not D[a] in now and D[a] in past: return False
            now.add(D[a])
            past.add(D[a])
            a //= D[a]
    return True

def gcd_all(A):
    from math import gcd
    g = 0
    for a in A: g = gcd(g, a)
    return g

def solve():
    if is_pairwise(A): return 0
    if gcd_all(A) == 1: return 1
    return 2

n = int(input())
A = [*map(int, input().split())]
print(['pairwise','setwise','not'][solve()], 'coprime')


Measured memory_bytes: 127268
#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  size_t n; std::cin >> n;
  auto a = std::vector<boost::dynamic_bitset<>>(n + 2, boost::dynamic_bitset<>(n + 2));
  auto insert = [&] (size_t i, size_t j, bool k) {
    a[i][j] = k;
    a[j][i] = !k;
  };
  for (size_t i = 1; i <= n; i++) {
    insert(i, 0, true);
    insert(i, n + 1, true);
  }
  for (size_t i = 2; i <= n; i++) {
    for (size_t j = 1; j < i; j++) {
      char x; std::cin >> x;
      insert(i, j, x == '1');
    }
  }
  auto dp = std::vector<boost::dynamic_bitset<>>(n + 2, boost::dynamic_bitset<>(n + 2));
  for (size_t i = 0; i <= n; i++) dp[i][i + 1] = dp[i + 1][i] = true;
  for (size_t d = 2; d <= n + 1; d++) {
    for (size_t i = 0, j = d; j <= n + 1; i++, j++) {
      dp[j][i] = dp[i][j] = (dp[i] & dp[j] & (a[i] | a[j])).any();
    }
  }
  int ret = 0;
  for (size_t i = 1; i <= n; i++) {
    if (dp[0][i] & dp[i][n + 1]) ret++;
  }
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n;
   int cnt = 0;
   cin >> n;
   vector<int> v(n);
   vector<int> v2;
   for(int i=0;i<n;i++)cin >> v[i];
   for(int i=0;i<n-1;i++){
       if(v[i] >= v[i+1])cnt++;
       else{
           v2.push_back(cnt);
           cnt = 0;
       }
   }
   v2.push_back(cnt);
   sort(v2.begin(),v2.end());
   cout << v2[v2.size()-1] << endl;
}

Measured memory_bytes: 4144
#include <iostream>
#include <string>
#include <vector>

using namespace std;


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

	cout << n * (n + 2 * l - 1) / 2 - (l > 0 ? l : (l + n - 1 > 0 ? 0 : l + n - 1));
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n, i, j, tmp;

    scanf("%d", &n);

    int A[n];

    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }

    for(i = 0; i < n; i++){
        tmp = A[i];
        for(j = i - 1; -1 < j && tmp < A[j]; j--){
            A[j + 1] = A[j];
        }
        A[j + 1] = tmp;

        for(j = 0; j < n; j++){
            printf("%d", A[j]);
            if(j != n - 1) printf(" ");
        }

        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2052
// clang-format off
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <iomanip>
#include <queue>
#include <map>

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

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T>& p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T>& vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
constexpr ll MOD = 1000000007;

int N, K;
constexpr int MAX = 5000;
ll a[MAX];
ll cnt = 0;
bool func(int i){
            vector<vector<bool>> check(N, vector<bool>(K, false)); // a[0]~a[j](a[i]除く)でL(L < K)が作れるか(ざこい)
        rep(l, K){
            check[0][l] = false;           
        }
        check[0][0] = true;
        if(i != 0){
            if(a[0] < K){
                check[0][a[0]] = true;
            }
        }
        rep1(j, N-1){
            if(i == j){
                rep(l, K){
                    check[j][l] = check[j-1][l];
                }
            } else {
                rep(l, K){
                    if(l >= a[j]){
                        if(check[j-1][l-a[j]]){
                            check[j][l] = true;
                            continue;
                        }
                    }
                    if(check[j-1][l]){
                        check[j][l] = true;
                        continue;
                    }
                }
            }
        }
        ll M = (K > a[i])?K-a[i]:0;
        bool f = false;
        for(int j = M; j < K; j++){
            if(check[N-1][j]){
                f = true;
                break;
            }
        }
        return f;
}

int main()
{
    cin >> N >> K;
    rep(i, N){
        cin >> a[i];
    }
    sort(a,a+N);

    int min = 0;
    if(func(min)){
        cout << 0 << endl;
        return 0;
    }
    int max = N;
    while(min < max){
        const int mid = (min+max)/2;
        if(func(mid)){
            max = mid;
        } else {
            if(min == mid){
                break;
            } else {
                min = mid;
            }
        }
    }

    // rep(i, N){
    //     func(i);
    // }
    cout << min +1 << endl;
    
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n,m;cin>>n>>m;

  vector<pair<pair<int,int>,int>> a(m);
  rep(i,m){
    cin>>a[i].fi.fi>>a[i].fi.se; 
    a[i].se = i;
  }
  sort(all(a));
  vector<pair<int,pair<int,int>>> ans(m);
  int cnt = 1;
  int tmp = -1000;
  rep(i,m){
    cnt++;
    ans[i].fi = a[i].se;
    ans[i].se.fi = a[i].fi.fi;
    if(ans[i].se.fi != tmp){
      cnt = 1;
      tmp = ans[i].se.fi;
    }
    ans[i].se.se = cnt;
  }
  sort(all(ans));
  rep(i,m){
    printf("%06d",ans[i].se.fi);
    printf("%06d\n",ans[i].se.se);
  }
  return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
#define N 100005

int n;
int ans,sum;
int a[N];

int main()
{
	
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++)
		if(a[i]>0) ans+=a[i];
		      else ans-=a[i];
	if(a[0]>0) ans-=a[0]*2;
	if(a[n-1]<0) ans+=a[n-1]*2;
	cout<<ans<<'\n';
	if(a[0]>0)
	{
		sum=a[0];
		for(int i=1;i<n-1;i++)
		{
			cout<<sum<<" "<<a[i]<<'\n';
			sum-=a[i];
		}
		cout<<a[n-1]<<" "<<sum<<'\n';
	}
	else if(a[n-1]<0)
	{
		sum=a[n-1];
		for(int i=n-2;i>=0;i--)
		{
			cout<<sum<<" "<<a[i]<<'\n';
			sum-=a[i];
		}
	}
	else
	{
		int i;
		sum=a[0];
		for(i=n-2;i>=0 && a[i]>0;i--)
		{
			cout<<sum<<" "<<a[i]<<'\n';
			sum-=a[i];
		}
		cout<<a[n-1]<<" "<<sum<<'\n';
		sum=a[n-1]-sum;
		for(;i>=1;i--)
		{
			cout<<sum<<" "<<a[i]<<'\n';
			sum-=a[i];
		}
	}
	
	return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int MOD = 1e9 + 7;

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

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

	if (d == 0) {
		cout << fixed;
		cout << setprecision(10) << 1. * 2 * (n - d)*(m - 1) / pow(n, 2) / 2 << endl;
	}
	else {
		cout << fixed;
		cout << setprecision(10) << 1. * 2 * (n - d)*(m - 1) / pow(n, 2) << endl;
	}
}

Measured memory_bytes: 256
$UFT = Array.new(100)
0.upto(100) do |i|
  $UFT[i] = i
end

def root(x)
  if ($UFT[x] == x)
    x
  else
    $UFT[x] = root($UFT[x])
    $UFT[x]
  end
end

def unite(x, y)
  $UFT[root(x)] = root(y)
end

def same(x, y)
  puts (root(x) == root(y) ? "1" : "0")
end

n = gets.to_i
graph = n.times.map{ gets.split.map(&:to_i) }
bridge = []
total = 0

n.times do |i|
  0.upto(i-1) do |j|
    cost = graph[i][j]
    next if cost == -1
    bridge << [cost, i, j]
  end
end

bridge.sort!.each do |cost, i, j|
  unless root($UFT[i]) == root($UFT[j])
    total += cost
    unite(i, j)
  end
end

puts total

Measured memory_bytes: 6184
package main

import "fmt"

var a, b, c, d int

func main() {
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)

	if Abs(a-c) <= d || Abs(a-b) <= d && Abs(b-c) <= d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func Abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}


Measured memory_bytes: 512
from bisect import bisect_left, bisect_right


def main():
    n = int(input())
    aa = sorted(map(int, input().split()))
    bb = sorted(map(int, input().split()))
    cc = sorted(map(int, input().split()))
    res = 0
    for b in bb:
        i_a = bisect_left(aa, b)
        i_c = bisect_right(cc, b)
        res += i_a * (n - i_c)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    int count_yoko=tx-sx;
    int count_tate=ty-sy;
    for(int i=0;i<count_tate;i++) cout << "U";
    for(int i=0;i<count_yoko;i++) cout << "R";
    for(int i=0;i<count_tate;i++) cout << "D";
    for(int i=0;i<=count_yoko;i++) cout << "L";
    for(int i=0;i<=count_tate;i++) cout << "U";
    for(int i=0;i<=count_yoko;i++) cout << "R";
    cout << "D"; cout << "R";
    for(int i=0;i<=count_tate;i++) cout << "D";
    for(int i=0;i<=count_yoko;i++) cout << "L";
    cout << "U";
    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
using namespace std;
int main(){
    int n;
    int a,b,sum=0;
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++){
        int num=0,m=i;
        while(m){
            num+=(m%10);
            m/=10;
        }
        if(num<=b&&num>=a) sum+=i;
        num=0;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
# Standard Deviation

end = 0
while end == 0:
    studentAmount = int(input())
    if studentAmount == 0:
        end += 1
    else:
        scoreData = [int(i) for i in input().rstrip().split()]
        totalScore = 0
        for score in scoreData:
            totalScore += score
        averageScore = totalScore / studentAmount
        # print('Average: ' + str(averageScore))
        totalSquareDistance = 0
        for score in scoreData:
            totalSquareDistance += (score - averageScore) ** 2
        variance = totalSquareDistance / studentAmount
        # print('Variance: ' + str(variance))
        standardDeviation = variance ** 0.5
        # print('Standard Deviation: ', end = '')
        print(str(standardDeviation))



Measured memory_bytes: 5680
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int primes[1230];
vector<int> twin_left, twin_right;

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

int main()  {

    int idx = 0, diff, id, n;
    for (int i = 2; i <= 10000; i++) if (isPrime(i)) primes[idx++] = i;
    for (int i = 1; i < idx; i++) {
        diff = primes[i] - 2;
        id = int(lower_bound(primes, primes+i, diff)-primes);
        if (id >= 0 && primes[id] == diff) twin_left.push_back(diff), twin_right.push_back(primes[i]);
    }
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        idx = int(upper_bound(twin_right.begin(), twin_right.end(), n) - twin_right.begin())-1;
        printf("%d %d\n", twin_left[idx], twin_right[idx]);
    }

    return 0;
}



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

using namespace std;

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

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

    uint64_t sum = 0;
    int max_h = A[0];
    for(int i = 1; i < n; i++) {
        if(A[i] > max_h) {
            max_h = A[i];
            continue;
        }
        if(A[i] < max_h) {
            sum += (max_h - A[i]);
        }
    }
    cout << sum << '\n';
}

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

    solve();
    return 0;    
}

Measured memory_bytes: 4380
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set;

public class Main implements Runnable {

	Set<Integer> set = new HashSet<>();
	int max = 0;

	public static void main(String[] args) {

		new Thread(null, new Main(), "", 16 * 1024 * 1024).start();

	}

	@Override
	public void run() {
		exec();
	}

	private void exec() {

		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n - 1];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = 0 ; i < n ; i++) {
			b[i] = sc.nextInt();
		}
		for(int i = 0 ; i < n - 1 ; i++) {
			c[i] = sc.nextInt();
		}

		int ans = 0;
		int pre = -1;
		for(int i = 0 ; i < n ; i++) {
			ans += b[a[i] - 1];
			if(a[i] == pre + 1) {
				ans += c[pre - 1];
			}
			pre = a[i];
		}

		System.out.println(ans);

	}

}

class FastScanner {

	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	public FastScanner(InputStream in) {
		this.in = in;
	}

	private boolean hasNextByte() {
		if(ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if(buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if(hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while(hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

}


Measured memory_bytes: 24660
#include<stdio.h>
int main(){
  int h,m,s,s3,m3,h3;
  while(1){
    scanf("%d %d %d",&h,&m,&s);
    if(h==-1&&m==-1&&s==-1)break;
    m+=60*h;
    s+=60*m;
    s=(120*60)-s;
    s3=3*s;
    h=s/3600;
    h3=s3/3600;
    s%=3600;
    s3%=3600;
    m=s/60;
    m3=s3/60;
    s%=60;
    s3%=60;
    printf("%02d:%02d:%02d\n%02d:%02d:%02d\n",h,m,s,h3,m3,s3);
  }
  return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,p;
    string s;
    cin>>n>>p;
    cin>>s;
    if(10%p==0){
        ll ans=0;
        rep(i,n){
            if((s[i]-'0')%p==0) ans+=i+1;
        }
        cout<<ans<<endl;
        return 0;
    }
    
    vector<ll> cnt(p,0);
    ll ten=1;
    ll a=0;
    cnt.at(a)++;
    for(int i=0;i<n;i++){
        a=((s[n-1-i]-'0')*ten+a)%p;
        ten=(ten*10)%p;
        cnt[a]++;
    }
    ll ans=0;
    for(int i=0;i<p;i++)ans+=cnt.at(i)*(cnt.at(i)-1)/2;
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#define pb push_back

const int N = (int)1e5 + 7;

int n, m;

vector < int > v[N];
int used[N];
int pr[N];

int get_dsu (int a) {
    if (pr[a] == a) return a;
    return pr[a] = get_dsu(pr[a]);
}

void connect (int a, int b) {
    a = get_dsu(a);
    b = get_dsu(b);
    if (a != b) {
        pr[a] = b;
    }
}

main() {
    scanf ("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
        pr[i] = i;
        int k; scanf ("%d", &k);
        for (int j = 1; j <= k; j++) {
            int x; scanf ("%d", &x);
            v[x].pb(i);
        }
    }
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j < v[i].size(); j++) {
            connect(v[i][j - 1], v[i][j]);
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        if (pr[i] == i) res++;
        if (res > 1) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}


Measured memory_bytes: 4608
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    cnt=0
    for i in range(N-2):
        l1=A[i]
        for j in range(i+1,N-1):
            l2=A[j]
            for k in range(j+1,N):
                l3=A[k]

                if abs(l1-l2)<l3<l2+l1 and l1!=l2 and l2!=l3 and l3!=l1:
                    cnt+=1
    print(cnt)



if __name__ == "__main__":
    main()

Measured memory_bytes: 73076
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	string s;
	cin>>s;
	int cnt=0;
	for(int i=0;i<=2;i++){
		if(s[i]=='R'){
			cnt++;
		}
	}
	if(cnt==0){
		cout<<0;
	}
	else if(cnt==1){
		cout<<1;
	}
	else if(cnt==2){
		if(s[1]=='R'){
			cout<<2;
		}
		else{
			cout<<1;
		}
	}
	else{
		cout<<3; 
	}
	return 0;
}


Measured memory_bytes: 3624
var f = [];
 
function main(){
  var localInput = input;
  
  for(var y=-2;y<12;y++){
    f[y] = [];
    for(var x=-2;x<12;x++){
      f[y][x] = 0;// initialize:undefined -> 0
    }
  }
 
  var len = localInput.length - 1;
  for(;len--;){
    var l = localInput[len];
    eval("d"+localInput[len][4]+"("+localInput[len][0]+","+localInput[len][2]+");");
  }
 
  var nd=0;//not dropped
  var md=0;//most dropped
  var y = 10;
  for(;y--;){
    var x = 10;
    for(;x--;){
      nd += !(f[y][x]);
      md = mx(f[y][x], md);
    }
  }
 
  console.log(nd);
  console.log(md);
}
 
function d1(x, y){
  f[y+1][x]++;
  f[y][x-1]++;
  f[y][x]++;
  f[y][x+1]++;
  f[y-1][x]++;
}
 
function d2(x, y){
  d1(x, y);
  f[y+1][x-1]++;
  f[y+1][x+1]++;
  f[y-1][x-1]++;
  f[y-1][x+1]++;
}
 
function d3(x, y){
  d2(x, y);
  f[y+2][x]++;
  f[y-2][x]++;
  f[y][x-2]++;
  f[y][x+2]++;
}

function mx(a, b){
 var t = (a-b);
 return a - (t & (t >> 31));
}
 
var
input = '';
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 7644
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  string str;
  cin>>str;
  int n = str.size();
  if(str[n-1] == 's')
  {
    str += "es";
  }
  else
  {
    str += "s";
  }
  cout<<str<<"\n";
  return 0;
}

Measured memory_bytes: 3624
main = do
  [n,m] <- map read . words <$> getLine
  print (ans n m)

ans :: Integer -> Integer -> Integer
ans n m
  | abs (n - m) >= 2 = 0
  | n == m = mod' (f n * f n * 2)
  | otherwise = mod' (f n * f m)

f :: Integer -> Integer
f n
  | n == 0 = 1
  | otherwise = mod' (n * mod' (f (n - 1)))

mod' :: Integer -> Integer
mod' n = n `mod` 1000000007


Measured memory_bytes: 7292
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] buka = new int[n];
		for(int i = 0; i < n-1; i++){
		    int boss = sc.nextInt()-1;
		    buka[boss]++;
		}
		
		// 計算
		//long result = -1;
		
		
		// 出力
		for(int i = 0; i < n; i++){
		    System.out.println(buka[i]);
		}
		//System.out.println(result);
	}
}



Measured memory_bytes: 55748
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque
from collections import defaultdict

def bfs(graph:list, start:int) -> list:
    # 未探索のノードは距離null
    node = len(graph)
    dist = [None]*node
    
    # 始点ノードの距離を0とし、bfsのためのqueueを作成
    dist[start] = 0
    que = deque([(0,start)])
    
    # 未探索のノードをqueueに入れる
    # kより大きいの距離のものを数える
    while que:
        cost, cur_node = que.popleft()

        for nex_cost, nex_node in graph[cur_node]:
            if dist[nex_node] is not None:
                continue
            else:
                dist[nex_node] = dist[cur_node] + nex_cost
                que.append((dist[nex_node], nex_node))
                
    return dist
  
# 入力, グラフ作成
n,k = li()
adj_list = [[] for _ in range(n)]
edges = []
for _ in range(n-1):
    a,b = li_()
    adj_list[a].append((1,b))
    adj_list[b].append((1,a))
    edges.append((a,b))

ans = n
dists = []
for i in range(n):
    dists.append(bfs(adj_list, i))
# kが奇数の時
if k%2:
    for a,b in edges:
        ans = min(ans, sum([min(d1,d2) > (k-1)//2 for d1,d2 in zip(dists[a], dists[b])]))
    
# kが偶数の時
else:
    for st in range(n):
        ans = min(ans, sum([d > k//2 for d in dists[st]]))

print(ans)

Measured memory_bytes: 132316
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;



int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << ' ' << y << ' ' << z;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int a, b, c;
  cin >> a >> b >> c;
  c -= (a - b);
  if (c < 0) c = 0;
  cout << c;
}
#endif


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
const int RANDOM1 = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
    int operator()(int x) const { return hash<int>{}(x ^ RANDOM1); }
};
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define deb(x) cout<<#x<<" : "<<x<<"\n";
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define all(a) (a).begin(),(a).end()
#define bs binary_search
#define sz size()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define clr fflush(stdout)
//#define clr cout.flush();
#define N 100001
#define fpr(i,a,b) for(int i=a;i<b;i++)
#define fdr(i,a,b) for(int i=a;i>b;i--)
#define repp(i,a,b,d) for(int i=a;i<b;i+=d)
#define repd(i,a,b,d) for(int i=a;i>b;i-=d)
#define LLMIN LLONG_MIN
#define LLMAX LLONG_MAX
#define AKASH_PATEL ios_base::sync_with_stdio(false);
#define SVNIT_SURAT cin.tie(NULL);cout.tie(NULL);
#define mset(x,a) memset(x,a,sizeof(x));
#define nl cout<<'\n';
#define print(c) cout<<c<<'\n';
#define setp(n) cout << fixed << setprecision(n)
#define take_arr(a,n) fpr(i,0,n) cin>>a[i];
#define print_arr(a,n) for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';
#define take_mat(mat,n,m) fpr(i,0,n) fpr(j,0,m) cin>>mat[i][j];
#define set_mat(mat,n,m,k) fpr(i,0,n) fpr(j,0,m) mat[i][j]=k;
#define print_mat(dist,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
int main()
{
    AKASH_PATEL;
    SVNIT_SURAT;
    string s;
    cin>>s;
    int c=0;
    fpr(i,0,s.size())
    {
        if(s[i]=='A')
        {
            c++;
        }
    }
    if(c==0 || c==s.sz)
    {
        print("No")
    } else{
        print("Yes")
    }
    return 0;
}





Measured memory_bytes: 256
from fractions import gcd


def lcm(x, y):
    return x // gcd(x, y) * y


N, M = map(int, input().split())
S = input()
T = input()

for i in range(N):
    if M * i % N == 0 and S[i] != T[M * i // N]:
        print(-1)
        exit()
print(lcm(N, M))

Measured memory_bytes: 5344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  vector<string> d(n);
  int len[n], check = 0;
  for(int i=0; i<n; i++) {
    cin >> s[i];
    len[i] = 0;
  }
  sort(s.begin(), s.end());
  d[0] = s[0];
  len[0] = 1;
  int mx = 0;
  for(int i=1; i<n; i++) {
    if (d[check] != s[i]) {
      check++;
      d[check] = s[i];
    }
    len[check]++;
    mx = max(mx, len[check]);
  }
  for(int i=0; i<n; i++) {
    if(len[i] == mx) {
      cout << d[i] << endl;
    }
  }
} 

Measured memory_bytes: 12160
def main():
    N, M = map(int, input().split(' '))
    Ks = [list(map(int, input().split(' ')))[1:] for _ in range(N)]
    
    duplicated = set(Ks[0])
    for i in range(1, len(Ks)):
        a = set(Ks[i])
        duplicated = duplicated & a

    print(len(duplicated))


    
main()

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

using namespace std;

#define watch(x) cout << (#x) << " is " << (x) << endl

typedef unsigned long long int ll;
typedef long double ld;
typedef long int li;
const int inf=1e9+5;

int main()
{
    // clock_t tStart = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    int k;cin>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector<int> dp(n,inf);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<i+k+1;j++)
        {
            if(j<n)
            {
                dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
    // prllf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 1024
def main():
    w = input()
    cnt = {}
    for c in w:
        if c not in cnt:
            cnt[c] = 0
        cnt[c] += 1
    for k in cnt:
        if cnt[k] % 2 == 1:
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>	
 
#define f first
#define s second
#define pb push_back
 
#define ll long long
 
#define int ll
 
#define mp make_pair
  
using namespace std;
                       
 
const int inf = 1e9 + 7;
 
const ll ll_inf = 1e18 + 7;
const int K = 2e5;
const int N = 2e3 + 300;
                                         
ll binpow (ll a, ll n)
{
    ll res = 1;
    while (n) {
        if (n & 1)
        {
            res *= a;
            res %= inf;
        }      	
        a *= a;
        n >>= 1;
        a %= inf;
    }                          
    return res;
}   
          
  
 
void boost()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}  

int ans;

int n,a[N],dp[N][N];

vector<pair<int,int> >v;

main()
{
	cin >> n;
	for (int i = 0;i < n;++i)
	{
		cin >> a[i];
		v.pb(mp(a[i],i));
	}               
 	sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
 	for (int i = 0;i < n;++i) 
 	{
        for(int l = 0;l <= i;++l) 
        {
        	int r = i - l;
            dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + v[i].f * abs(v[i].s - l));
            dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + v[i].f * abs(n - 1 - r - v[i].s));
        }
    }
                
                   
   	for (int i = 0;i <= n;++i)
        ans = max(ans, dp[i][n - i]);
 
    cout << ans << endl;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)

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

	cout<<n*(n-1)/2<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Set;

public class Main {

    private static class Entry {
        final int id;
        final long cost;
        
        Entry(int id, long cost) {
            this.id = id;
            this.cost = cost;
        }
    }

    public static void main(String[] args) throws IOException {
        int[][] costs;
        List<List<Entry>> links = new ArrayList<>();
        int n, m;
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
            String[] array;
            array = in.readLine().split(" ");
            n = Integer.parseInt(array[0]);
            m = Integer.parseInt(array[1]);
            
            for (int i = 0; i < n; ++i) {
                links.add(new ArrayList<>());
            }

            for (int i = 0; i < m; ++i) {
                array = in.readLine().split(" ");
                int l = Integer.parseInt(array[0]) - 1;
                int r = Integer.parseInt(array[1]) - 1;
                int c = Integer.parseInt(array[2]);
                
                links.get(r).add(new Entry(l, c));
            }
        }
        
        BitSet closed = new BitSet();
        PriorityQueue<Entry> h = new PriorityQueue<>(Comparator.comparingLong(e -> e.cost));
        h.add(new Entry(n - 1, 0));
        while (!h.isEmpty()) {
            Entry e = h.poll();
            
            int n1 = e.id;
            if (closed.get(n1)) {
                continue;
            }
            closed.set(n1);
            if (n1 == 0) {
                System.out.println(e.cost);
                System.exit(0);
            }

            long c1 = e.cost;
            for (Entry e2 : links.get(n1)) {
                int n2 = e2.id;
                if (closed.get(n2)) {
                    continue;
                }
                long c2 = e2.cost;
                h.add(new Entry(n2, c1 + c2));
            }
            
            int n3 = n1 + 1;
            if (n3 < n) {
                if (!closed.get(n3)) {
                    h.add(new Entry(n3, c1));
                }
            }
        }
        System.out.println(-1);
    }
}


Measured memory_bytes: 60828
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

void main() {
    int d, g;
    scan(d, g);

    auto p = new int[](d);
    auto c = new int[](d);

    foreach (i ; 0 .. d) {
        scan(p[i], c[i]);
    }

    int ans = 1<<30;

    foreach (s ; 0 .. (1<<d)) {
        int score;
        int toita;

        foreach (i ; 0 .. d) {
            if (s & (1<<i)) {
                score += 100*(i+1)*p[i];
                score += c[i];
                toita += p[i];
            }
        }

        foreach_reverse (i ; 0 .. d) {
            if (score >= g) {
                break;
            }
            if (s & (1<<i)) {
                continue;
            }
            int t = min(p[i], (g - score + (i+1)*100 - 1) / ((i+1)*100));
            score += t*(i+1)*100;
            toita += t;
        }

        ans = min(ans, toita);
    }

    writeln(ans);
}




























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#define PI 3.14159265358979323846
using namespace std;
int main()
{
	double r;
	cin >> r;
	printf("%.6f %.6f\n", r*r*PI, 2*r*PI);
    return 0;
}

Measured memory_bytes: 1240
import numpy as np
n,avea=tuple(map(lambda x:int(x),input().split()))
x=list(map(lambda x:int(x), input().split()))
x=np.array(x)
x=x-avea
w=max(abs(min(x)),abs(max(x)))*n
dp=np.zeros((n+1,2*w+1),dtype=int)
dp[0,w]=1
for i in range(1,n+1):
    for j in range(2*w+1):
        if 0<=j-x[i-1]<=2*w:
            dp[i,j]=dp[i-1,j]+dp[i-1,j-x[i-1]]
        else:
            dp[i,j]=dp[i-1,j]
print(dp[n,w]-1)


Measured memory_bytes: 15040