akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int fastpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

signed main(){

    int N; cin >> N;
    vec A(N); readvec(A);
    int mod = 1000000007;

    int factn = 1;
    FOR(i, 1, N + 1) factn = (factn * i) % mod;

    vec invsum(N + 1);
    FOR(i, 1, N + 1) invsum[i] = (invsum[i - 1] + fastpow(i, mod - 2, mod)) % mod;

    vec costnum(N);
    REP(i, N) costnum[i] = (invsum[i + 1] + invsum[N - i] - 1 + mod) % mod;
    int ans = 0;
    REP(i, N) ans = (ans + costnum[i] * A[i]) % mod;
    cout << (ans * factn) % mod << endl;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int r;

int main() {

	cin >> r;
	cout << r * r << endl;

	return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {

  val x = readInt()

  def solve() = {
    if(x >= 1800) 1
    else if(x >= 1600) 2
    else if(x >= 1400) 3
    else if(x >= 1200) 4
    else if(x >= 1000) 5
    else if(x >= 800) 6
    else if(x >= 600) 7
    else 8
  }


  println(solve())

}



Measured memory_bytes: 54620
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
      
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int sumAll = 0;

        for(int i=1;i <= n; i++) {
            int sum = 0;
            int div = i;
            while(true) {
                sum += div % 10;
                div = div / 10;

                if(div == 0) {
                    break;
                }
            }
            if(sum >=a && sum <=b) {
                sumAll += i;
            }
        }
        System.out.println(sumAll);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    int N;
    read(N);
    vector<int> x(N);
    vector<int> y(N);
    for(int i = 0; i < N; i++){
        read(x[i], y[i]);
    }
    double ans = 0;
    vector<int> perm(N);
    for(int i = 0; i < N; i++){
        perm[i] = i;
    }
    do{
        for(int i = 0; i < N - 1; i++){
            ans += sqrt((x[perm[i + 1]] - x[perm[i]]) * (x[perm[i + 1]] - x[perm[i]]) + (y[perm[i + 1]] - y[perm[i]]) * (y[perm[i + 1]] - y[perm[i]]));
        }
    }while(next_permutation(perm.begin(), perm.end()));
    for(int i = 2; i <= N; i++){
        ans /= i;
    }
    cout << fixed << setprecision(6) << ans;
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    BLANK, OBSTACLE, JUMP = 0, 1, 2
    ans = 0                     #  ??????????????°???????????°

    dy = [1, 1, 1]  # ?????????????????????????????????????§???????
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°????????????'x???_y???'???????????????
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == BLANK:              #  ?????????????????°?????´?????????????????????????????????
            t = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[t] = 1

    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if field[cy][cx] == OBSTACLE:
            continue
        elif field[cy][cx] == JUMP: #  ?????£????????§?????°?????????????????£????????°
            if cy+2 > y_limit-1:
                ans += num
            else:
                t = '{}_{}'.format(cx, cy+2)
                if not path[t]:
                    Q.append((cx, cy+2))
                path[t] += num
            continue
        elif cy == y_limit -1:
            ans += num
            continue

        for i in range(len(dx)):
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + dy[i]

            if 0<= nx < x_limit:
                if (ny >= y_limit - 1) and field[ny][nx] == BLANK:
                    ans += num
                else:
                    if field[ny][nx] == JUMP and dx[i] == 0: #  ?????£????????°????????£??????????????\????????´???
                        if ny+2 > y_limit - 1:
                            ans += num
                        else:
                            t = '{}_{}'.format(nx, ny+2)
                            if not path[t]:
                                Q.append((nx, ny+2))
                            path[t] += num
                    elif field[ny][nx] == BLANK:
                        t = '{}_{}'.format(nx, ny)
                        if not path[t]:
                            Q.append((nx, ny))
                        path[t] += num
    return ans


def main(args):
    while True:
        X, Y = map(int, input().strip().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().strip().split()]
            field.append(temp)
        result = solve(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8056
#include <stdio.h>
#include <math.h>
#include <ctype.h>

#define min(a,b) (((a)<(b))?(a):(b))

int main(void)
{
    int N,K;
    scanf("%d",&N);
    scanf("%d",&K);
    char S[100];
    scanf("%s",S);
    S[K-1] = tolower(S[K-1]);
    puts(S);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int r, c, i, j, k, x, y, z, a[3005][3005];
i64 f[3005][3005][4], ans;

i64 mxf(int i, int j) {
    return max(f[i][j][0], max(f[i][j][1], max(f[i][j][2], f[i][j][3])));
}

int main() {
    scanf("%d%d%d", &r, &c, &k);
    for (i = 1; i <= k; ++i) {
        scanf("%d%d%d", &x, &y, &z);
        a[x][y] = z;
    }
    fill(f[0][0], f[0][0] + (sizeof(f) / sizeof(i64)),
         numeric_limits<i64>::min());
    f[1][1][3] = 0;
    if (a[1][1] > 0)
        f[1][1][2] = a[1][1];
    for (i = 1; i <= r; ++i)
        for (j = 1; j <= c; ++j) {
            if (i > 1) {
                f[i][j][3] = mxf(i - 1, j);
                if (a[i][j] > 0)
                    f[i][j][2] = mxf(i - 1, j) + a[i][j];
            }
            for (x = 0; x <= 3; ++x)
                f[i][j][x] = max(f[i][j][x], f[i][j - 1][x]);
            if (a[i][j] > 0)
                for (x = 0; x <= 2; ++x)
                    f[i][j][x] = max(f[i][j][x], f[i][j - 1][x + 1] + a[i][j]);
            ans = max(ans, mxf(i, j));
        }
    printf("%lld", ans);
}

Measured memory_bytes: 321072
#include <stdio.h>

int main(){
   int n, x, ans;
   ans = 0;

   scanf("%d %d", &n, &x);
   while (n + x != 0){
      int i, j, k;
      for ( i = 1; i <= n-2 ; i++){
         for ( j = i + 1; j <= n-1; j++){
            for ( k = j + 1; k <= n; k++){
               if (i+j+k==x){
                  ans = ans + 1;
               }
            }
         }
      }
      printf("%d\n", ans);
      scanf("%d %d", &n, &x);
      ans = 0;
      if ( n + x == 0 ){
         break;
      }
   }

   return 0;
}


Measured memory_bytes: 2040
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
   ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
int main(){
  ll a,b,c;cin>>a>>b>>c;
  cout<<c/a*b;
}



Measured memory_bytes: 27036
#include <stdio.h>

int main() {
    int x;

    int r, g, b;
    scanf("%d %d %d", &r, &g, &b);

    x = 100 * r + 10 * g + b;

    if (x % 4 == 0) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;
}

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

int main(){
    int n;cin>>n;
    int t=0;//現在時刻
    vector<pair<int,int> > task(n);
  	rep(i,n){
      cin>>task.at(i).second>>task.at(i).first;
    }
  	//firstに締め切り,secondにかかる時間
    sort(task.begin(),task.end());
  
  	for(int i=0;i<n;i++){
      t+=task.at(i).second;
      if(t>task.at(i).first){
        cout<<"No"<<endl;
        return 0;
      }
    }
  	cout<<"Yes"<<endl;
  	
	return 0;
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;
const double PAI = acos(-1);

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    long double dh = (5*h + 5.0*m/60)*2*M_PI/60;
    long double dm = m*2*M_PI/60;
    long double d = abs(dh - dm);
    cout << fixed;
    cout << setprecision(20);
    cout << sqrt(1.0*a*a + b*b - 2*b*a*cos(d)) << endl;
    return 0;
}


Measured memory_bytes: 4180
#include<bits/stdc++.h>
using namespace std;
#define pf printf
#define sf scanf
#define ll long long
int main(){
	int n,ans=0,check=1;
	sf("%d",&n);
	int arr[n+1];
	for(int i=0;i<n;i++){
        sf("%d",&arr[i]);
        if(arr[i]%2==0 && (arr[i]%3!=0 && arr[i]%5!=0)){
            check=0;
        }
	}
    if(check==1){
    	pf("APPROVED");
    }else{
        pf("DENIED");
    }
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;

const int N = 1e5 + 10;
int n, k;
ll h[N], dp[N];

int main() {

	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++) scanf("%lld", h + i), dp[i] = 1e12;
	dp[1] = 0;
	for(int i = 1; i <= n; i++) {
		for (int j = 1; j <= k; j++) {
			if(i > j) dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}

	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;
const long long mod = 1000000007;

template<typename T>
void max_self(T& a, T b)
{
	a = max(a, b);
}
int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	string s;
	int n;
	cin >> n >> s;
	for (int i = 0; i < sz(s); i++)
		s[i] = ((s[i] - 'A') + n) % 26 + 'A';
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

main(){

int a[4],b[4],i,n;

scanf("%d %d %d",&a[0],&a[1],&a[2]);


if(a[0] > a[1]){

 b[0] = a[1];
 b[1] = a[0];
 b[2] = a[2];

 for(i=0;i<3;i=i+1){
 a[i] = b[i];
 }

}

if(a[1] > a[2]){

 b[0] = a[0];
 b[1] = a[2];
 b[2] = a[1];

 for(i=0;i<3;i=i+1){
 a[i] = b[i];
 }

}

if(a[0] > a[1]){

 b[0] = a[1];
 b[1] = a[0];
 b[2] = a[2];

 for(i=0;i<3;i=i+1){
 a[i] = b[i];
 }

}

printf("%d %d %d\n",a[0],a[1],a[2]);

return 0;

}



Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main()
{
    int n,k,s,i,j;cin>>n>>k;
    if(k>(n-1)*(n-2)/2){cout<<-1<<endl;return 0;}
    s=(n-1)*(n-2)/2+n-1-k;
    cout<<s<<endl;
    for(i=1;i<n&&s;i++)
        for(j=i+1;j<=n&&s;j++,s--)
            cout<<i<<" "<<j<<endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong D, L;
	cin >> D >> L;

	cout << min({D, D/L + D%L}) << endl;

	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=101;
char s[N];
short g[N][N],f[N][N],v[N][N][N][N];
inline void upd(short &x,short y) {x=max(x,y);}
int main() {
    int n,m,x,y,ans=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++) {
	scanf("%s",s+1);
	for(int j=1;j<=m;j++) {
	    if(s[j]=='E') x=i,y=j;
	    int t=(s[j]=='o');
	    f[i][j]=f[i][j-1]+t,g[i][j]=g[i-1][j]+t;
	}
    }
    memset(v,-1,sizeof(v));
    v[0][0][0][0]=0;
    for(int i=0;i<x;i++)
	for(int j=0;x+j<=n;j++)
	    for(int p=0;p<y;p++)
		for(int q=0;y+q<=m;q++) {
		    int d=v[i][j][p][q];
		    if(d==-1) continue;
		    ans=max(ans,d);
		    if(j+1<x-i) upd(v[i+1][j][p][q],d+f[x-i-1][min(y+q,m-p)]-f[x-i-1][max(y-p,q+1)-1]);
		    if(x+j<n-i) upd(v[i][j+1][p][q],d+f[x+j+1][min(y+q,m-p)]-f[x+j+1][max(y-p,q+1)-1]);
		    if(q+1<y-p) upd(v[i][j][p+1][q],d+g[min(x+j,n-i)][y-p-1]-g[max(x-i,j+1)-1][y-p-1]);
		    if(y+q<m-p) upd(v[i][j][p][q+1],d+g[min(x+j,n-i)][y+q+1]-g[max(x-i,j+1)-1][y+q+1]);
		}
    cout<<ans;
    return 0;
}

Measured memory_bytes: 203520
import sys

inf = 1<<30

def solve():
    while 1:
        a, L = map(int, sys.stdin.readline().split())

        if a == L == 0:
            return

        made = {a:0}
        i = 0

        while True:
            i += 1
            amax, amin = make_maxmin(a, L)
            a = amax - amin

            if a in made:
                print(made[a], a, i - made[a])
                break
            else:
                made[a] = i

def make_maxmin(a, L):
    amax = int(''.join(sorted(str(a).zfill(L), reverse=True)))
    amin = int(''.join(sorted(str(a).zfill(L))))

    return amax, amin

if __name__ == '__main__':
    solve()

Measured memory_bytes: 7640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String p = sc.next();
        int end = 0;
        int cnt = 0;
        int j = 0;
        for (int i = 0; i < p.length(); i++) {

            if (s.charAt(j) == p.charAt(i)) {
                cnt++;
                if (cnt == p.length()) {
                    System.out.println("Yes");
                    break;
                }
            }
            j++;
            if (j == s.length()) {
                j = 0;
            }
            if (i == p.length() - 1) {
                i = -1;
                end++;
                j = end;
                cnt = 0;
                if (end == s.length()) {
                    System.out.println("No");
                    break;
                }
            }

        }

    }
}

Measured memory_bytes: 26268
X=int(input())
a=0
if X >= 400 and X < 600:
    a = 8
elif X >= 600 and X < 800:
    a = 7
elif X >= 800 and X < 1000:
    a = 6
elif X >= 1000 and X < 1200:
    a = 5
elif X >= 1200 and X < 1400:
    a = 4
elif X >= 1400 and X < 1600:
    a = 3
elif X >= 1600 and X < 1800:
    a = 2
elif X >= 1800 and X < 2000:
    a = 1
print(a)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int num=2019;

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

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


/*

3 2
1 2
5 5
-2 8


*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c;
  in3(a, b, c);
  if(c <= a + b + 1){
    out(b + c);
    memi;
  }
  else{
    out(a + b + b + 1);
    memi;
  }
}

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

int main()
{
  static const int MAXN = 123456*2;
  static bool sieve[MAXN+1];
  for (int i = 2; i <= MAXN; i++) {
    if (!sieve[i]) {
      for (int j = i+i; j <= MAXN; j += i) {
        sieve[j] = true;
      }
    }
  }

  int N;
  while (cin >> N && N != 0) {
    int ans = 0;
    for (int i = N+1; i <= 2*N; i++) {
      if (!sieve[i]) {
        ++ans;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
s = input()
res = 0
for i in range(len(s)):
    cnt = 0
    while s[i]=="A" or s[i]=="C" or s[i]=="G" or s[i]=="T":
        cnt += 1
        i += 1
        if i==len(s):
          break
    res = max(res,cnt)
print(res)
      

Measured memory_bytes: 2940
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
long long mod=1000000007;
int main()
{
    long long n, k;
    cin>>n>>k;
    long long sum=0;
    for(int i=k; i<=n+1; i++)
    {
        sum+=(i*(n-i+1))%mod+1;
    }
    cout<<sum%mod;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
 
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
 
int N;
vector<int> w;
vector<vector<int>> dp;
 
int rec(int l = 0, int r = N) { // メモ化再帰
    if ((r - l) <= 1) return 0;
    if ((r - l) == 2) {
        if (abs(w[l] - w[l + 1]) <= 1) {  // 隣り合う2つの差が1以下
            return 2;
        } else {
            return 0;
        }
    }
 
    int &ret = dp[l][r];
    if (ret != -1) return ret;  // 既に計算済みならその値を使う
 
    // 1. 全部取り除けるとき
    if (abs(w[l] - w[r-1]) <= 1 && rec(l + 1, r - 1) == r - l - 2) chmax(ret, r - l);
    // 2. そうでない時
    for (int i = l + 1; i <= r - 1; i++) {
        chmax(ret, rec(l, i) + rec(i, r));
    }
 
    return ret;
}
 
int main() {
    vector<int> ans;
    while (true) {
        cin >> N;
        if (N == 0) break;
        w.resize(N);
        for (int i = 0; i < N; i++) {
            cin >> w.at(i);
        }
 
        dp.assign(N + 2, vector<int>(N + 2, -1));  // 初期化
 
        ans.push_back(rec());
    }
 
    for (auto i : ans) {
        cout << i << endl;
    }
 
    return 0;
}


Measured memory_bytes: 3268
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

int N, P;
int c[2];

int main() {
	register int i; int x;
	scanf("%d%d", &N, &P);
	for(i = 1; i <= N; ++i)
		scanf("%d", &x), ++c[x & 1];
	printf("%lld\n", c[1] ? 1ll << (N - 1) : P ? 0 : (1ll << N));
	return 0;
}

Measured memory_bytes: 128
from operator import itemgetter
n = int(input())
spl = [('', 0)]*n
for i in range(n):
    sp = input().split()
    spl[i] = (i+1, sp[0], -int(sp[1]))
for i, j, k in sorted(spl, key=itemgetter(1,2)):
    print(i)

Measured memory_bytes: 3060
while 1:
    n=int(raw_input())
    if n==0: break
    s=t=0
    for i in sorted([int(raw_input()) for _ in range(n)]):
        t+=s
        s+=i
    print t
#(s=t=0
#(1..$_.to_i).map{gets.to_i}.sort.map{|i|t+=s;s+=i}
#p t)while gets>?1

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

// constexpr long MOD = 998244353;
constexpr long MOD = 1000000007;
vector<long> fact, inv;

long mpow(long a, long b) {
  long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return res;
}

void init(int n) {
  fact.push_back(1);
  inv.push_back(1);
  for (int i = 0; i < n; i++) {
    fact.push_back(fact.at(i) * (i + 1) % MOD);
    inv.push_back(mpow(fact.at(i + 1), MOD - 2));
  }
}

long qcom(long n, long r) {
  return fact.at(n) * inv.at(r) % MOD * inv.at(n - r) % MOD;
}

long com(long n, long r) {
  long x = 1, y = 1;
  for (int i = 1; i <= r; i++) {
    x = x * (n - i + 1) % MOD;
    y = y * i % MOD;
  }
  return x * mpow(y, MOD - 2) % MOD;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  long ans = mpow(2, N);
  ans -= com(N, 0);
  ans -= com(N, A);
  ans -= com(N, B);
  while (ans < 0) ans += MOD;
  cout << ans << "\n";
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> arr = new ArrayList<>(Arrays.asList(sc.nextInt(), sc.nextInt(),sc.nextInt()));
        if (arr.contains(5)){
            arr.remove(arr.indexOf(5));
            if (arr.contains(5)){
                arr.remove(arr.indexOf(5));
                if (arr.contains(7)){
                    System.out.println("YES");
                }else{
                    System.out.println("NO");
                }
            }else{
                System.out.println("NO");
            }
        }else{
            System.out.println("NO");
        }
    }
}

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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    int x, y, z; x = y = z = 0;
    ll ans = 1;
    for (int i = 0; i < N; i++){
        int a; cin >> a;
        if(a==x && a==y && a==z){
            x++;
            ans = ans * 3 % mod;
        } else if(a==x && a==y){
            x++;
            ans = ans * 2 % mod;
        } else if(a==x){
            x++;
        } else if(a==y && a==z){
            y++;
            ans = ans * 2 % mod;
        } else if(a==y){
            y++;
        } else if(a==z){
            z++;
        } else {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int>H(N);
	vector<int>I(N);
	if (N == 1) {
		cout << "Yes";
	}
	else {
		for (int i = 0; i < N; i++) {
			cin >> H[i];
		}
		for (int i = N - 1; i > 0; i--) {
			if (H[i] < H[i - 1] ) {
				H[i - 1] = H[i - 1] - 1;
			}
		}
		I = H;
		sort(I.begin(), I.end());
		if (H == I) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=100005;
int n,a[N],cnt;
map<int,int> mp;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		mp[a[i]]++;
	}
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		if(it->second<it->first)
		  cnt+=it->second;
		else 
		  cnt+=it->second-it->first;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
    string s;
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>s;
    if(s=="Y"){
    	cout<<"Four"<<endl;
        break;
    }
    else if(i==n-1){
      cout<<"Three"<<endl;
    
    }
      
    }
    
}

Measured memory_bytes: 256
import java.util.PriorityQueue;
import java.util.Scanner;

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

		PriorityQueue pq = new PriorityQueue();
		for (int i = 0; i < N; i++) {
			int temp = sc.nextInt();
			pq.add(-temp);
		}
		sc.close();

		for (int i = 1; i <= M; i++) {
			int max = -(int) pq.poll();
			//System.out.println(max + "->" + max / 2);
			pq.add(-max / 2);
		}

		long sum = 0;
		while (!pq.isEmpty()) {
			//System.out.println(pq.peek());
			sum += -(int) pq.poll();
		}
		System.out.println(sum);

	}
}

Measured memory_bytes: 60892
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 305
#define mod 1000000007
int f[MN][MN][MN],ans;
vector<int>G[MN][4];
int n,m,l[MN],r[MN],x[MN];
void add(int &p,int val){p+=val;if(p>mod)p-=mod;}
int main(){
	n=read(),m=read();
	register int i,j,k,u;
	for(i=1;i<=m;i++)l[i]=read(),r[i]=read(),x[i]=read(),G[r[i]][x[i]].push_back(l[i]);
	f[0][0][0]=1;
	for(i=1;i<=n;i++){
		for(j=0;j<i;j++)for(k=0;k<i;k++)
        for(u=(j<i-1&&k<i-1)?i-1:0;u<i;u++)
        	add(f[i][k][u],f[j][k][u]),
        	add(f[j][i][u],f[j][k][u]),
        	add(f[j][k][i],f[j][k][u]);
        for(k=1;k<=3;k++)
        for(j=0;j<G[i][k].size();j++){
            int L=G[i][k][j];
            for(int a=0;a<=i;a++)
            for(int b=0;b<=i;b++)
            for(int c=(a<i&&b<i)?i:0;c<=i;c++)
            if((a>=L)+(b>=L)+(c>=L)!=k) f[a][b][c]=0;
        }
    }
    for(i=0;i<=n;i++)for(j=0;j<=n;j++) for(k=(i<n&&j<n)?n:0;k<=n;k++) add(ans,f[i][j][k]);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 110848
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    if (std::abs(N - M) > 1) {
        std::cout << 0 << std::endl;
        return 0;
    }

    int64_t ans = 0;
    if (N == M) {
        ans = 2;
    }
    else {
        ans = std::max(M, N);
        ans %= DIV1097;
    }

    auto O = std::min(M, N);
    for (int64_t i = 0 ; i < O; ++i) {
        ans *= O - i;
        ans %= DIV1097;
        ans *= O - i;
        ans %= DIV1097;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n,a[200000+10];
bool check(int x){
	map<int,int> Fill;
	rb(i,1,n){
		if(i!=1){
			if(a[i]<=a[i-1]){
				if(Fill.end()==Fill.begin()){
					Fill[a[i]]++;
					if(Fill[a[i]]+1>x) return false;
					continue;
				}
				map<int,int> :: IT ite;
				ite=Fill.end();
				ite--;
				while(1){
					if(ite->FIR>a[i]) Fill.erase(ite->FIR);
					else break;
					if(ite==Fill.begin()) break;
					ite--;
				}
				Fill[a[i]]++;
				int L=a[i];
				while(Fill[L]+1>x){
					Fill.erase(L);
					Fill[--L]++;
					
					if(L==0) return false;
				}
			}
		}
	}
	return true;
}
int main(){
	cin>>n;
	rep(i,n) cin>>a[i+1];
	int l=1,r=n;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
//		cout<<l<<" "<<r<<endl;
	}
	cout<<l<<endl; 
	return 0;
}

Measured memory_bytes: 1024
import sys

def main():
    def input():
        return sys.stdin.readline()[:-1]
    N = int(input())
    L = [list(map(int,input().split())) for k in range(N)]
    L = sorted(L,key = lambda x: (x[1],x[0]))
    t = 0
    for e in L:
        if t+e[0] > e[1]:
            print("No")
            exit(0)
        else:
            t += e[0]
    print("Yes")
if __name__ == '__main__':
    main()


Measured memory_bytes: 87004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    int n;cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    vi AB(n),A(n),B(n);
    rep(i,n){
        int num=(int)s[i].size();
        s[i]+='#';
        rep(j,num){
            if(s[i][j]=='A'&&s[i][j+1]=='B'){
                AB[i]++;
                j++;
            }
            else if(j==num-1&&s[i][j]=='A'){
                A[i]++;
            }
            else if(j==0&&s[i][j]=='B'){
                B[i]++;
            }
        }
    }
    int ans=0;
    int BA=0,AA=0,BB=0;
    rep(i,n){
        ans+=AB[i];
        if(A[i]&&B[i]) BA++;
        else if(A[i]) AA++;
        else if(B[i]) BB++;
    }
    //cout << ans << endl;
    //cout << BA << " " << AA << " " << BB << endl;
    if(BA>0){
        ans+=BA-1+(AA>0)+(BB>0);
        if(AA>0) AA--;
        if(BB>0) BB--;
        ans+=min(AA,BB);
    }
    else{
        ans+=min(AA,BB);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <fstream>
using namespace std;

string s;
int main() {
	cin >> s;
	char l = s[0], r = s[s.length() - 1];
	cout << l << s.length() - 2 << r << endl;
}

Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit
from copy import deepcopy as copy
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations, chain
setrecursionlimit(100000)

def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    H, W, K = map(int, input().split())
    MAP = [list(input()) for _ in range(H)]
    ans = 0
    for cols in powerset(range(H)):
        for rows in powerset(range(W)):
            MMAP = copy(MAP)
            for c in cols:
                for k in range(W):
                    MMAP[c][k] = 'r'
            for r in rows:
                for k in range(H):
                    MMAP[k][r] = 'r'
            # print(cols, rows)
            # for row in MMAP: print(*row)
            count = 0
            for i in range(H):
                for j in range(W):
                    if MMAP[i][j] == '#':
                        count += 1
            # print(count, K, ans)
            if count == K:
                ans += 1
    print(ans)



if __name__ == '__main__':
    main()

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

class Dice{
    vector<int> x;

    void advance_vertical(){ 
        advance(0, 1, 5, 4); // N方向
    }
    
    void advance_horizontal(){ 
        advance(0, 3, 5, 2); // E方向
    }

    void advance_rotation(){
        advance(1, 2, 4, 3);
    }

    void advance(int i, int j, int k, int l){
        int tmp = x[i]; 
        x[i] = x[j];
        x[j] = x[k];
        x[k] = x[l];
        x[l] = tmp;
    }

public:
    Dice(vector<int>& x) : x(x) {}
    
    void roll(const string& command){
        for(const auto c : command){
            if(c == 'E'){
                advance_horizontal();
            }
            else if(c == 'N'){
                advance_vertical();
            }
            else if(c == 'S'){
                for(int i = 0; i < 3; ++i){
                    advance_vertical();
                }
            }
            else{
                for(int i = 0; i < 3; ++i){
                    advance_horizontal();
                }
            }
        }      
    }

    int getNow(){
        return x[0];
    }

    int getRightSide(int top_side, int front){
        for(int i = 0; i < 6; i++){ // 面一つずつ見ていく
            for(int j = 0; j < 4; j++){ // rotate方向 4回す
                if(x[0] == front && x[4] == top_side){
                    return x[2];
                }
                advance_rotation();
            }
            if(i % 2 == 0){
                advance_vertical();
            }
            else{
                advance_horizontal();
            }
        }
        return 0; // 失敗
    }

    bool isSame(Dice dice){
        for(int i = 0; i < 6; i++){ // 面一つずつ見ていく
            for(int j = 0; j < 4; j++){ // rotate方向 4回す
                if(dice.x[0] == x[0] && dice.x[1] == x[1] && dice.x[2] == x[2]
                    && dice.x[3] == x[3] && dice.x[4] == x[4] && dice.x[5] == x[5]){
                    return true;
                }
                advance_rotation();
            }
            if(i % 2 == 0){
                advance_vertical();
            }
            else{
                advance_horizontal();
            }
        }
        return false;
    }
};

int main(){

    vector<int> x(6);
    for(int i = 0; i < 6; ++i){
        cin >> x[i];
    }
    vector<int> y(6);
    for(int i = 0; i < 6; ++i){
        cin >> y[i];
    }
    Dice dice1(x);
    Dice dice2(y);

    if(dice1.isSame(dice2)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


    return 0;
}


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

# uf treeの亜種


N,M = map(int,input().split())
root = list(range(N+1))
pos = [0] * (N+1) # rootからの相対座標
depth = [0] * (N+1)

def find_root(x):
  # root および 相対座標 を返す
  y = root[x]
  if x == y:
    return y,0
  z,p = find_root(y)
  root[x] = z
  pos[x] += p
  return z,pos[x]

def merge(x,y,d):
  # y = x + dという位置関係
  rx,px = find_root(x)
  ry,py = find_root(y)
  if rx == ry:
    return (py == px + d)
  # pos[ry] + py = pos[rx] + px + d
  # pos[ry] = pos[rx] + (px-py+d)
  dd = px-py+d
  if depth[rx] > depth[ry]:
    root[ry] = rx
    pos[ry] = dd
  else:
    root[rx] = ry
    pos[rx] = -dd
    depth[ry] += 1
  return True

answer = 'Yes'
for _ in range(M):
  L,R,D = map(int,input().split())
  if not merge(L,R,D):
    answer = 'No'
    break
print(answer)


Measured memory_bytes: 10612
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.q = l
        heapq.heapify(self.q)
        return

    def push(self, n):
        heapq.heappush(self.q, n)
        return

    def pop(self):
        return heapq.heappop(self.q)


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    M = Counter(A)
    MAX = 0
    for v in M.values():
        MAX += v * (v - 1) // 2
    for i in range(N):
        a = M[A[i]]
        ans = MAX - a * (a - 1) // 2 + (a - 1) * (a - 2) // 2
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 104668
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll [[maybe_unused]] = long long;
using ull [[maybe_unused]] = unsigned long long;
using ld [[maybe_unused]] = long double;

[[maybe_unused]] static constexpr int mod = (int)1e9 + 7;
[[maybe_unused]] static constexpr int inf = 100100100;
[[maybe_unused]] static constexpr ll linf = 1e18;
[[maybe_unused]] static constexpr double eps = 1e-9;
[[maybe_unused]] static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, a) for (ll i = a; i >= 0; --i)
#define all(obj) begin(obj), end(obj)
#define rall(obj) rbegin(obj), rend(obj)
#define pb push_back
#define fst first
#define snd second

ll c[4][4];

int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    rep (w, 3) {
        rep (h, 3) {
            ll tmp;
            cin >> c[w][h];
        }
    }
    vector<ll> v;
    rep (i, 3) {
        v.pb((c[i][0] - c[i][1]) == (c[(i + 1) % 3][0] - c[(i + 1) % 3][1]));
        v.pb((c[i][1] - c[i][2]) == (c[(i + 1) % 3][1] - c[(i + 1) % 3][2]));
        v.pb((c[i][2] - c[i][0]) == (c[(i + 1) % 3][2] - c[(i + 1) % 3][0]));
        v.pb((c[0][i] - c[1][i]) == (c[0][(i + 1) % 3] - c[1][(i + 1) % 3]));
        v.pb((c[1][i] - c[2][i]) == (c[1][(i + 1) % 3] - c[2][(i + 1) % 3]));
        v.pb((c[2][i] - c[0][i]) == (c[2][(i + 1) % 3] - c[0][(i + 1) % 3]));
    }
    for (ll i : v) {
        if (i == 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

using ll =  long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	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;
	}

	// 素因数分解 pair.firstで素数、pair.secondで対応する指数
	vector<pair<long long, long long> > prime_factorize(long long n) {
		vector<pair<long long, long long> > res;
		for (long long p = 2; p * p <= n; ++p) {
			if (n % p != 0) continue;
			int num = 0;
			while (n % p == 0) { ++num; n /= p; }
			res.push_back(make_pair(p, num));
		}
		if (n != 1) res.push_back(make_pair(n, 1));
		return res;
	}

	const int MAX = 2100000;

	//二項係数を求める前処理 テーブルを作る　O(n)
	// facは階乗
	long long fac[MAX], finv[MAX], inv[MAX];
	void COMinit() {
		fac[0] = fac[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i < MAX; i++) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - inv[mod % i] * (mod / i) % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}

	// 二項係数計算
	ll COM(int n, int k) {
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
	}
}


int main() {

	ll n, k;
	std::cin >> n >> k;
	std::vector<ll> a(n);
	rep(i, n) std::cin >> a[i];

	std::sort(allof(a));

	COMinit();

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

	ll ans = 0;

	for (int i = n - 1; i >= k - 1; --i) {
		ans += (COM(i, k - 1) * a[i]) % mod;
		ans %= mod;
	}


	for (int i = 0; i <= n - k; ++i) {
		ll add = 0;
		if (a[i] >= 0) {
			add = a[i];
			add = (add * COM(n - 1 - i, k - 1)) % mod;
			ans = (ans - add + mod) % mod;
		}
		else {
			add = -a[i];
			add = (add * COM(n - 1 - i, k - 1)) % mod;
			ans = (ans + add) % mod;
		}
	}

	std::cout << ans % mod << std::endl;

	return 0;
}


Measured memory_bytes: 50304
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
      n: usize, m: usize, q: usize,
      lrv: [(Usize1, Usize1); m],
      pqv: [(Usize1, Usize1); q]
    };

    let mut cv = vec![vec![0; n]; n];
    for (l, r) in lrv {
        cv[l][r] += 1;
    }
    let mut cucusum = vec![vec![0; n + 1]; n + 1];
    for l in 0..n {
        for r in 0..n {
            cucusum[l + 1][r + 1] =
                cucusum[l + 1][r] + cucusum[l][r + 1] - cucusum[l][r] + cv[l][r];
        }
    }
    for (p, q) in pqv {
        let res = cucusum[q + 1][q + 1] - cucusum[q + 1][p] - cucusum[p][q + 1] + cucusum[p][p];
        println!("{}", res);
    }
}


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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
	int n, d; scanf("%d%d", &n, &d);
	int ans = 0;
	while(n > 0) {
		ans++;
		n -= d * 2 + 1;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 384
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let mut m = std::collections::HashMap::new();
    for _ in 0 .. n {
        let mut s = get().as_bytes().to_vec();
        s.sort();
        let e = m.entry(s).or_insert(0);
        *e += 1;
    }
    let mut ans = 0_u64;
    for (_, &v) in m.iter() {
        ans += v * (v-1) / 2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 19028
N = int(input())
A = [int(input()) for _ in range(N)]
A.insert(0,0)
hist = [0 for _ in range(N+1)]
ind = 1
hist[1] = 1
cnt = 0
flag = 0
while True:
    cnt += 1
    ind = A[ind]
    if ind==2:
        flag = 1
        break
    if hist[ind]==1:
        flag = 0
        break
    hist[ind] = 1
if flag==1:
    print(cnt)
else:
    print(-1)

Measured memory_bytes: 55512