akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n+1];
        for(int i = 1; i <= n; i++) {
            h[i] = sc.nextInt();
        }
        int[] dp = new int[n+1];
        dp[0] = 0;
        dp[1] = 0;
        dp[2] = Math.abs(h[2] - h[1]);
        for(int i = 3; i <= n; i++) {
            dp[i] = Math.min(dp[i-2] + Math.abs(h[i] - h[i-2]), dp[i-1] + Math.abs(h[i] - h[i-1]));
        }
        System.out.println(dp[n]);
    }
}


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

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		vector<pair<int,int> > a(n); // capacity, value
		for(int i=0;i<n;i++)
			cin>>a[i].second>>a[i].first;
		sort(a.begin(),a.end());
		
		int sum=0;
		bool res=true;
		for(int i=0;i<n;i++){
			sum+=a[i].second;
			res&=a[i].first>=sum;
		}
		
		cout<<(res?"Yes":"No")<<endl;
	}
	
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;

const int MOD = 1e9+7;
const int INF = (1<<28);
const ll INFL = (1LL<<60);

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

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

int main() {
  ll n, m, g;
  bool flag = false;
  scanf("%lld %lld", &n, &m);
  scanf("%lld", &g); g >>= 1;
  ll G = g, C = 0;
  while (G % 2 == 0) {
    G >>= 1;
    C++;
  }
  rep(i,n-1) {
    ll a; scanf("%lld", &a); a >>= 1;
    g = lcm(g, a);
    ll A = a, cnt = 0;
    while (A % 2 == 0) {
      A >>= 1;
      cnt++;
    }
    if (g > m || cnt != C) flag = true;
  }
  if (flag) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = max(0.0, floor((double)(m+g)/2/g));
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int N;
	int flag = 0;
	int i = 1;
	scanf("%d",&N);
	while(i<=N){
		i *= 2;
	}
	i /= 2;//やりすぎたので修正
	
	for(;i>1;i/=2){
		for(int j=N-1;j>=0;j--){
			if(j%i==0){
				flag=1;
				break;
			}
		}
		if(flag == 1)
			break;
	}
	printf("%d",i);
}

Measured memory_bytes: 128
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=INF,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi A(n);
  VIN(A)
  REP(i,n){
    z = 0;
    while(A[i]%2==0){
      A[i] /= 2;
      z++;
    }
    x = min(x, z);
  }
  OUT(x);
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	int n;
	cin>>n;
	float a[n],ans;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	ans=(a[0]+a[1])/2;
	for(int i=2;i<n;i++){
		ans=(ans+a[i])/2;
	}
	cout<<ans;
}



Measured memory_bytes: 3692
using System;
using System.IO;
using System.Text.RegularExpressions;

namespace question1
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            p.Run();
        }

        void Run(){
            var x = Console.ReadLine();
            var regex = new Regex("^[357]$");

            if( regex.IsMatch(x)){
                Console.WriteLine("YES");
            }else{
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 15820
import sys
sys.setrecursionlimit(10000000)
 

def main():
    N = int(input())
    A = [int(c) for c in input().split()]


    dicts = {i: 0 for i in range(1, N + 1)}

    for i in A:
        dicts[i] += 1

    for _, v in dicts.items():
        print(v)



if __name__ == '__main__':
    main()


Measured memory_bytes: 38796
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

int main(){
    int n;
    cin>>n;
    vector<int64_t> a(n);
    rep(i,n){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    int l;
    if(n==2){
        cout << a[1]<<" "<<a[0]<<endl;
        return 0;
    }
    rep(i,n-1){
        if(a[i]*2>=a[n-1]){
            l=i;
            break;
        }
    }
    if(a[n-1]-a[l]>=a[l-1]){
        cout << a[n-1]<<" "<<a[l]<<endl;
    }
    else{
        cout << a[n-1] <<" "<<a[l-1]<<endl;
    }

}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, m, i, j, k, x, y, a, b;
	cin >> n >> m;
	vector<string> s(n);
	for (i = 0; i < n; i++) cin >> s[i];
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			if (s[i][j] == '#') continue;

			int c = 0;

			for (a = -1; a <= 1; a++) 
				for (b = -1; b <= 1; b++) {
					if ((a == 0) && (b == 0)) continue;
					x = i + a; y = j + b;
					if ((x >= 0) && (x < n) && (y >= 0) && (y < m) && (s[x][y] == '#')) c++;
				}

			s[i][j] = '0' + c;
		}
	}

	for (auto p : s) cout << p << "\n";
	

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
ll ans[100005]={0};
int main(){
  ll n,k;
  n=3;
  cin>>k;
  ll res=0;
  for(ll m=k;m>=1;m--){
    ll a1=pow(k/m,n);
    for(ll i=2*m;i<=k;i+=m){
      a1-=ans[i];
      a1+=mod;
      a1%=mod;
    }
    ans[m]=a1;
    res+=a1*m;
    res%=mod;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 3636
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
 
int main() {
 long long int t,y;
  cin >> t >> y;
  if(t>1&&y>1){
    cout <<(t-2)*(y-2) << endl;
  }
  else if(t==1&&y==1){
    cout << "1" << endl;
  }
  else{
    cout << max(t,y)-2 << endl;
  }
}

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

int main()
{
    string s;
    cin >> s;
    vector<bool> dict(26);
    for (int i = 0; i < s.size(); ++i) {
        dict[s[i] - 'a'] = true;
    }
    for (int i = 0; i < 26; ++i) {
        if (dict[i] == false) {
            cout << char('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
int main()
{
    char str[13];
    scanf("%s",str);
    printf("%c%c%c%c %c%c%c%c%c%c%c%c\n",str[0],str[1],str[2],str[3],str[4],str[5],str[6],str[7],str[8],str[9],str[10],str[11]);
    return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int N,M;
	cin>>N>>M;
	int ball[SIZE]={};
	for(int i=0;i<SIZE;i++)
		ball[i]=1;
	bool red[SIZE]={};
	red[1]=1;
	for(int i=0;i<M;i++){
		int x,y;
		cin>>x>>y;
		ball[x]--;
		ball[y]++;
		red[y]=(red[x]|red[y]);
		if(ball[x]==0)
			red[x]=0;
	}
	int ans=0;
	for(int i=0;i<SIZE;i++){
		if(red[i])
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768
def rotate90 array
  length = array.size
  rotated = Array.new(length).map{Array.new(length)}
  for y in 0...length
    for x in 0...length
      rotated[x][length - 1 - y] = array[y][x]
    end
  end
  rotated
end

def solveInRowColumn array
  n = array.size
  maxLengthInRow = -1
  maxLengthInColumn = -1
  n.times do |j|
    currentInRow = 0
    currentInColumn = 0
    maxInRow = 0
    maxInColumn = 0
    n.times do |i|
      #横
      if array[j][i] == 1
        if (i > 0 && array[j][i - 1] == 1) || i == 0
          currentInRow += 1
        else
          currentInRow = 1
        end
        maxInRow = [maxInRow, currentInRow].max
      end
      #縦
      if array[i][j] == 1
        if(i > 0 && array[i - 1][j] == 1) || i == 0
          currentInColumn += 1
        else
          currentInColumn = 1
        end
        maxInColumn = [maxInColumn, currentInColumn].max
      end
    end
    #全体での最大値更新
    maxLengthInRow = [maxInRow, maxLengthInRow].max
    maxLengthInColumn = [maxInColumn, maxLengthInColumn].max
  end
  [maxLengthInRow, maxLengthInColumn].max
end

def solveToDiagonal array
  n = array.size
  maxLength = -1
  n.times do |i|
    current = 0
    max = 0
    i.downto(0) do |j|
      if array[i - j][j] == 1
        if((i > 0 && j >= 0) && array[i -j - 1][j + 1] == 1) || i - j == 0
          current += 1
        else
          current = 1
        end
        max = [max, current].max
      end
    end
    maxLength = [max, maxLength].max
  end
  maxLength
end

while (n = $stdin.gets.to_i) != 0
  grid = Array.new
  n.times do
    grid << $stdin.gets.chomp.split("").map(&:to_i)
  end
  p [solveInRowColumn(grid), solveToDiagonal(grid), solveToDiagonal(grid.reverse!().each{|r| r.reverse!}), solveToDiagonal(rotate90(grid)), solveToDiagonal(rotate90(grid.reverse!().each{|r| r.reverse!}))].max
end

Measured memory_bytes: 7468
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}


int main(){
  int a,b;
  cin>>a>>b;
  for(int i = b-a+1; i <= b+a-1; i++){
    cout<<i<<" ";
  }
  cout<<endl;
  return 0;
}

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

long long int fizzbuzz(long long int n){
    if(n%3==0 && n%5==0){return true;}
    if(n%3==0){return true;}
    if(n%5==0){return true;}
    return false;
}


int main(){
    long long int t,i,y,sum=0;
    cin>>t;
    for(i=1;i<=t;i++){
        if(!fizzbuzz(i)){
            sum+=i;
        }
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void)
{
    long long int n, k, ans = 0, inf;
    inf = 1000000007;
    scanf("%lld%lld", &n, &k);

    int a[2000], i, j, flip;
    for(i=0; i<n; i++) scanf("%d", &a[i]);

    for(i=0; i<n; i++)
    {
        flip = 0;
        for(j=0; j<n; j++)
        {
            if(a[i] > a[j]) flip++;
        }
        ans = (ans + (flip * (((k-1)*k/2)%inf))%inf) % inf;
        flip = 0;
        for(j=i+1; j<n; j++)
        {
            if(a[i] > a[j]) flip++;
        }
        ans = (ans + (flip*k)%inf)%inf;
    }

    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	uint64_t N;
#if 0
	uint64_t soinsu[128];
#endif
	int64_t soinsuNum[128];
	int soinsuCount = 0;
	uint64_t cur, chk;
	int kotae;
	int i;
	if (scanf("%" SCNu64, &N) != 1) return 1;
	for (cur = N, chk = 2; chk * chk <= cur; chk++) {
		if (cur % chk == 0) {
#if 0
			soinsu[soinsuCount] = chk;
#endif
			soinsuNum[soinsuCount] = 0;
			while (cur % chk == 0) {
				soinsuNum[soinsuCount]++;
				cur /= chk;
			}
			soinsuCount++;
		}
	}
	if (cur > 1) {
#if 0
		soinsu[soinsuCount] = cur;
#endif
		soinsuNum[soinsuCount] = 1;
		soinsuCount++;
	}

	kotae = 0;
	for (i = 0; i < soinsuCount; i++) {
		int delta = 1;
		int hp = soinsuNum[i];
		while (hp >= delta) {
			kotae++;
			hp -= delta;
			delta++;
		}
	}
	printf("%d\n", kotae);
	return 0;
}


Measured memory_bytes: 1732
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, tmp, count = 0;

		n = sc.nextInt();
		int[] nums = new int[n];
		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}

		n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			tmp = sc.nextInt();
			if (Arrays.binarySearch(nums, tmp) >= 0) {
				count++;
			}
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 76164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmp(const void *a, const void *b)
{
    return *(long long int*)a - *(long long int*)b;
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	long long int a[n];
	int i;
	for(i=0;i<n;i++) scanf("%lld",&a[i]);
	if(k>=n){
		printf("0");
		return 0;
	}
	else if(k==0){
		long long int sum=0;
		for(i=0;i<n;i++) sum+=a[i];
		printf("%lld",sum);
	}
	else{
		long long int t,sum=0;
		qsort(a,n,sizeof(a[0]),cmp);
		for(i=0;i<n-k;i++){
			sum+=a[i];
		}
		
		printf("%lld",sum);
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)
 
#define INF 987654321
#define IINF 2987654321987654321
#define MOD 1000000007

typedef unsigned long long ull;


const int LOGN = 18;
int n, m;
ll a[(1<<LOGN)];
void readInput() {
	scanf("%d", &n);
	m = (1<<n);
	for(int i = 0; i < m; i++)
		scanf("%lld", &a[i]);
}


ll f[(1<<LOGN)];
pll dp[(1<<LOGN)][2];
void calcDP() {
	for(ull i = 0; i < m; i++) 
		f[i] = (ll)((~i) & (ull)(m-1));

	for(ll i = 0; i < m; i++)
		dp[f[i]][0] = {a[i], i};
	for(int x = m-1; x >= 0; x--) {
		for(int i = 0; i < n; i++) {
			if(!(x & (1<<i))) {
				for(int j = 0; j < 2; j++) {
					pll t = dp[x | (1<<i)][j];
					if(t > dp[x][0]) {
						dp[x][1] = dp[x][0];
						dp[x][0] = t;
					} else if(t != dp[x][0] && t > dp[x][1]) {
						dp[x][1] = t;
					}
				}
			}
		}
	}
}


void solve() {
	for(int k = 1; k < m; k++) {
		ll mx = 0;
		int cur = 0;
		for(int i = n-1; i >= 0; i--) {
			if(k & (1<<i)) {
				int x = (cur | (1<<i));
				mx = max(mx, dp[x][0].first + dp[x][1].first);
			} else {
				cur |= (1<<i);
			}
		}
		mx = max(mx, dp[cur][0].first + dp[cur][1].first);
		printf("%lld\n", mx);
	}
}


int main() {
	readInput();
	calcDP();
	solve();
}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
#include <sys/time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldo;
#define endl            "\n"
#define pi              3.1415926535897932384626433832795
#define mod             (ll)1000000007
#define pp              pair<ll,ll>
#define vii             vector<int>
#define vll             vector<ll>
#define vpp             vector<pp>
#define vss             vector<string>
#define pb              push_back
#define pob             pop_back
#define mp              make_pair
#define pf              push_front
#define pof             pop_front
#define eb              emplace_back
#define ff              first
#define ss              second
#define bs(v,x)         binary_search(v.begin(),v.end(),x)
#define ub(v,x)       upper_bound(v.begin(),v.end(),x)
#define lb(v,x)       lower_bound(v.begin(),v.end(),x)
#define print(A,n)      for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n)       for(ll i=0;i<n;++i)cin>>A[i];
#define set(x)          memset(x,0,sizeof(x));
#define Sort(x)         sort(x.begin(),x.end())
#define fast            ios_base::sync_with_stdio(false);cin.tie(NULL);
#define setd(s,s1,S1)   set_difference(s.begin(),s.end(),s1.begin(),s1.end(),inserter(S1,S1.end())); //set and multi set
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(f) for(auto it=f.begin();it!=f.end();it++)cout<<*it<<" ";cout<<endl;


int main()
{
    fast;
    ll t=1;
//    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll ans=0;
        for(ll i=1;i<=n;i++){
            ll fin=n/i;
            ans+=i*(fin*(fin+1)/2);
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
const int xx = (1<<21) + 1;

int dp[xx][21];
// int cp[8][3];
// ll ar[21][21];
ll n;
ll allmask;
vector <int> v[22];
ll count(ll mask, ll bit)
{
	if(allmask == mask)
		return 1;
	if(dp[mask][bit]!=-1)
		return dp[mask][bit];
	ll sz = v[bit].size(), ans = 0;
	for(int i=0;i<sz;i++)
	{
		if(!(mask&(1<<v[bit][i])))
		{
			ans += count(mask|(1<<v[bit][i]), bit+1);
			ans %= mod;
		}
	}
	return dp[mask][bit] = ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,m,k,q,x; 
    t = 1;
    // cin>>t;
    while(t--)
    {
    	cin>>n;
    	for(int i=0;i<n;i++)
    	{
    		for(int j=0;j<n;j++)
    		{
    			cin>>x;
    			if(x)
    				v[i].pb(j);
    		}
    	}
    	memset(dp,-1,sizeof(dp));
    	allmask = (1<<n) - 1;
    	ll ans = count(0,0);
    	cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 172288
#include <iostream>
#include <algorithm>


using namespace std;


int main(void){
    int n;
    cin>>n;
    long long int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    sort(a,a+n);
    
    long long int b[n];
    b[0]=a[0];
    b[1]=a[1];
    for(int i=1;i<n;i++){
        b[i]=b[i-1]+a[i];
    }
    
    //for(int i=0;i<n;i++)cout<<b[i]<<endl;
    
    
    int ans=0;
    for(int i=n-1;i>=0;i--){
        if(b[i-1]*2>=a[i]){
            ans++;
        }else{
            break;
        }
    }
    cout<<min(ans+1,n)<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
#define N 200010
using namespace std;

ll n, m, a[N];

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
	return s * w;
}

inline void work(){
	n = read();
	REP(i, 2, n) m = read(), a[m]++;
	REP(i, 1, n) printf("%lld\n", a[i]);
}

int main(){
	work();
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll, int> ii;
typedef pair <ii,int> iii;

const ll inf = 1e17;
const ll mod = 1e9 + 7;
const int N = 200005;

void solve(){
	int n;
	cin >> n;
	cout << ((n+1000-1)/1000)*1000-n << endl;
}

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


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;
 
int main() {
    int w;
    int a,b;
    bool h1,h2;
    int dif;
  
    cin >> w >> a >> b;
 
    dif = b - a - 1;
    h1 = abs(a - b) >= w;
  
    if (h1) { 
      if(b > a){
        cout << b -( a + w );
      }
      else{
       cout << a - ( b + w ) << endl;
      }
    }else{
      cout << 0 << endl;
    }
 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_set>

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main(){
    unordered_set<string> dic;
    int n; cin >> n;

    string s, t;
    rep(i,n){
        cin >> s >> t;
        if(s[0] == 'i'){
            dic.insert(t);
        }else if(s[0] == 'f'){
            if(dic.count(t) > 0){
                cout << "yes" << endl;
            }else{
                cout << "no" << endl;
            }
        } 
    } 

    return 0;
}

Measured memory_bytes: 32104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long 
//写し
int q, dp[1007][1007]; string s, t;
int main() {
	cin >> q;
	rep(i,q){
		cin >> s >> t;
		for(int i = 0; i < s.size(); i++) {
			for(int j = 0; j < t.size(); j++) {
        if(s[i] == t[j]){
          dp[i + 1][j + 1] = dp[i][j] + 1;
        }else{
          dp[i + 1][j + 1] =  max(dp[i][j + 1], dp[i + 1][j]); 
        }
			}
		}
		cout << dp[s.size()][t.size()] << endl;
	}
  return 0;
}


Measured memory_bytes: 7156
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

struct ModInt {
    ll v;
    static unsigned M;
    ModInt() : v(0) {}
    ModInt(ll x) : v((x % M + M) % M) {}

    ModInt& operator+=(const ModInt& r) {
        v = (v + r.v) % M;
        return *this;
    }
    ModInt& operator-=(const ModInt& r) {
        v = (v - r.v + M) % M;
        return *this;
    }
    ModInt& operator*=(const ModInt& r) {
        v = (v * r.v) % M;
        return *this;
    }
    ModInt operator-() const { return (M - v % M); }

    friend ModInt operator+(ModInt l, const ModInt& r) { return l += r; }
    friend ModInt operator-(ModInt l, const ModInt& r) { return l -= r; }
    friend ModInt operator*(ModInt l, const ModInt& r) { return l *= r; }
    friend bool operator==(ModInt l, const ModInt& r) { return l.v == r.v; }
    friend bool operator!=(ModInt l, const ModInt& r) { return !(l == r); }

    ModInt pow(ll n) const {
        ModInt base = *this, ans = 1;
        while (n) {
            if (n & 1) ans *= base;
            base *= base;
            n /= 2;
        }
        return ans;
    }
};
unsigned ModInt::M;
ostream& operator<<(ostream& o, const ModInt& r) {
    o << r.v;
    return o;
}

ModInt fact(ll n) {
    if (n == 0) return 1;
    if (n == 1) return 1;
    return ModInt(n) * fact(n - 1);
}

ModInt comb(ll n, ll a) {
    return fact(n) * (fact(a) * fact(n - a)).pow(ModInt::M - 2);
}

int main() {
    ModInt::M = 1000000007;
    ll n, k; cin >> n >> k;
    ll m = n - k + 1;

    loop1 (k, i) {
        if (m < i) {
            cout << 0 << endl;
            continue;
        }
        ModInt ans = comb(m, i);
        ans *= comb(k - 1, i - 1);
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;++i)
#define repi(i,n) for(ll i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define slf(n) scanf("%lf", &n);
typedef long long ll;
typedef double lf;
static const ll max_n = 100010;
static const ll mod = 1000000007;
static const ll max_value = 100000000000100;
// vector<vector<vector<ll>>> dp(max_n, vector<vector<ll>>(max_n, vector<ll>(max_n*max_n, 0)));
vector<ll> dp(max_n, 0);
vector<ll> dp_sum(max_n, 0);
// static const ll max_x = max_value * max_value;
vector<ll> A(max_n);
// vector<ll> cards(max_n);
// vector<ll> S(max_n);
// vector<pair<ll, ll>> times_vec(max_n);


void Main(){
    // bool is_ok = true;
    // printf("------------- V=%lld---------\n", V);
    ll X;
    sll(X);
    ll now_money = 100;
    ll idx = 0;
    while(now_money < X){
        now_money += (now_money) / 100;
        idx ++;
    }
    printf("%lld\n", idx);

    // cout<<fixed<<setprecision(10)<<num<<endl;
    // cout << num << endl;

}

int main(){
    Main();

    return 0;

}

Measured memory_bytes: 5012
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    string s;
    string t;
    bool ans = false;
    cin >> s;
    cin >> t;

    if(s.size()+1 == t.size()){
        REP(i,s.size()){
            if( s[i] != t[i] ){
                ans = true;
            }
        }
        if(ans){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 3e5 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

char x;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>x;
    if (x >= 'A'&&x <= 'Z') cout<<'A';
    else cout<<'a';
}


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

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(){
    ll n;
    cin>>n;
    ll ans = 0;
    auto p = prime_factorize(n);
    for(auto &a:p){
        int k=1;
        int a1 =a.first;
        int a2=a.second;
       
        while(a2>=k){
            ans++;
            a2-=k;
            k++;
        }

    }
    cout<<ans<<endl;
    
return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  string s;
  cin >> n >> s;
  vector<int> W(n, 0), E(n, 0);
  for(int i = 0; i < n - 1; ++i)
  {
    W[i + 1] = W[i] + (s[i] == 'W');
  }
  for(int i = n - 1; i >= 1; --i)
  {
    E[i - 1] = E[i] + (s[i] == 'E');
  }

  int ans = n;
  for(int i = 0; i < n; ++i)
  {
    ans = min(ans, W[i] + E[i]);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 6092
#include <stdio.h>

int selectionSort(int A[], int N) {
  int i, j, t, sw =0, minj;
  for(i=0;i<N-1;i++) {
    minj = i;
    for(j=i;j<N;j++) {
      if(A[j]<A[minj]) minj = j;
    }
    t=A[i]; A[i]=A[minj]; A[minj]=t;
    if(i!=minj) sw++;
  }
  return sw;
}

int main(void) {
  int A[100], N, i, sw;

  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);

  sw = selectionSort(A,N);

  for(i=0;i<N;i++) {
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",sw);

  return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	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;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)




int main() {
	ll H1, H2, M1, M2, K;
	std::cin >> H1 >> M1 >> H2 >> M2 >> K;

	ll m = (H2 - H1) * 60;
	m += M2 - M1;

	std::cout << m - K << endl;

	return 0;
}


Measured memory_bytes: 3632
def main():
    import heapq
    n,m = map(int,input().split())
    A = {}
    for i in range(n):
        a,b = map(int,input().split())
        if a not in A.keys():
            A[a] = [b]
        else:
            A[a].append(b)
    J = []
    ans = 0
    for i in range(1,m+1):
        if A.get(i)!=None:
            for k in A[i]:
                heapq.heappush(J,-1*k)
        if len(J)>0:
            ans += -1* heapq.heappop(J)
    print(ans)

if __name__ == "__main__":
    main()


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

void swap(int &A, int &B) {
	int dum = A;
	A = B;
	B = dum;
	return;
}

int main(){
	string text;
	cin >> text;
	vector<int> alphabet(26, 0);
	vector<int> nodeval(26, 0);
	for (int i = 0; i < (int)text.length(); i++) alphabet[text[i] - 'a']++;
	vector< vector<int> > rel(26, vector<int>(26, 0));
	int alphanum = 0;
	for (int i = 0; i < (int)('z' - 'a' + 1); i++) {
		nodeval[i] = alphabet[i];
		if (nodeval[i] != 0) rel[i][i] = 1, alphanum++;;
	}
	int smlnode1 = -1;
	int smlnode2 = -1;
	while (true) {
		smlnode1 = -1;
		smlnode2 = -1;
		for (int i = 0; i < (int)('z' - 'a' + 1); i++) {
			if (nodeval[i] != 0) {
				if (smlnode1 == -1) {
					smlnode1 = i;
					continue;
				}
				else if (smlnode2 == -1) {
					smlnode2 = i;
					if (nodeval[smlnode1] > nodeval[smlnode2]) swap(smlnode1, smlnode2);
					continue;
				}
				else if (nodeval[i] < nodeval[smlnode1]) {
					smlnode2 = i;
					swap(smlnode1, smlnode2);
				}
				else if (nodeval[i] < nodeval[smlnode2]) {
					smlnode2 = i;
				}
			}
		}
		if (smlnode2 == -1) break;
		nodeval[smlnode1] = nodeval[smlnode1] + nodeval[smlnode2];
		nodeval[smlnode2] = 0;
		for (int i = 0; i < (int)('z' - 'a' + 1); i++) {
			rel[i][smlnode1] = rel[i][smlnode1] != 0 ? rel[i][smlnode1] + 1 : (rel[i][smlnode2] != 0 ? rel[i][smlnode2] + 1 : 0);
		}

	}
	
	int res = 0;
	for (int i = 0; i < (int)('z' - 'a' + 1); i++) if (rel[i][smlnode1] != 0) res += alphabet[i] * (alphanum == 1 ? 1 : rel[i][smlnode1] - 1);

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3348
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

bool equation(string& s, int& i,vector<bool>& v);
bool formula(string& s, int& i, vector<bool>& v);

bool equation(string& s, int& i, vector<bool>& v) {
	bool a = formula(s, i,v);
	i++;
	bool b = formula(s, i, v);
	return a == b;
}

bool formula(string& s, int& i, vector<bool>& v) {
	if (s[i] == 'T') {
		i++;
		return true;
	}
	else
		if (s[i] == 'F') {
			i++;
			return false;

		}else
			if ('a' <= s[i] && s[i] <= 'k') {
				int aa = s[i] - 'a';
				i++;
				return v[aa];
			}else
				if (s[i] == '-') {
					i++;
					bool a = formula(s, i, v);
					return !a;
				}
				else {
					i++;
					bool a = formula(s, i, v);
					char op = s[i];
					if (op == '-') {
						i++;
					}
					i++;
					bool b = formula(s, i, v);
					i++;
					if (op == '*') {
						return a&&b;
					}else
						if (op == '+') {
							return a || b;
						}
						else {
							return (!a) || b;
						}
				}
}


int main()
{
	while (true) {
		string ss;
		cin >> ss;
		if (ss[0] == '#') { break; }
		bool flag = true;
		for (int j = 0; j < 2048; ++j) {
			int bai = 1;
			vector<bool> v(9999, false);
			for (int k = 0; k < 11; ++k) {
				if (j % (bai * 2) - j % (bai * 1) == 0) {
					v[k] = false;
				}
				else {
					v[k] = true;
				}
				bai *= 2;
			}
				int index = 0;
				if (!equation(ss, index, v)) {
					flag = false;
					break;
					}
			
		}
		if (flag) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

}

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

#define _BIGNUM_ 100000000

using namespace std;
typedef long long ll;

const ll mod = 1e9+7;

int main() {
  ll x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  ll w = x2 - x1, h = y2 - y1;
  cout << x2 - h << " " << y2 + w << " " << x1 - h << " " << y1 + w << endl;
}


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

int main() {
    int m,d;
    cin >> m >> d;
    int c = 0;
    for (int i = 1; i <= m; i++) {
        for(int j = 22; j <= d; j++) {
            int a = j % 10;
            int b = j /10;
            if( a >= 2 && a * b == i ) c++;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 410;
const int MAXP = 10000000;
const u64 MOD = 1000000007;
const f80 MI = f80(1)/MOD;
const int INF = 1000000010;

int n, m;
char s[MAXN][MAXN];
int u[MAXN][MAXN];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

ll ans;

void solve(int sx, int sy)
{
	u[sx][sy] = 1;
	queue<pii> Q;
	Q.emplace(sx, sy);
	ll ans1 = 0;
	ll ans2 = 0;
	while (!Q.empty())
	{
		int x = Q.front().X;
		int y = Q.front().Y;
		if (s[x][y] == '.') ans1 ++;
		if (s[x][y] == '#') ans2 ++;
		Q.pop();
		for (int k = 0; k < 4; ++ k)
		{
			int tx = x+dx[k], ty = y+dy[k];
			if (1 <= tx && tx <= n && 1 <= ty && ty <= m && s[tx][ty] != s[x][y] && !u[tx][ty])
			{
				u[tx][ty] = 1;
				Q.emplace(tx, ty);
			}
		}
	}
	ans += ans1*ans2;
}

int main()
{
	
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++ i)
		scanf("%s", s[i]+1);
	for (int i = 1; i <= n; ++ i)
		for (int j = 1; j <= m; ++ j)
			if (s[i][j] == '#' && !u[i][j])
			{
				solve(i, j);
			}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    P = LMIIS()
    Q = LMIIS()
    from math import factorial

    def index(P):
        candidates = list(range(1,N+1))
        ans = 0
        for i in range(N-1):
            ans += candidates.index(P[i]) * factorial(N-1-i)
            candidates.remove(P[i])
        return ans + 1

    print(abs(index(P)-index(Q)))

    



   




if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
import java.util.Arrays;
import java.util.Scanner;

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

		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		Arrays.parallelSort(a);

		int sup = a[n - 1];
		int inf = -1;
		int mid;
		while (sup - inf > 1) {
			mid = (sup + inf) / 2;
			if (count(mid, n, a) <= m) {
				sup = mid;
			} else {
				inf = mid;
			}
			;
		}

		long sum = 0;
		for (int i = 0; i < n; i++) {
			while (a[i] > sup) {
				a[i] >>= 1;
				m--;
			}
			sum += a[i];
		}

		sum -= (long) (sup - sup / 2) * m;

		System.out.println(sum);
	}

	static int count(int threshold, int n, int[] a) {
		int count = 0;
		for (int i = 0, x; i < n; i++) {
			x = a[i];
			while (x > threshold) {
				x >>= 1;
				count++;
			}
		}
		return count;
	}

}


Measured memory_bytes: 52756
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*

*/

ll n,mod=1e9+7,a[30]={},ans=1;
string s;

int main(void){
	cin>>n>>s;
	rep(i,n){
		a[s[i]-'a']++;
	}
	rep(i,26){
		ans=(ans*(a[i]+1))%mod;
	}
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 1144
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	int[] eq;
	int len;
	
	int index;
	int token;
	int value;
	int ch;
	
	final int NUM = -256;
	final int LF = '\n';
	
	int[] pqr = new int[3];
	
	int not(int x) {
		if (x == 0)
			return 2;
		else if (x == 1)
			return 1;
		else if (x == 2)
			return 0;
		
		return -1;
	}
	
	int and(int x, int y) {
		if (x == 0 || y == 0)
			return 0;
		else if (x == 1 || y == 1)
			return 1;
		else if (x == 2 || y == 2)
			return 2;
		
		return -1;
	}
	
	int or(int x, int y) {
		if (x == 2 || y == 2)
			return 2;
		else if (x == 1 || y == 1)
			return 1;
		else if (x == 0 || y == 0)
			return 0;
		
		return -1;
	}
	
	
	void gettoken() {
		if (ch == '-' || ch == '(' || ch == ')' || ch == '*' || ch == '+') {
			token = ch;
			ch = eq[index++];
		} else if (ch == LF){
			token = ch;
		} else {
			token = NUM;
			
			switch (ch) {
			case '0': value = 0; break;
			case '1': value = 1; break;
			case '2': value = 2; break;
			case 'P': value = pqr[0]; break;
			case 'Q': value = pqr[1]; break;
			case 'R': value = pqr[2]; break;
			}
			
			ch = eq[index++];
		}
	}
	
	int F() {
		int v = 0;
		if (token == NUM) {
			v = value;
			gettoken();
		} else if (token == '-') {
			gettoken();
			v = not(F());
		} else if (token == '(') {
			int vnext, savetoken;
			gettoken(); 
			v = F();
			savetoken = token;
			gettoken();
			vnext = F();
			if (savetoken == '*') {
				v = and(v, vnext);
			} else if (savetoken == '+') {
				v = or(v, vnext);
			}
			if (token == ')') gettoken();
		}
		
		return v;
	}
	
	void run() {
		String s;
		while (true) {
			s = sc.nextLine();
			if (s.equals(".")) break;
			len = s.length();
			eq = new int[len+1];
			for (int i = 0; i < len; i++)
				eq[i] = s.charAt(i);
			eq[len] = LF;
			
			int ans = 0;
			for (int p = 0; p <= 2; p++) {
				for (int q = 0; q <= 2; q++) {
					for (int r = 0; r <= 2; r++) {
						pqr[0] = p;
						pqr[1] = q;
						pqr[2] = r;
						
						index = 0;
						ch = eq[index++];
						gettoken();
						if (F() == 2) ans++;
					}
				}
			}
			out.println(ans);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 25968