akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;

int main(){
    ll n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    ll ans = 0;

    ll tmp = 1;
    sort(all(a));

    rep(i,n-1){
        if(a[i] == a[i+1]){
            tmp++;
        }
        else{
            if(tmp >= a[i]){
                ans += tmp-a[i];
            }
            else ans += tmp;

            tmp = 1;
        }
    }

            if(tmp >= a[n-1]){
                ans += tmp-a[n-1];
            }
            else ans += tmp;

    
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<(b); i++)

int main() {
  string S;
  cin >> S;
  long long ans = 0;
  int n = S.size();
  
  for (int bit=0; bit<(1<<n-1); bit++) { //0から2のn-1乗まで
    string ss = "";
    for (int i=0; i<n; i++) {
      ss += S[i];
      if (bit >> i & 1) { //bitをi行分だけ右シフトしたものと、0b00…001の間でandを考える
        ans += stoll(ss); //文字列をlong long型に変換
        ss ="";
      }
    }
    ans += stoll(ss);
    ss = "";
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3588
//以下模範解答
#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 n;
    cin >> n;
    map<string,int> mp;//std::map<std::string, int> mp[str]でint返る
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;//その文字列が現れたら値が足される、初期は普通0
    }
    ll ans = 0;
    for(auto& p : mp){//範囲ベースfor for(変数宣言:範囲)と書く}
        //p はstrとintのmapになってる,auto&で参照と書き換え可能
        int s = p.second;
        ans += (ll)s*(s-1)/2;//sC2してる、siがsjのアナグラムであるものを探すから順列の半分
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 11136
// have a try@!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k, n, a[200005];
ll mod = 1000000000 + 7;
int main(void) {
	scanf("%lld%lld", &n, &k);
	ll _1 = 0, _2 = 0, _3 = 0;
	for (ll i = 0; i < n; i++){
		scanf("%lld", &a[i]);
		if (a[i] < 0)
			_1++;
		else if (a[i] == 0)
			_2++;
		else
			_3++;
	}
	sort(a, a + n);
	ll ans = 1;
	if (k % 2 == 1){
		if (_3 == 0)
		{
			for (ll i = 0; i < k; i++)
			{
				ans *= a[n - i - 1];
				ans %= mod;
			}
			printf("%lld", (ans % mod + mod) % mod);
			return 0;
		}
		ans = a[n - 1];
		n--;
		_3--;
		k--;
	}
	ll bg = 0, ed = n - 1;
	while (true)
		if (k == 0) break;
		else if (_3 > 1 && _1 > 1)
		{
			if (a[bg] * a[bg + 1] > a[ed] * a[ed - 1])	{
				ans *= a[bg] * a[bg + 1] % mod;
				ans %= mod;
				bg += 2;
				_1 -= 2;
				k -= 2;
			}else{
				ans *= a[ed] * a[ed - 1] % mod;
				ans %= mod;
				ed -= 2;
				_3 -= 2;
				k -= 2;
			}
		}else if (_3 > 1){
			ans *= a[ed] * a[ed - 1] % mod;
			ans %= mod;
			ed -= 2;
			_3 -= 2;
			k -= 2;
		}else if (_1 > 1){
			ans *= a[bg] * a[bg + 1] % mod;
			ans %= mod;
			bg += 2;
			_1 -= 2;
			k -= 2;
		}else{
			for (ll i = ed; i > ed - k; i--)
			{
				ans *= a[i];
				ans %= mod;
			}
			break;
		}
	printf("%lld", (ans % mod + mod) % mod);
}
#if 0
end
#endif

Measured memory_bytes: 5320
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		System.out.println(n*n*n);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

int main() {
  int n,m;
  cin >> n >> m;
  ll ans = 1;
  vector<int> a(m);
  rep(i,m){
    cin >> a[i];
  }
  vector<int> howmany(n+1);
  howmany[0] = 1;
  howmany[1] = 1;
  for(int i=1;i<n;i++){
    howmany[i+1] = (howmany[i]+howmany[i-1])%1000000007;
  }
  if(m > 0){
    ans = ans*howmany[a[0]-1]%1000000007;
    rep(i,m-1){
     ans = ans*howmany[a[i+1]-a[i]-2]%1000000007;
    }
    ans = ans*howmany[n-a[m-1]-1]%1000000007;
    int continuedFlag = 1;
    rep(i,m-1){if(a[i+1]-a[i]==1) continuedFlag = 0;}
    ans *= continuedFlag;
  }
  else ans = howmany[n];
  cout << ans << endl;
  return 0;
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> v(n + 1, vector<int>(n + 1, 0));

    int l, r;
    for (int i = 0; i < m; i++) {
        cin >> l >> r;
        for (int j = 1; j <= l; j++) {
            v[j][r]++;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            v[i][j] += v[i][j - 1];
        }
    }
    int p, o;
    for (int i = 0; i < q; i++) {
        cin >> p >> o;
        cout << v[p][o] << endl;
    }
}


Measured memory_bytes: 1920
N, M = list(map(int, input().split()))
A, B = [0 for i in range(N)], [0 for i in range(N)]
for i in range(N):
    A[i], B[i] =  list(map(int, input().split()))
C, D =  [0 for i in range(M)], [0 for i in range(M)]
for i in range(M):
    C[i], D[i] =  list(map(int, input().split()))

# 距離求める
def distance(a, b, c, d):
    return abs(a - c) + abs(b - d)

# i番目の人が行く場所調べる
def judge(i):
    tmp = -1
    re = -1
    for j in range(M):
        dis = distance(A[i], B[i], C[j], D[j])
        if tmp == -1 or tmp > dis:
            tmp = dis
            re = j
#    print(re, ' ', tmp)
    return re+1

for i in range(N):
    print(judge(i))

Measured memory_bytes: 3064
import sys
#import numpy as np

for i in sys.stdin:
    a,b,c,d,e,f=list(map(float, i.split()))
    #A=np.matrix([[a,b],[d,e]])
    #inv_A = np.linalg.inv(A)
    #P=np.matrix([[c],[f]])
    #X=inv_A.dot(P)
    y = (f-(d*c)/a)/((a*e-d*b)/a)
    x = (c-b*y)/a
    print("{0:.3f} {1:.3f}".format(x,y))

Measured memory_bytes: 5580
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



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

    l *= 100000;
    
    double i = l/3;
    double j = i + l%3;

    i /= 100000;
    j /= 100000;
    
    printf("%.10f\n",i*i*j);
 
    return  0;
}


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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;

#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

int main(){
    ll N, startU, startV;
    cin >> N >> startU >> startV;
    startU--; startV--;

    vector<vector<ll>> E(N);
    REP(i,0,N-1){
        ll A, B;
        cin >> A >> B;
        A--; B--;
        E[A].push_back(B);
        E[B].push_back(A);
    }

    vector<ll> visitV(N,-1);
    queue<ll> q;

    visitV[startV] = 0;
    q.push(startV);
    
    while(!q.empty()){
        ll i = q.front(); q.pop();
        ll c = visitV[i];
        for(ll v : E[i]){
            if(visitV[v] < 0){
                visitV[v] = c+1;
                q.push(v);
            }
        }
    }

    vector<ll> visitU(N,-1);
    q.push(startU);
    visitU[startU] = 0;
    ll m = -1;
    ll last;
    
    while(!q.empty()){
        ll i = q.front(); q.pop();
        ll c = visitU[i];
        if(m < visitV[i]){
            m = visitV[i];
            last = i;
        }

        for(ll v : E[i]){
            if(visitU[v] < 0 && c < visitV[v]){
                visitU[v] = c + 1;
                q.push(v);
            }
        }
    }
    cout << m-1 << endl;

    return 0;
}

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define RSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))
#define PREC(n) setprecision(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef unsigned long long lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

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

int main() {
    ll a,b;

    cin>>a>>b;

    cout<<a*b/yaku(a,b);
	
	return 0;
}


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

using ll = long long;

int main() {
      	string s;
	cin >> s;

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

	string ans = s.substr(8, s.size() - 8);
	
	reverse(ans.begin(), ans.end());

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3528
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
const int mm=1e6;
ll d[mm];
ll dd[mm];
map<string,ll>name; 
int main()
{
	ll n,i,j,m,t,a,b,c;
	string s;
	cin>>s;
	ll k=0,kk=0;
	for(i=0;i<3;i++)
	{
		if(s[i]=='A')
		k++;
		else
		kk++;
	}
	if(k==0||kk==0)
	printf("No\n");
	else
	printf("Yes\n");
	
	
	
    
}


Measured memory_bytes: 256
N, Y = map(int, input().split())

yukichi = -1
ichiyo = -1
hideyo = -1

hasFound = False

for x in range(N+1):
  for y in range(N+1-x):
    z = N - x - y
    total = x * 10000 + y * 5000 + z * 1000
    if total == Y:
      yukichi = x
      ichiyo = y
      hideyo = z
      hasFound = True
      break
  if hasFound:
    break
print('{} {} {}'.format(yukichi, ichiyo, hideyo))

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
  int l, r;
  cin >> l >> r;
  if (r - l >= 2019) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 2019;
  for (int i = l; i <= r; i++) {
    for (int j = i+1; j <= r; j++) {
      ans = min(ans, ((i%2019) * (j%2019)) % 2019);
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int A[110000];

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

    rep(i,n) cin >> A[i];

    sort(A, A+n, greater<int>());

    int power = 0;
    rep(i,n) {
        power += A[i];
        if (power >= h) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	static final long MOD = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		HashMap<Long, Integer> num = new HashMap<>();
		int[][] c = new int[N][4];
		for(int i=0; i<N; i++) {
			for(int j=0; j<4; j++)
				c[i][j] = sc.nextInt();
			Long code = getCode(c[i]);
			if(num.containsKey(code))
				num.put(code, num.get(code)+1);
			else
				num.put(code, 1);
		}
		
		long ans = 0;
		int[][] side = new int[4][4];
		long[] sideCode = new long[4];

		for(int i=0; i<N; i++) {
			Long bottomCode = getCode(c[i]);
			num.put(bottomCode, num.get(bottomCode)-1);
			
			for(int j=0; j<4; j++) {
				side[j][0] = c[i][j];
				side[j][3] = c[i][(j+1)%4];
			}
			for(int j=i+1; j<N; j++) {
				long topCode = getCode(c[j]);
				for(int d=0; d<4; d++) {
					long temp = 1;
					for(int k=0; k<4; k++) {
						side[k][2] = c[j][(d-k+4)%4];
						side[k][1] = c[j][(d-k+5)%4];
						sideCode[k] = getCode(side[k]);

						Integer cnt = num.get(sideCode[k]);
						if(cnt!=null && cnt>0) {
							if(sideCode[k]==topCode && cnt>0)
								cnt--;
							
							for(int l=0; l<k; l++)
								if(sideCode[k]==sideCode[l] && cnt>0)
									cnt--;
							
							if(bit(sideCode[k], 0, 20)==bit(sideCode[k], 20, 40)) {
								cnt <<=1;
								if(bit(sideCode[k], 0, 10)==bit(sideCode[k], 10, 20))
									cnt <<=1;
							}
							temp *= cnt;
						} else {
							temp = 0;
							break;
						}
					}
					ans += temp;
				}
			}
		}
		
		System.out.println(ans);
		sc.close();
	}
	
	static long getCode(int[] c) {
		long code[] = new long[4];
		for(int i=0; i<4; i++) {
			for(int j=0; j<4; j++) {
				code[i] = code[i]<<10 | c[(i+j)%4];
			}
		}
		Arrays.sort(code);
		return code[0];
	}
	
	static long bit(long v, int s, int t) {
		v >>= s;
		return v & ((1<<(t-s))-1);
	}
}


Measured memory_bytes: 45040
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextInt();
        double b = sc.nextInt();
        double x = sc.nextInt();
        double max = a*a*b;
        if(max/2 >= x){
            System.out.println(90d - Math.toDegrees(Math.atan((2*x/(a*b))/b)));
        }else{
            x = max-x;
            System.out.println(Math.toDegrees(Math.atan((2*x/(a*a))/a)));
        }
        
    }
}

Measured memory_bytes: 22996
#include <stdio.h>
int main()
{
	long long int x,y,z,a,b;
	while(scanf("%lld%lld%lld",&x,&y,&z)!=EOF){
	a=x-y;
	b=a%z;
	printf("%lld\n",b);
	}
	return 0;
}

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

int main() {
    int limit, point_a = 0, point_b = 0;
    cin >> limit;

    vector<int> card_num(limit);

    for (int i = 0; i < card_num.size(); i++)
        cin >> card_num.at(i);

    sort(card_num.begin(), card_num.end());
    reverse(card_num.begin(), card_num.end());

    for (int i = 0; i < card_num.size(); i++) {
        if( i % 2 == 0) {
            point_a += card_num.at(i);
        } else if( i % 2 == 1) {
            point_b += card_num.at(i);
        }
    }

    cout << point_a - point_b << endl;

    return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[1, a] for a in list(map(int, input().split()))]
BC = [list(map(int, input().split())) for i in range(M)]

q = sorted(A+BC, key=itemgetter(1), reverse=True)

ans = 0
i = 0

while N:
    n = min(q[i][0], N)
    ans += q[i][1] * n
    N -= n

    i += 1

print(ans)

Measured memory_bytes: 47828
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath>
#include<set>
#include<utility>

using namespace std;


int main()
{
	int n; 
	cin >> n;
	long long int a[100];
	a[0] = 2;
	a[1] = 1;
	for (int i = 2; i < n+1; i++)
	{
		a[i] = a[i - 1] + a[i - 2];
	}
	cout << a[n] << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll N;
    cin >> N;
    
    cout << (N*(N-1))/2 << endl;

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n){
        cin >> p[i];
        q[i] = p[i];
    }
    int res = 0;
    sort(q.begin(),q.end());
    rep(i,n){
        if(p[i] != q[i]) res++;
    }
    if(res <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

int main() {
  int n, count = 0;
  cin >> n;
  int p[n];
  rep(i, n) {
    cin >> p[i];
  }
 
  rep(i, n) {
    if (p[i] != i + 1) {
      count++;
    }
    
  }
  if (count == 0 || count == 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
li = list(map(int,input().split()))

def swap(a,b):
    c = li[a]
    li[a] = li[b]
    li[b] = c

ans = 0
i = 0
while i < n-1:
    memo = i+1

    if memo == li[i]:
        swap(i,i+1)
        ans += 1
        i+= 1
    i+=1

if li[n-1] == n:
    ans += 1

print(ans)



Measured memory_bytes: 14004
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var S = Enumerable.Repeat("", n).Select(s => Read()).ToArray();
            var letter = new Dictionary<char, int>();
            for (char c = 'a'; c <= 'z'; c++)
            {
                var cnt = int.MaxValue;
                for (int i = 0; i < n; i++)
                {
                    var tmp = 0;
                    for (int j = 0; j < S[i].Length; j++)
                    {
                        if (S[i][j] == c) tmp++;
                    }
                    if (tmp < cnt) cnt = tmp;
                }
                letter.Add(c, cnt);
            }
            var ans = "";
            foreach(var l in letter)
            {
                if (l.Value > 0)
                {
                    ans += new string(l.Key, l.Value);
                }
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 11360
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
#define max(a,b) a > b ? a : b
using namespace std;
using ll = long long;

class unionfind{
    public:
    vector<int> par,rank,size;
    
    unionfind(int n){
        par.resize(n);
        rank.resize(n);
        size.resize(n);

        rep(i,n){
            par[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }

    int getSize(int x){
        return size[x];
    }

    int find(int x){
        int m = max(size[x],size[par[x]]);
        size[x] = m;
        size[par[x]] = m;
        if(par[x]==x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x,int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
        int sx = size[x];
        int sy = size[y];
    size[x] = sx+sy;
    size[y] = sx+sy;
    }

    bool same(int x,int y){
        return find(x) == find(y);
    }
};

    vector<int> like[100010];
    vector<int> block[100010];

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    unionfind uf(n);
    
    int f,t;
    
    rep(i,m){
        cin >> f >> t;
        f--; t--;
        like[f].push_back(t);
        like[t].push_back(f);
        uf.unite(f,t);
    }

    rep(i,k){
        cin >> f >> t;
        f--; t--;
        block[f].push_back(t);
        block[t].push_back(f);
    }
rep(i,n){
    uf.find(i);
}
    rep(i,n){
        int ll = 0,bb=0;
        rep(j,like[i].size()){
            if(uf.same(i,like[i][j])) ll++;
        }
        rep(j,block[i].size()){
            if(uf.same(i,block[i][j])) bb++;
        }
        int ans = max(0,uf.size[i] - ll - bb - 1);
        cout << ans;
        if(i != n-1) cout << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 13048
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int p;

  cin >> p;
  cout << p/500*500 << endl;
  
  return 0;
}



Measured memory_bytes: 3092
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
import math
a,b,h,m = iim()

th_m = 6*m
th_h = 30*h+0.5*m

theta = abs(th_m-th_h) if abs(th_m-th_h)<180 else 360-abs(th_m-th_h)
#print(th_m-th_h)

l = a**2+b**2-2*a*b*math.cos(math.radians(theta))
print(l**0.5)

Measured memory_bytes: 9532
#include <bits/stdc++.h>
#include <experimental/iterator>

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* debug */
auto debug = std::experimental::make_ostream_joiner(std::cout, " ");

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val > 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	std::string s, t;
	cin >> s >> t;
	t.pop_back();
	if(s == t){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

class Main{
    public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String[] ss=br.readLine().split(" ");
            int n=Integer.parseInt(ss[0]);
            int m=Integer.parseInt(ss[1]);
            if(n%2==0){
                n--;
            }
                int l = 1, r = n / 2;
                while(l<r){
                    if(m==0)
                        return;
                    System.out.println(l+" "+r);
                    m--;
                    l++;
                    r--;
                }
                l=n/2 +1;
                r=n;
                while(l<r){
                    if(m==0)
                        return;
                    System.out.println(l+" "+r);
                    m--;
                    l++;
                    r--;
                }




        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    }
    static int mod(int a,int b){
        if (a>b){
            return a-b;
        }
        return b-a;
    }
    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
}


Measured memory_bytes: 51784
#include<bits/stdc++.h>
using namespace std;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
bool t=1;
string s;
char ss[1000001];
int main()
{
	cin>>s;
	int l=s.size();
	for(int i=0;i<s.size();++i)
	 {
	 	if(s[l-i-1]=='p')
	 	 ss[i]='q';
	 	if(s[l-i-1]=='q')
	 	 ss[i]='p';
	 	if(s[l-i-1]=='d')
	 	 ss[i]='b';
	 	if(s[l-i-1]=='b')
	 	 ss[i]='d';
	 }
	for(int i=0;i<l;++i)
	 {
	 	if(s[i]!=ss[i])
	 	 t=0;
	 }
	if(t==1)
	 cout<<"Yes\n";
	else
	 cout<<"No\n";
	return 0;
}

Measured memory_bytes: 512
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
a = a.sort
al = []
bl = []
while
     al  << a.pop
     if a == []
        break
     end
     bl << a.pop
     if a == []
        break
     end
end
all = al.inject(:+)
bll = bl.inject(:+)
puts all - bll

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

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 10;
ll a[maxn], sub[maxn];

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
    for(int i = 1; i <= n; i ++)
        if(i % 2) sub[i] = sub[i - 1] + a[i];
        else sub[i] = sub[i - 1] - a[i];
    for(int i = 1; i <= n; i ++)
    {
        ll res = sub[n] - sub[i - 1], tmp = sub[i - 1];
        if(i % 2 == 0) res = -res;
        if(i % 2) res -= tmp;
        else res += tmp;
        printf("%lld", res);
        printf("%c", i == n ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define loop(i,a,B) for (int i = a; i B; i++)
#define loopR(i,a,B) for (int i = a; i B; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", my_dmp(#__VA_ARGS__, __VA_ARGS__)
void my_dmp(const char*) { cerr << endl; }
template <class T, class... U>
void my_dmp(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; my_dmp(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
#define OUTPUT(...) ostream& operator<<(ostream& os, __VA_ARGS__ const& v) { os << "{"; for (auto const& x : v) os << " " << x; return os << " }"; }
template <class T> OUTPUT(vector<T>)
template <class T> OUTPUT(deque<T>)
template <class T> OUTPUT(set<T>)
template <class T> OUTPUT(multiset<T>)
template <class T, class U> OUTPUT(map<T,U>)
#undef OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S>& p) { return is >> p.first >> p.second; }
struct my_Init { my_Init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } my_init;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
template <class It> auto sumof(It b, It e) { return accumulate(b,e,typename iterator_traits<It>::value_type{}); }
////////////////////////////////
vector<pair<char,int> > RLE(string const& v) {
    if (v.empty()) return {};
    vector<pair<char,int> > ret;
    int ii = -1, n = v.size();
    rep (i,n) if (i == n-1 || v[i] != v[i+1]) {
        ret.emplace_back(v[i],i-ii);
        ii = i;
    }
    return ret;
}

int32_t main() {
    int n; cin >> n;
    string s; cin >> s;
    cout << RLE(s).size() << "\n";
}


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

bool revp2(const pair<ll,ll>&a,const pair<ll,ll>&b){return a.first>b.first;}
bool revp3(const pair<ll,ll>&a,const pair<ll,ll>&b){if(a.first==b.first)return a.second<b.second;
return a.first>b.first;}

int main()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    ll n,x,a=10000,s=0;
    cin>>n>>x;
    ll l1[n+1];
    for(int i=1;i<=n;i++){
        cin>>l1[i];
        a=min(a,l1[i]);
        s+=l1[i];
    }
    cout<<n+(x-s)/a;

}


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

int main() {
  int N,K;
  cin>>N>>K;
  vector<int>d(K);
  set<int>A;
  for(int i=0;i<K;i++){
    cin>>d.at(i);
    for(int j=0;j<d.at(i);j++){
      int a=0;
      cin>>a;
      A.insert(a);
    }
  }
  cout<<N-A.size()<< endl;
}
      


Measured memory_bytes: 3592
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = []() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

/*  There are 26 of len 1
 *  26 * cnt[1]+cnt[1] on len=2
 *  26 * cnt[2]+cnt[2] of len 3
 */
const int N=1e16+1;
void solve() {
    cini(n);
    vi cnt(14);
    vi c26(14);
    cnt[0]=0;
    cnt[1]=26;
    c26[0]=1;
    c26[1]=26;
    int x26=26;
    for(int i=2; i<14; i++) {
        x26*=26;
        cnt[i]=cnt[i-1]+x26;
        c26[i]=x26;
    }
    //cerr<<"cnt.size()="<<cnt.size()<<" cnt.back()="<<cnt.back()<<endl;

    if(n<=26) {
        string ans=" ";
        ans[0]=(char)('a'+n-1);
        cout<<ans<<endl;
        return;
    }

    string ans;
    for(int i=cnt.size()-1; i>=0; i--) {
        if(ans=="") {
            if(cnt[i]+1<=n) {
                ans=string(i+1, 'a');
                n-=(cnt[i]+1);
            }
        } 

        if(ans!="") {
            while(c26[i]<=n) {
                ans[i]++;
                n-=c26[i];
//cerr<<"cnt[i]="<<cnt[i]<<" ans="<<ans<<" n="<<n<<endl;
            }
        }
    }

    reverse(all(ans));
    cout<<ans<<endl;

}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int c,maxNum=753,x,Num;
    char str[11];
    scanf("%s",str);
    for(c=0;str[c+2]!='\0';c++)
    {
        x=fabs(753-((str[c]-'0')*100+(str[c+1]-'0')*10+str[c+2]-'0'));
        if(maxNum>=x)
        {
            maxNum=x;
            Num=((str[c]-'0')*100+(str[c+1]-'0')*10+str[c+2]-'0');
        }

    }

    printf("%d",maxNum);
    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int64 N, A, B, C, X;
	while(cin >> N >> A >> B >> C >> X && (N || A || B || C || X)){
		vector<int64> y(N);
		REP(i, N) cin >> y[i];
		int32 in = 0;
		int32 cnt = 0;
		while(in < N){
			if(X == y[in]){
				in++;
				if(in == N) break;
			}
			X = (X*A+B)%C;
			cnt++;
			if(cnt > 10000) break;
		}
		if(cnt > 10000) cout << -1 << endl;
		else cout << cnt << endl;
		
	}

}


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

using ll = long long;

struct RMQ {
	using type = int;
	static type id() { return INT_MAX; }
	static type op(const type& l, const type & r) { return min(l, r); }
};

template <typename T>
class node {
public:
	T val;
	node<T> *l, *r;
	node(T val_) : val(val_), l(nullptr), r(nullptr) {}
	~node() {
		if (l) delete l;
		if (r) delete r;
	}
};

template <typename M>
class DynamicSegmentTree {
	using T = typename M::type;
	const ll n;
	node<T> *root;
	T value(node<T> *t) {
		return t ? t->val : M::id();
	}
	T sub(ll l, ll r, node<T>* n, ll lb, ll ub) {
		if (!n || ub <= l || r <= lb) return M::id();
		if (l <= lb && ub <= r) return n->val;
		ll c = (lb + ub) / 2;
		return M::op(sub(l, r, n->l, lb, c), sub(l, r, n->r, c, ub));
	}
	node<T> *suc(ll p, node<T>* t, ll lb, ll ub, T val) {
		if (!t) t = new node<T>(M::id());
		if (lb + 1 == ub) {
			t->val = val;
			return t;
		}
		ll c = (lb + ub) / 2;
		if (p < c) t->l = suc(p, t->l, lb, c, val);
		else t->r = suc(p, t->r, c, ub, val);
		t->val = M::op(value(t->l), value(t->r));
		return t;
	}
public:
	DynamicSegmentTree(ll n_) :
		n(1 << (int)ceil(log2(n_))), root(nullptr) {}
	~DynamicSegmentTree() {
		if (root) delete root;
	}
	void update(ll p, T val) {
		root = suc(p, root, 0, n, val);
	}
	T find(ll l, ll r) {
		return sub(l, r + 1, root, 0, n);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q, com, x, y;
	cin >> n >> q;
	DynamicSegmentTree<RMQ> st(n);
	while (q--) {
		cin >> com >> x >> y;
		if (com) {
			printf("%d\n", st.find(x, y));
		}
		else {
			st.update(x, y);
		}
	}
	return 0;
}

Measured memory_bytes: 7048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint pow2(ll n){
  mint ans = 1;
  if(n == 0){
    return ans;
  }
  else if(n % 2 == 0){
    ans = pow2(n/2);
    ans *= ans;
    return ans;
  }
  else{
    ans = pow2(n/2);
    ans *= ans;
    ans *= 2;
    return ans;
  }
}

vector<mint> fac(2000003, 1);
 
void calc(int n){
  rep(i, n){
    fac.at(i+1) = fac.at(i) * (i+1);
  }
  return;
}
 
mint f(int n, int k){ // nCk
  mint a = fac.at(n);
  mint b = fac.at(k);
  mint d = fac.at(n-k);
  mint ans = a / (b * d);
  return ans;
}

int main(){
  ll n, k;
  cin >> n >> k;
  calc(n);
  mint ans = 0;
  rep(i, min(k+1, n)){
    ans += f(n, i) * f(n - 1, i);
  }
  cout << ans.x << endl;
}

Measured memory_bytes: 15872
mod = 998244353

N, K = map(int, input().split())
L = []
R = []
for i in range(K):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

dp = [0] * (N)
dp[0] = 1

ruisekiwa = [0] * (N+1)
ruisekiwa[1] = 1

for i in range(1, N):
    for k in range(K):
        l = max(0, i-R[k])
        r = i-L[k]
        if r < 0:
            continue
        dp[i] += ruisekiwa[r+1] - ruisekiwa[l]
        # print("p", i, k, l, r, ruisekiwa, dp[i])
        dp[i] %= mod
    ruisekiwa[i+1] = ruisekiwa[i] + dp[i]

# print(dp)
print(dp[-1])


Measured memory_bytes: 71080
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int N;
  cin >> N;
  int num = N;
  if (N % 2 == 1)
    N--;
  int ma = 0;
  for (int i = N; i > 1; i--) {
    int j = i;
    int c = 0;
    while (j % 2 == 0) {
      j /= 2;
      c++;
    }
    if (ma < c) {
      ma = c;
      num = i;
    }
  }
  cout << num << endl;
}

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

int main() {
  int N, sum = 0;
  cin >> N;
  vector<int> B(N - 1);
  for (int i = 0; i < N - 1; i++) {
      cin >> B.at(i);
    }
    sum += B.at(0) + B.at(N - 2);
    for (int i = 0; i < N - 2; i++) {
        sum += min(B.at(i), B.at(i + 1));
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
using System;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var S = Console.ReadLine();

            if (S == "SAT")
            {
                Console.WriteLine(1);
            }
            else if (S == "FRI")
            {
                Console.WriteLine(2);
            }
            else if (S == "THU")
            {
                Console.WriteLine(3);
            }
            else if (S == "WED")
            {
                Console.WriteLine(4);
            }
            else if (S == "TUE")
            {
                Console.WriteLine(5);
            }
            else if (S == "MON")
            {
                Console.WriteLine(6);
            }
            else if (S == "SUN")
            {
                Console.WriteLine(7);
            }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    if(a > b || (n == 1 && a != b)){
        cout << 0 << endl;
        return 0;
    }
    ll res = (n - 2) * (b - a) + 1;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << ""; print(ts...); }

int main(){
  string s="pphbhhphph";
  int n; cin >>n;
  print(s[n%10],"on");
}

int solve(){
  int a,b,k; cin >>k >>a >>b;
  print((b/k-(a-1)/k>=1)?"OK":"NG");
}


Measured memory_bytes: 3636
# N, D, K = map(int,input().split())
# LR = [list(map(int,input().split())) for _ in range(D)]
# ST = [list(map(int,input().split())) for _ in range(K)]

from math import floor
# 約数全列挙(ソート済み)
# n = 24 -> [1,2,3,4,6,8,12,24]
def divisor(n):
    left = [1]
    right = [n]
    sup = floor(pow(n,1/2))
    for p in range(2,sup+1):
        if n % p == 0:
            if p == n//p:
                left.append(p)
                continue
            left.append(p)
            right.append(n//p)
    res = left + right[::-1]
    return res

N, M = map(int,input().split())
cand = divisor(M)
ans = 1
for ch in cand:
    if M // ch >= N:
        ans = max(ans, ch)

print(ans)

Measured memory_bytes: 3188
//https://atcoder.jp/contests/abc126/tasks/abc126_a
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N, K;
    string S;
    cin >> N >> K >> S;

    string res;
    REP(i, N){
        res += ( i + 1 != K ? S[i] : tolower(S[i]) );
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

/*

?¨???????

2????????´??° a, b ??¨1??????????????? op ?????????????????§???a op b ????¨??????????????????°?????????????????????????????????????????????????????? op ??????"+"(???)???"-"(???)???"*"(???)???"/"(???)???????????¨?????????????????§????????????????????´??????????°???°?????\??????????????¨????????????????¨????????????¨????????????

Input
??\???????????°????????????????????????????§???????????????????????????????????????????????????¢????????\????????¨????????§???:

a op b

op ??? '?' ?????¨??? ??\?????????????????????????????????????????±???????????????????????£????????????????????????

Output
?????????????????????????????????????¨?????????????1??????????????????????????????

*/

int main( void )
{
	int a, b;

	char c;

	while ( 1 ) {

		scanf( "%d %c %d", &a, &c, &b );

		switch ( c ) {
			default:
				break;
			case '+':
				printf( "%d\n", a + b );
				break;
			case '-':
				printf( "%d\n", a - b );
				break;
			case '*':
				printf( "%d\n", a * b );
				break;
			case '/':
				printf( "%d\n", a / b );
				break;
		}

		if ( c == '?' ) {
			break;
		}
	}

	return 0;
}

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

const int mod = 1000000007;

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

    int n;
    cin >> n;

    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    ll ans = 0;

    for(int i = 0; i < 60; i++){
        ll x = 0;
        for(int j = 0; j < n; j++){
            if(a[j] >> i & 1) x++;
        }
        ll add = x * (n - x) % mod;
        for(int j = 0; j < i; j++){
            add = add * 2 % mod;
        }
        ans += add;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560