akhauriyash/Code-Regression huggingface dataset:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===
cnt = 0
while True:
    cnt += 1
    x = int(input())
    if x != 0:
        print("Case ", cnt, ": ", x, sep="")
    else:
        exit(0)



Measured memory_bytes: 6936
from collections import Counter
import numpy as np

p = 2.5e5
n = int(input())
l = np.array([list(map(int, input().split())) for _ in range(n)], dtype=np.float32)
ans = np.zeros(n)

a = np.linspace(0, 2 * np.pi, p, endpoint=False)
b = np.array([np.sin(a), np.cos(a)], dtype=np.float32)

for i, v in Counter(np.argmax(np.dot(l, b), axis=0)).items():
  ans[i] += v / p

print('\n'.join(map(str, ans)))

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    map<int,int> mp;    
    rep(i,n){
        int m; cin >> m;
        mp[m]++;
    }
    ll res = 0;
    for(auto a:mp){
        if(a.second % 2)res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 4992
using System;

namespace ITP1_4_A {
    class Program {
        static void Main(string[] args) {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int d = a / b;
            int r = a % b;
            decimal f = (decimal)a / (decimal)b;
            Console.WriteLine("{0} {1} {2}", d, r, f);
        }
    }
}

Measured memory_bytes: 9200
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<limits.h>

int pw(int n) {
    if(n==0) {
        return 1;
    }
    int i;
    int ans = 1;
    for(i=0; i<n; i++) {
        ans *=10;
    }
    return ans;
}

int main(void){
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);

    int n;
    int ans = 0;
    for(n=1; n<=N; n++) {
        int number = n;
        int digit = 0;
        while(number!=0) {
            number = number / 10;
            ++digit;
         }

        int i;
        int sum = 0;
        for(i=0; i<digit; i++) {
            sum += (n/pw(i)) % 10;
        }
        if(sum >= A && sum <= B) {
            ans += n;
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;
#define ll long long
inline ll read()
{
    ll d=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){d=d*10+ch-'0';ch=getchar();}
    return d*f;
}
int pw(int n,int t)
{
    int a=1;
    for(int i=0;i<t;i++)
        a*=n;
    return a;
}
int main()
{
    int n;
    n=read();
    int cnt=0,t=n;
    while(t)
        t/=10,cnt++;
    int ans=0;
    if(cnt%2==0)
        n=pw(10,cnt-1)-1,cnt--;
    while(n>0)
    {
        t=pw(10,cnt-1);
        ans+=n-t+1;
        n=t/10-1;
        cnt-=2;
    }
    cout << ans;
    return 0;
}


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

int N, K;
char X[22][1 << 20];
int dp[2][22][1 << 20];

int main() {
    scanf("%d %d", &N, &K);

    for(int i = 0; i <= N; i++) {
        scanf("\n");
        for(int j = 0; j < (1 << i); j++) {
            scanf("%c", &X[i][j]);
        }
    }

    for(int p = N; p >= 0; p--) {
        for(int len = 0; len <= N; len++) {
            for(int mask = 0; mask < (1 << max(p, len)); mask++) {
                dp[p & 1][len][mask] = 0;

                if(len <= p) {
                    dp[p & 1][len][mask] += X[p][mask] - '0';
                    if(p < N) {
                        dp[p & 1][len][mask] += dp[ (p ^ 1) & 1 ][len][mask];
                        dp[p & 1][len][mask] += dp[ (p ^ 1) & 1 ][len][mask ^ (1 << p)];
                    }
                    continue;
                }
                int t = (mask & (1 << p))? 1 : 0;
                int nmask = mask & ((1 << (N + 1)) - (1 << p));
                nmask <<= 1;
                nmask += (mask & ((1 << p) - 1));
                if(!t) nmask += (1 << p);
                dp[p & 1][len][mask] += dp[ (p ^ 1) & 1 ][len][mask];
                if(len < N) dp[p & 1][len][mask] += dp[ (p ^ 1) & 1 ][len + 1][nmask];
            }
        }
    }

    string ans = "";
    for(int i = N; i >= 0; i--) {
        for(int j = 0; j < (1 << i); j++) {
            if(dp[0][i][j] >= K) {
                string tmp;
                for(int k = i - 1; k >= 0; k--) {
                    tmp.push_back((j & (1 << k))? '1' : '0');
                }
                if(ans == "" || ans > tmp) ans = tmp;
            }
        }
        if(ans != "") {
            cout << ans;
            return 0;
        }
    }
}


Measured memory_bytes: 198912
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    int last_a = 0;
    int first_b = 0;
    int both = 0;
    int res = 0;
    rep(i, N) {
        string s;
        cin >> s;
        bool judge1 = 0, judge2 = 0;
        if (s[0] == 'B')
            judge1 = 1;
        if (s[s.size() - 1] == 'A')
            judge2 = 1;
        if (judge1 && judge2)
            both++;
        if (judge1 && !judge2)
            first_b++;
        if (!judge1 && judge2)
            last_a++;
        char prev = '#';
        rep(j, s.size()) {
            if (prev == 'A' && s[j] == 'B')
                res++;
            prev = s[j];
        }
    }

    if (both >= 2) {
        res += (both - 1);
        if (first_b >= 1 && last_a >= 1) {
            first_b--, last_a--;
            res += 2;
            res += min(first_b, last_a);
        } else if (first_b == 0 && last_a != 0) {
            res += 1;
        } else if (first_b != 0 && last_a == 0) {
            res += 1;
        }

    } else if (both == 1) {
        if (first_b >= 1 && last_a >= 1) {
            first_b--, last_a--;
            res += 2;
            res += min(first_b, last_a);
        } else if (first_b == 0 && last_a != 0) {
            res += 1;
        } else if (first_b != 0 && last_a == 0) {
            res += 1;
        }
    } else {
        res += min(first_b, last_a);
    }

    cout << res << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    r,D,x=map(int,input().split())
    l=[x]
    for i in range(10):
        l.append(l[i]*r-D)
    l=list(map(str,l))
    print(' '.join(l[1:]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=5e2+50;
const ll mod=1e9+7;
using namespace std;
int dx[]={-1,1,0,0},dy[]={0,0,-1,1},n,p[nmax*nmax],f[nmax][nmax],a[nmax][nmax],x,y,nx,ny,i,j,rs,vl,v[nmax][nmax];
pair<int,int>pr[nmax*nmax];
queue<pair<int,int> >q;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n*n;i++)cin>>p[i];
	for(i=1;i<=n;i++)for(j=1;j<=n;j++)f[i][j]=min(min(i-1,j-1),min(n-i,n-j)),a[i][j]=1,pr[n*(i-1)+j]=mkp(i,j);
	for(i=1;i<=n*n;i++)
	{
		x=pr[p[i]].fr,y=pr[p[i]].sc;
		rs+=f[x][y];
		a[x][y]=0;
		q.push(mkp(x,y));
		while(!q.empty())
		{
			x=q.front().fr,y=q.front().sc;
			q.pop();
			vl=f[x][y]+a[x][y];
			for(j=0;j<4;j++)
			{
				nx=x+dx[j],ny=y+dy[j];
				if(nx<1 || nx>n || ny<1 || ny>n || f[nx][ny]<=vl)continue;
				q.push(mkp(nx,ny));
				f[nx][ny]=vl;
			}
		}
	}
	cout<<rs<<endl;
	return 0;
}


Measured memory_bytes: 8588
#include <iostream>
using namespace std;
int main()
{
  int D, N;
  cin >> D >> N;
  if (N == 100)
    N += 1;
  int ans = N;
  for (int i = 1; i <= D; i++)
    ans *= 100;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
public class Main {


  private static void solve() {
    int n = ni();
    int k = ni();
    
    System.out.println(n >= k * 2 - 1 ? "YES"  : "NO");
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define maxn 200005
#define INF 0x3f3f3f3f
#define mod 1000000007
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
using namespace std;

void slove()
{
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a >= k) {
		cout << k;
		return;
	}
	ll sum = a;
	if (k-a <= b) {
		cout << sum;
		return;
	}
	cout << sum - (k-b-a);
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:\\Users\\Fish_Brother\\Desktop\\in", "r", stdin);
	//freopen("C:\\Users\\Fish_Brother\\Desktop\\out", "w", stdout);
#endif

		slove();

	return 0;
}

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

int main(){
  int n;
  long long ans;
  
  scanf(" %d",&n);
  
  ans=1;
  for(int i=1;i<=n;i++){
    ans*=i;
  }
  
  printf("%lld\n",ans);
  
  return 0;
}

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

using namespace std;

int main()
{
    long long  a, b, n;
    cin >> n >> a >> b;
    long sub = 0;
    if (a + b != 0) {
        sub = n / (a + b);
    }

    long mod = n - sub * (a + b);
    if (mod > a)
    {
        mod = a;
    }

    long res = 0;
    if (sub == 0 && n > a)
    {
        res = a;
    }
    else
    {
        res = sub * a + mod;
    }

    cout << res << endl;


    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------変数-----------------------//
//-------------------関数----------------------//
#define control 40001
ll pl[214514];
int main() {
  ll n;
  cin >> n;
  REP(i, n) {
    ll a;
    cin >> a;
    pl[a - 1] = i;
  }
  REP(i, n) {
    if (i)
      cout << " ";
    cout << i * control + pl[i] + 1;
  }
  cout << endl;
  REP(i, n) {
    if (i)
      cout << " ";
    cout << (n - 1 - i) * control + pl[i] + 1;
  }
  cout << endl;
}


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

int main(){
     int house[4][3][10]={0};
     int n,b,f,r,v;
     cin>>n;
     for(int i=0;i<n;i++){
         cin>>b>>f>>r>>v;
         house[b-1][f-1][r-1]+=v;
     }
     for(int i=0;i<4;i++){
          for(int j=0;j<3;j++){ 
              for(int k=0;k<10;k++){
                  cout<<" "<<house[i][j][k];
              }
              cout<<endl;
           }
           if(i!=3){
                for(int k=0;k<20;k++) cout<<"#";
                cout<<endl;
           }
      } 
}

Measured memory_bytes: 3076
L, R = map(int, input().split())
MOD = 2019

if R - L >= 2019:
    print(0)
    exit()

ans = (L * (L + 1)) % MOD
for i in range(L, R + 1):
    for j in range(L + 1, R):
        ans = min(ans, (i * j) % MOD)

print(ans)


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

ll modpow(ll a, ll n)
{
  ll res=1;
  while (n>0) {
    if (n&1) res = res*a % mod;
    a = a*a % mod;
    n >>= 1;
  }
  return res;
}

int main()
{
  ll N, K; cin >> N >> K;

  vector<ll> d(K+1);
  for (int i=K; i>=1; i--) {
    ll tmp = modpow(K/i, N);
    for (int j=2; j*i<=K; j++) {
      tmp = (tmp + mod - d[j*i]) % mod;
    }
    d[i] = tmp;
  }

  ll ans = 0;
  for (int i=1; i<=K; i++) {
    ans = (ans + i*d[i]) % mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3996
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		String b = next();
		String result = "";
		switch(b) {
		case "A": 
			result = "T";
			break;
		case "C": 
			result = "G";
			break;		
		case "G": 
			result = "C";
			break;
		case "T": 
			result = "A";
			break;
		}
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define assign(x,val) memset(x,val,sizeof(x))
const ll mod=1e9+7;
void solve(){
    int x;
    cin>>x;
    if(x==0) {cout<<0;return;}
    for(int i=1;;i++){
        if(i*(i+1)/2>=x&&(i-1)*i/2<x){
        cout<<i;return;}
    }
}
int main() {
    crap;
	int t=1;
	//cin>>t;
	while(t--){
	    solve();
	}
	return 0;
}

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



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

  int n;
  cin >> n;
  vector<pair<int,int>> item(n);
  rep(i,n) cin >> item[i].first >> item[i].second;
  vector<vector<int>> dp(min(1<<9,n), vector<int>(100001));
  for (int j = 0; j < 100001; j++) {
    dp[0][j] = (j >= item[0].second ? item[0].first : 0);
  }
  for (int i = 1; i < min(1<<9,n); i++) {
    int p = (i - 1) / 2;
    for (int j = 0; j < 100001; j++) {
      dp[i][j] = dp[p][j];
      if (j >= item[i].second) {
        dp[i][j] = max(dp[i][j], dp[p][j- item[i].second] + item[i].first);
      }
    }
  }
  int q;
  cin >> q;
  rep(_,q){
    int v,l;
    cin >> v >> l;
    --v;
    vector<int> knap1;
    while(v>=(1<<9)){
      knap1.push_back(v);
      v = (v-1)/2;
    }
    map<int,int> mp1;
    ll ans = 0;
    rep(i,1<<((int)knap1.size())){
      ll val, wei;
      val = wei = 0;
      rep(j,knap1.size()){
        if(i & 1<<j){
          val += item[knap1[j]].first;
          wei += item[knap1[j]].second;
        }
      }
      if(wei>l) continue;
      ans = max(ans,val + dp[v][l-wei]);
    }
    cout << ans << endl;
  }
  
  return 0;
    

}


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

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2  

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;



int main(){
    bool flag=true;
    ll ans=0,sum=0;

    int n,k;
    cin >>n>>k;
    int lim = ((n-1)*(n-2))/2;
    vector<pii> uni;
    vector<pii> es;

    if( k > lim){
        cout << -1 << endl;
        return 0;
    }

    for (int i = 2; i <= n; i++){
        uni.pb(pii(1,i));
    }
    
    for (int i = 2; i < n; i++){
        for (int j = i+1; j <= n; j++){
            es.pb(pii(i,j));
        }
    }

    for (int i = 0; i < lim - k; i++){
        uni.pb(es[i]);
    }

    cout << uni.size() <<endl;
    for (int i = 0; i < uni.size(); i++){
        int a = uni[i].first;
        int b = uni[i].second;

        cout <<a<<" "<<b<<endl;
    }
    

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define maxn 105
using namespace std;
char s[maxn];

int main()
{scanf("%s",s);
int len=strlen(s);
ll sum=0;
for(int i=0;i<(1<<(len-1));i++)
{ll temp=0;
    for(int j=0;j<len;j++)
    {
        temp=temp*10+(s[j]-'0');
        if(j==(len-1)||i&(1<<(j)))
        {
            sum+=temp;
            temp=0;
        }
        if(j==len-1)
            break;

    }
}
printf("%lld\n",sum);
return 0;

}


Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑





int a, b, k[2005], l[2005];
int main() {
	cin >> a >> b;
	vector<vector<ll>>dp(a + 1, vector<ll>(b + 1));
	for (int i = 0; i < a; ++i) { cin >> k[i]; }
	for (int i = 0; i < b; ++i) { cin >> l[i]; }

	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < b; ++j) {
			dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD;
			if (k[i] == l[j]) { dp[i + 1][j + 1] = (dp[i + 1][j + 1] + 1) % MOD; }
			else { dp[i + 1][j + 1] = (dp[i + 1][j + 1] - dp[i][j] + MOD) % MOD; }
		}
	}

	//""
	cout << (dp[a][b] + 1) % MOD << endl;
}

Measured memory_bytes: 31616
#include<stdio.h>
#define ll long long
#define chmax(p,q)((p)<(q)?(p)=(q),1:0)
#define MOD 1000000007
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define inv(a,p)pom(a,p-2,p)

ll e[1000010];
ll a[10010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%lld",a+i);
	for(int i=0;i<n;i++){
		int temp=a[i];
		for(int p=2;p*p<=temp;p++)if(temp%p==0){
			int cnt=0;
			while(temp%p==0)temp/=p,cnt++;
			chmax(e[p],cnt);
		}
		if(temp!=1)chmax(e[temp],1);
	}
	ll L=1;
	for(int i=2;i<=1000000;i++)if(e[i])L=L*pom(i,e[i],MOD)%MOD;
	ll ans=0;
	for(int i=0;i<n;i++)ans+=inv(a[i],MOD);
	
	printf("%lld",ans%MOD*L%MOD);
}

Measured memory_bytes: 6528
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


def frog(num, stride, heights):
    """
    Prameters
    ---------
    num : int
        足場の数

    stride : int
        ジャンプステップ

    heights : list
        足場の高さ

    Return
    ------
    min_cost : int
        最小コスト
    """
    dp = np.zeros(num, dtype=int)
    heights = np.array(heights)
    for i in range(1, num):
        start = max(0, i - stride)
        dp[i] = (dp[start: i] + np.abs(heights[i] - heights[start: i])).min()
    return dp[-1]

N, K = ds_in()
h_list = ds_in()

print(frog(N, K, h_list))


Measured memory_bytes: 22876
#include<iostream>
#include<string>
using namespace std;
int n,f[100],p,a,b;
string s;
int main()
{
  cin>>n>>s;
  for(int i=0;i<n;i++)
  {
    p=0;
	if(s[i]==')')
	{
	  for(int j=i-1;j>=0;j--)
        if(s[j]=='('&&f[j]<1){f[j]=p=1;break;}
      if(p<1)a++;
	}
    else
    {
      for(int j=i+1;j<n;j++)
        if(s[j]==')'&&f[j]<1){f[j]=p=1;break;}
      if(p<1)b++;
    }
  }
  for(int i=0;i<a;i++)cout<<'(';
  for(int i=0;i<n;i++)cout<<s[i];
  for(int i=0;i<b;i++)cout<<')';
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define REP(i,n) for (int i=0;i<(n);i++)
int main(){
long long x;
long long sum=0;
scanf("%lld",&x);
sum += (x/11);
sum *= 2;
x = x%11;
if(x==0){
}else if(x<=6){
sum++;
}else{
sum++;sum++;
}
printf("%lld",sum);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
        int k, x; cin >> k >> x;

        if (500 * k >= x) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        Integer inputVal = new Integer(in.readLine());
        Integer outputVal = 0;
        for (int i = 0; i <= inputVal; i++) {
        	if (i % 2 == 0) {
        		continue;
        	}
        	Integer countVal = 0;
        	for (int s = 1;s <= i;s++) {
        		if (i % s == 0) {
        			countVal++;
        		}
        	}
        	if (countVal == 8) {
        		outputVal++;
        	}
        }
        System.out.println(outputVal);
   }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int n;
vector<vector<int>> G;
vector<bool> seen;
map<P, int> mp;

void dfs(int v, int used) {
    debug(v, used);
    int color = 0;
    seen[v] = true;
    for(const auto& nv: G[v]) {
        if (seen[nv]) continue;
        if (color == used) color++;
        if (v<nv) mp[{v,nv}] = color;
        else mp[{nv, v}] = color;
        debug(v, nv, used, color);
        dfs(nv, color);
        color++;
    }
}

int main() {
    cin >> n;
    G.resize(n);
    seen.assign(n, false);
    vector<P> edges(n-1);
    rep(i, n-1) {
        int x, y; cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
        edges[i] = {x, y};
    }
    // print(G);
    dfs(0, -1);
    int ans = 0;
    for(const auto& m: mp) chmax(ans, m.se);
    cout << ans+1 << endl;
    for(const auto& p: edges) {
        cout << mp[{p.fi, p.se}]+1 << endl;
    }
}

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

using namespace std;

#define int long long

void lol(string s, int k, int big) {
    if (k == 0) {
        cout << s << '\n';
        return;
    }
    for (int i = 0; i <= min(25ll, big + 1); ++i) {
        if (i == big + 1) lol(s + (char) ('a' + i), k - 1, big + 1);
        else lol(s + (char) ('a' + i), k - 1, big);
    }
}

void solve() {
    int n;
    cin >> n;
    lol("a", n - 1, 0);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll a[100100];

int main(void){
	int n,i;
	ll m;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	sort(a,a+n);
	if(a[0]>=0){
		m = -a[0];
		for(i=1; i<n; ++i){
			m += a[i];
		}
		cout << m << endl;
		for(i=1; i<n; ++i){
			if(i==n-1){
				swap(a[0],a[i]);
			}
			cout << a[0] << " " << a[i] << endl;
			a[0] -= a[i];
		}
	}else if(a[n-1]<=0){
		reverse(a,a+n);
		m = a[0];
		for(i=1; i<n; ++i){
			m -= a[i];
		}
		cout << m << endl;
		for(i=1; i<n; ++i){
			cout << a[0] << " " << a[i] << endl;
			a[0] -= a[i];
		}
	}else{
		m = 0ll;
		for(i=0; i<n; ++i){
			m += abs(a[i]);
		}
		cout << m << endl;
		for(i=1; i<(n-1); ++i){
			if(a[i]>0){
				cout << a[0] << " " << a[i] << endl;
				a[0] -= a[i];
			}else{
				cout << a[n-1] << " " << a[i] << endl;
				a[n-1] -= a[i];
			}
		}
		cout << a[n-1] << " " << a[0] << endl;
	}
	return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define traceloop(x,a) {for(ll i=0;i<x;i++) cerr<<a[i]<<" "; cerr<<endl;}
ll ab(ll x) {return x>0LL?x:-x;}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n;
	cin>>n;
	vector<ll> v(n);
	for(int i=0; i<n; i++)
		cin>>v[i];
	ll ans=0;
	for(int i=0; i<n-1; i++)
		for(int j=i+1; j<n; j++)
			ans+=v[i]*v[j];

	cout<<ans;

	return 0;
}
	

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

enum Tile{
    RIGHT, LEFT, UP,DOWN, FINISH,UNKOEN
};

void MagicTile(int width, int height){
    int x=0,y=0,i=0,j=0;
    string string;
    Tile t;
    Tile *map = new Tile[width * height];
    
    for(i=0;i<height;i++){
        cin >> string;
        //cout <<string <<endl;
        for(j=0;j<width;j++){
            switch (string[j]){
                case '>': t = RIGHT;break;
                case '<': t = LEFT;break;
                case '^': t = UP;break;
                case 'v': t = DOWN;break;
                case '.': t = FINISH;break;
                //default: t = UNKOEN;
            }
            map[j+i*width] = t;
        }
        
    }
    int count=0,total=width*height;
    while(map[x+y*width]!=FINISH){
        switch (map[x+y*width]){
            case RIGHT: x++;break;
            case LEFT: x--;break;
            case UP: y--;break;
            case DOWN: y++;break;
            case FINISH: break;
        }
        count++;
        if(total<=count) break;
    }
    if(count==total){
        cout <<"LOOP"<<endl;
    }
    else {
        cout << x <<" "<< y << endl;
    }
}


int main(){
    int m,n;
    cin >> m >> n;
    cin.ignore();
    while(!(m==0 && n==0)){
        MagicTile(n,m);
        cin >> m >> n;
    }
    return 0;
}

Measured memory_bytes: 1292
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N, M; cin >> N >> M;
		if (!N)break;
		vector<int>prices(N);
		for (int i = 0; i < N; ++i) {
			cin >> prices[i];
		}
		sort(prices.begin(), prices.end(), greater<int>());
		int ans=0,num = 0;
		for (int i = 0; i < N; ++i) {
			num++;
			if (num == M) {
				num = 0;
			}
			else {
				ans += prices[i];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2988
function Main(input) {
  const words = input.split(' ');
  const a = words[0];
  const b = words[1];
  const c = words[2];

  if(b.startsWith(a.slice(-1)) && c.startsWith(b.slice(-1))) {
    console.log('YES');
  } else {
    console.log('NO')
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
def examA():
    N = DI()/dec(7)
    ans = N
    print(N)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    N = I()
    n = (N-1).bit_length()
    V = [[-1]*(1<<n) for i in range(1<<n)]
    #print(V)
    for i in range(n):
        b1 = 1 << i
        b2 = 1 << (i + 1)
        for j in range(1<<i):
            for k in range(1<<(n-i)):
                for l in range(1<<(n-i)):
                    #print(i,j,k,l,j+k*b2,j+b1+l*b2)
                    if j+k*b2>=N or j+b1+l*b2>=N:
                        continue
                    u,v = sorted([j+k*b2,j+b1+l*b2])
                    #print(u,v)
                    V[u][v-1] = i+1
    ans = [[]for _ in range(N-1)]
    for i in range(N-1):
        for v in V[i]:
            if v>=0:
                ans[i].append(v)
    for v in ans:
        print(" ".join(map(str,v)))
    return

# 解説
def examD2():
    N = I()
    ans = [[-1]*(N-1-i) for i in range(N-1)]
    n = N.bit_length()
    for i in range(N):
        for j in range(i+1,N):
            k = 0
            while(True):
                if i&(1<<k) != j&(1<<k):
                    break
                k += 1
            #print(i,j,j-i)
            ans[i][j-i-1] = k+1
    for v in ans:
        print(" ".join(map(str,v)))
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD2()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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

using namespace std;

const int M = 1e5 + 5;
int n, m, out[M], vis[M];
vector <int> adj[M], g[M];
string s;
set <pair <int, int> > st, used, there;

void DFStree (int u) {
  vis[u] = 1;
  for (int v : adj[u]) {
    if (vis[v]) continue;
    used.insert({u, v});
    DFStree(v);
  } 
}

bool dfs (int u, int p ) {
  bool id = s[u] == '1' ? 1 : 0;
  for (int v : g[u]) {
    if (v == p) continue;
    bool k = dfs(v, u);
    if (k == 0) continue;
    used.erase({u, v});
    used.insert({v, u});
    if (id) id = 0;
    else id = k;
  }
  return id;
}

int main () {
  scanf ("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--; v--; 
    there.insert ({u, v});
    adj[u].push_back (v);
    adj[v].push_back (u);
  }
  //puts("here");
  DFStree (0);
  for (auto i : used) {
    g[i.first].push_back(i.second);
  }
  for (auto i : there) {
    if (used.find({i.second, i.first}) != used.end()) out[i.second]++;
    else out [i.first]++;
  }
  for (int i = 0; i < n; i++) {
    s += (out[i]%2) ? '1' : '0';
  }
  if (m % 2 || dfs (0, -1) != 0) {puts ("-1"); return 0;}
  for (auto i : there) {
    if (used.find({i.first, i.second}) != used.end() || used.find({i.second, i.first}) != used.end()) continue;
    used.insert({i.first, i.second});
  }
 /* memset (out, 0, sizeof out);
  for (auto i : used) out[i.first]++;
  for (int i = 0; i < n; i++) {
    if (out[i] % 2) {puts ("-1"); return 0;}
  }*/
  for (auto i : used) cout << i.first+1 << ' ' << 1+i.second << endl;
}


Measured memory_bytes: 32128
#include <iostream>
#include <vector>

using namespace std;

int mod = 998244353;
const int size_max = 200001;
long long fac[size_max], finv[size_max];

long long mpow(long long a, long long b);
void com_init();
long long com(long long n, long long k);

int main()
{
	long long n, m, k;
	cin >> n >> m >> k;

	vector<long long> a(n);
	a[n - 1] = m;
	for (int i = n - 2; i >= 0; i--) {
		a[i] = a[i + 1] * (m - 1);
		a[i] %= mod;
	}

	com_init();
	long long ans = 0;
	long long tmp;
	for (int i = 0; i <= k; i++) {
		tmp = a[i] * com(n - 1, i);
		tmp %= mod;
		ans += tmp;
		ans %= mod;
	}
	cout << ans << endl;

	return 0;
}

long long mpow(long long a, long long b)
{
	long long t = a;
	long long ans = 1;
	for (int i = 0; b != 0; i++) {
		if ((b & 1) == 1) {
			ans *= t;
			ans %= mod;
		}
		t *= t;
		t %= mod;
		b >>= 1;
	}

	return ans;
}

void com_init()
{
	fac[0] = fac[1] = 1;

	for (int i = 2; i < size_max; i++) {
		fac[i] = fac[i - 1] * i;
		fac[i] %= mod;
	}

	finv[size_max - 1] = mpow(fac[size_max - 1], mod - 2);

	for (int i = size_max - 2; i >= 2; i--) {
		finv[i] = finv[i + 1] * (i + 1) % mod;
	}
	finv[0] = finv[1] = 1;
}

long long com(long long n, long long k)
{
	if (n < k) {
		return 0;
	}

	if (n < 0 || k < 0) {
		return 0;
	}

	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

Measured memory_bytes: 7848
X = input()
xlst = []
xlst.append(X[0])
for i in range(1, len(X)):
    if X[i] == 'S':
        xlst.append(X[i])
    else:
        if xlst != [] and xlst[-1] == 'T':
            xlst.append(X[i])
        elif xlst != [] and xlst[-1] == 'S':
            xlst.pop()
        else:
            xlst.append(X[i])

print(len(xlst))


Measured memory_bytes: 51936
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(5*1e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
struct edge { int to, cost; };
int dx[5] = { 0,1,0,-1 }, dy[5] = { 1,0,-1,0 };
map<int, int>factor(int x) {
	map<int, int>res;
	for (int i = 2; i*i <= x; i++) {
		while (x%i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1)res[x]++;
	return res;
}
/*--------Library Zone!--------*/

int n, x, a[2019], b[2019];
signed main() {
	cin >> n >> x;
	int ans = inf;
	rep(i, n)cin >> a[i], b[i] = inf;
	rep(i, n+1) {
		rep(j, n) {
			b[j] = min(b[j], a[(j + n - i) % n]);
		}
		int cnt = 0;
		rep(j, n) {
			cnt += b[j];
		}
		ans = min(ans, cnt + i * x);
	}
	cout << ans << endl;
	endre;
}


Measured memory_bytes: 256
// Problem : B - Distance 
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mod (int)1e9+7
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define repf(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define N 100005
int main()
{
	FAST
    int t=1;
    // cin>>t;
    while(t--)
    {
		int i,n;ll d;
		cin>>n>>d;
		int c=0;
		// vector<pll> v(n);
		repf(i,0,n)
		{
			ll a,b;
			cin>>a>>b;
			ll sq=d*d;
			if(a*a+b*b<=sq) c++;
		}
		cout<<c;
		
    }
    return 0;
} 


Measured memory_bytes: 3664
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M >> K;
	if (N <= K&&M >= K)cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main() {
    ll N, W;
    cin >> N >> W;
    ll i, j;
    ll w[111], v[111];
    ll dp[N+5][W+5];
    
    memset(dp, 0, sizeof(dp));
    
    for(i=0; i<N; i++) {
        cin >> w[i] >> v[i];
    }
    
    for(i=1; i<=N; i++) {
        for(j=0; j<=W; j++) {
            if(j>=w[i-1])
                dp[i][j]=max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1]);
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    
    pr(dp[N][W]);
}



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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e & 1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) {
        return 0;
    }
    if (n == r || r == 0) {
        return 1;
    }
    r = min(r, n - r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * (n - i + 1)) / (i);
    }
    return ans;
}

ll nCr(tuple<ll, ll> t) {
    auto n = get<0>(t);
    auto k = get<1>(t);
    return nCr(n + k - 1, k);
}

template <typename T>
void print(T v) {
    cout << v << " ";
}

template <typename T>
void print(vector<T> v) {
    for (auto &i : v) {
        print(i);
    }
    cout << endl;
}

void solve() {
    ll n, k;
    cin >> n >> k;

    vector<ll> A(n);
    for (auto &i : A) {
        cin >> i;
    }

    vector<ll> out(3 * n + 2, 0);
    ll start = 1;
    ll idx = 0;
    out[idx] = start;
    map<ll, bool> visited;
    visited[1] = true;

    ll cycleStart = -1;
    ll cycleLength = 0;
    ll cycle = 0;
    ll straight = 0;
    bool firstTime = true;
    bool secondTime = true;

    while (idx < 3 * n + 1) {
        ++idx;
        start = A[start - 1];
        out[idx] = start;

        if (!visited[start] && firstTime) {
            straight++;
        } else if (visited[start] && firstTime) {
            //cycle entered here
            cycleStart = start;  //start of cycle node
            firstTime = false;
            cycle = 1;
        } else if (start == cycleStart && !firstTime && secondTime) {
            cycleLength = cycle;
            secondTime = false;
        } else if (!firstTime && secondTime) {
            ++cycle;
        }

        visited[start] = true;
    }
    straight = straight - cycleLength + 1;
    //printf("%lld %lld %lld\n", straight, cycleLength, cycleStart);
    if (k >= straight) {
        k = straight + ((k - straight) % cycleLength);
    }

    /**
     * 
     * 1 6 2x 5 3x
     * 
     */
    cout << out[k] << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef D_LOCAL
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif

    solve();

    return 0;
}

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

int main() {
  int N, Har = 0;
  cin >> N;
  
  int M = N;
  
  for (int i = 0; i < 9; i++) {
    Har += N % 10;
    N /= 10;
  }
  if (M % Har == 0) {
    cout << "Yes" << endl;
  }
  else 
    cout << "No" << endl;
}

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


int main(){
  int a,b,c,d,e,na,nb,nc;
  while(cin>>a>>b>>c>>d>>e,a!=0){
    cin>>na>>nb>>nc;
    int ans = 0;
    int tmp_ans = 0;
    for(int i=0;i<nc+nb+na;i++){
      int tmp;
      if(i<nc)tmp=c;
      else if(i<nc+nb)tmp=b;
      else if(i<nc+nb+na)tmp=a;
      tmp_ans+=tmp;
      if(i<d-1){
      }else if(i==d-1){
        ans =min(tmp_ans,d*e);
        tmp_ans=0;
      }else if(i<nc){
        tmp_ans=0;
        ans += e;
      }
    }
    if(nc+nb+na < d){
      ans = min(tmp_ans,d*e);
      tmp_ans = 0;
    }
    cout<<ans+tmp_ans<<endl;
  }
}

Measured memory_bytes: 1160