akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

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

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

using namespace std;

const long long MOD = 1000000007;

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

	int n, k;
	ll s;
	cin >> n >> k >> s;
	rep(i, k) {
		cout << s << " ";
	}
	REP(i, k, n) {
		if (s != 1000000000) {
			cout << s + 1 << " ";
		}
		else {
			cout << s - 1 << " ";
		}
	}
	cout << "\n";

	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1 << 30;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//2016-6 Pancake
int main() {
    int n;
    cin >> n;
    vector<int> a(n,0);
    rep(i,n)cin >> a[i];
    ll res = INF;
    rep(f,4){
        vector<int> bake(n,0);
        bake.front() += f;
        rep(i,n-1){
            int p = a[i] - bake[i];
            if(p <= 0)continue;
            bake[i] += p;
            bake[i+1] += p;
        }
        bake.back() += max(0, a.back() - bake.back());
        chmin(res,accumulate(all(bake),0LL));
    }
    cout << res << "\n";
    return 0;
}


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


// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3") 
// #pragma GCC optimization ("unroll-loops")
 
#define ll  long long int
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;
 
#define MD          1000000007
#define M           1000011
#define N 			20
long long  md=MD;

int solve(){
	int n,i,j,k,m;
	cin>>n;
	multiset<int> st;
	for(i=0;i<(1<<n);++i){
		int x;
		cin>>x;
		st.insert(-x);
	}
	n=1<<n;
	int flg=1;
	int mx=-*st.begin();
	st.erase(st.begin());
	multiset<int> used;
	vector<int> v;
	v.pb(-mx);
	while(st.size()){
		int k=v.size();
		for(i=0;i<k;++i){
			int ma=v[i];
			if(st.upper_bound(ma)==st.end()){
				cout<<"No\n";die();
			}
			int p=*st.upper_bound(ma);
			st.erase(st.find(p));
			v.pb(p);
		}
		sort(all(v));

	}
	cout<<"Yes\n";die();


}


int main(){

 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    t=1;
    // cin>>t;

    while(t--){
    	solve();
    }
    die();



    

}



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

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
const ll LINF = 1e18;

int main()
{
  int H, W; cin >> H >> W;
  int h, w; cin >> h >> w;

  cout << H * W - h * W - w * H + w * h << endl;
}

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

int main(){

int H,W,i,j;

while(1){

H=0;
W=0;

cin>>H>>W;

if(H==0&&W==0)break;

for(j=0;j<H;j++){

for(i=0;i<W;i++){

cout<<"#";

}

cout<<"\n";

}

cout<<"\n";




}

return 0;

}

Measured memory_bytes: 1124
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
const double pie  =3.141592653589793238463;
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n" 
#define t4(x,y,z,a) cout<<"x is "<<x<<"    y is "<<y<<"    z is "<<z<<"    a is "<<a<<endl;
#define t3(x,y,z) cout<<"x is "<<x<<"    y is "<<y<<"    z is "<<z<<endl;
#define t2(x,y) cout<<"x is "<<x<<"    y is "<<y<<endl;
#define t1(x) cout<<"x is "<<x<<endl;
using namespace std;
ll arr[100][100];
ll cost[100];
ll n,m,x;
ll mini=INT_MAX;
void psa(vector<ll>arr1,ll n1)
{
    ll i,j,k;
    ll cost1=0;
    rep(i,0,n1)
    {
        cost1+=cost[arr1[i]];
    }
    rep(i,0,m)
    {
        ll xd=0;
        rep(j,0,n1)
        {
            xd+=arr[arr1[j]][i];
        }
        if(xd<x)
            return;
    }
    mini=min(mini,cost1);
}
void pss(ll arr1[],ll ind, vector<ll>sav)
{
    if(ind==n)
    {
        ll l=sav.size();
        if(l!=0)
            psa(sav,l);
    }
    else
    {
        pss(arr1,ind+1,sav);
        sav.push_back(ind);
        pss(arr1,ind+1,sav);
    }
    return;
}
int main()
{
    // fastio
    ll t,i,j,k,l,a,b,y,z,c,d,e,p,nl,np,q,r;
    string str2,str3;
    ll mx=INT_MIN;
    ll mn=INT_MAX;
    ll ans=0,s1=0,s2=0;
    string s;
    cin>>n>>m>>x;
    
    rep(i,0,n)
    {
        cin>>cost[i];
        rep(j,0,m)
        {
            cin>>arr[i][j];
        }
    }
    vector<ll>sav;
    pss(cost,0,sav);
    if(mini==INT_MAX)
        cout<<-1;
    else
        cout<<mini<<endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#define endl '\n'
using namespace std;
typedef long long ll;
int main()
{
	ll n; cin >> n;
	ll N = n,sum=0;
	while(n!=0)
	{
		sum += (n%10);
		n/=10;
	}
	if(N%sum==0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3640
n = input()

if n == "SAT":
	print (1)
elif n == "SUN":
	print (7)
elif n == "MON":
	print (6)
elif n == "TUE":
	print (5)
elif n == "WED":
	print (4)
elif n == "THU":
	print (3)
else:
	print (2)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 2000009;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf= 1e14;
ll mod = 1e9+7;
ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
// ll fact[N];


// ll ncr(ll n,ll r){
//      return (((fact[n]*powm(fact[r],mod-2))%mod)*powm(fact[n-r],mod-2))%mod;
// }
bool comp(string a,string b){
     if(a+b>b+a){
          return false;
     }
     return true;
}
 int main() {   
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
     // #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
     // #endif
     ll t = 1;
     // cin>>t;
     while(t--){
          ll n;cin>>n;
          double v[n];
          for(int i = 0;i<n;i++){
               cin>>v[i];
          }
          sort(v,v+n);
          double ans = v[0];
          for(int i = 1;i<n;i++){
               // cout<<ans<<'\n';
               ans = (ans + v[i])/2;
          }
          cout<<ans;

     }
}            


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    // Your code here!
    int A,B,K;
    cin >>A >> B;

    K = (A+B)/2 ;
    if(abs(A-K)==abs(B-K))
    cout << (A+B)/2;
    else cout<< "IMPOSSIBLE";
    
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD1 1000000007

int main() {
  int a,b;
  cin >> a >> b;
  cout << (a + b + 1)/2 << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef pair<pl, ll> ppl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  string s;
  cin >> s;

  if(s.back() == 's') s += "es";
  else s += "s";

  cout << s << newl;
  return 0; 
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;

int main() {

    string N;
    cin>>N;
  for(int i=0;i<N.size();i++)cout<<'x';
  cout<<endl;
    // vector<int> A(N);
    // for(int i=0; i<N; i++){cin>>A[i];}
    // vector<vector<int>> A(N,vector<int>(M));
    // for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
    //sort(A.begin(),A.end());
    //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i])}
    //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i])}
   // cout <<  << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;

#define MOD 998244353


ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}
  
  

int main(){
    ll n;
    cin>>n;
    
    if(n%111 == 0)cout<<n<<endl;
    else cout<<(n/111 + 1)*111<<endl;
    return 0;
}

    
    



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

using namespace std;

int main(void){
  int n,cnt=0;
  cin >> n;
  vector<int>v(n);
  for(int i=0;i<n;i++)cin >> v[i];
  for(int i=0;i<n;i++)
    for(int j=0;j+1<n;j++)
      if(v[j]>v[j+1])cnt++,swap(v[j],v[j+1]);
  for(int i=0;i<n;i++)cout << v[i] << (i<n-1?" ":"\n");
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main() {
  /*  #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
  ll n,c=0;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      c+=(a[i]*a[j]);
    }
  }
cout << c << endl;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int power(int x, int y) {
    int sum = 1;
    for (int i = 0; i < y; i++) sum *= x;
    return sum;
}

int main() {
    int A[15], N, x[15][14], y[15][14], i, j, k, which[15], honests, ans=0, success;

    scanf("%d", &N);

    for (i = 0; i < N; i++) {
        scanf("%d", A+i);
        for (j = 0; j < A[i]; j++) {
            scanf("%d %d", x[i]+j, y[i]+j);
            x[i][j]--;
        }
    }

    for (k = 0; k < power(2, N); k++) {
        honests = 0;
        for (i = 0; i < N; i++) {
            which[i] = (k>>i) & 1;
            honests += which[i];
        }
        success = 1;
        for (i = 0; i < N; i++) {
            if (which[i]) {
                for (j = 0; j < A[i]; j++) {
                    if (which[x[i][j]] != y[i][j]) success = 0;
                }
            }
        }
        if (success && ans < honests) ans = honests;
    }

    printf("%d", ans);
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
import math
import numpy as np

def solve(A: int, B: int, H: int, M: int):
    theta_m = math.radians(-M*360/60)
    theta_h = math.radians(-(H)*360/12) + theta_m / 12 

    x_m, y_m = B*math.cos(theta_m), B*math.sin(theta_m)
    x_h, y_h = A*math.cos(theta_h), A*math.sin(theta_h)

    print(math.sqrt((x_m-x_h)**2 + (y_m - y_h)**2))

    # theta = abs(theta_m - theta_h)
    # theta = theta if theta <= math.pi else theta - math.pi

    # ans = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta))
    # print(ans)
    return 


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(A, B, H, M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27256
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
      	int B = sc.nextInt();
      
      	if((A * B) %2 == 1) {
        	System.out.println("Yes");
        } else {
          	System.out.println("No");
        }
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main() {
	int cou = 0;
	int A[4];
	cin >> A[0] >> A[1] >> A[2] >> A[3];
	sort(A, A + 4);
	if (A[0] == 1)cou++;
	if (A[1] == 4)cou++;
	if (A[2] == 7)cou++;
	if (A[3] == 9)cou++;
	if (cou == 4)cout << "YES" << endl;
	else cout << "NO" << endl;
	cin >> cou;
	return 0;
}

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

int main() {
	int n;
	int tmp;
	int num = 1;
	int s = 0;

	scanf("%d", &n);

	for(int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		if(tmp == num) {
			s++;
			num++;
		}
	}

	cout << (s == 0 ? -1 : n - s);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,l,ans;
int main() {
    cin>>n>>l;
    if (l<=0 and n+l-1>=0) {
        for (int i=l; i<n+l; i++) ans+=i;
        cout<<ans<<'\n';
    }
    else if (l<0) {
        for (int i=l; i<n+l-1; i++) ans+=i;
        cout<<ans<<'\n';
    }
    else {
        for (int i=l+1; i<n+l; i++) ans+=i;
        cout<<ans<<'\n';
    }
}

Measured memory_bytes: 3616
S = list(map(int,list(input())))
N = len(S)
ans = 0
for i in range(2 ** (N - 1)):
    cnt = 0
    temp = S[0]
    for j in range(N - 1):
        flag = i & 1
        if flag:
            cnt += temp
            temp = S[j + 1]
        else:
            temp = temp * 10 + S[j + 1]
        i >>= 1
    ans += cnt + temp
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  char a[H+1][W+1]={};
  for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
          cin>>a[i][j];
      }
  }
  char red[H+1][W+1]={};
  char blue[H+1][W+1]={};
  for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
          red[i][j]=a[i][j];
          blue[i][j]=a[i][j];
      }
  }

  for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
          if(j==0) red[i][j]='#';
          else if(j==W-1) blue[i][j]='#';
          else if(i%2==0) red[i][j]='#';
          else blue[i][j]='#';
      }
  }
  for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
          cout<<red[i][j];
      }
      cout<<endl;
  }
  cout<<endl;
  for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
          cout<<blue[i][j];
      }
      cout<<endl;
  }


  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
 
int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    ll ok=ll(1e18)+1;
    ll ng=-ok;
    while (ok-ng>1) {
        ll x=(ok+ng)/2;
        // cout << "x=" << x << endl;
        ll cnt=0;
        for (int i=0;i<n;i++) {
            if (a[i]<0) {
                ll l=-1,r=n;
                while (r-l>1) {
                    int mid=(l+r)/2;
                    if (a[i]*a[mid]<x) r=mid;
                    else l=mid;
                }
                cnt+=n-r;
            } else {
                ll l=-1,r=n;
                while (r-l>1) {
                    int mid=(l+r)/2;
                    if (a[i]*a[mid]<x) l=mid;
                    else r=mid;
                }
                cnt+=r;
            }
            if (a[i]*a[i]<x) cnt--;
            // cout << i << ' ' << cnt << endl;
        }
        if (cnt/2<k) ng=x;
        else ok=x;
        // cout << cnt/2 << ' ' << ok << ' ' << ng << endl;
    }
    cout << ng << endl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int chk[100001];
Vi v[1000];
int main() {
	for(int i=2;i*(i-1)/2<=100000;i++)chk[i*(i-1)/2]=i;
	int n;
	scanf("%d",&n);
	if(!chk[n])return !printf("No");
	puts("Yes");
	printf("%d\n",chk[n]);
	int now=1;
	fup(i,1,chk[n],1)
		fup(j,i+1,chk[n],1)
	{
		v[i].pb(now);
		v[j].pb(now++);
	}
	fup(i,1,chk[n],1)
	{
		printf("%d ",v[i].size());
		for(int x:v[i])printf("%d ",x);
		puts("");
	}
}

Measured memory_bytes: 2688
N = int(input())
A = list(map(int, input().split()))
a = [0] * (N+1)

for i in range(1,N+1):
    a[i] = a[i-1] + A[i-1]

a.sort()
#print(a)

ans = 0
s = 0

for i in range(N+1):
    if i == 0:
        s += 1
    elif 1 <= i <= N -1:
        if a[i] == a[i-1]:
            s += 1
        else:
            if s >= 2:
                tmp = s*(s-1) //2
                ans += tmp
            s = 1
    elif i == N :
        if a[i] == a[i-1]:
            s += 1
            if s >= 2:
                tmp = s*(s-1) //2
                ans += tmp
        else:
            if s >= 2:
                tmp = s*(s-1) //2
                ans += tmp
            s = 1
#    print(ans, s)






print(ans) 



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

int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0;i < 4;++i) {
			if (s[i] == '+')ans++;
			else ans--;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//a.c A-Buttons
#include<stdio.h>

int max(int a,int b,int c){
    int max = a;
    if(max<b){
        max = b;
    }
    if(max<c){
        max = c;
    }
    return max;
}

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    int x1=0,x2=0,x3=0,ans=0;
    x1 = a + (a-1);
    x2 = a + b;
    x3 = b + (b-1);
    ans = max(x1,x2,x3);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
w = list(map(int,input().split()))
a=0
b=0
li = []
for i in range(1,n):
  for j in range(1,i+1):
    a += w[j-1]
  for k in range(i+1,n+1):
    b += w[k-1]
  li.append(abs(a-b))
  a = 0
  b = 0
  
print(min(li))

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

int main(){
    //int a,n,ans,count,answer;
    ll n,ans;
    string s,t;
    cin >> n;
    //vector<int> h(n);
    ans=n*(n-1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: u64,
    }

    println!("{}", solve(n));
}

fn solve(n: u64) -> u64 {
    (0..=n)
        .filter(|i| i % 3 != 0)
        .filter(|i| i % 5 != 0)
        .sum()
}

Measured memory_bytes: 2164
n=int(input())
red=[list(map(int,input().split()))for i in range(n)]
blue=[list(map(int,input().split()))for i in range(n)]
red.sort(reverse=True)#降順に並び替える
blue.sort(key=lambda x:x[1])#y座標を基準にソート
ans=0
for i in range(n):
    redx,redy=red[i][0],red[i][1]
    for j in range(len(blue)):
        bluex,bluey=blue[j][0],blue[j][1]
        if redx<bluex and redy<bluey:
            ans+=1
            blue.pop(j)
            break
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef pair < int , int > Pi;
int main()
{
    int N, M;
    int p, q, r;
    int x, y;
    int sizex, sizey;
    while(cin >> N, N) {
        vector < Pi > order;
        cin >> M;
        cin >> p >> q >> r;
        order.push_back(Pi(1, N));
        for(int i = 0; i <= M; i++) {
            vector < Pi > tempa, tempb, tempc;
            if(i < M) cin >> x >> y;
            else x = p - 1, y = q;
            sizex = x, sizey = y;
            for(int j = 0; j < order.size(); j++) {
                if(order[j].second > sizey) {
                    if(sizex > 0) tempc.push_back(Pi(order[j].first, sizex));
                    if(sizey > 0) tempb.push_back(Pi(order[j].first + sizex, sizey - sizex));
                    tempa.push_back(Pi(order[j].first + sizey, order[j].second - sizey));
                    sizey = sizex = 0;
                } else if(order[j].second > sizex) {
                    if(sizex > 0) tempc.push_back(Pi(order[j].first, sizex));
                    tempb.push_back(Pi(order[j].first + sizex, order[j].second - sizex));
                    sizey -= order[j].second;
                    sizex = 0;
                } else {
                    tempc.push_back(Pi(order[j].first, order[j].second));
                    sizey -= order[j].second;
                    sizex -= order[j].second;
                }
            }
            while(!order.empty()) order.pop_back();
            for(int j = 0; j < tempa.size(); j++) order.push_back(tempa[j]);
            for(int j = 0; j < tempb.size(); j++) order.push_back(tempb[j]);
            for(int j = 0; j < tempc.size(); j++) order.push_back(tempc[j]);
            if(i == M) {
                int sum = 0;
                for(int j = 0; j < tempb.size(); j++) {
                    sum += max(0, min(r - tempb[j].first + 1, tempb[j].second));                }
                cout << sum << endl;
                break;
            }
        }
    }
    return (0);
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
using namespace std;
using namespace std::chrono;
#define int long long
#define f(a,b,c) for(a=b;a<=c;a++)
#define frev(a,b,c) for(a=b;a>=c;a--)
#define rep(a,b,c) for(a=b;a<c;a++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define endl '\n'
#define ff first
#define ss second
#define ld long double
int M1=1000000007;
int M2=67280421310721;
int M3=998244353;
int INF=1e18;
int power(int a, int b, int mod)
{
    int ans=1;
    int prod=a;
    while(b)
    {
        if(b%2)
            ans=(ans*prod)%mod;
        prod=(prod*prod)%mod;
        b/=2;
    }
    return ans;
}
int inv(int a, int mod)
{
    return power(a, mod-2, mod);
} 
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int fact(int n,int mod){
    int f=1;
    for(int i=1;i<=n;i++) f=(f*i)%mod;
    return f;
}
int ncr(int n,int r,int mod){
    if(mod==1){
    return (fact(n,mod)/fact(r,mod))/fact(n-r,mod);
    }
    return (((fact(n,mod)*inv(fact(r,mod),mod))%mod)*inv(fact(n-r,mod),mod))%mod;
}
void solve(){
    //code starts here
    int n;
    cin>>n;
    n=n%10;
    if(n==2||n==4||n==5||n==7||n==9) {
        cout<<"hon"<<endl;
    }   
    else if(n==0||n==1||n==6||n==8){
        cout<<"pon"<<endl;
    }
    else cout<<"bon"<<endl;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<fixed<<setprecision(10);
    auto start = high_resolution_clock::now();
    int i,t=1;
    //cin>>t;
    f(i,1,t) solve();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    //cout << duration.count() << endl;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

int main(){
	int a,b,k;
	cin>>a>>b>>k;
	for(int i = a; i <= b; i++){
		if(  a<= i && i < a+k ){
			cout<<i<<endl;
		}else if( b - k < i && i <= b){
			cout<<i<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
unordered_map <string, int> mp;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }

  ll ans = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    ll count = it->second;
    ans += count * (count - 1) / 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 10660
N, K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
V = {'r':P, 's':R, 'p':S}
ans = 0
 
 
for i in range(K):
    check = T[i]
    ans += V[check]
    while True:
        i += K
        if i >= N:
            break
        if check == T[i]:
            check = '-1'
        else:
            ans += V[T[i]]
            check = T[i]
print(ans)

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

typedef long long ll;

ll gcd(ll a,ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

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

    ll a,b;
    cin >> a >> b;
    cout << lcm(a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <queue>
#include <array>
#include <random>
#include <chrono>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

struct custom_hash {
    static ui64 splitmix64(ui64 x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(ui64 x) const {
        static const ui64 FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

void Solve(istream& is, ostream& os) {
    int x_start = 0, y_start = 0, x_end, y_end, n;
    is >> x_end >> y_end >> n;
    
    while (n--) {
        int x, y, type;
        is >> x >> y >> type;
        switch (type) {
            case 1:
                x_start = max(x_start, x);
                break;
            case 2:
                x_end = min(x_end, x);
                break;
            case 3:
                y_start = max(y_start, y);
                break;
            case 4:
                y_end = min(y_end, y);
                break;
            default:
                throw runtime_error("impossible");
        }
    }
    os << max(x_end - x_start, 0) * max(y_end - y_start, 0);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << setprecision(20) << fixed;
    Solve(cin, cout);
    return 0;
}


Measured memory_bytes: 256
sub f{my$r=my$s=$v[$_]=1;my$p=$h[my$c=$c[$_-1]-1];$v[$_]or$a[$c]+=$s*($;=($r+=f())-$s-$h[$c]+$p),$s+=$;for@$_;$a[$c]+=($p+$r-$h[$c])*(@a-($h[$c]=$p+$r))+1;$r}$_=@a=(0)x<>;@c=glob<>;map{push@$_,$u-$_+$;for($u,$;)=split}<>;f;print"@a"

Measured memory_bytes: 549404
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

s, w = map(int, input().split())

if s<=w:
    print("unsafe")
else:
    print("safe")

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



int main(){
  ll n, k;
  cin >> n >> k;


  if(k == 1){
    cout << 0 << endl;
    return 0;
  }

  cout << n-k << endl;


  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char str[100],str2[100],in[100];
    int st,st1,out1,out2;
    //gets(str);
    //gets(str1);
    scanf("%s%s",&str,&str2);
    scanf("%d%d",&st,&st1);
    scanf("%s",&in);
    if(0==strcmp(str,in))
    {
        out1=st-1;
        out2=st1;
    }
    else if(0==strcmp(str2,in))
    {
        out1=st;
        out2=st1-1;
    }
    printf("%d %d\n",out1,out2);
    return 0;
}


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

int partition(vector<int>& nums, int l, int r) {
    int pivot = nums[r - 1];
    int i = -1;
    for (int j = 0; j < nums.size() - 1; j++) {
        if (nums[j] <= pivot) {
            swap(nums[++i], nums[j]);
        }
    }
    swap(nums[++i], nums[r - 1]);
    return i;
}

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

    int q = partition(nums, 0, nums.size());
    for (int i = 0; i < nums.size(); i++) {
        if (i > 0) {
            cout << " ";
        }
        if (i == q) {
            cout << "[";
        }
        cout << nums[i];
        if (i == q) {
            cout << "]";
        }
    }
    cout << endl;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
priority_queue <int> q;
int i,j,cnt=0;
long long p[2];
int main(){
    long long n,a,b;
    cin>>n;
    while(i!=n){
        cin>>a;
        q.push(a);
        i++;
    }
    i=0;
    cnt = 0;
    while(cnt!=2&&!q.empty()){
        a = q.top();q.pop();
        b= q.top();
      //  printf("%lld %lld\n",a,b);
        if(a==b){
        	p[cnt]=a;
        	cnt++;
        	q.pop();
        	//printf("%lld %lld\n",p[0],p[1]);
		}
		if(q.size()==1)break;
    }
    //
    if(cnt!=2)printf("0");
    else {
        long long area;
        area = p[0]*p[1];
        printf("%lld",area);
    }
    
}

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

bool IsPrime(int n) {
  for(int i=2;i*i<=n;i++){
      if(n % i == 0) {
          return false;
      }
  }
  return true;
}


int main(void)
{
    int count = 0;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int p;
        cin >> p;
        if(IsPrime(p)) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3080
// In the name of God
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <bitset>
#define sqr(a) (a)*(a)
using namespace std;

template <typename T>
T next_int() {
	T x = 0, p = 1;
	char ch;
	do { ch = getchar(); } while(ch <= ' ');
	if(ch == '-') {
		p = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		x = x * 10 + (ch - '0');
		ch = getchar();
	}
	return p * x;
}
	
const int max_int = (int)1e9 + 227 + 1;
const int max_n = (int)1e6 + 227 + 1;	
const int mod = (int)1e9 + 7;

int main() {
//	freopen(".in", "r", stdin);

	long long a = next_int<int>();
	long long b = next_int<int>();
	long long c = next_int<int>();

	cout << min((a % 2) * b * c, min((b % 2) * c * a, (c % 2) * a * b)) << "\n";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int h, w;
	cin >> h >> w;
	char a[h][w];

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < h-1; i++) {
		for (int j = 0; j < w-1; j++) {
			if (a[i][j+1] == '#') {
				for (int k = i+1; k < h; k++) {
					// cout << "1: " << k << " " << j << "\n";
					// cout << a[k][j] << "\n";
					if (a[k][j]=='#') {
						cout << "Impossible" << "\n";
						return 0;
					}
				}
			}
			if (a[i+1][j] == '#') {
				for (int k = j+1; k < w; k++) {
					if (a[i][k]=='#') {
//						cout << i+1 << " " << k << "\n";
						cout << "Impossible" << "\n";
						return 0;
					}
				}
			}
		}
	}
	cout << "Possible" << "\n";
}


Measured memory_bytes: 256
MOD=998244353
N,K=map(int,input().split())

lrlist=[]
for _ in range(K):
  l,r=map(int,input().split())
  lrlist.append((l,r))
#print(lrlist)

class SegTree:
  #init(init_val, ide_ele): 配列init_valで初期化 O(N)
  def __init__(self, init_val, segfunc, ide_ele):
    #init_val: 配列の初期値
    #segfunc: 区間にしたい操作
    #ide_ele: 単位元
    #n: 要素数
    #num: n以上の最小の2のべき乗
    #tree: セグメント木(1-index)
    n = len(init_val)
    self.segfunc = segfunc
    self.ide_ele = ide_ele
    self.num = 1 << (n - 1).bit_length()
    self.tree = [ide_ele] * 2 * self.num
    # 配列の値を葉にセット
    for i in range(n):
      self.tree[self.num + i] = init_val[i]
    # 構築していく
    for i in range(self.num - 1, 0, -1):
      self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

  #update(k, x): k番目の値をxに更新 O(logN)
  def update(self, k, x):
    #k番目の値をxに更新
    #k: index(0-index)
    #x: update value
    k += self.num
    self.tree[k] = x
    while k > 1:
      self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
      k >>= 1

  #query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
  def query(self, l, r):
    #[l, r)のsegfuncしたものを得る
    #l: index(0-index)
    #r: index(0-index)
    res = self.ide_ele
    l += self.num
    r += self.num
    while l < r:
      if l & 1:
        res = self.segfunc(res, self.tree[l])
        l += 1
      if r & 1:
        res = self.segfunc(res, self.tree[r - 1])
      l >>= 1
      r >>= 1
    return res
  
#segfunc
def segfunc(x,y):
  return x+y #区間和
#ide_ele
ide_ele=0 #区間和

#初期化
seg=SegTree([0]*(N+1), segfunc, ide_ele)
seg.update(1,1)

for i in range(2,N+1):
  for l,r in lrlist:
    left=i-r
    right=i-l    
    if right<1:
      continue
    elif left<1:
      left=1
    
    current=seg.query(i,i+1)
    sum_intv=seg.query(left,right+1)
    seg.update(i,(current+sum_intv)%MOD)
    #print(i,left,right,current,sum_intv)
    
print(seg.query(N,N+1))

Measured memory_bytes: 75592
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int a,b,n;
  cin >> a >> b >> n;
  if(min(b,n)==b)
    cout << floor((a*(b-1))/b) << endl;
  else
    cout << floor((a*n)/b) << endl;
  return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
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;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp
const ll mod=1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    ll m;
    cin >> m;
    ll ans=0;
    if(n!=1){
        ans=2*(m%mod+1)%mod*((m/(n-1))%mod)-((m/(n-1))%mod)*((m/(n-1)+1)%mod)*(n-1)%mod+m+1;
    }else{
        ans=(m+1)%mod;
    }
    cout<<ans%mod<<endl;
}



Measured memory_bytes: 3204
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int n;
	cin >> n;
	map<ll, int> mp;
	rep(i, n) {
		ll k;
		cin >> k;
		mp[k]++;
	}
	vector<pair<ll, int>> a;
	for (auto i = mp.begin(); i != mp.end(); i++) {
		a.push_back(make_pair(i->first, i->second));
	}
	sort(a.begin(), a.end());
	int cnt = 2;
	ll ans = 1;
	for (int i = a.size() - 1; i >= 0; i--) {
		if (cnt == 2 && a[i].second >= 4) {
			cout << a[i].first * a[i].first << endl;
			return 0;
		}
		else if (cnt == 2 && a[i].second >= 2) {
			cnt--;
			ans *= a[i].first;
		}
		else if (cnt == 1 && a[i].second >= 2) {
			ans *= a[i].first;
			cout << ans << endl;
			return 0;
		}
	}
	cout << 0 << endl;
}

Measured memory_bytes: 8696
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    int mini = INF;
    int maxi = -INF;
    REP(i,n){
        cin >> a[i];
        mini = min(mini,a[i]);
        maxi = max(maxi,a[i]);
    }

    int ans = INF;
    FOR(i,mini,maxi+1){
        int tmp = 0;
        REP(j,n){

            tmp += pow(a[j]-i,2);

        }
        ans = min(ans,tmp);
        //cout << i << ans << endl;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    n,m = map(int,input().split())
    p = list(map(int,input().split()))
    xy = [list(map(int,input().split())) for _ in range(m)]

    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):
            return_list = [list() for i in range(n)]
            for i in range(n):
              return_list[self.find(i)].append(i)
            return return_list

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

    uf = UnionFind(n)
    ans = 0
    for x,y in xy:
        uf.union(x-1,y-1)
    for v in uf.all_group_members():
        set1 = set()
        for i in v:
            set1.add(p[i]-1)
        ans += len(set(v)&set1)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 119392
// Code by Nguyen Huu Lam
#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;

typedef long long LL;

#define y0 Sword_Art_Online
#define y1 Your_lie_in_April
#define yn Darling_in_the_Franxx
#define tm Plastic_Memories
#define lr Charlotte
#define norm Weathering_with_you
#define left Violet_Evergarden
#define have Date_a_live
#define ends Your_name
#define prev Five_centimeters_per_second
#define hash Silent_voice
#define endl "\n"

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

LL Rand(LL l, LL h){
    return uniform_int_distribution<LL>(l, h)(rng);
}

template <typename T> void read(T &t){
    t = 0; char ch = getchar(); int f = 1;
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    do { (t *= 10) += ch - '0'; ch = getchar(); } while (isdigit(ch)); t *= f;
}

const LL MaxN = 1 + 2e5;

LL n, test;
vector<LL> le[MaxN], ri[MaxN];

void InOut(){
    #define TASK "ABC"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
}

int main(){
    // InOut();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> test;
    while(test--){
        cin >> n;
        LL ans = 0;
        priority_queue<LL, vector<LL>, greater<LL> > pq;
        for(int i = 1 ; i <= n ; ++i){
            le[i].clear();
            ri[i].clear();
        }
        for(int i = 0 ; i < n ; ++i){
            LL k, l, r;
            cin >> k >> l >> r;
            if(l > r){
                le[k].push_back(l - r);
                ans += r;
            }
            if(r > l){
                ri[n - k].push_back(r - l);
                ans += l;
            }
            if(l == r) ans += l;
        }
        for(int i = 1 ; i <= n ; ++i){
            for(int j : le[i]) pq.push(j);
            while(pq.size() > i) pq.pop();
        }
        while(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
        for(int i = 1 ; i <= n ; ++i){
            for(int j : ri[i]) pq.push(j);
            while(pq.size() > i) pq.pop();
        }
        while(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 18332
unittest
{
	assert( [ "3", "3 1 2" ].parse.expand.solve == 11 );
	assert( [ "7", "5 0 7 8 3 3 2" ].parse.expand.solve == 312 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto ds = input.front.split.to!( long[] );
	return tuple( ds );
}

auto solve( long[] ds )
{
	auto ans = 0L;
	foreach( ai, a; ds )
	{
		foreach( b; ds[ ai + 1 .. $ ] )
		{
			ans += a * b;
		}
	}
	return ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

int main(void) {
  int n, k;
  cin >> n >> k;
  int h[n];
  for(int i=0;i<n;i++) cin >> h[i];
  long long int cost[n];
  fill(cost, cost+n, 1e9);
  cost[0]=0;
  for(int i=0;i<n-1;i++) {
    for(int j=1;j<=min(k, n-i-1);j++) {
       cost[i+j] = min(cost[i+j], cost[i] + abs(h[i]-h[i+j]));
    }
  }

  cout << cost[n-1] << endl;
  
}

Measured memory_bytes: 1408