akhauriyash/Code-Regression huggingface dataset:
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=1e9+7;

int dp[4111][4111],n,a[200111],b[200111];
int f[8111],invf[8111];
int power(int x,int y){int ret=1;do{if(y&1)ret=1ll*ret*x%mod;x=1ll*x*x%mod;}while(y>>=1);return ret;}
int calc(int x,int y){return 1ll*f[x+y]*invf[x]%mod*invf[y]%mod;}
int main()
{
	f[0]=1;for(int i=1;i<8111;i++)f[i]=1ll*i*f[i-1]%mod;
	invf[8111-1]=power(f[8111-1],mod-2);for(int i=8111-2;i>=0;i--)invf[i]=1ll*invf[i+1]*(i+1)%mod;
	get1(n);
	for(int i=1;i<=n;i++)
	{
		get2(a[i],b[i]);
		dp[2001-a[i]][2001-b[i]]++;
	}
	for(int i=1;i<=4002;i++)for(int j=1;j<=4002;j++)
	{
		dp[i][j]+=dp[i-1][j]+dp[i][j-1];
		while(dp[i][j]>=mod)dp[i][j]-=mod;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=mod-calc(a[i]*2,b[i]*2);if(ans>=mod)ans-=mod;
		ans+=dp[2001+a[i]][2001+b[i]];if(ans>=mod)ans-=mod;
	}
	ans=1ll*ans*(mod+1)/2%mod;
	printendl(ans);
	return 0;
}

Measured memory_bytes: 67840
#include<bits/stdc++.h>
using namespace std;
int main(void) {
    string s;
    cin >> s;
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        string o;
        int a, b;
        cin >> o >> a >> b;
        if(o == "print"){
            cout << s.substr(a, b - a + 1) << endl;
        }
        else if(o == "reverse"){
            for(int x = a, y = b; x < y; x++, y--) swap(s[x], s[y]);
        }
        else {
            string p;
            cin >> p;
            for(int j = a; j <= b; j++) s[j] = p[j - a];
        }
    }
    return 0;
}


Measured memory_bytes: 3212
N = int(input())

max_num = 3500
for h in range(1,max_num+1):
    for n in range(1, max_num+1):
        if 4*h*n - N*n - N*h <= 0:
            continue
        if N*h*n % (4*h*n - N*n - N*h) == 0:
            w = int(N*h*n / (4*h*n - N*n - N*h))
            Ans = [h, n, w]
            break

print(' '.join(map(str, Ans))) 

Measured memory_bytes: 42332
#include <iostream>                                        
using namespace std;                                       
                                                           
int main(){                                                
  int num;                                                 
  int i=1;                                                 
                                                           
  while(1){                                                
    cin >> num;                                            
    if (num == 0) break;                                   
    cout << "Case" << " " << i << ":" << " " << num << end\
l;                                                         
    i++;                                                   
  }                                                        
                                                           
  return 0;                                                
} 

Measured memory_bytes: 3096
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] a = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a, Collections.reverseOrder());
        int alice = 0;
        int bob = 0;
        for (int i = 0; i < a.length; i++) {
            if (i % 2 == 0) {
                alice += a[i];
                continue;
            }
            bob += a[i];
        }
        System.out.println(alice - bob);
    }

}


Measured memory_bytes: 23124
<?php
fscanf(STDIN,'%d',$N);
fscanf(STDIN,'%d',$K);
$X=explode(" ",trim(fgets(STDIN)));
$L=0;
for ($i=0; $i <$N ; $i++) {
  // code...
  $L+=min($X[$i]*2,($K-$X[$i])*2);
}
echo $L;
echo "\n";



 ?>


Measured memory_bytes: 3576
#include <stdio.h>

int main(int argc, char const *argv[])
{
	long long n,m,l;
	scanf("%lld %lld",&n,&m);
 if(n ==1 && m == 1){
 	l = 1;
 }else if(n == 1){
 	l = m-2;
 }else if(m==1){
 	l = n -2;
 }else{
 	l = (n - 2) * (m - 2);
 }
	printf("%lld\n",l);

	return 0;
}

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

using Graph = vector<vector<int>>;

vector<bool> has_visited;
vector<int> latest;
queue<int> suspended;
void BFS(const Graph &G, int v)
{
    has_visited[v] = true;
    suspended.push(v);

    while (!suspended.empty())
    {
        int u = suspended.front();
        suspended.pop();
        for (auto w : G[u])
        {
            if (has_visited[w])
                continue;
            else
            {
                has_visited[w] = true;
                latest[w] = u;
                suspended.push(w);
            }
        }
    }
}

int main()
{
    int N, M;
    cin >> N >> M;
    Graph G(N);
    for (int i = 0; i < M; i++)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    has_visited.assign(N, false);
    latest.assign(N, -1);

    BFS(G, 0);

    for (int i = 0; i < N; i++)
    {
        if (!has_visited[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++)
    {
        cout << latest[i] + 1 << endl;
    }
    return 0;
}

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

using namespace std;
int main() {
    int n, m;
    int t;
    cin >> n >> m;
    
    if (n > m) {
        t = m;
        m = n;
        n = t;
    }
    // n < m
    
    while (n > 0) {
        t = n;
        n = m % n; // n' < n
        m = t;     // n' < m' (=n)
    }
    cout << m << endl;
}


Measured memory_bytes: 3100
from math import sqrt

N, D = map(int, input().split())

X = [tuple(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if tmp == int(sqrt(tmp)) ** 2:
            ans += 1

print (ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s, t;
  cin >> s >> t;
  
  int ns = s.size();
  int nt = t.size();
  vector<int> match(ns-nt+2);
  match[0] = nt;
  
  for(int i = 0; i < ns-nt+1; i++){
    int mat = nt;
    for(int j = 0; j < nt; j++){
      if(t[j]==s[i+j]){
        mat--;
      }
    }
    match[i+1] = min(match[i], mat);
  }
  
  cout << match[ns-nt+1] << endl;
}
  
  


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int D = sc.nextInt();		
		
		if(D ==25){
			System.out.println("Christmas");
		}else if(D==24) {
			System.out.println("Christmas Eve");
		}else if(D==23) {
			System.out.println("Christmas Eve Eve");
		}else if(D==22) {
			System.out.println("Christmas Eve Eve Eve");
		}
	
	}
}

Measured memory_bytes: 21972
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

int main() {
    int a;
    string s;
    cin >>a>>s;
    string ans = (a >= 3200) ? s:"red";
    cout <<ans;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MAX (ll)(1e5 + 4)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e18)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false), cin.tie (nullptr);

using namespace std;
using ll = long long;
using ld = long double;

int main () {
	int a, b;
	cin >> a >> b;
	cout << ((a / b) + (a % b > 0)) << "\n";
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int P = sc.nextInt();
        String S = sc.next();
        char[] c = S.toCharArray();
        int[] a = new int[N];
        for (int i=0;i<N;i++) {
            a[i] = (int)c[i]-'0';
        }

        if (P==2 || P==5) {
            long ans = 0L;
            for (int i=0;i<N;i++) {
                if (a[i]%P==0) {
                    ans+=(i+1);
                }
            }
            System.out.println(ans);
            return;
        }

        int[] cnt = new int[P];
        int tmp = 0;
        int num = 1;
        long ans = 0;
        for (int i=N-1;i>=0;i--) {
            tmp=(tmp+num*a[i])%P;
            ans+=cnt[tmp];
            cnt[tmp]++;
            if (tmp==0) ans++;
            num=num*10%P;
        }
        System.out.println(ans);
    }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, t;
  cin >> n >> t;

  vector<int> cost(n), time(n);
  for (int i = 0; i < n; ++i) {
    cin >> cost[i] >> time[i];
  }

  int ans = 1001;
  for (int i = 0; i < n; ++i) {
    if (time[i] <= t) {
      if (cost[i] < ans) {
        ans = cost[i];
      }
    }
  }

  if (ans == 1001) {
    cout << "TLE" << "\n";
  } else {
    cout << ans << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  int p[100];
  string s[100];
  pair<string,pair<int,int> > a[100];
  cin>>n;
  rep(i,n){
    cin>>s[i]>>p[i];
    a[i]=make_pair(s[i],make_pair(p[i],i));
  }
  sort(a,a+n);
  rep(j,n){
  for(int i=n-1;i>=1;i--){
    if(a[i].first==a[i-1].first && a[i].second.first>a[i-1].second.first){
      swap(a[i],a[i-1]);
    }
  }
  }
  //  cout<<1<<endl;
  rep(i,n){
    cout<<(a[i].second.second)+1<<endl;
  }
    
    
 

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,y,a,b,c;
    bool flag=false;
    cin>>n>>y;
    for(a=0;a<=n;a++){
        for(b=0;b<=n;b++){
            c=n-a-b;
            if(c>=0&&a*10000+b*5000+c*1000==y){
                flag=true;
                break;
            }
        }
        if(flag) break;
    }
    if(flag) printf("%d %d %d\n", a,b,c);
    else cout<<"-1 -1 -1\n";

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e18

struct RangeMinQuery{
  ll dat[(1<<20)-1];
  int size;

  void init(int n_){
    size=1;
    while(size<n_) size*=2;
    for(int i=0;i<2*size-1;i++)dat[i]=INF;
  }

  void update(int k,ll a){
    k+=size-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }

  ll subquery(int a,int b,int k,int l,int r){
    if(r<=a||b<=l)return INF;
    if(a<=l&&r<=b)return dat[k];
    else{
      return min(subquery(a,b,k*2+1,l,(l+r)/2),subquery(a,b,k*2+2,(l+r)/2,r));
    }
  }
  
  ll query(int a,int b){
    return subquery(a,b,0,0,size);
  }
};

ll n;
ll b[201010];
ll cnt[2][201010];
ll f[201010];
ll q;
RangeMinQuery dp,dp2;
vector<P> ps; 

int main(){
	cin>>n;
  rep(i,n)cin>>b[i];
  rep(i,n){
    cnt[b[i]][i+1]++;
  }
  rep(j,2)rep(i,n)cnt[j][i+1]+=cnt[j][i];
  cin>>q;
  rep(i,q){
    ll l,r;
    cin>>l>>r;
    l--;
    ps.push_back(P(l,r));
  }
  sort(all(ps));
  rep(i,n+1)f[i]=cnt[0][i]-cnt[1][i];
  dp.init(n+1); dp2.init(n+1);
  dp.update(0,cnt[1][n]);
  dp2.update(0,dp.query(0,1)-f[0]);
  for(P p : ps){
    ll l=p.fi,r=p.se;
    ll crt=INF;
    minch(crt,dp.query(0,l+1)+(cnt[0][r]-cnt[0][l])-(cnt[1][r]-cnt[1][l]));
    minch(crt,dp2.query(l+1,r)+(cnt[0][r]-cnt[1][r]));
    ll pre=dp.query(r,r+1);
    if(crt<pre) dp.update(r,crt);
    pre=dp2.query(r,r+1);
    if(crt-f[r]<pre) dp2.update(r,crt-f[r]);
  }
  cout<<dp.query(0,n+1)<<endl;
	return 0;
}


Measured memory_bytes: 23020
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		if(N == 1){
			Console.WriteLine(0);
			return;
		}
		
		var di = PrimDec(N);
		int cnt = 0;
		foreach(var k in di.Keys){
			int c0 = 1;
			int tot = di[k];
			int cc = 0;
			while(tot >= c0){
				cc++;
				tot -= c0;
				c0++;
			}
			cnt += cc;
		}
		Console.WriteLine(cnt);
		
		
		
	}
	long N;
	public Sol(){
		N = rl();
	}
	
	static Dictionary<long,int> PrimDec(long A){
	 	Dictionary<long,int> D=new Dictionary<long,int>();
	 	if(A==1)return null;
	 	long rem=A;
	 	for(long i=2;i*i<=A;i++){
	 		if(rem%i==0){
	 			int cnt=0;
	 			while(rem%i==0){cnt++;rem/=i;}
	 			D.Add(i,cnt);
	 		}
	 		if(rem==1)break;
	 	}
	 	if(rem!=1)D.Add(rem,1);
	 	return D;
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 18016
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0;true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void AnsYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void AnsYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}







//ここまでライブラリ
//ここから本文





int main() {
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (getDigit(i) % 2 == 1)  cnt++;
	}
	cout << cnt << endl;
}


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  return __gcd(a,b);
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}


int main() {
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL N, su =0, li=0;
  cin >> N;
  
  VLL A(N);
  REP(i,N){
    cin >> A.at(i);
    su += A.at(i);
  }
  li =N;
  SORT(A);
  
  for(int i=N-1; i>=0; --i){
    su -= A.at(i);
    if( 2*su < A.at(i)){
      li -= i;
      break;
    }
  }
  
  cout << li << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0) return 1;
	else if(N % 2 == 0) return power(MOD(a * a), N / 2);
	else return MOD(a * power(a, N - 1));
}

int inverse(int a){
	return power(a, p - 2);
}

int fact(int N){
	static vector<int> _fact(1, 1);
	for(int i = _fact.size(); i <= N; i++){
		_fact.push_back(MOD(i * _fact[i - 1]));
	}
	return _fact[N];
}
 
int fact_inv(int N){
	static vector<int> inv(2, 1), _fact_inv(2, 1);
	for(int i = inv.size(); i <= N; i++){
		inv.push_back(MOD(-(p / i) * inv[p % i]));
		_fact_inv.push_back(MOD(inv[i] * _fact_inv[i - 1]));
	}
	return _fact_inv[N];
}
 
int combination(int N, int k){
	if(k < 0 || N < k || N < 0) return 0;
	else return MOD(fact(N) * MOD(fact_inv(N - k) * fact_inv(k)));
}

int solve(int r, int c){
	int ans = 0, i;
	for(i = 0; i <= c; i++){
		ans = MOD(ans + combination(r + i + 1, r));
	}
	return ans;
}

signed main(){
	int r1, c1, r2, c2;
	scanf("%lld%lld%lld%lld", &r1, &c1, &r2, &c2);
	r1--;
	c1--;
	int ans = MOD(solve(r2, c2) - solve(r2, c1) - solve(r1, c2) + solve(r1, c1));
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 39656
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

int main() {
    string s, t;
    cin >> s >> t;
    if(s.length() == t.length() -1 ) {
        if(s == t.substr(0, s.length())){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;

}


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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	vector<int>p(n);
	for(int i=0; i<n; i++){
		cin>>p[i];
	}
	int cnt=0;
	for(int i=1; i<n-1; i++){
		int maxv=max(p[i-1],max(p[i], p[i+1]));
		int minv=min(p[i-1],min(p[i], p[i+1]));
		if(maxv!=p[i]&&minv!=p[i]){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}

signed main(){
	//while(1)
	solve();
}

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

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

  int cur = 0;
  int mul = 1;
  vector<int> cnt(2019);
  cnt[0] = 1;

  for (int i = s.size() - 1; i >= 0; --i) {
    cur += mul * (s[i] - '0');
    cur %= 2019;
    ++cnt[cur];
    mul = mul * 10 % 2019;
  }

  long long ans = 0;
  for (int c : cnt) {
    ans += (long long)(c - 1) * c / 2;
  }

  cout << ans << '\n';
}


Measured memory_bytes: 3764
#include <iostream>

int main() {
  std::string S;
  std::cin >> S;

  if (S[0] == '7' || S[1] == '7' || S[2] == '7') {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N-1){
    int a;
    cin >> a;
    A[a-1]++;
  }
  rep(i,N) printf("%d\n",A[i]);
  return 0;
}

Measured memory_bytes: 4056
using System;

namespace ABC179A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            if (S.EndsWith("s"))
            {
                Console.WriteLine(S + "es");
            }
            else
            {
                Console.WriteLine(S + "s");
            }
        }
    }
}


Measured memory_bytes: 26212
#include <bits/stdc++.h>
  using namespace std;
  typedef long long int ll;
  #define mod 1000000007
  #define all(v)  v.begin(),v.end()
  #define pb push_back
  #define size(v)  (int) v.size()
  #define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
  ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
  ll inv(ll a){return power_mod(a,mod-2);}
  ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}

  int main()
  {



     int n,x;
     cin>>n>>x;
     int res=1;
     int a[n+1];
     for(int i=1;i<=n;i++) cin>>a[i];

      int curr=0;
      for(int i=1;i<=n;i++)
      {
        
          curr+=a[i];
          if(curr<=x) res++;  
      }

      cout<<res<<endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int MAXN = 10000010;
bool is_p[MAXN];
vector<int> p, fp;

void sieve() {
  fill_n((bool*)is_p, MAXN, true);
  is_p[0] = is_p[1] = false;
  for (int i = 2; i < MAXN; i++) {
    if (!is_p[i]) continue;
    p.emplace_back(i);
    for (int j = 2 * i; j < MAXN; j += i) {
      is_p[j] = false;
    }
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  sieve();
  for (int i = 0; i + 3 < int(p.size()); i++) {
    if (p[i + 1] != p[i] + 2) continue;
    if (p[i + 2] != p[i] + 6) continue;
    if (p[i + 3] != p[i] + 8) continue;
    fp.emplace_back(p[i + 3]);
  }
  int n;
  while (cin >> n, n) {
    cout << *(upper_bound(fp.begin(), fp.end(), n) - 1) << endl; 
  }

  return 0;
}


Measured memory_bytes: 16648
#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;
string res;
ll n,i,a[N],p;
ll q,x,y,sum;
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>>n;
    for (i = 1;i <= n;i++){
        cin>>a[i];
        p = p^a[i];
    }
    for (i = 1;i <= n;i++){
        ll ans = p^a[i];
        cout<<ans<<" ";
    }
}



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

int main() {
  int X1, X2, Y1, Y2;
  cin >> X1 >> Y1 >> X2 >> Y2;
  
  int yoko = X2-X1;
  int tate = Y2-Y1;
  int X3, X4, Y3, Y4;
  Y3 = Y2 + yoko;
  X3 = X2 - tate;
  Y4 = Y3 - tate;
  X4 = X3 - yoko;
  cout << X3 << " " << Y3 << " "<< X4 << " " << Y4 << " " << endl;
  
}

Measured memory_bytes: 256
//
//  main.cpp
//  atcoderX
//
//  Created by 村井真奈美 on 2018/06/16.
//  Copyright © 2018年 村井真奈美. All rights reserved.
//

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

int main() {
    
    int A,B;
    cin >> A >> B;
    
    if(A>8 || B>8)cout << ":(" << endl;
    else cout << "Yay!" << endl;

 
}


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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;++i)cin >> a[i];
    vector<bool> dp(k+1);
    for(int stones = 0; stones<=k ;++stones)
    {
        for(int x:a)
        {
            if(stones>=x && !dp[stones-x])
            dp[stones] = true;
        }
    }

    cout << (dp[k]?"First":"Second");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main()
{
int n,m;
cin>>n>>m;
vector<int> a(m,0);
vector<int> b(m,0);
vector<int> cnt(n,0);
for(int i=0; i<m; i++)
{
    cin>>a[i]>>b[i];
    ++cnt[a[i]-1];
    ++cnt[b[i]-1];
}

for(int l=0; l<n; l++)
{
    cout<<cnt[l]<<endl;
}
}


Measured memory_bytes: 256
import numpy as np

N = int(input())
D = list(map(int, input().split()))
if N > 23:
    print(0)
    exit()
if D.count(0) >= 2:
    print(0)
    exit()
for i in range(1, 13):
    if D.count(i) >= 3:
        print(0)
        exit()
for i in range(13):
    if (D.count(i) + D.count(i+1)) == 4:
        print(1)
        exit()

# 深さ優先探索で全通りを探索できるのでは curは０からスタート
def dfs(cur, times):
    global answer
    if cur == N:
        times.sort()
        arr = np.array(times)
        result = (arr[1:] - arr[:-1]).min()
        if result > answer:
            answer = result
    else:
        x = D[cur]
        dfs(cur+1, times + [x])
        dfs(cur+1, times + [24-x])

answer = 0
dfs(0, [0, 24])
print(answer)


Measured memory_bytes: 13516
#include <stdio.h>

int solve(int, int);

int n;
int A[20];

int main(){
  int i, j, q, M[2000];

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

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

  for(i = 0; i < q; i++){
    j = solve(0, M[i]);
    if(j == 1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int solve(int i, int m){
  int r;
  if(m == 0) return 1;
  if(i >= n) return 0;
  r = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return r;
}

Measured memory_bytes: 588
row = int(input())
data = list(str(input()))

def checker(big,end,index):
	if big == end:
		return 1
	else :
		return 2

resp = []
for var in range(1,row):
	if checker(data[var-1],data[var],var) == 1:
		resp.append(var)
	else:
		pass

resp.reverse()
#逆順にして長さを変化しなくする
for deldex in resp:
	del data[deldex]
	

print(len(data))

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

vector<string> v;

int main(void){
    int N, M, A, B;
    cin >> N >> M >> A >> B;
    v.resize(N);
    for(int i=0; i<N; ++i){
        v[i].assign(M, '.');
    }
    if(N*(M/2)<A || (N/2)*M<B){
        cout << "NO" << endl;
        return 0;
    }
    int rb=(N/2)*M;
    if(N%2==0){
        for(int i=0; i<A; ++i){
            v[i%N][i/N*2]='<';
            v[i%N][i/N*2+1]='>';
            if(i%2==0) rb -= 2;
        }
    }
    else if(M%2==0){
        int now=0;
        while(now<A && now*2<M){
            v[0][now*2]='<';
            v[0][now*2+1]='>';
            ++now;
        }
        for(int i=0; i<A-now; ++i){
            v[i%(N-1)+1][i/(N-1)*2]='<';
            v[i%(N-1)+1][i/(N-1)*2+1]='>';
            if(i%2==0) rb -= 2;
        }
    }
    else{
        int nox=0;
        while(nox<A && nox*2<M-1){
            v[0][nox*2]='<';
            v[0][nox*2+1]='>';
            ++nox;
        }
        int p=N-1, q=M-2, r=-1;
        for(int i=nox; i<A; ++i){
            v[p][q]='<';
            v[p][q+1]='>';
            if(q==0 && r==-1){
                ++p;
                r=1;
            }
            else if(q==M-2 && r==1){
                --p;
                r=-1;
            }
            else{
                p=N-p;
                q += r;
            }
            --rb;
        }
    }
    if(rb<B){
        cout << "NO" << endl;
        return 0;
    }
    int fb=0;
    for(int i=0; i<M; ++i){
        if(fb==B) break;
        for(int j=0; j+1<N; ++j){
            if(v[j][i]=='.' && v[j+1][i]=='.'){
                v[j][i]='^';
                v[j+1][i]='v';
                ++fb;
                if(fb==B) break;
            }
        }
    }
    cout << "YES" << endl;
    for(int i=0; i<N; ++i) cout << v[i] << endl;
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <map>
#include <set>
typedef long long ll;
using namespace std;

int main(void) {
    ll N,K;cin>>N>>K;
    map<ll, ll> mp;
    for (ll i = 1; i <= N; i++) {
        ll A;cin>>A;
        mp[i] = A;
    }
    set<ll> se;
    vector<ll> vc;
    ll cur = 1;
    while (true) {
        if (se.find(cur) != se.end()) break;
        se.insert(cur);
        vc.push_back(cur);
        cur = mp[cur];
    }
    ll loop_index;
    for (ll i = 0; i < N; i++) {
        if (vc[i] == cur) {
            loop_index = i;
            break;
        }
    }
    if (K <= loop_index) cout << vc[K] << endl;
    else cout << vc[loop_index + ((K - loop_index) % (vc.size() - loop_index))] << endl;
    return 0;
}

Measured memory_bytes: 25944
def gcd(a, b)
  if a < b
    return gcd(b, a)
  end
  if b == 0
    return a
  end
  gcd(b, a % b)
end

def lcm(a, b)
  a * b / gcd(a, b)
end

ans = 1

n = gets.to_i
n.times {
  t = gets.to_i
  ans = lcm(ans, t)
}
puts ans


Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

unordered_map<long, unordered_set<long>> children;
vector<long> X(1010, 0);

// color, rest_color
pair<long,  long> rec(long node) {
  if (children[node].size() == 0) {
    return make_pair(X[node], 0);
  }
  set<pair<long, long>> ret;
  ret.insert(make_pair(0, 0));
  for (auto c: children[node]) {
    set<pair<long, long>> next;
    auto c_res = rec(c);
    if (c_res.second == -1) return make_pair(X[node], -1);
    for (auto before: ret) {
      next.insert(make_pair(before.first + c_res.first, before.second + c_res.second));
      next.insert(make_pair(before.first + c_res.second, before.second + c_res.first));
    }
    ret = next;
  }
  long minimum = -1;
  for (auto it: ret) {
    if (it.first <= X[node]) {
      if (minimum == -1 or minimum > it.second) minimum = it.second;
    }
  }
  return make_pair(X[node], minimum);
}

int main(void) {
  cout.precision(12);

  long N;
  cin >> N;

  for (long i = 2; i <= N; i++) {
    long p;
    cin >> p;
    children[p].insert(i);
  }
  for (long i = 1; i <= N; i++) cin>> X[i];

  auto result = rec(1);
  if (result.second != -1) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;


int main(){
    long long N;
    cin >> N;
    long long count = N;
    long long ans = 0;
    bool ok = true;
    for(int j = N;j<1000+N;j++){
        ok = true;
        for(int i = 2;i<=j/2;i++){
            if(j%i == 0){
                ok = false;
                break;
            }
        }
        if(ok == true){
            ans = j;
            break;
        }
    }
    
    

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << (x) << "( (L" << __LINE__ << ")" << endl;
using namespace std;

#define ll long long

ll n,m;
int main() {
    priority_queue<ll> q;
    cin >> n >> m;
    for(ll i = 0; i < n; i++) {
        ll tmp;
        cin >> tmp;
        q.push(tmp);
    }
    for(ll i = 0; i < m; i++) {
        ll tmp = q.top();
        q.pop();
        q.push(tmp / 2);
    }
    ll result = 0;
    while(!q.empty()) {
        result += q.top();
        q.pop();
    }
    cout << fixed << result;
}

Measured memory_bytes: 1400
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
  int n,i;
  char w[111][11];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",w[i]);
    if(i>0&&w[i][0]!=w[i-1][strlen(w[i-1])-1]){
      puts("No");
      return 0;
    }
  }
  qsort(w,n,sizeof(w[0]),strcmp);
  for(i=1;i<n;i++){
    if(strcmp(w[i],w[i-1])==0){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int K; cin >> K;
    ll i = 7%K;
    ll cou = 1;
    if(K%2==0 || K%5==0){
        AA(-1);
        return 0;
    }
    while(i!=0){
        i = i*10 + 7;
        i = i%K;
        cou++;
    }
    AA(cou);
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

ll Msquare(ll x)
{
	return (x * x) % MOD_P;
}

ll Mpower(ll x, int y)
{
	if (y == 1) {
		return x;
	}
	if (y % 2) {
		return (Msquare(Mpower(x, y / 2)) * x) % MOD_P;
	} else {
		return (Msquare(Mpower(x, y / 2))) % MOD_P;
	}
}

int main()
{
	int n;
	cin >> n;
	ll p10 = Mpower(10, n);
	ll p9 = Mpower(9, n);
	ll p8 = Mpower(8, n);
	p9 *= 2;
	p9 %= MOD_P;
	p10 += p8;
	p10 %= MOD_P;
	p10 -= p9;
	if (p10 < 0) {
		p10 += MOD_P;
	}
	

	printf("%lld", p10);


	return 0;
}

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

int a[100010]={0};

int main()
{
    char t;
    int n=-1;
    while(n++,~scanf("%c",&t)&&t!='\n')if(t=='L')a[n]=-1;

    int cnt=0;
    for(int i=0;i<n-1;i++)
    {
        if(a[i]==0&&a[i+1]==0)
            cnt++;
        else if(a[i]==0&&a[i+1]==-1)
            a[i]=cnt+1,cnt=0;
    }
    cnt=0;
    for(int i=n-1;i>0;i--)
    {
        if(a[i]==-1&&a[i-1]==-1)
            cnt++;
        else if(a[i]==-1&&a[i-1]>0)
            a[i]=cnt+1,cnt=0;
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]<=0)printf("0 ");
        else if(i<n-1&&a[i+1]>0)
        {
            int num = a[i]+a[i+1];
            if((num&1)==0)printf("%d %d ",num>>1,num>>1);
            else if((a[i]&1)==0)
                printf("%d %d ",num>>1,(num>>1)+1);
            else printf("%d %d ",(num>>1)+1,num>>1);
            i++;
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 768
import Data.List

ints :: String -> [Int]
ints s = map read $ words s

getLines :: IO [[Int]]
getLines = do
  s <- getLine
  let [a, b] = ints s
  if a == 0 && b == 0
    then return []
    else do
      rest <- getLines
      return ([a, b] : rest)


calc :: Int -> Int -> String
calc w h = intercalate "\n" $ replicate h $ replicate w '#'

main :: IO ()
main = do
  xs <- getLines
  putStrLn $ intercalate "\n\n" $ [calc w h | ys <- xs, let [h, w] = ys]
  putStrLn ""

Measured memory_bytes: 4980
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N, M, K, Q, H, W;
string S;

using P = pair<int, int>;
inline bool get_sum(int K, vector<vector<int>> const &sum, vector<P> const &hs, int w1, int w2) {
    for (auto p : hs) {
        int h1 = p.first;
        int h2 = p.second;
        if (sum[h2][w2] - sum[h1][w2] - sum[h2][w1] + sum[h1][w1] > K) {
            return false;
        }
    }
    return true;
}

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

    cin >> H >> W >> K;

    auto S = make_vec<int>(H, W);
    auto sum = make_vec<int>(H + 1, W + 1);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char t;
            cin >> t;
            S[i][j] = (int)(t - '0');
        }
    }

    // 累積
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + S[i][j];
        }
    }

    int ans = INF;
    for (int bit = 0; bit < (1 << (H - 1)); bit++) {
        int cnt = -2;
        int h1 = 0;
        int h2 = 0;
        vector<P> hs;
        for (int i = 0; i < H; i++) {
            if ((bit & (1 << i)) > 0 || i == H - 1) {  // i番目の線に沿って割る
                cnt++;
                h2 = i + 1;
                hs.push_back(make_pair(h1, h2));
                h1 = h2;
            }
        }
        int w2 = 0;
        for (int w1 = 0; w1 < W;) {
            while (w2 < W && get_sum(K, sum, hs, w1, w2 + 1)) {
                w2++;
            }
            if (!get_sum(K, sum, hs, w1, w2 + 1) && w1 == w2) {
                cnt = INF;
                break;
            }
            cnt++;
            if (cnt >= ans) break;
            w1 = w2;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}


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

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

  vector<string> a(h);
  for (int i = 0; i < h; i++){
    cin >> a.at(i);
  }

  int d[h][w];
  bool checked[h][w];
  queue<pair<int, int>> que;
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (a.at(i).at(j) == '#'){
        d[i][j] = 0;
        checked[i][j] = true;
        que.push(make_pair(i, j));
      }else{
        checked[i][j] = false;
      }
    }
  }

  while (que.size() != 0){
    pair<int, int> p = que.front();
    que.pop();
    int x = p.first; int y = p.second;

    if (x - 1 >= 0 && checked[x - 1][y] == false){
      d[x - 1][y] = d[x][y] + 1;
      que.push(make_pair(x - 1, y));
      checked[x - 1][y] = true;
    }

    if (x + 1 < h && checked[x + 1][y] == false){
      d[x + 1][y] = d[x][y] + 1;
      que.push(make_pair(x + 1, y));
      checked[x + 1][y] = true;
    }

    if (y - 1 >= 0 && checked[x][y - 1] == false){
      d[x][y - 1] = d[x][y] + 1;
      que.push(make_pair(x, y - 1));
      checked[x][y - 1] = true;
    }

    if (y + 1 < w && checked[x][y + 1] == false){
      d[x][y + 1] = d[x][y] + 1;
      que.push(make_pair(x, y + 1));
      checked[x][y + 1] = true;
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (d[i][j] > ans) ans = d[i][j];
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 14352
#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<map>
#include<iterator>
using namespace std;
#define tt int t;cin>>t;while(t--)
#define ll long long
#define nl endl
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.begin(),v.end(),greater<int>());
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define amax(a,n) *max_element(a,a+n)
#define amin(a,n) *min_element(a,a+n)
#define vmax(a) *max_element(a.begin(),a.end())
#define vmin(a) *min_element(a.begin(),a.end())
#define so ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define a_size 100
ll i,j;

int main()
{
        so

        ll n,sum=0;
        cin>>n;
        for(i=2;i<n;i++)
        {
                  if(n%i==0){
                    sum+=n/i-1;
                    continue;
                  }
                  sum+=(n/i);
        }
        cout<<sum+n-1;

        return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

//最大公約数
ll gcd(ll a, ll b){
    if(b==0) return a;
    else return gcd(b, a%b);
}

//最小公倍数
ll lcm(ll a, ll b){
    return a / gcd(a,b) * b;
}

int main(){
    ll  a,b;cin >>a>>b;
    ll ans = lcm(a,b);
    cout << ans<<endl;

}



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

struct Compress {
	map<int, int>mp;
	map<int, int>revmp;

	Compress(vector<int>vs) {
		setmp(vs);
	}
	Compress(const set<int>&vs) {
		setmp(vs);
	}
	Compress() :mp(), revmp() {

	}
	void setmp(vector<int>vs) {
		sort(vs.begin(), vs.end());
		vs.erase(unique(vs.begin(), vs.end()), vs.end());
		for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
			mp[vs[i]] = i;
			revmp[i] = vs[i];
		}
	}
	void setmp(const set<int>&vs) {
		int num = 0;
		for (auto v : vs) {
			mp[v] = num;
			revmp[num] = v;
			num++;
		}
	}
};

struct rect {
	int l, d, r, u;
};


struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main() {
	while (1) {

		int W, H; cin >> W >> H;
		if (!W)break;
		vector<int>xs{ 0,W }, ys{ 0,H };
		int N; cin >> N;
		vector<rect>rects;
		for (int i = 0; i < N; ++i) {
			int l, d, r, u; cin >> l >> u >> r >> d;
			xs.push_back(l); xs.push_back(r);
			ys.push_back(d); ys.push_back(u);
			rects.push_back(rect{ l,d,r,u });
		}
		Compress compx(xs), compy(ys);
		vector<vector<pair<int, int>>>pluss(compy.mp.size()), minuss(compy.mp.size());
		for (auto&rect : rects) {
			rect.l = compx.mp[rect.l];
			rect.r = compx.mp[rect.r];
			rect.u = compy.mp[rect.u];
			rect.d = compy.mp[rect.d];
			pluss[rect.u].push_back(make_pair(rect.l, rect.r));
			minuss[rect.d].push_back(make_pair(rect.l, rect.r));
		}
		vector<int>v(compx.mp.size());
		vector<vector<int>>field(compy.mp.size(), vector<int>(compx.mp.size()));
		for (int y = 0; y < compy.mp.size(); ++y) {
			vector<int>nextv(v);
			for (auto plus : pluss[y]) {
				for (int x = plus.first; x < plus.second; ++x) {
					nextv[x]++;
				}
			}
			for (auto minus : minuss[y]) {
				for (int x = minus.first; x < minus.second; ++x) {
					nextv[x]--;
				}
			}
			for (int x = 0; x < compx.mp.size(); ++x) {
				field[y][x] = nextv[x];
			}
			v = nextv;
		}
		UnionFind uf(compx.mp.size()*compy.mp.size());
		for (int i = 0; i < compy.mp.size()-1; ++i) {
			for (int j = 0; j < compx.mp.size()-1; ++j) {
				const int num = i*compx.mp.size() + j;
				if (!field[i][j]) {
					if (i&&!field[i - 1][j]) {
						uf.unionSet(num, num - compx.mp.size());
					}
					if (j&&!field[i][j - 1]) {
						uf.unionSet(num, num - 1);
					}
				}
			}
		}
		set<int>aset;
		for (int y = 0; y < compy.mp.size()-1; ++y) {
			for (int x = 0; x < compx.mp.size()-1; ++x) {
				if (!field[y][x]) {
					aset.emplace(uf.root(y*compx.mp.size() + x));
				}
			}
		}
		int ans = aset.size();
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 5376
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PrintWriter pw = new PrintWriter(System.out);

    while (true) {
        String s = sc.next();

        if ("-".equals(s)) break;

        int m = sc.nextInt();

        for (int i = 0; i < m; i++) {
            int h = sc.nextInt();
            s = s.substring(h) + s.substring(0, h);
        }

        pw.println(s);
    }

    pw.flush();
  }
}


Measured memory_bytes: 26216