akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cctype> // isdigit
using namespace std;

#define MAX 10000

// ¡fÌ\¢Ì
struct Complex{int real,imag;};
Complex operator+(Complex a, Complex b)
{
  Complex c;
  c.real = a.real + b.real;
  c.imag = a.imag + b.imag;
  return c;
}
Complex operator-(Complex a, Complex b)
{
  Complex c;
  c.real = a.real - b.real;
  c.imag = a.imag - b.imag;
  return c;
}
Complex operator*(Complex a, Complex b)
{
  Complex c;
  c.real = a.real*b.real - a.imag*b.imag;
  c.imag = a.real*b.imag + a.imag*b.real;
  return c;
}

// ðÍÉg¤\¢Ì
struct Result{Complex value;int pos;};

bool overflow;

// vg^Cvé¾
bool isOverflow(Complex);
Complex calculate(string expression);
Result equation(string expression,int pos);
Result factor(string expression,int pos);
Result term(string expression,int pos);

// Ö
bool isOverflow(Complex c)
{
  return c.real<-MAX || MAX<c.real || c.imag<-MAX || MAX<c.imag;
}

Complex calculate(string expression)
{
  return equation(expression,0).value;
}
Result equation(string expression,int pos)
{
  Result r=factor(expression,pos);
  // Á¸Z
  while(expression[r.pos]=='+' || expression[r.pos]=='-'){
    Result _r=factor(expression,r.pos+1);
    if(expression[r.pos]=='+')r.value = r.value + _r.value;
    if(expression[r.pos]=='-')r.value = r.value - _r.value;
    r.pos=_r.pos;
    if(!overflow)overflow = isOverflow(r.value);
  }
  return r;
}
Result factor(string expression,int pos)
{
  Result r=term(expression,pos);
  // æZ
  while(expression[r.pos]=='*' || expression[r.pos]=='/'){
    Result _r=term(expression,r.pos+1);
    if(expression[r.pos]=='*')r.value = r.value * _r.value;
    r.pos=_r.pos;
    if(!overflow)overflow = isOverflow(r.value);
  }
  return r;
}
Result term(string expression,int pos)
{
  Result r;
  // l
  if(isdigit(expression[pos])){
    Complex c;
    c.real=0;
    c.imag=0;
    r.pos=pos;
    while(isdigit(expression[pos])){
      c.real = c.real*10 + expression[pos++]-'0';
      if(!overflow)overflow = isOverflow(c);
    }
    r.value=c;
    r.pos=pos;
    if(!overflow)overflow = isOverflow(r.value);
    return r;
  }
  // i
  if(expression[pos]=='i'){
    pos++;
    r.value.real=0;
    r.value.imag=1;
    r.pos=pos;
    return r;
  }
  // Ê
  if(expression[pos]=='('){
    r=equation(expression,pos+1);
    r.pos++; // Â¶Êª
    return r;
  }
}

int main()
{
  string s;
  while(cin>>s){
    overflow=false;
    Complex c=calculate(s);
    if(overflow)puts("overflow");
    else if(c.real==0 && c.imag==0)puts("0");
    else if(c.real==0)printf("%di\n",c.imag);
    else if(c.imag==0)printf("%d\n",c.real);
    else if(c.imag<0)printf("%d%di\n",c.real,c.imag);
    else printf("%d+%di\n",c.real,c.imag);
  }
}

Measured memory_bytes: 0
n = int(input())
lst = []
for i in range(n):
    s, p = input().split()
    lst.append([s, int(p), i+1])

beta = sorted(lst, key=lambda x: x[1], reverse=True)
alpha = sorted(beta, key=lambda x: x[0])

for i in range(n):
    print(alpha[i][2])

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int N = 3010;
ll dp[N][N];


const int DEBUG = 0;


int main(void){
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  VI que(n, 0);
  REP(i, 0, n) {
    que[i] = i;
  }
  REP(i, 0, m) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    que[l] = max(que[l], r);
  }
  REP(i, 0, n - 1) {
    que[i + 1] = max(que[i + 1], que[i]);
  }
  VI zs(n + 1), os(n + 1);
  REP(i, 0, n) {
    zs[i + 1] = zs[i] + (s[i] == '0');
    os[i + 1] = os[i] + (s[i] == '1');
  }
  dp[0][0] = 1;
  REP(i, 1, n + 1) {
    int end = que[i - 1];
    int zero = zs[end + 1];
    int one = os[end + 1];
    if (DEBUG) {
      cerr << "[" << i << "]:" << zero << " " << one << endl;
    }
    REP(j, 0, i + 1) {
      ll &ret = dp[i][j];
      // adds zero
      if (j <= zero && j >= 1) {
	ret += dp[i - 1][j - 1];
	ret %= mod;
      }
      // adds one
      if (i - j <= one && j <= i - 1) {
	ret += dp[i - 1][j];
	ret %= mod;
      }
    }
    if (DEBUG) {
      cerr << "dp[" << i << "]:";
      REP(j, 0, i + 1) { cerr << " " << dp[i][j]; }
      cerr << endl;
    }
  }
  ll tot = 0;
  REP(i, 0, n) {
    tot = (tot + dp[n][i]) % mod;
  }
  cout << tot << endl;
}


Measured memory_bytes: 46592
/*
 * atcoder/abc129_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/* Mod */
#define MOD 1000000007
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}

const int MAX = 100100;
int N, M;
bool A[MAX] = {0};
mint dp[MAX] = {0};



void solve() {
  cin >> N >> M;
  int a;
  loop(n,0,N+1) A[n] = true;
  loop(m,0,M) {
    cin >> a;
    A[a] = false;
  }

  dp[0] = 1;
  for (int n=0; n<N; n++) {
    if (A[n+1]) dp[n+1] += dp[n];
    if (A[n+2]) dp[n+2] += dp[n];
  }
  cout << dp[N] << endl;
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
 
int n,m;
int As[222222];
int Bs[222222];
int main() {
	int A,B,M;
	scanf("%d%d%d", &A, &B, &M);
	ll bestAns = 1LL<<62;
	ll bestA = 1LL<<62, bestB = 1LL<<62;
	REP(i, A) {
		scanf("%d", As+i);
		bestA=min(bestA,(ll)As[i]);
	}
	REP(i, B) {
		scanf("%d", Bs+i);
		bestB=min(bestB,(ll)Bs[i]);
	}
	bestAns = bestA+bestB;
	REP(i, M) {
		int ii,j,c;
		scanf("%d%d%d", &ii,&j,&c);
		ii--;j--;
		bestAns=min(bestAns, (ll)As[ii]+Bs[j]-c);
	}
	printf("%lld\n", bestAns);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>

using namespace std;

void show(vector<int> &v, string s = "") {
	if (s.size() > 0) {
		cout << s << endl;
	}
	for (auto e : v) {
		cout << e << " ";
	}
	cout << endl;
}

int main() {
	int n, m, q;

	scanf("%d %d %d", &n, &m, &q);
	vector<int> a(q);
	for (int i = 0; i < q; i++) {
		scanf("%d", &a[i]);
		a[i]--;
	}

	reverse(a.begin(), a.end());

	vector<int> order;
	map<int, int> num_pos;
	vector<int> num_used(m, false);

	vector<int> fixed_index(n, 0);

	for (int i = 0; i < q; i++) {
// printf("a[%d] = %d\n", i, a[i]);
// show(fixed_index, "fixed_index");

		if (!num_used[a[i]]) {
			num_used[a[i]] = true;

			num_pos[a[i]] = order.size();
			order.emplace_back(a[i]);

			fixed_index.back()++;
			continue;
		}

		int pos = num_pos[a[i]];
// printf("pos %d\n", pos);
		auto it_bound = upper_bound(fixed_index.begin(), fixed_index.end(), pos);
		if (it_bound != fixed_index.begin()) {
			it_bound = prev(it_bound);
		}
// printf("it_bound %d\n", *it_bound);
		if (*it_bound == pos) {
			*it_bound += 1;
		}
	}

	// show(order, "order");
	// show(fixed_index, "fixed_index");

	for (int i = 0; i < m; i++) {
		if (!num_used[i]) {
			order.emplace_back(i);
		}
	}
	// show(order, "order");

	bool ok = true;
	for (int i = fixed_index[0]; i < order.size() - 1; i++) {
		if (order[i] > order[i+1]) {
			ok = false;
			break;
		}
	}

	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 6520
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>

#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

/*---------------------------------------------------*/

int n,m;

void solve(pi p[]){
  ll cnt=0,d=0;
  sort(p,p+n);reverse(p,p+n);
  rep(i,n){
    d+=p[i].second;
    if(p[i].second<=m){
      m-=p[i].second;
      p[i].second=0;
    }else{
      p[i].second-=m;
      m=0;
    }
    cnt+=p[i].first*p[i].second;
  }
  cout<<cnt<<endl;
}

int main(){
  while(cin>>n>>m){
    if(n==0&&m==0)break;
    pi p[n];
    rep(i,n)cin>>p[i].second>>p[i].first;
    solve(p);
  }
  return 0;
}

Measured memory_bytes: 3092
/*
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
using li = long long;
using vi = vector<li>;
using vs = vector<string>;


int main()
{
    li a,b,ans;
    cin>>a>>b;
    if(a%3==0 || b%3==0) ans=0;
    else ans=min(a,b);
    rep(i,a){
        li x[3]={b*i,(a-i)*((b/2)+(b%2)),(a-i)*(b/2)};
        sort(x,x+3);
        ans=min(ans,x[2]-x[0]);
    }
    rep(i,b){
        li x[3]={a*i,(b-i)*((a/2)+(a%2)),(b-i)*(a/2)};
        sort(x,x+3);
        ans=min(ans,x[2]-x[0]);
    }
    cout<<ans<<endl;
    
    return 0;
}

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

using namespace std;

int N, nr;
char sir[200009], stk[200009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%s", sir + 1), N = strlen (sir + 1);
for (int i=1; i<=N; i++)
{
    if (nr > 0 && stk[nr] == 'S' && sir[i] == 'T') nr --;
    else stk[++nr] = sir[i];
}
printf ("%d\n", nr);

return 0;
}


Measured memory_bytes: 1020
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        char a = sc.Next()[0];
        char b = sc.Next()[0];

        if (a < b)
        {
            Console.WriteLine(new string(a, b - '0'));
        }
        else
        {
            Console.WriteLine(new string(b, a - '0'));
        }
    }

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

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

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

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

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

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

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

int main(){
   int W,H,x,y;
   cin >> W >> H>> x >> y;
   cout << double(W)*double(H)/2;
   if(x+x==W && y+y==H){
       cout << " 1" ;
   }
   else {
       cout <<" 0";
   }
  cout <<endl;
}

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

int main()
{
  int n,tmp;
  int a[101];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n/2;i++){
    tmp=a[i];
    a[i]=a[n-1-i];
    a[n-i-1]=tmp;
  }
  for(int i=0;i<n-1;i++)cout<<a[i]<<" ";
  cout<<a[n-1]<<endl;
  return 0;
}
  

Measured memory_bytes: 1160
n, a, b = map(int, input().split())
li_x = list(map(int, input().split()))
delta = []
for i in range(1, n):
    delta.append(li_x[i]-li_x[i-1])
ans = 0
for i in  delta:
    if i*a >= b:
        ans += b
    else:
        ans += i*a
print(ans)

Measured memory_bytes: 19996
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int p[maxn];
int main(){
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> p[i];
	}
	sort(p + 1, p + n + 1);
	int ans = 0;
	for(int i = 1; i <= k; i++) ans += p[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cmath>


typedef struct{
	int t = 0;
	int x = 0;
	int y = 0;
}Data;


int main(void){

	int n;
	std::cin >> n;

	Data* data = new Data[n + 1];
	for(int i = 1; i < n + 1; i++){
		std::cin >> data[i].t >> data[i].x >> data[i].y;
	}

	Data diff;
	int i;
	for(i = 0; i < n; i++){	
		diff.t = data[i + 1].t - data[i].t;
		diff.x = std::abs(data[i + 1].x - data[i].x);
		diff.y = std::abs(data[i + 1].y - data[i].y);

		int sumDiff = diff.x + diff.y;
		if((sumDiff - diff.t) > 0 ||
		   std::abs(sumDiff - diff.t) % 2 == 1){

			break;
		}

	}

	std::cout << ((i == n) ? "Yes" : "No") << std::endl;

	delete[] data;

	return 0;
}

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

int lcs(string x, string y) {
  int dp[1001][1001];
  int maxl=0;
  x = ' ' + x;
  y = ' ' + y;
  for (int i = 0; i < x.size(); i++)
  {
    dp[i][0] = 0;
  }
  for (int i = 0; i < y.size(); i++)
  {
    dp[i][0] = 0;
  }
  for (int i = 1; i < x.size(); i++)
  {
    for (int j = 1; j < y.size(); j++)
    {
      if (x[i] == y[j]) {
        dp[i][j] = dp[i-1][j-1] + 1;
      }
      else {
        dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
      }
    maxl = max(maxl, dp[i][j]);
    }
    
  }
  return maxl;
}

int main(){

  //std::ifstream in ("input.txt");
  //std::cin.rdbuf(in.rdbuf());
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    string a, b;
    cin >> a >> b;
    cout << lcs(a, b) << endl;
  }
  return 0;
  
}




Measured memory_bytes: 7024
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define _for(i,a,b) for(int i = (a);i<(b);i++)
#define endl  '\n'
#define inf 0x3f3f3f3f
using namespace std;
const int mod=1e9+7;
const int MAX=1e6+7;
//ll a[MAX];
int main()
{
 	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	string s,ss;
	 cin>>s>>ss;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!=ss[i]){
			cout<<"No";
			return 0; 
		}
	}
	cout<<"Yes";	
 	
}

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

int main()
{
    int balls[10];
    int out[2][10];
    int outCount[2]={0};
    int num;
    cin>>num;
    while(num!=0){
        bool flag=false;
        int a[10]={0};
        for(int i=0;i<10;i++){
            cin>>balls[i];
        }
        for(a[0]=0;a[0]<2;a[0]++){
            for(a[1]=0;a[1]<2;a[1]++){
                for(a[2]=0;a[2]<2;a[2]++){
                    for(a[3]=0;a[3]<2;a[3]++){
                        for(a[4]=0;a[4]<2;a[4]++){
                            for(a[5]=0;a[5]<2;a[5]++){
                                for(a[6]=0;a[6]<2;a[6]++){
                                    for(a[7]=0;a[7]<2;a[7]++){
                                        for(a[8]=0;a[8]<2;a[8]++){
                                            for(a[9]=0;a[9]<2;a[9]++){
                                                for(int i=0;i<10;i++){
                                                    out[a[i]][outCount[a[i]]]=balls[i];
                                                    if(out[a[i]][outCount[a[i]]-1]>balls[i]&&outCount[a[i]]!=0){
                                                        break;
                                                    }
                                                    if(i==9){
                                                        flag=true;
                                                    }
                                                    outCount[a[i]]++;
                                                }
                                                for(int i=0;i<10;i++){
                                                    out[0][i]=0;
                                                    out[1][i]=0;
                                                }
                                                outCount[0]=0;
                                                outCount[1]=0;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if(flag){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
        num--;
    }
    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define frr(i,s,n) for(int i=s;i<=n;i++)
#define fr(i,s,n) for(int i=s;i<n;i++)
#define lli long long int
#define llu unsigned long long int
#define vi vector <int>
#define vii vector <long long int>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define mk make_pair
#define mpp map<int,int>
#define ff first
#define ss second
#define mod 1000000007

using namespace std;

vector <int> v[100001];
vector <int> vis(100001);
int dp[100001];
int dfs(int node)
{
	if(vis[node])
		return dp[node];
	vis[node] = 1;
	int mx = 0;
	for(auto child : v[node])
		mx = max(mx,dfs(child) + 1);
	return dp[node] = mx;
}

void loop()
{
	string s;
	cin>>s;
	cout<<s;
	if(s[s.size()-1] == 's')
	{
		cout<<"es\n";
	}
	else
		cout<<"s\n";
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	fast;
    int t=1;
    //cin>>t;
    while(t--)
    	loop();
}


Measured memory_bytes: 6100
#include <bits/stdc++.h>
using namespace std;
  
  int main() {
  long long N;
  cin >> N;
  vector <long long>vec(N);
  long long ans = 0;
  for(long long i = 0; i < N; i++){
    if((i+1) % 5 != 0 && (i+1) % 3 != 0){
      vec.at(i) = i+1;
      ans += vec.at(i);
    }
    else{
      ans +=0;
    }
  }
  cout << ans << endl;

  }
  

Measured memory_bytes: 11180
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] costs = new int[n][n];
		ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>();
		for (int i = 0; i < n; i++) {
		    graph.add(new HashMap<>());
		}
		PriorityQueue<Path> queue = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {
		    for (int j = 0; j < n; j++) {
		        costs[i][j] = sc.nextInt();
		        if (i < j) {
		            queue.add(new Path(i, j, costs[i][j]));
		        }
		    }
		}
		long total = 0;
		while (queue.size() > 0) {
		    Path p = queue.poll();
		    boolean flag = true;
		    for (int i = 0; i < n; i++) {
		        if (i == p.from || i == p.to) {
		            continue;
		        }
		        int cost = costs[p.from][i] + costs[i][p.to];
		        if (cost < p.value) {
		            System.out.println(-1);
		            return;
		        } else if (cost == p.value) {
		            flag = false;
		            break;
		        }
		    }
		    if (flag) {
		        total += p.value;
		    }
		}
		System.out.println(total);
    }
    
    static class Path implements Comparable<Path> {
        int from;
        int to;
        int value;
        
        public Path (int from, int to, int value) {
            this.from = from;
            this.to = to;
            this.value = value;
        }
        
        public int compareTo(Path another) {
            return value - another.value;
        }
    }
}



Measured memory_bytes: 64444
H,W = map(int,input().split())
C = {chr(i):0 for i in range(97,123)}
for _ in range(H):
    s = input().strip()
    for j in range(W):
        C[s[j]] += 1
ind1 = 0
for i in range(97,123):
    if C[chr(i)]==1:
        ind1 = C[chr(i)]
D = {0:0, 1:0, 2:0,3:0}
D1 = {0:0,1:0,2:0,3:0}
for c in C:
    D[C[c]%4] += 1
    D1[C[c]%4] += C[c]
if H%2==0 and W%2==0:
    if D[1]==0 and D[2]==0 and D[3]==0:
        flag = "Yes"
    else:
        flag = "No"
elif H%2==0 and W%2==1:
    if D[1]+D[3]>0:
        flag = "No"
    else:
        m = H//2
        if m>=D[2]:
            flag = "Yes"
        else:
            flag = "No"
elif H%2==1 and W%2==0:
    if D[1]+D[3]>0:
        flag = "No"
    else:
        m = W//2
        if m>=D[2]:
            flag = "Yes"
        else:
            flag = "No"
else:
    if D[1]+D[3]!=1:
        flag = "No"
    else:
        m = (H+W-1)//2
        if m>=D[2]:
            flag = "Yes"
        else:
            flag = "No"
print(flag)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

const int max_n = 1e5 + 9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int main()
{
    int n;
    cin >> n;
    double PI = 3.141592653589793238;
    printf("%lf" , 2*PI*n);
    return 0;
}

Measured memory_bytes: 3756
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
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())

n = ni()
a = list(li())

dp = [[0]*(n+1) for _ in range(n+1)]

for length in range(1,n+1):
    for stidx in range(n-length+1):
        # 次郎の手番
        if(n-length)%2:
            dp[stidx][stidx+length] = min(dp[stidx+1][stidx+length] - a[stidx],
                                          dp[stidx][stidx+length-1] - a[stidx+length-1])
        # 太郎の手番
        else:
            dp[stidx][stidx+length] = max(dp[stidx+1][stidx+length] + a[stidx],
                                          dp[stidx][stidx+length-1] + a[stidx+length-1])
            
print(dp[0][n])

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

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    vector<vector<ll>> job(n,vector<ll>(2));
    
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        job[i][0] = b;
        job[i][1] = a;
    }
    
    sort(job.begin(), job.end());
    
    bool flag = true;
    if(n == 1){
        if(job[0][1]>job[0][0]) flag = false;
    }
    rep(i,n-1){
        job[i+1][1] += job[i][1];
        if(job[i+1][1] > job[i+1][0]){
            flag = false;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


Measured memory_bytes: 11264
/*
      author : nishi5451
      created: 11.08.2020 21:52:00
*/

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


int main(){
    int p,q,r;
    cin >> p >> q >> r;
    cout << p+q+r-max(max(p,q),r) << endl;
    return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  int A=a+11;
  int B=b+11;
  if (A%13>B%13){
    cout<<"Alice"<<endl;
  }
  else if (A%13==B%13){
    cout<<"Draw"<<endl;
  }
  else{
    cout<<"Bob"<<endl;
  }
  
}

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

int main(){
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for(int i=0; i<N; i++){
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    string ans ="";
    for(int i = 0; i<N; i++){
        ans += S[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
int map[1002][1002], was[1002][1002];
int main(void)
{
	int count = 0, H, W, N, i, j;
	char c=0;
	pair<int, int> q,a[10];
	queue<pair<int, int> > que;
	queue<int> quec;
	quec.push(0);
	scanf("%d %d %d", &H, &W, &N);
	for (i = 0; i <= H + 1; i++)
	{
		map[i][0] = -1;
		map[i][W + 1] = -1;
		was[i][0] = -1;					/*?????????????£???????(???)*/
		was[i][W + 1] = -1;
	}
	for (j = 1; j <= W; j++)
	{
		map[0][j] = -1;
		map[H + 1][j] = -1;           /*?????????????£???????????¨????*/
		was[0][j] = -1;
		was[H + 1][j] = -1;
	}
	for (i = 1; i <= H; i++)
	{
		for (j = 1; j <= W; j++)			/*???????????????(??????????????°???????????????????????????????????¨??°??????????????????*/
		{
			cin >> c;
			if (c == 'X')
				map[i][j] = -1;
			if (c == 'S')
			{
				q.first = i;
				q.second = j;
			}
			if (c == '1')
			{
				a[1].first = i;
				a[1].second = j;
			}
			if (c == '2')
			{
				a[2].first = i;
				a[2].second = j;
			}
			if (c == '3')
			{
				a[3].first = i;
				a[3].second = j;
			}
			if (c == '4')
			{
				a[4].first = i;
				a[4].second = j;
			}
			if (c == '5')
			{
				a[5].first = i;
				a[5].second = j;
			}
			if (c == '6')
			{
				a[6].first = i;
				a[6].second = j;
			}
			if (c == '7')
			{
				a[7].first = i;
				a[7].second = j;
			}
			if (c == '8')
			{
				a[8].first = i;
				a[8].second = j;
			}
			if (c == '9')
			{
				a[9].first = i;
				a[9].second = j;
			}
		}
	}
	/*for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cout << map[i][j];
		}
		cout << endl;
	}*/
	que.push(q);
	i = 1;
	while (i <= N)
	{
		count = quec.front();
		quec.pop();
		q = que.front();
		que.pop();

		if (q == a[i])
		{

			i++;
			memset(was, 0, sizeof(was));
			while (!que.empty())
				que.pop();
			while (!quec.empty())
				quec.pop();
			quec.push(count);
			que.push(q);
			continue;
		}
		if (map[q.first][q.second + 1] != -1 && was[q.first][q.second + 1] != -1)
		{
			was[q.first][q.second+1] = -1;
			q.second++;
			que.push(q);					/*???????????????*/
			count++;
			quec.push(count);
			count--;
			q.second--;
		}
		if (map[q.first][q.second - 1] != -1 && was[q.first][q.second-1] != -1)
		{
			was[q.first][q.second-1] = -1;
			q.second--;
			que.push(q);
			count++;						/*???????????????*/
			quec.push(count);
			count--;
			q.second++;
		}
		if (map[q.first + 1][q.second] != -1 && was[q.first + 1][q.second] != -1)
		{
			was[q.first + 1][q.second] = -1;
			q.first++;
			que.push(q);
			count++;						/*???????????????*/
			quec.push(count);
			count--;
			q.first--;
		}
		if (map[q.first - 1][q.second] != -1 && was[q.first - 1][q.second] != -1)
		{
			was[q.first-1][q.second] = -1;
			q.first--;
			que.push(q);
			count++;							/*???????????????*/
			quec.push(count);
			count--;
			q.first++;
		}
	}

	printf("%d\n", count);					/*????????£???????????????????¨??????????*/
	return 0;
}

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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

#define MOD097 1000000007

///// For Debug

#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// 提出時はコメントアウト
// #define LOCAL
#define DEBUG_

#ifndef LOCAL
#undef DEBUG_
#endif

#ifdef DEBUG_

#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)

#endif

//////////

int main() {
    #ifdef LOCAL
    ifstream in("../../Atcoder/input.txt");
    cin.rdbuf(in.rdbuf());
    #endif

    ll X,A,B;
    cin >> X >> A >> B;

    X -= A;

    X%= B;

    cout << X << endl;


    return 0;
}


Measured memory_bytes: 3580
from collections import Counter
N = int(input())


# 素因数分解
def prime_factorization(n):
    table = []
    for x in range(2, int(n**0.5)+1):
        while n % x == 0:
            table.append(x)
            n //= x
    if n > 1:
        table.append(n)
    return table


T = []
for i in range(2, N + 1):
    T.extend(prime_factorization(i))

C = list(Counter(T).values())


def num(x):
    return len([n for n in C if n >= x - 1])


ans = num(5) * (num(5) - 1) * (num(3) - 2) // 2 +\
      num(25) * (num(3) - 1) + \
      num(15) * (num(5) - 1) +\
      num(75)
print(ans)


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

public class A
{
    static void Main()
    {
        int[] intRecord = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();

        var h = intRecord[0];
        var a = intRecord[1];

        int answer = h % a == 0 ? h / a : h / a + 1;

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
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 (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    int n;
    cin >> n;
    vector<ll> A(n);
    rep(i,n) {
        cin >> A[i];
    }
    bool j = true;
    int cnt = 0;
    while(j==true) {
        rep(i,n) {
            if (A[i]%2 == 1) {
                j=false;
            } else {
                A[i] /=2;
            }
        }
        if (j==true) cnt++;
    }
    cout << cnt << "\n";
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int K = sc.nextInt();
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0; i<N; i++)
			A[i] = sc.nextInt();
		
		int ans = K;
		for(int i=0; i<N-1; i++) {
			ans = Math.min(ans, K-(A[i+1]-A[i]));
		}
		ans = Math.min(ans, A[N-1]-A[0]);

		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 80200
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 1e6 + 5 ; 
char s[N] ; 
int f[N][2] ;
signed main()
{
	scanf("%s", s + 1 ) ;
	int n = strlen( s + 1 ), Ans = 0 ; s[0] = '0' ;
	f[n + 1][0] = 0, f[n + 1][1] = 100 ;
	for( re int i = n; i >= 0; -- i ) {
		int u = s[i] - '0' ; 
		f[i][1] = min( f[i + 1][1] - u - 1, f[i + 1][0] - u ) + 10 ;
		f[i][0] = min( f[i + 1][1] + u + 1, f[i + 1][0] + u ) ;
	}
	cout << f[0][0] << endl ;
	return 0 ;
}//hgfh


Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}

const ll MOD = 1e9 + 7;
void mainsolve(){

	ll n;
	cin >> n;
	vector<ll> c(n);
	rep(i,n) cin >> c[i];
	sort(c.begin(), c.end());

	vector<ll> pow2(n+1);
	pow2[0] = 1;
	rep(i,n) pow2[i+1] = (pow2[i] * 2) % MOD;
	ll res = 0;

	rep(i,n){
		ll d = 0;
		ll r = n-1-i;
		ll a = pow2[r];
		ll b = (r * pow2[r-1]) % MOD;
		(d += (a + b) % MOD) %= MOD;
		(d *= pow2[n-1-r]) %= MOD;
		(res += (c[i] * d) % MOD) %= MOD;
	}

	(res *= pow2[n]) %= MOD;
	cout << res << endl;

	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll N; cin >> N;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  vector<ll> cnt(1e6 + 10, 0);
  vector<ll> chk(1e6 + 10, 0);
  for (ll i = 0; i < N; i++) {
    ll a = A[i];
    cnt[a]++;
    if (cnt[a] > 1) continue;
    for (ll j = 2; j < 1e6 + 10; j++) {
      ll temp = a * j;
      if (temp > 1e6) break;
      chk[temp]++;
    }
  }

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ll a = A[i];
    if (cnt[a] == 1 && chk[a] == 0) ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 20340
N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(N-1):
    if a[i]+a[i+1] > x:
        ans += a[i]+a[i+1]-x
        if a[i+1] > a[i]+a[i+1]-x:
            a[i+1] -= a[i]+a[i+1]-x
        else:
            a[i+1] = 0
print(ans)

Measured memory_bytes: 63984
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), is_sorted(),


int n;
vi v;

signed main(){
    FASTER;
    cin>>n;
    v=vi(n);cin>>v;
    
    int p=1000,st=0;
    
    for(int i=0;i<n;i++){
        int s=i;
        while(i+1<n && v[i]<=v[i+1])i++;
        int e=i;
        
        if(e-s+1>1){
            int pp=p;
            p-=(pp/v[s])*v[s];
            st+=(pp/v[s]);
            
            p+=st*v[e];
            st=0;
            
        }
        
    }
    
    cout<<p;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int x = stdIn.nextInt();
		int y = stdIn.nextInt();
		stdIn.close();
		System.out.println(x*y + " " + 2*(x+y));

	}

}



Measured memory_bytes: 25812
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        ret = dict()
        for i in range(self.n):
            r = self.find(i)
            if r in ret:
                ret[r].append(i)
            else:
                ret[r] = [i]
        return ret

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = in_nn()

    lang = [[] for _ in range(M)]
    for i in range(N):
        line = in_nl()
        for j in range(1, len(line)):
            lang[line[j] - 1].append(i)

    uni = UnionFind(N)

    # print(lang)

    for i in range(M):
        for j in range(len(lang[i]) - 1):
            uni.union(lang[i][j], lang[i][j + 1])
            # print(lang[i][j], lang[i][j + 1])

    if uni.group_count() == 1:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 20604
n = int(input())
num_list = []
checkFlg = False
cnt = 0
for i in range(n):
    d1, d2 = input().split()
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        print('Yes')
        checkFlg = True
        break
if not checkFlg:
    print('No')


Measured memory_bytes: 62304
#include <bits/stdc++.h>
#include <unordered_map>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define REP(i,a,b) for(int i=a; i<=b; i++)
using namespace std;

typedef long long int ll;

int main() {
    ll n,q,a,b;
    cin >> n;
    ll cur=0;
    unordered_map<ll,ll> x;
    REP(i,0,n-1){
        cin >> a;
        cur+=a;
        x[a]++;
    }
    cin >> q;
    while(q--){
        cin >> a >> b;
        ll add=(b-a)*x[a];
        x[b]+=x[a];
        x[a]=0;
        cur+=add;
        cout << cur << endl;
    }
    return 0;
}


Measured memory_bytes: 6996
def main():
    N, K = map(int, input().split())
    if (N -1) * (N - 2) / 2 < K:
        print(-1)
        return -1
    l = [(1, i) for i in range(2,N+1)]
    i = 2
    j = 3
    for _ in range(int((N-1) * (N-2)/2) - K):
        l.append((i,j))
        if j == N:
            i += 1
            j = i + 1
        else:
            j += 1
    print(len(l))
    for i, j in l:
        print(i, j)
main()


Measured memory_bytes: 3992
#include<stdio.h>
int a[105];
int main(){
	int n;
	int max;
	int min;
	int len;
	max = 0;min = 10002;
	scanf("%d",&n);
	for(int i = 0; i < n;i++){
		scanf("%d",&a[i]);
		if(a[i]>max){
			max = a[i];
		}
		if(a[i]<min){
			min = a[i];
		}
	}
	len = max - min;
	printf("%d\n",len);
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
class d{
  public static void Main(){
    long n = long.Parse(Console.ReadLine());
    long[] num = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
    long[] count = new long[(long)Math.Pow(10,5)+1];
    long sum = 0;
    for(long i=0; i<n; i++){
      count[num[i]]++;
      sum += num[i];
    }
    long q = long.Parse(Console.ReadLine());
    for(long i=0; i<q; i++){
      long[] order = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
      if(count[order[0]] == 0){
        Console.WriteLine(sum);
        continue;
      }
      long mult = count[order[0]];
      count[order[1]] += mult;
      count[order[0]] = 0;
      sum += (order[1]-order[0])*mult;
      Console.WriteLine(sum);
    }
  }
}


Measured memory_bytes: 32376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int K;
    string S;
    cin >> K >> S;
    if (S.length() <= K)
    {
        cout << S << endl;
    } else
    {
        cout << S.substr(0, K) << "..." << endl;
    }
    return 0;
    
}

Measured memory_bytes: 3628
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;



int main(){

	int n;
	int a;

	cin>>n>>a;

	cout<<n*n-a<<endl;











}


Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val (N, L) = listOfInt()
    val A = listOfInt()
    var c = 0
    while (c < N - 1) {
        if (A[c] + A[c + 1] >= L) {
            println("Possible")
            for (n in 0 until c) println(n + 1)
            for (n in (c + 1 until N - 1).reversed()) println(n + 1)
            println(c + 1)
            return
        } else c++
    }
    println("Impossible")
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }


Measured memory_bytes: 70220
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
using ll = long long;
#define max(a,b) ((a)>(b) ? (a):(b))
#define min(a,b) ((a)<=(b) ? (a):(b))
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

int main(){
  double H,A,ans;
  cin >> H >> A;
  ans = ceil(H/A);
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int max(int a,int b)
{
  int max;
  max = (a>b) ? a : b;
  return max;
}

int main(void)
{
  int l,a,b,c,d;
  int cnt1,cnt2;
  scanf("%d",&l);
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  while(a>0){
  a -= c;
  cnt1 ++;
  } 
  while(b>0){
  b -= d;
  cnt2 ++;
  }
  printf("%d\n",l-max(cnt1,cnt2));
return 0;
}

Measured memory_bytes: 596
def solve(n, b):
    ans = 0
    for i in range(n):
        if i == 0:
            ans += b[0]
        elif i == n-1:
            ans += b[-1]
        else:
            ans += min(b[i-1], b[i])
    return ans

n = int(input())
b = list(map(int, input().split()))
print(solve(n, b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	double N;
	cin >> N;
	cout << (N / 3) * (N / 3) * (N / 3) << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 384