akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

void clr(auto &a,int n){
  a.clear();
  a.resize(n);
}

void unq(auto &a){
  sort(all(a));
  a.resize(unique(all(a))-a.begin());
}

const int N=200005;

bool check(string s){
  string z=s;
  reverse(all(z));
  return z==s;
}


void solve(){
  string s;
  cin>>s;
  int n=s.length();
  bool flag=true;
  flag&=check(s);
  flag&=check(s.substr(0,(n-1)/2));
  flag&=check(s.substr((n+1)/2,n-(n+1)/2));
  if(flag){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
  
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //cin>>tc;
  for(int _=0;_<tc;_++){
    //cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,m;
  int i,j,rear,a,b,co;
  while(scanf("%d %d",&n,&m),n||m){
    int f[501];
    char c[501]={0};
    char r[501][501]={0};
    rear=0;
    for(i=0;i<m;i++){
      scanf("%d %d",&a,&b);
      if(a==1){
	f[rear++]=b;
	c[b]=1;
      }
      else{
	r[a][b]=1;
	r[b][a]=1;
      }
    }
    co=rear;
    // printf("%d ",co);
    for(i=0;i<rear;i++){
      for(j=2;j<=n;j++){
	if(c[j]==0&&r[f[i]][j]){
	  co++;
	  c[j]=1;
	}
      }
    }
    printf("%d\n",co);
  }
  return 0;
}

Measured memory_bytes: 856
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
from itertools import permutations
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return


def main():
    n,m = map(int, input().split())
    graph = [[0 for _ in range(n)] for _ in range(n)]
    for i in range(m):
        a,b = map(int, input().split())
        graph[a-1][b-1] = 1
        graph[b-1][a-1] = 1
    # n!通りの並べ方があり，各並べ方について成立するかどうかを調べる．
    # 成立しないと判明した時点で探索をやめる
   
    a = [i+1 for i in range(n)]
    p = permutations(a)

    def check(x):
        # x: (1,3,4,6,7,2)
        for i in range(n-1):
            if not graph[x[i]-1][x[i+1]-1]:
                return False
        return True
    cnt = 0
    for x in p:
        if x[0] != 1:
            continue
        if check(x):
            cnt += 1       
    print(cnt)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 5072
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) 
{
	cout << *it << " = " << a;
	nl;
	err(++it, args...);
}
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
set<ll> s[26];
string str;
cin>>str;
int q;
cin>>q;
for(int i=0;i<n;i++)
{
    s[str[i]-'a'].insert(i+1);
}
while(q--)
{
  cin>>temp;
  if(temp==1)
  {
      cin>>a;
      char c;
      cin>>c;
      for(int i=0;i<26;i++)
      {
          s[i].erase(a);
      }
      s[c-'a'].insert(a);
  }
  else
  {
      int ans=0;
      cin>>a>>b;
      for(int i=0;i<26;i++)
      {
          auto it=s[i].lower_bound(a);
          if(it==s[i].end())
          continue;
          if(*it<=b)
          ans++;
      }
      cout<<ans;
      nl;
  }
}









return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 24220
#include <iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstdlib>
#include <vector>

using namespace std;

int main(){

  int st[150];
  int si = 0;

  string t;

  int x,y;
  while( cin >> t ){

    if( t=="+"){
      si--; x = st[si];
      si--; y = st[si];
      st[si] = x+y ;si++;
    }else if( t=="*" ){
      si--; x = st[si];
      si--; y = st[si];
      st[si] = x*y ;si++;
    }else if( t=="-" ){
      si--; x = st[si];
      si--; y = st[si];
      st[si] = y-x ;si++;
    }else if( t==";"){
      break;
    }else{
      st[si] = stoi(t);
      si++;
    }
  }
  si--;
  cout << st[si] << endl;

}



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

#define DeltaCube23 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define MOD 1000000007
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i >= (b); i--)

typedef long long int lli;

using namespace std;

const int mx=2e6+5;

int main()
{
    DeltaCube23
	int t=1;
	//cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    vector<lli> a(n);
	    forf(i,0,n)
	    cin>>a[i];
	    sort(a.begin(),a.end());
	    lli ans=0;
	    forf(i,0,n)
	    {
	        forf(j,i+1,n)
	        {
	            forf(k,j+1,n)
	            {
	                if((a[i]+a[j] > a[k]) && a[i]!=a[j] && a[i]!=a[k] && a[k]!=a[j])
	                {
	                    //cout<<i<<j<<k<<"\n";
	                    ans++;
	                }
	            }
	        }
	    }
	    cout<<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3664
<?php
$M = explode(" ",trim(fgets(STDIN)));
$L = $M[0]+$M[1];
$R = $M[2]+$M[3];
if  ($L>$R){
  echo 'Left';
} elseif($L<$R){
   echo 'Right';
}  else{
      echo 'Balanced';
    }

Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define ll long long
#define out(a) printf("%d",a)
#define outl(a) printf("%lld",a)
#define writeln printf("\n")
#define rep(i,a,b) for (int i=a;i<=b;i++)
using namespace std;
int n;
int x[100050];
int num[100050];
int sum=0;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	n=read();
	rep(i,1,n) {
	  x[i]=read();
	  num[i-1]=abs(x[i]-x[i-2])-abs(x[i]-x[i-1])-abs(x[i-1]-x[i-2]);
	  sum+=abs(x[i]-x[i-1]);
    }
    sum+=abs(x[n]);
    num[n]=abs(x[n-1])-abs(x[n])-abs(x[n]-x[n-1]);
    //out(sum);
    rep(i,1,n) {
     //out(num[i]); cout<<' ';
      out(sum+num[i]);
      writeln;
  }
  return 0;
}

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

int main(int argc, char const* argv[]) {
	string s[3];
	for (int i = 0; i < 9; i++) {
		cin >> s[i];
	}
	printf("%c%c%c\n", s[0][0], s[1][1], s[2][2]);

	return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  int a=n%10;
  if(a==2||a==4||a==5||a==7||a==9)cout<<"hon";
  if(a==0||a==1||a==6||a==8)cout<<"pon";
  if(a==3)cout<<"bon";
  
}

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

using namespace std;

int main() {
    int N,K,X,Y;
    cin >> N >> K >> X >> Y;
    int a,b;
    cin >> a >> b;
    if(N <= K){
      a = N * X;
      b = 0;
    }
    else if(N > K){
        a = K * X;
        b = (N-K) * Y;
    }
    int ans;
    ans = a+ b;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
struct edge{long long to,cost;};
typedef pair<int,int>P;
#define inf 1000000007
string alph("abcdefghijklmnopqrstuvwxyz");
vector<int> es[114514];

const int limit=50;

int n,m;int a[limit],b[limit];
bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
    visited[v]=true;
    for(int v2=0; v2<n;++v2){
        if(!graph[v][v2])continue;
        if(visited[v2])continue;
        dfs(v2);
    }
}
signed main(){
    cin>>n>>m;
    rep(i,0,m){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
    int ans=0;
    rep(i,0,m){
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
        rep(j,0,n)visited[j]=false;
        dfs(0);
        bool bridge=false;
        rep(j,0,n)if(!visited[j])bridge=true;
        if(bridge)ans++;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define INF 1e+18
#define int long long
using namespace std;

signed main(){
	int n,m,cnt[50] = {},ans = 0;
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		int k;
		cin >> k;
		for(int j = 0;j < k;j++){
			int t;
			cin >> t;
			cnt[t - 1]++;
		}
	}
	for(int i = 0;i < m;i++){
		if(cnt[i] == n) ans++;
	}
	cout << ans << endl;
}

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

int main() {
  int N,M;
  int sum=0;
  
  cin >> N >> M;
  vector<int> A(M);
  for(int i=0;i<M;i++){
    cin >> A.at(i);
    sum+=A.at(i);
  } 
  if(N-sum>=0){
    cout << N-sum<<endl;
  }else{
    cout<<-1<<endl;
  }
  
  
}

Measured memory_bytes: 3664
Q,H,S,D=[int(i) for i in input().split()]
N=int(input())
Price2 = [Q*8,H*4,S*2,D]
ans = 0
if N==1:
    print(min(Price2[:3])//2)
else:
    Two = N//2
    N %= 2
    print(Two*min(Price2) + N * min(Price2[:3])//2)

Measured memory_bytes: 3060
;; D - Dice in Line

(defun solve (n k ps)
  "隣接するk個のサイコロの目の合計の期待値の最大値"
  ; 合計の期待値 = 期待値の合計
  ; 面数pのサイコロの目の期待値 = (1 + ... + p)/p
  ;                          = p * (p + 1)/(2 * p)
  (let ((es (make-array n :initial-contents
              (mapcar #'(lambda (p) (/ (* p (1+ p)) (* 2 p))) ps))))
    (loop for i from 0 to (- n k)
          and s = (loop repeat k for e across es sum e)
                  then (+ s (- (aref es (min (+ i k) (1- n)))
                               (aref es i)))
          maximize s)))

(let* ((n  (read))
       (k  (read))
       (ps (loop repeat n collect (read))))
  (princ (float (solve n k ps))))


Measured memory_bytes: 61800
/*
by:-  
                     _ __ ___ 119574 
                    | '__/ __| 
                    | |  \__ \ 
                    |_|  |___/ 
                    

*/ 

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,n) for (ll i = 0; i < n; ++i) 
#define endl "\n"
const ll mod=1e9+7;
const db eps=1e-9;
const double pi=acos(-1);

void solve(){
    ll n,m;
    cin>>n>>m;
    ll a[m],b[m];
    for(ll i=0;i<m;i++)cin>>a[i]>>b[i];
    sort(a,a+m);
    sort(b,b+m);
    ll temp=b[0]-a[m-1]+1;
    if(temp<0)temp=0;
    cout<<temp<<endl;


	return;
}
signed main(){
	IOS;
	ll t=1;
// 	cin>>t;
	while(t--)solve();
fflush(stdout);return 0;
}

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

int main(){
	std::vector<int> mountain(10, 0);
	
	for(int i = 0; i < 10; ++i){
		std::cin >> mountain[i];
	}
	
	std::sort(mountain.begin(), mountain.end(), std::greater<int>());
	for(int i = 0; i < 3; ++i){
		std::cout << mountain[i] << std::endl;
	}
	
	return 0;
}

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

using namespace std;

map<int,int> mi;

int main() {
    int i, n;

    scanf("%d",&n);
    for (i=0;i<n;i++) {
        int a;
        scanf("%d",&a);
        if (mi.find(a)==mi.end()) mi[a] = 1;
        else mi[a]++;
    }
    auto it = mi.begin();
    int res = 0;
    while (it!=mi.end()) {
        res += (it->first<=it->second)?(it->second-it->first):it->second;
        it++;
    }
    printf("%d\n",res);

    return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

const LL INF = 1e18;

LL b[60];

bool f(LL x) {
    rep(i, 60) if((1ll << i) & x) {
        if(!b[i]) {
            b[i] = x;
            return true;
        }
        x ^= b[i];
    }
    return false;
}

int main()
{
    int T;
    cin >> T;
    while(T--) {
        memset(b, 0, sizeof b);
        int n;
        cin >> n;
        vector<LL> a(n);
        for(LL &x: a) cin >> x;
        string s;
        cin >> s;
        for(int i = n-1; i >= 0; --i) {
            if(f(a[i]) && s[i] == '1') {
                puts("1");
                goto _;
            }
        }
        puts("0");
        _: ;
    }
	return 0;
}


Measured memory_bytes: 3484
#include<iostream>
#include <math.h>
#include <iomanip>
#include <vector>

typedef long long ll;

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

using namespace std;

int main() {
    ll a,b;
    cin >>a >> b;
    cout << a*b;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define N 500009
#define inf 1e18
//int mod=1e9+7;
int mod=998244353;
#define P pair<int,int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(),v.end()

#define ordered_set tree<P, null_type,less<P>, rb_tree_tag,tree_order_statistics_node_update> 

void end(int n=-1){
	cout<<n<<"\n";exit(0);
}

string s,t;
int dp[3009][3009];

int32_t main(){
    AB_BHI_NI_DEGI
	cin>>s>>t;
	int m=s.size(),n=t.size();
	for(int i=0;i<=m;i++){
		for(int j=0;j<=n;j++){
			if(i==0 or j==0)dp[i][j]=0;
			else if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1;
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	string ans="";
	int index=dp[m][n];
	int i=m,j=n;
	while(i>0 and j>0){
		if(s[i-1]==t[j-1]){
			ans+=s[i-1];
			i--;j--;
		}
		else if(dp[i-1][j]>dp[i][j-1])i--;
		else j--;
	}
	reverse(all(ans));
	cout<<ans<<"\n";
    return 0;
}

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

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 3e5+35;
const int maxn = 4e3+23;
int num[maxn],n,m,q,ans;
int a[maxn],b[maxn],c[maxn],d[maxn];
void dfs(int x){
    if(x > n){
        int sum = 0;
        for(int i = 1;i <= q; ++i){
            if(num[b[i]]-num[a[i]] == c[i]) sum += d[i];
        }
        ans = max(ans,sum);
        return;
    }
    for(int i = num[x-1];i <= m; ++i){
        num[x] = i; dfs(x+1);
    }
}
int main(){
    cin >> n >> m >> q; num[0] = 1;
    for(int i = 1;i <= q; ++i) cin >> a[i] >> b[i] >> c[i] >> d[i];
    dfs(1);
    cout << ans;
    return 0;
}


Measured memory_bytes: 3652
from sys import stdin
data = [None] * 5
data_amari = [None] * 5
data_kiriage = [None] * 5
for itr in range(0,5):
    data[itr] = int(stdin.readline().rstrip())
    if (data[itr]%10 != 0):
        data_amari[itr] = data[itr] % 10
        data_kiriage[itr] = data[itr] + (10-data[itr] % 10)
    else:
        data_amari[itr] = 10
        data_kiriage[itr] = data[itr]

sum = 0
for itr in range(0,5):
    if itr != data_amari.index(min(data_amari)):
        sum += data_kiriage[itr]
    else:
        sum += data[itr]
print(sum)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  int a,b,c;cin>>a>>b>>c;
  if(b>=a*c){
    cout<<c<<endl;
  }else{
    cout<<b/a<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int x[10000],c=0;
    for (int i=0; ; i++)
    {
        cin>>x[i];
        if (x[i]!=0) c++;
        if (x[i]==0) break;
    }
    for (int i=0; i<c; i++)
    {
        cout<<"Case "<<i+1<<": "<<x[i]<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int N, check, cut;

ll pw10[50];
ll dp[50][1<<20];
ll solve(const int n, const int mask){
  if((mask & check) == check){
    return pw10[N - n];
  }
  if(n >= N)return 0;
  if(dp[n][mask] != -1)return dp[n][mask];
  ll res = 0;
  for(int i=1;i<=10;i++){
    int nmask = ((mask << i) & cut) | 1;
    res = (res + solve(n + 1, nmask)) % MOD;
  }
  return dp[n][mask] = res;
}

int main(){
  pw10[0] = 1;
  for(int i=1;i<50;i++)pw10[i] = pw10[i-1] * 10 % MOD;

  int X, Y, Z;
  cin >> N >> X >> Y >> Z;
  check = 1 | (1 << Z) | (1 << (Z + Y)) | (1 << (Z + Y + X));
  cut = (1 << (X + Y + Z + 1)) - 1;

  memset(dp, -1, sizeof(dp));
  cout << solve(0, 1) << endl;
  return 0;
}


Measured memory_bytes: 409856
use std::io;

fn main() {
    loop {
        let mut line = String::new();
        io::stdin().read_line(&mut line).unwrap();

        let mut iter = line.split_whitespace().map(|i| i.parse::<i32>().unwrap());
        let n = iter.next().unwrap();
        let x = iter.next().unwrap();

        if n == 0 && x == 0 { break; }

        let combos = (1..n-1).flat_map(|a| {
            (a+1..n).flat_map(move |b| {
                (b+1..n+1).map(move |c| (a, b, c))
            })
        }).filter(|&(a, b, c)| a + b + c == x);

        println!("{}", combos.count());
    }
}



Measured memory_bytes: 5028
times = int(input())  

data = [int(input()) for i in range(times)] 

N = data[0]

cards = data[0:]

#バブルソート
for i in range(0, len(cards), 1):
  
  for j in range(i + 1, len(cards), 1):
    
    if cards[i] < cards[j]:
      tmp1 = cards[i]
      tmp2 = cards[j]
      
      cards[i] = tmp2
      cards[j] = tmp1
      
#鏡餅を積んで行くぜ！！

print(len(set([str(x) for x in cards])))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N, M;
int A[105000];

void f() {
    int ans = 1e9;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    for(int i = 0; i <= 1; i++) {
        int num = 0;
        for(int j = 1; j <= N; j++) {
            if(A[j] % 2 != (i + j) % 2) num++;
        }
        chmin(ans, num);
    }
    cout << ans << endl;

}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> M >> N;
    if(M == 2) {
        f();
        return 0;
    }
    int num = 0;
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        if(A[i] == A[i-1]) num++;
        else {
            ans += num / 2;
            num = 1;
        }
    }
    ans += num / 2;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3608
n=int(input())
a=list(map(int,input().split()))

#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#n=len(a)

a.sort()

from collections import Counter
a=Counter(a)
csum=0
for i,icnt in a.most_common():
    csum+=icnt-1
if csum%2==1:
    csum+=1
print(n-csum)
    

Measured memory_bytes: 25272
#include<bits/stdc++.h>
using namespace std;
int main(){
 int N,i;
  cin>>N;
  vector<int> a(N);
  for(i=0;i<N;i++) cin>>a.at(i);
  int j=1,count=0;
  for(i=0;i<N;i++){
    j=a.at(j-1);
    count++;
    if(j-1==1){
      cout<<count<<endl;
      break;
    }
  }
  if((j-1)!=1) cout<<-1<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  static int close[(1<<(5*5))/32];
  static int cls[1000000];

  for (int n; scanf("%d", &n), !(n==0); ){

    vector<vector<int> > pats(33);
    static int tmp[5][5];

    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
	for (int k=i; k<n; k++){
	  for (int l=j; l<n; l++){
	    for (int a=i; a<=k; a++)
	      for (int b=j; b<=l; b++)
		tmp[a][b]=1;
	    int bd=0;
	    for (int a=0; a<n; a++){
	      for (int b=0; b<n; b++){
		bd=(bd<<1)|tmp[a][b];
	      }
	    }
	    pats[__builtin_clz(bd)].push_back(bd);
	    for (int a=i; a<=k; a++)
	      for (int b=j; b<=l; b++)
		tmp[a][b]=0;
	  }
	}
      }
    }

    int bd=0;
    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
	int t; scanf("%d", &t);
	bd=(bd<<1)|t;
      }
    }

    int cls_cnt=0, cls_cur=0;
    close[bd>>5]|=(1<<(bd&31));
    cls[cls_cnt++]=bd;
    for (;;){
      int dep=cls[cls_cur]>>25;
      int cbd=cls[cls_cur]&0x1ffffff;
      cls_cur++;
      const vector<int> &ps=pats[__builtin_clz(cbd)];
      int sz=ps.size();
      for (int i=0; i<sz; i++){
	int nbd=cbd^ps[i];
	if (close[nbd>>5]&(1<<(nbd&31)))
	  continue;
	close[nbd>>5]|=(1<<(nbd&31));
	cls[cls_cnt++]=((dep+1)<<25)|nbd;
	if (nbd==0){
	  for (int i=0; i<=dep; i++)
	    printf("myon");
	  puts("");
	  goto _exit;
	}
      }
    }
  _exit:;
    {
      int i=0;
      for (; i+3<cls_cnt; i+=4){
	close[(cls[i+0]&0x1ffffff)>>5]=0;
	close[(cls[i+1]&0x1ffffff)>>5]=0;
	close[(cls[i+2]&0x1ffffff)>>5]=0;
	close[(cls[i+3]&0x1ffffff)>>5]=0;
      }
      for (; i<cls_cnt; i++)
	close[(cls[i]&0x1ffffff)>>5]=0;
    }
  }
  return 0;
}

Measured memory_bytes: 3516
#include <stdio.h>

int main(void){
    int k, s, count = 0;;
    scanf("%d %d", &k, &s);

    for(int x = s; x >= 0; x--){
        for(int y = 0; x + y <= s; y++){
            if(x <= k && y <= k && s - x - y <= k) count++;
        }
    }
    printf("%d", count);

    return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#ifdef LOCAL
#define see(x) cout  << #x << ": " << (x) << endl
#endif

#ifndef LOCAL
#define see(x)
#endif

template<class T>
int sign(const T &a) {
    if(a==0) return 0;
    if(a>0) return 1;
    return -1;
}

template<typename T>
void print(const T &t) {
    cout << t << '\n';
}

template<typename T, typename ...Args>
void print(const T &t, const Args &...rest) {
    cout << t << ' ';
    print(rest...);
}

// this overload is chosen when there's only one argument
template <class T>
void scan(T &t){
    cin >> t;
}

template<class T, class ...Args>
void scan(T &a, Args &...rest){
    cin >> a;
    scan(rest...);
}


using vec = vector<int>;
using mat = vector<vec>;
using pii = pair<int,int>;

using ll = long long;
const int mod = 1e9+7;
const int N = 1e4+5;
const int M = 1<<20;

int c[105][105];

int a, b;



int main(){
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif
    scan(a, b);
    bool flag = false;
    for(int i=1; i<=100; i+=2){
        if(a > 1){
            for(int j=2; j<=100; j+=2){
                if(a>1){
                    c[i][j] = 1;
                    if(!flag) {
                        flag = true;
                        --b;
                    }
                    --a;
                    if(a==1){
                        for (int k = j + 1; k <= 100; k++) {
                            c[i][k] = 1;
                        }
                        break;
                    }
                }
            }
            if(a >= 1) { // 将上面的白连通块与整体的白连通块隔开。
                for (int j = 1; j <= 100; j++) {
                    c[i+1][j] = 1;
                }
            }
        }
        else if(b){
            for(int j = 1; j<=100; j+=2){
                if(b) {
                    c[i+1][j] = 1;
                    --b;
                }
                else break;
            }
        }
        else break;
    }
    print(100, 100);
    for (int i = 1; i <= 100; i++) {
        for(int j=1; j<=100; j++) {
            putchar(c[i][j] ? '#' : '.');
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/caddi2018/tasks/caddi2018_a

fun main() {
    caddi2018a()
}

fun caddi2018a() {
    val (n, p) = readLine()!!.split(" ").map { it.toLong() }
    if (n == 1L) {
        println(p)
        return
    }
    if (p == 1L) {
        println(1)
        return
    }
    // 素因数分解
    val primes = mutableMapOf<Long, Int>()
    var t = p
    var i = 2L
    while (i * i <= t) {
        var count = 0
        while (t % i == 0L) {
            t /= i
            count++
        }
        primes[i] = count
        i++
    }
    if (t != 1L) primes[t] = 1
    var gcd = 1L
    for ((prime, count) in primes.filterValues { it >= n }) {
        val factor = count / n
        repeat(factor.toInt()) {
            gcd *= prime
        }
    }
    println(gcd)
}

Measured memory_bytes: 48068
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N;
  cin >> N;
  VEC<int> A(N), B(N), C(N, 0);
  REP(i, 0, N) {
    cin >> A[i];
    A[i]--;
  }
  REP(i, 0, N) { cin >> B[i]; }
  REP(i, 0, N - 1) { cin >> C[i]; }
  LL sum = 0;
  int pre = -1;
  REP(i, 0, N) {
    int j = A[i];
    LL s = B[j];
    if (pre == j - 1) {
      s += C[j - 1];
    }
    sum += s;
    // DUMP(sum, j, pre);
    pre = j;
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

int main() {
  i64 r;
  cin >> r;
  cout << r * r << endl;
}


Measured memory_bytes: 256
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N,A,B = map(int,input().split())
v = sorted(list(map(int,input().split())),reverse=True)

if len(set(v)) == 1:
    print(1)
    print(1125899906842623)
    exit()

m = sum(v[:A])/A
print(m)

if len(set(v[:A]))==1:
    ans = 0
    c = v.count(v[0])
    for i in range(A,B+1):
        if i <= c:
            ans += cmb(c,i)
    print(ans)
    exit()

mi = min(v[:A])
n = v[:A].count(mi)
m = v.count(mi)
print(cmb(m,n))

Measured memory_bytes: 3064
import qualified Data.Vector.Unboxed as VU
import           Data.Ord
import           Data.List (sortOn)

main :: IO ()
main = do
  count <- readLn
  vects <- VU.replicateM count (readLn :: IO Int)
  let (first:second:_) = sortOn Down $ VU.toList vects
  VU.forM_ vects
    $ \i -> print
    $ if i == first
      then second
      else first



Measured memory_bytes: 36092
#include <stdio.h>

int main(void)
{
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if(x>=r && x<=W-r && y>=r && y<=H-r){
printf("Yes\n");
} else {
printf("No\n");
}

return 0;

}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a == b)
        cout << c << endl;
    else if (b == c)
        cout << a << endl;
    else if (c == a)
        cout << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <iomanip>
#include <utility>
#include <string>
#include <map>
#include <algorithm> //using for swap()
#include <tr1/unordered_map>
using namespace std;
 
array<pair<char,int>,100001> A;

tr1::unordered_map<int,pair<string,int>> dat; 

int Partition(int p,int  r){
    int x = A[r].second;
    int i = p-1;
    for(int j=p;j<r;j++){
        if(A[j].second <= x){
            i++;
            swap(A[i],A[j]);
        }
    }
    swap(A[i+1],A[r]);
    return i+1;
}

void quick(int p,int r){
    if(p<r){
        int q = Partition(p,r);
        quick(p,q-1);
        quick(q+1,r);
    }
}
 
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
	    char tmp1;
        int  tmp2;
        cin>>tmp1>>tmp2;
        A[i].first =tmp1;
	    A[i].second=tmp2;
        if(dat.count(tmp2)==0){
            string s="";
            s+=tmp1;
            dat.insert(map<int,pair<string,int>>::value_type
                    (tmp2,pair<string,int>(s,0)));
        }else{
            dat[tmp2].first=dat[tmp2].first+tmp1;
        }
    }
    quick(0,n-1);
    bool isStable=true;
    for(int i=0;i<n;i++){
         if(dat[A[i].second].first[dat[A[i].second].second]!=
             A[i].first){
             isStable=false;
         }
         dat[A[i].second].second++;
    }
    if(isStable){
        cout<<"Stable"<<endl;
    }else{
        cout<<"Not stable"<<endl;
    }
    for(int i=0;i<n;i++){
	   cout<<A[i].first<<" "<<A[i].second<<endl;
    }
    return 0;
}

Measured memory_bytes: 4444
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  REP(i, N) { cin >> L[i]; }
  sort(L.begin(), L.end());

  int sum = 0;
  REP(i, N - 1) { sum += L[i]; }
  if (sum > L[N - 1]) {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int[][] l=new int[2][1000];
        int fs=0;
        while (sc.hasNext()) {
            String str = sc.nextLine();
            if (str.equals("")) {
                fs++;
            } else {
                int n=Integer.parseInt(str.split(",")[0])-1;
                l[fs][n]++;
            }
        }
        for(int i=0;i<l[0].length;i++) {
            if(l[0][i]>0&&l[1][i]>0) {
                System.out.println((i+1)+" "+(l[0][i]+l[1][i]));
            }
        }
    }
}


Measured memory_bytes: 26164
#include <iostream>
#include <string>
 
int main(){
 
const int MIN = -40;
const int MAX = 40;
const int THRES = 30;
std::string fStr = "";
std::cin >> fStr;
 
int fTemp = stoi(fStr);
if(fTemp < MIN|| fTemp > MAX){return -1;}
 
if(fTemp < THRES){std::cout<<"No" <<std::endl;}
else{std::cout<<"Yes"<<std::endl;}
 
return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
#define N 20000000
int main(void)
{
  char s[N], t[N];
  int count = 0, i;

  scanf("%s", s);
  scanf("%s", t);

  for(i=0;s[i]!='\0';i++){
    if(s[i]!=t[i]){
      count++;
    }
  }

  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 2124
#include <iostream> // {{{
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <cstdio> // }}}

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

using namespace std;

long lucas(int i);

long memo[90];

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

    for(auto &i : memo) i = 0;

    cout << lucas(n) << endl;

    return 0;
}

long lucas(int i) {
    if(i==0) return 2;
    if(i==1) return 1;

    if(memo[i] != 0) return memo[i];

    memo[i] = lucas(i-1)+lucas(i-2);
    return memo[i];
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int n;
	cin>> n;
	int day[101];
	for (int i=0; i<n; i++){
		cin>>day[i];
	}
	for(int i=n-1;i>=0;i--){
		cout<<day[i];
		if(i!=0){
			cout<<" ";
		}
    }
	cout<<endl;
   return 0;
}
 


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

int main() {
  int n,sum = 0,wa = 0;
  int ans = 100000;
  
  cin >> n;
  vector<int>s(n);
  
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  
  for (int i = 0; i < n; i++) {
    sum += s.at(i);
  }
  
  for (int i = 0; i < n; i++) {
    wa += s.at(i);
    if (sum - 2*wa >= 0) {
      ans = min(ans,sum-2*wa);
    }
    else {
      ans = min(ans,2*wa-sum);
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i,n) {cin >> d.at(i);}
	sort(d.begin(), d.end());
	if (d.at(n / 2) != d.at(n / 2 - 1)) {
		cout << d.at(n / 2) -d.at(n / 2 - 1) << endl;
	}
	else {
		cout << 0 << endl;
	}

	
}



Measured memory_bytes: 640
// abc137c.cpp : Green Bin
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

	vector<ll> v;
	while (n--){
		string s; cin>>s;
		sort(s.begin(), s.end());
		ll k = 0, power = 1;
		for(int j=9; j>=0; j--){
			k += power * (s[j]-'a');
			power *= 26;
		}
		v.push_back(k);
	}

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

	ll ans = 0, c = 0, d = v[0];
	for(ll e: v){
		if(d==e) c++;
		else{
			if(c>1) ans += c * (c-1) / 2L;
			c = 1;
			d = e;
		}
	}
	if(c>1) ans += c * (c-1) / 2L;
	cout<< ans << endl;
}

Measured memory_bytes: 1400
// 2009ツアツジツアツ地ツ凝ヲツ予ツ選 C : Swimming Jam
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		vector<int> t(n), c(n);
		for(int i=0;i<n;i++) cin >> t[i] >> c[i];
		for(int i=0;i<n;i++) c[i] *= 2;
		int ans = 0, count = 0;
		vector<int> lest = t;
		vector<bool> start(n,true);
		while(count != n){
			vector<int> nlest(n);
			vector<bool> nstart(n);
			for(int i=0;i<n;i++){
				if(c[i] == 0) continue;
				if(start[i]){
					int slow = t[i];
					for(int j=0;j<n;j++){
						if(c[j]!=0&&c[i]%2==c[j]%2&&!start[j])
							slow = max(slow, lest[j]);						
					}
					nlest[i] = slow - 1;
					nstart[i] = false;
				} else {
					nlest[i] = lest[i] - 1;
				}
				if(nlest[i] == 0){
					nstart[i] = true;
					c[i]--;
					if(c[i]==0) count++;
				}				
			}
			lest = nlest;
			start = nstart;
			ans++;
		}
		cout << ans << endl;
	}
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/11  Problem: ABC 087 D / Link: http://abc087.contest.atcoder.jp/tasks/abc087_d  ----- */

template<typename T>
class DiffUnionFind {
	T calc(int x) {
		int r = root(x);
		return dist[x] + diff[x] - diff[r];
	}
	vector<int> par;
	vector<T>dist, diff;

public:
	DiffUnionFind(int n) {
		par.assign(n, -1);
		dist.assign(n, 0);
		diff.assign(n, 0);
	}
	int size(int x) { return -par[root(x)]; }
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) {
		if (par[x] < 0)return x;
		int r = root(par[x]);
		dist[x] += dist[par[x]];
		return par[x] = r;
	}
	void unionSet(int x, int y, T val) {
		int rx = root(x), ry = root(y);
		val = val - (dist[y] + diff[y]) + (dist[x] + diff[x]);
		if (rx == ry)return;
		if (size(ry) < size(rx)) {
			swap(ry, rx);
			val = -val;
		}
		par[rx] += par[ry];
		par[ry] = rx;
		dist[ry] = val;

	}

	pair<bool, T>comp(int x, int y) {
		if (!same(x, y))return make_pair(false, 0);
		return make_pair(true, (calc(y) - calc(x)));
	}
};


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

	LL N, Q; cin >> N >> Q;
	DiffUnionFind<LL> duf(N);
	LL ans = 1;
	FOR(_, 0, Q) {
		LL L, R, D; cin >> L >> R >> D;
		L--, R--;
		if (duf.same(L, R)) {
			ans &= duf.comp(L,R).second == D;
		}
		else {
			duf.unionSet(L, R,D);
		}
	}



	cout << (ans ? "Yes" : "No") << "\n";

	return 0;
}


Measured memory_bytes: 2304
#include<stdio.h>

typedef long long lld;
lld gcd(lld a, lld b){return b?gcd(b,a%b):a;}

lld N, ba[101010], sum, xo; char st[2][9]={"First","Second"};

int main(){
	scanf("%lld", &N);
	for(int i=0; i<N; i++)scanf("%lld",&ba[i]), sum+=ba[i];
	while(1){
		bool n1=0;
		for(int i=0; i<N; i++){
			if(ba[i]>1)n1=1;
		}
		if(!n1){puts(st[1^xo]);return 0;}
		if((sum+N)%2){puts(st[xo]);return 0;}

		int hcn=0, hi=0;
		for(int i=0; i<N; i++){
			if(ba[i]%2)hcn++, hi=i;
		}
		if(hcn>1 || ba[hi]==1){puts(st[xo^1]);return 0;}
		ba[hi]--;

		int g=ba[0];
		for(int i=1; i<N; i++)g=gcd(g,ba[i]);
		sum=0;
		for(int i=0; i<N; i++)ba[i]/=g, sum+=ba[i];
		xo^=1;
	}
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  string ans;
  if (S == "Sunny") {
    ans = "Cloudy";
  } else if (S == "Cloudy") {
    ans = "Rainy";
  } else {
    ans = "Sunny";
  }
  cout << ans << endl;
}

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

template<class M> struct SegmentTree
{
	int n;
	int size;
	vector<M> data;
	const function<M(M, M)> op;
	const M ID;

	SegmentTree(int n, function<M(M, M)> op, M id, const vector<M> &init_vals=vector<M>()) : n(n), op(op), ID(id) {
		size = 1;
		while (size < n) size <<= 1;
		data.assign(size * 2, ID);
		for (int i = 0; i < init_vals.size(); i++) data[size+i] = init_vals[i];
		for (int i = size-1; i > 0; i--) data[i] = op(data[2*i], data[2*i+1]);
	}
	
	void update(int idx, M x) {
		idx += size;
		data[idx] = x;
		while (idx /= 2) {
			data[idx] = op(data[2*idx], data[2*idx+1]);
		}
	}

	M query(int l, int r) {
		M L = ID, R = ID;
		for (l += size, r += size; l < r; l /= 2, r /= 2) {
			if (l & 1) L = op(L, data[l]), l++;
			if (r & 1) r--, R = op(data[r], R);
		}
		return op(L, R);
	}

	M val(int idx) {
		return data[size + idx];
	}

	vector<M> val_vec() {
		vector<M> res(n);
		for (int i = 0; i < n; i++) res[i] = data[size+i];
		return res;
	}
};

template<int N> bitset<N> myor(bitset<N> a, bitset<N> b) {
	return a | b;
}

int main() {
	int n, Q;
	string s;
	cin >> n >> s >> Q;
	vector<bitset<26>> v(n, 0);
	for (int i = 0; i < n; i++) {
		v[i][s[i]-'a'] = 1;
	}
	SegmentTree<bitset<26>> st(n, myor<26>, bitset<26>(0), v);
	for (int q = 0; q < Q; q++) {
		int type;
		cin >> type;
		if (type == 1) {
			int i;
			char c;
			cin >> i >> c;
			i--;
			bitset<26> bs(0);
			bs[c - 'a'] = 1;
			st.update(i, bs);
		} else {
			int l, r;
			cin >> l >> r;
			l--;
			bitset<26> bs = st.query(l, r);
			int ans = bs.count();
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 15624
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <stack>
#include <list>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

int a, b, c;
int main() {
  cin >> a >> b >> c;
  int cnt = 1;
  if (a != b)
    cnt++;
  if (a != c && b != c)
    cnt++;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	memo := make([][]int, n)
	for i := 0; i < n ; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		memo[i] = make([]int, 3)
		memo[i][0], memo[i][1], memo[i][2] = a, b, c
	}
	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, 3)
	}
	arr[0][0], arr[0][1], arr[0][2] = memo[0][0], memo[0][1], memo[0][2]
	for i := 0; i < n - 1; i++ {
		for j := 0; j < 3; j++ {
			arr[i + 1][j] = max1(arr[i][(j + 1) % 3], arr[i][(j + 2) % 3]) + memo[i + 1][j]
		}
	}
	mx := 0
	for i := 0; i < 3; i++ {
		if mx < arr[n - 1][i] {
			mx = arr[n - 1][i]
		}
	}
	fmt.Println(mx)
}

func max1(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

Measured memory_bytes: 12672
// In god we trust

#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>

#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define INF 1000000000
#define LINF 1000000000000000
#define int long long
using namespace std;
using namespace std::chrono;



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

  string s;
  cin >> s;
  int n = s.size();

  bool could = true;
  
  for (int i = 0; i < n; i ++)
    if (s[i] != s[n - 1 - i])
      could = false;
  
  for (int i = 0; i < (n - 1) / 2 - 1; i++)
    if (s[i] != s[(n - 1) / 2 - 1 - i])
      could = false;

  for (int i = (n + 3) / 2 - 1; i < n; i++)
    if (s[i] != s[n - 1 + (n + 3) / 2 - 1 - i])
      could = false;

  if (could)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    
  
}  






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

int main() {
  int N;
  string S, T;
  cin >> N >> S >> T;
  
  vector<char> ans(N * 2);
  for (int i = 0; i < N * 2; i++) {
    if (i % 2 == 0)
      ans[i] = S[i / 2];
    else
      ans[i] = T[i / 2];
  }
  
  for (int i = 0; i < N * 2; i++)
    cout << ans[i];
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast")
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e6;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
pll a[200001];
ll sz[200001], p[200001];
ll get(ll v)
{
    while (p[v] > 0) v = p[v];
    return v;
}
void unite(ll x, ll y)
{
    x = get(x), y = get(y);
    if (x == y) return;
    if (sz[x] < sz[y]) swap(x, y);
    p[y] = x;
    sz[x] += sz[y];
    sz[y] = 0;
}

int main()
{
    fast_io;
    ll n, m, i, s = 0;
    cin >> n >> m;
    for (i = 1; i <= n; i++) sz[i] = 1, p[i] = -1;
    for (i = 1; i <= m; i++)
    {
        cin >> a[i].first >> a[i].second;
        unite(a[i].first, a[i].second);
    }
    for (i = 1; i <= n; i++) s = max(s, sz[i]);
    cout << s;
    return 0;
}

Measured memory_bytes: 9832
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    hon = {2, 4, 5, 7, 9}
    pon = {0, 1, 6, 8}
    bon = {3}

    if int(str(N)[-1]) in hon:
        return "hon"
    elif int(str(N)[-1]) in pon:
        return "pon"
    else:
        return "bon"


if __name__ == "__main__":
    print(main())


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

int main(){
	string s;
	cin >> s;
	bool flag = 1;
	for(int i = 0;i < s.size()-1;++i)
		flag &= (s[i] != s[i+1]);
	cout << (flag ? "Good" : "Bad");
}


Measured memory_bytes: 3612