akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100009
#define MAXM 320
#define EPS 1e-9
#define MOD 1000000007
#define INF 1000000009
#define FOR(x,n) for(int x=0; x<n; x++)
#define FOR1e(x,n) for(int x=1; x<=n; x++)
#define pb push_back
#define all(x) x.begin(), x.end()
typedef long long ll;

int val[55], target[55];
set<ll> memo[55];
bool visited[55];

void check(int v, int t) {
	int h; visited[v] = true;

	for (int i = v; i > 0; i--) {
		if (v%i == t) { memo[v].insert(1LL << (i-1)); continue; }

		int h = v%i;
		if (h < t) continue;
		if (!visited[h]) {
			check(h, t);
		}
		for (auto it : memo[h]) {
			memo[v].insert(it | (1LL << (i-1)));
		}
	}
}

int main() {
	int n;

	ll ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &val[i]);
	}

	vector<set<ll> > candidates;

	for (int i = 0; i < n; i++) {
		scanf("%d", &target[i]);

		if (val[i] == target[i]) continue;

		for (int j = 0; j < 51; j++) { memo[j].clear(); visited[j] = false; }
		check(val[i], target[i]);
		if (memo[val[i]].empty()) { puts("-1"); return 0; }
		candidates.pb(memo[val[i]]);
	}

	while (!candidates.empty()) {
		ll mv = 0;
		for (int i = 0; i < (int)candidates.size(); i++) {
			mv = max(*candidates[i].begin(), mv);
		}

		int bit = 0;
		for (int j = 51; j >= 0; j--) {
			if ((mv >> j)) {
				bit = j; break;
			}
		}
		ans |= (1LL << bit);
		
		for (int i = 0; i < (int)candidates.size(); i++) {
			set<ll> ns;
			for (auto it : candidates[i]) {
				ll tmp = it;
				tmp = min(tmp, tmp^(1LL << bit));
				ns.insert(tmp);
			}

			if ((*ns.begin()) == 0) {
				swap(candidates[i], candidates.back());
				candidates.pop_back();
				i--;
			} else {
				candidates[i] = ns;
			}
		}
	}
	printf("%lld\n", 2LL*ans);	
}

// 10 -> target

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=1e8;
ll mod=1e9+7;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
//#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pi acos(-1)
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define SIZE 5000 + 1

ll expo(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}

void solve()
{
  ll a,b,c;
  cin>>a>>b>>c;
  swap(a,b);
  swap(a,c);
  cout<<a<<" "<<b<<" "<<c;
}

int main()
{
  boost;
  ll t=1;
  //cin>>t;
  //sieve();
  //int ca=0;
  while(t--)
  {
     // ca++;
     // cout<<"Case #"<<ca<<":"<<" ";
      solve();
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=301;
bool b[N][N];
long long f[N][N],ans;
int n;
int main(){
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
	for (int j=1; j<=n; j++)
	scanf("%lld",&f[i][j]);
	for (int k=n; k>=1; k--)
	for (int i=1; i<=n; i++)
	for (int j=1; j<=n; j++)
	if (i!=k&&k!=j&&i!=j){
		if (f[i][k]+f[k][j]<f[i][j]){
			puts("-1");
			return 0;
		}
		else if (f[i][k]+f[k][j]==f[i][j]) b[i][j]=1;
	}
	for (int i=1; i<=n; i++)
	for (int j=1; j<=n; j++)
	if (!b[i][j]) ans+=f[i][j];
	printf("%lld",ans>>1);
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
using namespace std;
int main(){
  int n, i, a;
  cin >> n;
  char s[10001];
  cin >> s;
  a=strlen(s);
  for(i=0; i<a; i++)
    if(s[i]+n<='Z') s[i]+=n;
    else s[i]+=(n-26);
  cout << s << endl;
  return 0;
}

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

class Main {

    public static int X = 0;
    public static int Y = 1;
    public static int R = 2;
    public static int A = 0;
    public static int B = 1;    
    
    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	final int T = stdin.nextInt();
	for ( int t = 0; t < T; t++ ) {
	    final double[][] circles = new double[2][3];
	    
	    for ( int i = 0; i < 2; i++ ) {
		for ( int j = 0; j < 3; j++ ) {
		    circles[i][j] = stdin.nextDouble();
		}
	    }

	    final double dx = circles[A][X] - circles[B][X];
	    final double dy = circles[A][Y] - circles[B][Y];
	    final double dist = Math.sqrt( dx * dx + dy * dy );

	    if ( circles[A][R] + circles[B][R] < dist ) {
		System.out.println( 0 );
	    } else if ( circles[A][R] > dist + circles[B][R] ) {
		System.out.println( 2 );
	    } else if ( circles[B][R] > dist + circles[A][R] ) {
		System.out.println( -2 );
	    } else {
		System.out.println( 1 );
	    }
	}
	    
    }
    
}

Measured memory_bytes: 20520
#include<bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
#define ff first
#define se second
#define MAX 1000001
#define MAXN 100005
#define mod 1000000007 
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m,c,i,j,sum=0,count=0,x;
    cin>>n>>m>>c;
    ll b[m];
    for(i=0;i<m;i++){
        cin>>b[i];
    }
    for(i=0;i<n;i++){
        sum=0;
        for(j=0;j<m;j++){
            cin>>x;
            sum+=x*b[j];
        }
        sum+=c;
        if(sum>0){
            count++;
        }
    }
    cout<<count;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int x = Integer.parseInt(sc.next());
        
        if(x == 7 || x == 5 || x == 3){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pa pair<int,int>
#define pii pair<ll,ll>
#define st first
#define nd second
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;
const int MAX=10005;
pa tab[MAX];
int dp[MAX];
const int inf=1e9+9;
int main()
{
  BOOST;
  int n,h;
  cin>>h>>n;
  for (int i=1;i<=n;i++)
  {
    cin>>tab[i].st>>tab[i].nd;
  }

  for (int i=1;i<=h;i++)
  {
    dp[i]=inf;
  }

  for (int i=1;i<=h;i++)
  {
    for (int j=1;j<=n;j++)
    {
       if (i-tab[j].st<=0)dp[i]=min(dp[i],tab[j].nd);
       else dp[i]=min(dp[i],dp[i-tab[j].st]+tab[j].nd);
    }
  }

  cout<<dp[h];
  return 0;
}


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

using namespace std;
typedef long long ll;
// Segment Tree
// コンストラクタには要素数を渡す
/* 根               : 1
 * 左からx番目の葉  : x+N
 * iの親のindex     : i/2
 * iの子のindex     : i*2+0, i*2+1
 * iの兄弟(sibling) : i^1
 * iの深さ(depth)   : log_2 iの整数部分
 * iの区間幅(width) : N/highest(i)
 * iの区間の左端    : (i-highest(i))*width(i)
 */

inline int highest(long long x){
    int res = -1;
    for(int i=0;i<64;i++){
        if(1LL<<i < x) res=i;
        else break;
    }
    return res;
}

typedef ll data_t;
struct SegTree {
    vector<data_t> dat; int n;
    SegTree(int n_){
        int k = 1;
        while(k < n_) k<<=1;
        this->n = k;
        dat.assign(k*2, 0);
    }

    // ボトムアップ
    void update(int k, int x){
        int i = n + k; // leaf
        dat[i] = x;
        while(i != 1){ // 1 is root
            dat[i>>1] = dat[i] + dat[i^1];
            i>>=1;
        }
    }

    // 区間[a,b)の最小値を求める
    // kはセグメントの番号でl,rはそれが覆う開区間の両端
    // トップダウン
    data_t query(int a, int b, int k=1, int l=0, int r=-1){
        if(r == -1) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return dat[k];
        data_t v1 = query(a, b, k<<1,   l,       (l+r)/2 );
        data_t v2 = query(a, b, k<<1|1, (l+r)/2, r       );
        return v1+v2;
    }
};

int main(){
    int n,q;
    cin>>n>>q;
    SegTree t(n);
    for(int i=0;i<q;i++){
        ll c,x,y;
        cin>>c>>x>>y;
        if(c==0){ // update
            x--;
            ll a = t.query(x,x+1);
            t.update(x, a+y);
        } else { // query
            x--;y--;
            cout << t.query(x, y+1) << endl;
        }
        // for(int i=0;i<t.n;i++){
        //     printf("%lld,", t.dat[i]);
        // }
        // puts ("");
    }
}

Measured memory_bytes: 3108
// g++ temp.cpp
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <string>
#include <climits>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
//#define REP(i,n) FOR(i,1,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
const unsigned long long MOD = 100000000000000000;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
void solve(){
  string a,b,c;
  cin>>a>>b>>c;
  char l=a[0];
  int i=1,j=0,k=0;
  while(true){
   // cout<<l<<endl;
    if(l=='a'){
      if(i<a.size()){
      l=a[i];
      i++;
      } else {
      cout<<"A"<<endl;
      return;  
    }
     } else if( l == 'b'){
      if(j<b.size()){
      l=b[j];
      j++;
      } else {
      cout<<"B"<<endl;
      return;  
    }
     } else {
      if(k<c.size()){
      l=c[k];
      k++;
      } else {
      cout<<"C"<<endl;
      return;  
    }
     }
  }
}
int main(){
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  string s;
  cin>>s;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]-'0'==i%2)cnt++;
  }
  cout<<min(cnt,(int)s.size()-cnt)<<endl;
  return 0;
}


Measured memory_bytes: 512
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, y;
    cin >> n >> y;
    for (int a = 0; a <= n; ++a) for (int b = 0; b <= n; ++b) {
        int c = n - a - b;
        if (c >= 0 && 10000 * a + 5000 * b + 1000 * c == y) {
            print3(a, b, c);
            return 0;
        }
    }

    print3(-1, -1, -1);

    return 0;
}



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

using namespace std;

int main(){
    int i, j;
    int N, K;
    cin >> N >> K;
    vector <int> d(K);
    vector <int> A(N*K);
    A.assign(N*K, 0);
    for(i=0; i<K; i++){
        cin >> d[i];
        for(j=0; j<d[i]; j++){
            vector <int> tmp(d[i]);
            cin >> tmp[j];
            A[N*i+(tmp[j]-1)] = 1;
        }
    }
    // for(i=0; i<K; i++){
    //     for(j=0; j<N; j++){
    //         cout << A[N*i+j];
    //     }
    //     cout << endl;
    // }
    vector <int> sum;
    int counter = 0;
    sum.assign(N, 0);
    for(i=0; i<N; i++){
        for(j=0; j<K; j++){
            sum[i] += A[N*j+i];
        }
        if(sum[i] == 0){
            counter++;
        }
    }

    cout << counter << endl;
    return 0;
}



Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
using namespace std;

const long MAXV=301;
const long MAXD=(long) 1e12;

long V;

void warshall_floyd(vector<vector <long> > &d) {
    for(long k = 1; k <= V; k++) {
        for(long i = 1; i <= V; i++) {
            for(long j = 1; j <= V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    return;
}

int main(){
    long N,M,L,Q;
    cin >> N >> M >>L;

    vector <vector <long> > d(MAXV, vector<long>(MAXV, MAXD));
    vector <vector <long> > f(MAXV, vector<long>(MAXV, MAXD));

    V=N;

    vector <long> ans;

    for(long i=0; i<M; i++){
        long a,b,c;
        cin >> a >> b >> c;

        d[a][b] = c;
        d[b][a] = c;

    }

    warshall_floyd(d);

    for(long i=1; i<=V; i++){
        for(long j=1; j<=V; j++){
            if(d[i][j]<=L){
                f[i][j]=1;
                f[j][i]=1;
            }
        }
    }
    
    warshall_floyd(f);

    cin >> Q;

    vector <long> s(Q), t(Q), r(Q);
    for(long i=0; i<Q; i++){
        long result;
        cin >> s[i] >> t[i];
        /*
        if( d[s[i]][t[i]]<MAXD ){
            r[i] = d[s[i]][t[i]];
        }else{
            r[i] = -1;
        }
        */
        if( f[s[i]][t[i]]>=MAXD ){
            result = -1;
            ans.push_back(result);
        }else{
            result = f[s[i]][t[i]]-1;
            ans.push_back(result);
        }
    }

    for(long i=0; i<Q; i++){
        //cout << "i s t d[s][t] r[i]" << i << " " << s[i] << " " << t[i] << " " << r[i] << endl;
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4984
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
}

const int MX=1e5+10;

int memo[10007][2][106];

str K; int D,N;

int solve(int u, int st, int mod){
	if(u==N && mod==0) return 1;
	if(u==N) return 0;
	if(memo[u][st][mod]!=-1) return memo[u][st][mod];

	int ans=0;
	for(int i=0; i<K[u]-'0'; i++) ans+=solve(u+1,1,(mod+i)%D),ans%=MOD;
	ans=(ans+solve(u+1,st,(mod+K[u]-'0')%D))%MOD;
	for(int i=K[u]-'0'+1; i<10 && st==1; i++) ans=(ans+solve(u+1,1,(mod+i)%D))%MOD;

	return memo[u][st][mod]=ans;
}



int32_t main(){
   boost;
   IO();

   cin>>K>>D;
   N=sz(K);
   for(int i=0; i<=N; i++) for(int j=0; j<=101; j++) memo[i][0][j]=memo[i][1][j]=-1;
   
   cout << (solve(0,0,0)-1+MOD)%MOD << endl;

   

   return 0;
}



Measured memory_bytes: 20960
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF 100000000
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long

using namespace std;

#define MAX_N 100005

#define MAX_K 10

int N, K;
int D[MAX_K];

void input(){

	cin >> N >> K;
	for (int i = 0; i < K; i++){
		cin >> D[i];
	}

}

void solve(const vector<int>& NList, int &ans, int sum){

	if (sum >= ans)
		return;

	if (sum >= N){
		ans = min(ans, sum);
		return;
	}

	for (int i = 0; i < (int)NList.size(); i++){
		if (sum == 0 && NList[i] == 0)
			continue;
		solve(NList, ans, sum * 10 + NList[i]);
	}

}

int main(){

	input();

	vector<int> NList;

	for (int i = 0; i < 10; i++){
		bool flag = true;
		for (int j = 0; j < K; j++){
			if (D[j] == i){
				flag = false;
				break;
			}
		}
		if (flag){
			NList.push_back(i);
		}
	}

	int ans = INF;
	solve(NList, ans, 0);

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define LOG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

/*
100
 */

char s[3][101];
char ans[] = "ABC";

int main(){
  int l[3];
  REP(i,3){
    cin >> s[i];
    l[i] = strlen(s[i]);
  }
  int i[3] = {0,0,0};
  int turn = 0;
  while(i[turn] < l[turn]){
        turn = s[turn][i[turn]++] - 'a';
  }

  cout << ans[turn] << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

void solve(int test) {
	
	int n; cin >> n;
	int a[n+1] , pf[n+1] = {} ; rep(i,1,n+1) cin >> a[i] , pf[i] = ( pf[i-1] + a[i]) % mod;

	int ans = 0 ;

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

	cout << ans ; 
}

int32_t main() {
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif   

    fast;
	int t=1;
	// cin>>t;
	rep(i,1,t+1) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

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

void fastio()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}

void solve()
{

  int n,m;cin>>n;
  int sum=0;
  for(int i=1;i<=n;i++)
  {
  	m = n/i;
  	sum+=(i*(m*(m+1)))/2;
  }
  cout<<sum<<endl;
}

int32_t main()
{
    // fastio();
    // int t;cin>>t;
    // while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3628
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}



int main(){
    ll n,w,d;
    while(cin>>n>>w>>d,w){
        vector<pair<pll,ll>> A={{{w,d},0}};
        for(ll i=1;i<=n;i++){
            ll p,s;
            cin>>p>>s;
            p--;
            pair<pll,ll> &P=A[p];
            pll C=P.F;
            s%=(C.F+C.S)*2;
            if(s>C.F*2+C.S){s-=C.F*2+C.S; s=C.F+C.S-s;}
            else if(s>C.S+C.F){s-=C.S+C.F; s=C.F-s;}
            if(s>C.F){
                s-=C.F;
                P={{C.F,s},i};
                A.push_back({{C.F,C.S-s},i});
            }
            else{
                P={{s,C.S},i};
                A.push_back({{C.F-s,C.S},i});
            }
            sort(A.begin(),A.end(),[](pair<pll,ll> a,pair<pll,ll> b){return a.S!=b.S?a.S<b.S:a.F.F*a.F.S<b.F.F*b.F.S;});
        }
        sort(A.begin(),A.end(),[](pair<pll,ll> a,pair<pll,ll> b){return a.F.F*a.F.S<b.F.F*b.F.S;});
        for(int i=0;i<A.size();i++){cout<<A[i].F.F*A[i].F.S<<(i+1==A.size()?"\n":" ");}
    }
    
    return 0;
}



Measured memory_bytes: 3032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			int[] a = in.nextIntArray(n);

			long ans = 0;
			int xor = 0, sum = 0;
			for (int l = 0, r = 0; l < n; l++) {
				while (r < n && (xor^a[r]) == (sum+a[r])) {
					xor ^= a[r];
					sum += a[r];
					r++;
				}
				ans += r - l;
				xor ^= a[l];
				sum -= a[l];
			}
			out.println(ans);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 45780
#include<bits/stdc++.h>
using namespace std;
#define ll long long
auto speedup = [](){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
	#endif
	return 0;
}();

int main(){
	string str;
	cin>>str;
	ll sum = 0;
	for(int i=0; i<str.size(); ++i){
		sum += str[i] - 48;
	}
	if((sum%9) == 0)
		cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007, INF = 1e9;
 
int main ()
{
    int a, b, c, x, ans = 0;
    cin >> a >> b >> c >> x;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                int y = (500*i)+(100*j)+(50*k);
                if(x == y)ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pr pair<int,int>
#define endl "\n"
#define MOD 1000000007 // 10^9 + 7
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define all(c) (c).begin(), (c).end()

using namespace std;

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

	//freopen("addin.txt","r",stdin);
	//freopen("addout.txt","w",stdout);

	int n;
	cin >> n;
	vi v(n);
	for(auto &x : v) cin >> x;
	bool f = false;
	int ind = 0,last = 0,ct = 0;
	for(int i = 0;i < v.size()-1;i++){
		if(v[i] > v[i+1]){
			if(!f) {
				ind = i;
				last = i+1;
				f = true;
			}
			else last = i+1;
			ct++;
			if(ct > 2) break;
		}
	}
	if(ct > 2){
		cout<<"NO"<<endl;
	}
	else if(!f) cout<<"YES"<<endl;
	else {
		swap(v[ind],v[last]);
		if(last != (n-1) && ind != 0){
			if( (v[ind] <= v[ind+1] && v[ind-1] <= v[ind]) && (v[last] <= v[last+1] && v[last-1] <= v[last]) ) 
				cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		else if(last == (n-1) && ind == 0) {
			if((v[ind] <= v[ind+1] ) && (v[last-1] <= v[last])) 
				cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		else if(last == (n-1)){
			if((v[ind] <= v[ind+1] && v[ind-1] <= v[ind]) && (v[last-1] <= v[last])) 
				cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		else if(ind == 0) {
			if((v[ind] <= v[ind+1]) && (v[last] <= v[last+1] && v[last-1] <= v[last])) 
				cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		else {
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
use text_io::*;
use std::process::exit;
use im_rc::*;
use std::cmp::*;

fn main(){
    let mut n:usize = read!();
    let mut a:String = read!();
    let mut v:Vec<char> = a.chars().collect();
    let mut a:usize = 0;
    let mut b:usize = 0;
    let al:[char;26] = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    for i in 0..v.len() {
        while a==0{
            if v[i]==al[b] {
                v[i]=al[(b+n)%26];
                a+=1;
            }
            b+=1;
        }
        a = 0;
        b = 0;
    }
    let s:String = v.iter().collect();
    println!("{}",s);
}

Measured memory_bytes: 2104
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    string res = "No";
    if(n % 10 == 9 or n / 10 == 9){
        res = "Yes";
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int main(){
  int n,k,x,y;
  cin>>n;
  cin>>k;
  cin>>x;
  cin>>y;
  int ans;
  if(k <= n)
    ans = x*k+y*(n-k);
  else
    ans = x*n;

  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 764
#include<stdio.h>

int main()
{
	int num;
	scanf("%d", &num);
	
	
	if(num >= 1 && num <= 9)
		printf("%d\n", num);
	else if(num >= 10 && num <= 99)
		printf("9\n");
	else if(num >= 100 && num <= 999)
		printf("%d\n",  num + 10 - 100);
	
	else if(num >= 1000 && num <= 9999)
		printf("909\n");
	else if(num >= 10000 && num <= 99999)
		printf("%d\n", num + 909 - 10000 + 1);
	else if(num >= 100000)
		printf("90909\n");
		
	return 0;
}

Measured memory_bytes: 1704
counter=0
def answer(h:list) -> int:
  global counter
  if len(h)==0:
    return
  if len(h)==1:
    counter+=h[0]
    return
  min_a=min(h)
  for i in range(len(h)):
    h[i]-=min_a
  counter+=min_a
  answer(h[:h.index(0)])
  answer(h[h.index(0)+1:])

n=int(input())
h=list(map(int,input().split()))
answer(h)
print(counter)

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

bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
    {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

int main(){

  int n;
  cin >> n;
  vector<int> p;

  for (int i = 1; i <= n; i++) {
    if (IsPrime(i)) {
      p.push_back(i);
    }
  }

  vector<ll> sum(p.size());

  /*for (int i = 0; i < p.size(); i++) {
    cout << p.at(i) << endl;
  }*/

  //cout << '\n';

  for (int i = 0; i < p.size(); i++) {
    int t = p.at(i);
    int s = p.at(i);
    while (n >= t) {
      sum.at(i) += n/t;
      t*=s;
    }
    //cout << sum.at(i) << endl;
  }

  ll a = 1;
  for (int i = 0; i < sum.size(); i++) {
    a *= (sum.at(i)+1);
    a %= 1000000007;
  }
  std::cout << a << '\n';

}


Measured memory_bytes: 256
/*
 * atcoder/abc128_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const int MAX = 11;
int N, M;
vector<int> S[MAX], P(MAX, 0);
ll all = 0;

void solve() {
  cin >> N >> M;
  int k, s;
  loop(m,0,M) {
    cin >> k;
    loop(i,0,k) {
      cin >> s;
      s--;
      S[m].push_back(s);
    }
  }
  loop(n,0,N) all |= (1<<n);
  loop(m,0,M) cin >> P[m];

  ll total = 0;
  for (ll T=0; T<=all; T++) {
    bool allOn = true;
    loop(m,0,M) {
      int count = 0;
      for (auto &&s: S[m]) {
        count += T>>s;
      }
      allOn &= count%2 == P[m];
    }
    total += allOn;
  }
  cout << total << endl;
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100000

int partition(int *,int,int);

int main(void){

  int i,n,a,S[N];

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  a=partition(S,0,n-1);

  for(i=0;i<n;i++){
    if(i==a) printf("[%d]",S[i]);
    else printf("%d",S[i]);
    if(i != n-1) printf(" ");
    

  }
  printf("\n");
  
  return 0;

}

int partition(int *S,int p,int r){
  int x,i,j,temp;

  x=S[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(S[j]<=x){
      i=i+1;
      temp=S[i];
      S[i]=S[j];
      S[j]=temp;

    }
  }
  temp=S[i+1];
  S[i+1]=S[r];
  S[r]=temp;

  return i+1;

}



Measured memory_bytes: 2108
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
#define INF 2000000000
#define REP(i,b,n) for(int i = (b); i < n; i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int gcd(int a, int b){return b ? gcd(b, a % b): a;}
void yes(){cout<<"Yes"<<endl;return;}
void no(){cout<<"No"<<endl;return;}

int main()
{
    int n;
    cin >> n;
    double ans = 0;
    REP(i,0,n){
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY") ans += x;
        else ans += x * 380000.0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())

# 出発点と終着点もリストに追加しておく
AN = [0]
AN += list(map(int, input().split()))
AN += [0]

# 全地点行った場合の各距離と合計距離を出しておく
All = []
for i in range(N+1):
	All.append(abs(AN[i] - AN[i+1]))
dist = sum(All)

# 行かなくなった箇所に応じた距離の増減をして出力
for i in range(1, N+1):
	tmp = dist
	tmp -= All[i-1] + All[i]
	tmp += abs(AN[i-1] - AN[i+1])
	print(tmp)

Measured memory_bytes: 14048
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = 1e18+5;

int main()
{
	int n;
	cin >> n;
	ll tempt,tempa,t,a;
	cin >> t >> a;
	tempt = t; tempa = a;
	rep(i,n-1)
	{
		cin >> t >> a;
		ll nt = (tempt + t - 1) / t, na = (tempa + a - 1) / a;
		tempt = max(nt,na) * t;
		tempa = max(nt,na) * a;
		
		//cout << "now:" << tempt << " " << tempa << endl;
	}
	cout << tempt + tempa << endl;
	return 0;
}

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

class Team
{
public:
	int id, af, n, pen;
	Team(int id, int af, int n, int pen)
		: id(id), af(af), n(n), pen(pen) {}
	bool operator<(const Team& t) const {
		if (n != t.n) return n < t.n;
		else if (pen != t.pen) return pen > t.pen;
		else return id > t.id;
	}
};

int main()
{
	int N;
	while (cin >> N, N)
	{
		priority_queue<Team> pq;
		for (int i=0; i<N; i++)
		{
			int id, af, n, pen;
			cin >> id >> af >> n >> pen;
			pq.push(Team(id, af, n, pen));
		}

		int pass = 0;
		vector<int> n_af(1001,0);
		while (!pq.empty())
		{
			Team now = pq.top(); pq.pop();

			if (pass < 10)
			{
				if (n_af[now.af] < 3)
				{
					n_af[now.af]++;
					cout << now.id << endl;
					pass++;
				}
			}
			else if (pass < 20)
			{
				if (n_af[now.af] < 2)
				{
					n_af[now.af]++;
					cout << now.id << endl;
					pass++;
				}
			}
			else if (pass < 26)
			{
				if (n_af[now.af] < 1)
				{
					n_af[now.af]++;
					cout << now.id << endl;
					pass++;
				}
			}
		}
	}
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll a[N];
main(){ll mx=0;
int n;cin>>n;ll ans=0;
for(int i=0;i<n;i++){
    cin>>a[i];
    if(mx>a[i]) ans+=mx-a[i];
    mx=max(a[i],mx);
}
cout<<ans;
}


Measured memory_bytes: 5232
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N),B(N),C(N);
  rep(i,0,N){
    cin>>A[i]>>B[i];
    C[i]=i;
  }
  double ans=0;
  do{
    int mem=-1,me=-1;
    for(auto p:C){
      if(me==-1){
        me=A[p];
        mem=B[p];
      }
      else{
        double X=A[p]-me,Y=B[p]-mem;
        me=A[p];
        mem=B[p];
        double Z=sqrt(X*X+Y*Y);
        ans+=Z;
      }
      
    }
  }while(next_permutation(ALL(C)));
  REP(i,1,N) ans/=i;
  printf("%.10lf\n",ans);
  }


Measured memory_bytes: 256
import sys


def alg_combination_mod(n, r, mod):
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i) % mod
        molecule = 1
        for i in range(1, r + 1):
            molecule = (molecule * i) % mod
        return denominator * pow(molecule, mod - 2, mod) % mod


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(k):
        if n - k + 1 >= i + 1 and k - 1 >= i:
            print((alg_combination_mod(n - k + 1, i + 1, mod) * alg_combination_mod(k - 1, i, mod)) % mod)
        else:
            print(0)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 42352
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<cstdio>
#include<string.h>
#include<cmath>
using namespace std;
int main() {
	bool flag = false;
	string temp;
	cin >> temp;
	int ans = 0;
	int cnt = 0;
	for (int i = 0; i < temp.size(); i++) {
		if (temp[i] == 'A' || temp[i] == 'C' || temp[i] == 'G' || temp[i] == 'T') {
			if (flag == false) {
				flag = true;
				cnt = 1;
			}
			else {
				cnt++;
			}
			if (i == temp.size() - 1) {
				if (cnt > ans)ans = cnt;
			}
		}
		else {
			if (flag == true) {
				if (cnt > ans)ans = cnt;
				flag = false;
			}
			else continue;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
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 (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> cnt(n, 1);
    vector<bool> r(n, false);
    r[0] = true;
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        if (r[x])
        {
            if (cnt[x] <= 1)
            {
                r[x] = false;
            }
            r[y] = true;
        }
        cnt[x]--;
        cnt[y]++;
    }
    cout << count(ALL(r), true) << endl;
}

Measured memory_bytes: 640
from itertools import combinations

H, W, K = map(int, input().split())

field = [input() for i in range(H)]

ans = 0

#塗られてない行と列を列挙し、そこに黒がどんだけあるか数える。
for i in range(H+1):
    for j in range(W+1):
        for sh in combinations(range(H), i):
            for sw in combinations(range(W), j):
                v = 0
                for h in sh:
                    for w in sw:   
                        if field[h][w] == '#':
                            v += 1
                if v == K:
                    ans += 1            
print(ans)

Measured memory_bytes: 74148
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>

int main(int argc, void **argv)
{
	long long n;
	long long h[100000];
	long long i;

	scanf("%lld", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%lld", &h[i]);
	}

    if( n == 1 ) {
        puts("Yes");
        exit(0);
    }

    for (i = n - 1; i > 0; i--)
	{
        long long s = h[i] - h[i - 1];
        
        if( s < -1 ) {
            puts("No");
            exit(0);
        }

        if( s == - 1 ) {
            h[i-1]--;
        }
    }

    puts("Yes");

    return 0;
}


Measured memory_bytes: 1024
def main():
    N, L = map(int, input().split())
    pia = 0
    for i in range(1, N+1):
        pia += L + i - 1

    eat = L
    for i in range(1, N+1):
        if abs(eat) > abs(L+i-1):
            eat = L+i-1

    print(pia - eat)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args)throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Reader in = new Reader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Reader in, PrintWriter out) throws Exception {
            int n = in.nextInt();
            int k = in.nextInt();
            int max = in.nextInt();
            int g = max;
            for (int i = 0; i < n - 1; ++i) {
                int b = in.nextInt();
                max = Math.max(max, b);
                g = gcd(g, b);
            }
            if (k <= max && k % g == 0) {
                out.println("POSSIBLE");
            } else {
                out.println("IMPOSSIBLE");
            }
        }

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

    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer;
        private int bytesRead;

        public Reader(InputStream in) {
            din = new DataInputStream(in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg) {
                c = read();
            }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg) {
                return -ret;
            }
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) {
                buffer[0] = -1;
            }
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead) {
                fillBuffer();
            }
            return buffer[bufferPointer++];
        }

    }
}



Measured memory_bytes: 21460