akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

string N;
int K;

int dp[1000][2][4];
int rec(int k = 0, bool tight = true, int sum = 0) {
	if (sum > K)return 0;
	if (k == N.size())return sum == K;

	int x = N[k] - '0';
	int r = (tight ? x : 9);

	int& res = dp[k][tight][sum];
	if (~res)return res;
	res = 0;

	rep(i, r + 1) {
		res += rec(k + 1, tight && i == r, sum + (i != 0));
	}
	return res;
}

int main() {
	init();

	cin >> N >> K;
	memset(dp, -1, sizeof(dp));
	cout << rec() << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
typedef long long ll;
int ceil(int a,int b){// a以上でbの倍数の最小値を出力//
    return (a+b-1)/b*b;
}

//シフト演算　(1<<k) 2のk乗

int stoii(string s){//stoi関数の代用 文字列を数値として読み取りint型に変換//
    return atoi(s.c_str());
}
int main (void){
    int a,b,x;
    cin>>a>>b>>x;
    if(a<=x && x<=a+b) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

typedef long long LL;
#define MAXN 1000
#define _MOD 1000000009

int N;
char M[MAXN][MAXN];
bool dp[MAXN][MAXN][304];

int main() {
#ifdef OJ
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    std::ios_base::sync_with_stdio(false);

    scanf("%d", &N);
    if (N == 1) {
        return 0*printf("1\n");
    }

    for (int i = 0; i < N; i++) {
        scanf("%s", M[i]);
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N-1; j++) {
            M[i][j+N] = M[i][j];
        }
    }


    for (int j = 0; j < N; j++) {
        for (int i = 0; i < N-1; i++) {
            M[i+N][j] = M[i][j];
        }
    }

    for (int i = 0; i < N-1; i++) {
        for (int j = 0; j < N-1; j++) {
            M[i+N][j+N] = M[i][j];
        }
    }

    //for (int i = 0; i < 2*N-1; i++) {
        //M[i][2*N-1] = 0;
        //printf("%s\n", M[i]);
    //}
    //printf("\n");
    //return 0;

    int N1 = N*2-1;
    int ans = 0;

    for (int i = 0; i < N1; i++)
        for (int j = 0; j < N1; j++)
            dp[i][j][1] = 1;

    for (int k = 2; k <= N; k++) {
        for (int i = 0; i < N1; i++) {
            int i1 = i+k-1;
            if (i1 >= N1)
                continue;
            for (int j = 0; j < N1; j++) {
                int j1 = j+k-1;
                if (j1 >= N1)
                    continue;

                if (dp[i][j][k-1] && dp[i+1][j+1][k-1] && M[i][j1] == M[i1][j]) {
                    dp[i][j][k] = 1;
                    //printf("%d %d %d\n", k, i, j);
                    if (k == N)
                        ans++;
                }

            }
        }
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 180224
#include<stdio.h>
#include<string.h>
int t[100009];
int main(){
    int a;
    scanf("%d",&a);
    int o = 0;
    for(int i = 0;i<a;i++){
        scanf("%d",&t[i]);
        if(t[i]==2) o = 1;
    }
    if(o==0) printf("-1\n");
    else{
    int k = 0;
	int j = 0;
      while(1){
        if(k==a){
            printf("-1\n");
            break;
        }
        if(t[j]!=2){
            k++;
            j = t[j]-1;
			
        }
        else if(t[j]==2){
            printf("%d\n",k+1);
            break;
        }
       }
    }

return 0;

}


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

#define ll unsigned long long
#define INF 1234567890
#define N (int)(1e5 + 5)
#define pi acos(-1)

int t[N], cost[N];

void solve()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> t[i];
    cost[1] = 0;
    cost[2] = abs(t[1] - t[2]);
    for(int i = 3; i <= n; ++i)
        cost[i] = min(cost[i - 1] + abs(t[i] - t[i - 1]), cost[i - 2] + abs(t[i] - t[i - 2]));
    cout << cost[n];
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


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

using namespace std;

int main() {
    int H, W, h, w, Swap = 0;
    cin >> H >> W >> h >> w;
    if(H % h == 0 && W % w == 0) {
        puts("No");
    } else {
        puts("Yes");
        int val = (h * w - 1) * 2333 + 1;
        for(int i = 1; i <= H; i++) {
            for(int j = 1; j <= W; j++) {
                if(i % h == 0 && j % w == 0)
                    printf("%d ", -val);
                else
                    printf("2333 ");
            }
            puts("");
        }
    }
    return 0;
}

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

map < int, int > vis;

int main()
{
	vis.clear();
	for(int i = 10000;i <= 99999;i++){
		int k = i/1000;
		if(((i%100)%10*10)+((i%100)/10)==k%100){
			vis[i]= 1;
		}
	}
	int a, b;
	cin >> a >> b;
	int cnt = 0;
	for(int i = a;i <= b;i++){
		if(vis[i] == 1) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <queue>
#include <stack>
#include <cstring>
#include <ctime>
#include <cassert>


#define pb emplace_back
#define re return
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265359;

int h, n;
int a[100000];
int main()
{
    //freopen("distance.in", "r", stdin);
    //freopen("distance.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> h >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int s = accumulate(a, a + n, 0);
    if (s >= h)
        cout << "Yes";
    else
        cout << "No";
}
/// ACTUAL CODE STARTS HERE:
//  I'm red in soul
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n,ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x=i,pos=0;
		while(x){
			pos++;
			x/=10;
		}
		if(pos&1)ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	void run(){
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		int sum = 0;
		for(int i=1;;i++){
			sum += i;
			if(sum >= x && sum-i < x){
				System.out.println(i);
				break;
			}
			if(sum>1000000000){
				break;
			}	
		}
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
}


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

int n, m;

class WeightedUnionFind{
	public:
		vector<int> Parent;
		vector<int> Rank;
		vector<long long> Weight;
		WeightedUnionFind(int n){
			++n;
			Parent.resize(n, 0);
			Rank.resize(n, 0);
			Weight.resize(n, 0);
			for(int i=0; i<n; ++i)
				Parent[i] = i;
		}

		int find(int x){
			if(Parent[x] == x) return x;
			int pastparent = Parent[x];
			Parent[x] = find(Parent[x]);
			Weight[x] += Weight[pastparent];
			return Parent[x];
		}

		bool unite(int x, int y, long long z){ // a[y] - a[x] == z
			int sx = x, sy = y;
			x = find(x);
			y = find(y);
			if(x == y) return false;
			if(Rank[x] < Rank[y]){
				Parent[x] = y;
				Weight[x] = z + Weight[sy] - Weight[sx];
			}else{
				Parent[y] = x;
				Weight[y] = - z - Weight[sy] + Weight[sx];
				if(Rank[x] == Rank[y]) ++Rank[x];
			}
			return true;
		}

		bool same(int x, int y){
			return find(x) == find(y);
		}

		long long cost(int x, int y){ // call only if same(x, y) == true
			return Weight[x] - Weight[y];
		}
};

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> m;
	WeightedUnionFind wuf(n);
	for(int i=0; i<m; ++i){
		int l, r, d;
		cin >> l >> r >> d;
		if(wuf.same(l, r) && wuf.cost(l, r) != d){
			cout << "No\n";
			return 0;
		}
		wuf.unite(l, r, d);
	}
	cout << "Yes\n";
}

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

using namespace std;

long double dp[303][303][303];
int n;

long double count(int a1, int a2, int a3)
{
	if (dp[a1][a2][a3] != -1)
		return dp[a1][a2][a3];
	int sum = a1 + a2 + a3;
	if(sum == 0)
		return 0;
	int zero = n - sum;
	dp[a1][a2][a3] = double(n) / double(sum);
	if (a1)
		dp[a1][a2][a3] += a1 * count(a1 - 1, a2, a3) / (double) sum;
	if (a2)
		dp[a1][a2][a3] += a2 * count(a1 + 1, a2 - 1, a3) / (double) sum;
	if (a3)
		dp[a1][a2][a3] += a3 * count(a1, a2+1, a3 - 1) / (double) sum;
	return dp[a1][a2][a3];
}


int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	for (int i = 0; i < 303; ++i)
	{
		for (int j = 0; j < 303; ++j)
		{
			for (int k = 0; k < 303; ++k)
			{
				dp[i][j][k] = -1;
			}
		}
	}
	cin >> n;
	int a[4] = {0,0,0,0};
	for (int i = 0; i < n; ++i)
	{
		int t;
		cin >> t;
		a[t]++;
	}
	cout << setprecision(20) << count(a[1],a[2],a[3]);

	return 0;
}

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

int main()
{
    char n[3];
    for (int i = 0; i < 3; i++)
        cin >> n[i];

    bool flag = false;
    for (int i = 0; i < 3; i++) {
        if (n[i] == '7') {
            flag = true;
            break;
        }
        else
            flag = false;
    }

    if (flag)
        cout << "Yes\n";
    else
        cout << "No\n";
    

    return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <complex>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

//#define _DEBUG_ 3

bool check(int zero, int one, int n, std::string& s) {
	std::vector<int> arr(n, 0);
	arr[0] = zero, arr[1] = one;

	for (int i = 1; i < n - 1; i++) {
		if (s[i] == 'o') {
			if (arr[i] == 1)
				arr[i + 1] = arr[i - 1];
			else
				arr[i + 1] = arr[i - 1] * (-1);
		} else {
			if (arr[i] == -1)
				arr[i + 1] = arr[i - 1];
			else
				arr[i + 1] = arr[i - 1] * (-1);
		}
	}

	if (s[0] == 'o') {
		if (arr[0] == 1 && arr[1] != arr[n - 1]) return false;
		if (arr[0] == -1 && arr[1] == arr[n - 1]) return false;
	} else {
		if (arr[0] == 1 && arr[1] == arr[n - 1]) return false;
		if (arr[0] == -1 && arr[1] != arr[n - 1]) return false;
	}

	if (s[n - 1] == 'o') {
		if (arr[n - 1] == 1 && arr[n - 2] != arr[0]) return false;
		if (arr[n - 1] == -1 && arr[n - 2] == arr[0]) return false;
	} else {
		if (arr[n - 1] == 1 && arr[n - 2] == arr[0]) return false;
		if (arr[n - 1] == -1 && arr[n - 2] != arr[0]) return false;
	}

	for (auto c : arr) {
		cout << (c == 1 ? "S" : "W");
	}
	cout << endl;
	return true;
}

void run() {
	int n;
	std::string s;
	cin >> n;
	cin >> s;
	// s s
	if (check(1, 1, n, s)) return;
	if (check(1, -1, n, s)) return;
	if (check(-1, 1, n, s)) return;
	if (check(-1, -1, n, s)) return;
	cout << "-1" << endl;
}

int main() {
#ifdef _DEBUG_
	using std::chrono::system_clock;
	using std::chrono::duration_cast;
	system_clock::time_point  start, end;
	std::ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
	for (int i = 0; i < _DEBUG_; i++) {
		cout << "-------------------------- (cnt:" << i << ")" << endl;
		start = system_clock::now();
		run();
		end = system_clock::now();
		int elapsed = duration_cast<std::chrono::milliseconds>(end - start).count();
		cout << "-------------------------- (time:" << elapsed << "ms)" << endl << endl;
}
#else
	run();
#endif
	return 0;
}


Measured memory_bytes: 1016
#include <iostream>
#include <climits>
#include <cstdlib>

using namespace std;

int getLength( int x1, int x2, int y1, int y2 ) {
  return ( abs( x1 - x2 ) + abs( y1 - y2 ) );
}

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  int minL = INT_MAX;
  for( int w = 1; w <= n; w++ ) {
    int ax = a % w;
    int ay = a / w;
    int bx = b % w;
    int by = b / w;
    int cx = c % w;
    int cy = c / w;
    int dx = d % w;
    int dy = d / w;
    
    int ablen = getLength( ax, bx, ay, by );
    int cdlen = getLength( cx, dx, cy, dy );
    int len = ablen + cdlen;

    minL = minL > len ? len : minL;
  }

  cout << minL << endl;

  return 0;
}

Measured memory_bytes: 1164
import math
n,m=map(int,input().split())
ans=1
for i in range(1,n+1):
    ans=ans*i%1000000007
for i in range(1,m+1):
    ans=ans*i%1000000007

if abs(n-m)>1:
    print(0)
elif n!=m:
    print(ans)
else:
    print(ans*2%1000000007)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,i,j;
	cin>>n>>k;
	vector<int> arr(n);
	for(i=0;i<n;++i)
		cin>>arr[i];
	vector<int> dp(n);
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	int m;
	for(i=2;i<n;++i){
		m=INT_MAX;
		for(j=1;j<=k&&i-j>=0;++j)
			m=min(m,dp[i-j]+abs(arr[i]-arr[i-j]));
		dp[i]=m;
	}
	cout<<dp[n-1];
	return 0;
}


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

int main() {

  string in;

  while( cin >> in ) {

    long long int ans = 0;
    long long int b = 0;
    long long int a;
    for( long long int i = 0; i < in.size(); i++ ) {
      if ( in[i] == 'I' ) {
	a = 1;
      }else if ( in[i] == 'V' ) {
	a = 5;
      }else if ( in[i] == 'X' ) {
	a = 10;
      }else if ( in[i] == 'L' ) {
	a = 50;
      }else if ( in[i] == 'C' ) {
	a = 100;
      }else if ( in[i] == 'D' ) {
	a = 500;
      }else if ( in[i] == 'M' ) {
	a = 1000;
      }
      if ( b == 0 ) {
	b = a;
      }else {
	if ( b < a ) {
	  ans -= b;
	  ans += a;
	  b = 0;
	}else {
	  ans += b;
	  b = a;
	}
      }
    }
    ans += b;
    cout << ans << endl;

  }

  return 0;

}

Measured memory_bytes: 1180
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=5e5+5;

set<pll>s;

ll solve(ll p,ll q,vpll& a,ll i){


ll c=0;

for(int j=0;j<sz(a);j++){
  ll x=a[j].ff,y=a[j].ss;

  if(s.count({x+p,y+q}))c++;
}

return c;
}


int main()
{ 

IOS;


ll n;cin>>n;

vpll a(n);
FOR(i,n){
  cin>>a[i].ff>>a[i].ss;
  s.insert({a[i].ff,a[i].ss});
}

sort(all(a));

ll d=0;

for(int i=0;i<n;i++){
  for(int j=i+1;j<n;j++){
    ll p=a[j].ff-a[i].ff;
    ll q=a[j].ss-a[i].ss;
    //d2(p,q);
    if(p||q)chmax(d,solve(p,q,a,i));
  }
}

cout<<n-d;






//end_routine();

return 0;
 
}


Measured memory_bytes: 3696
s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
s = [int(i) for i in s.split(",")]
print(s[int(input())-1])

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lef(x) (x<<1)
#define rig(x) (lef(x)+1)
#define int long long
const ll MOD=1e9+7LL;
const int N=200100;
ll a[N];
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
    	cin>>a[i];
    	a[i]+=a[i-1];
    }
    ll tot=a[n];
    ll ans=a[n];
    for (int i = 1; i <=n; ++i)
    {
    	ans=min(ans,abs(2*a[i]-tot));
    }
    cout<<ans<<"\n";
    return 0;   
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;


int main(int argc, char* argv[]){
	int a[4];
	int sum = 0;
	for (int i=0; i<4; i++){
		scanf("%d", &a[i]);
		sum+=a[i];
	}
	int min = 10000;
	for(int i=0; i<4; i++){
		for(int j=i+1; j<4; j++){
			int team1 = a[i]+a[j];
			int team2 = sum - team1;
			if(abs(team1-team2)<min){
				min = abs(team1-team2);
			}
		}
	}
	printf("%d\n", min);


	return 0;
}







Measured memory_bytes: 3212
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM = 1000000007;

int main()
{
  ll K;
  cin >> K;
  set<ll> visited;
  ll current = 0;
  ll ans = 0;
  bool found = false;
  while(true){
    current = (current * 10 + 7) % K;
    ans++;
    if (current == 0){
      found = true;
      break;
    }else if(visited.find(current) != visited.end()){
      break;
    }else{
      visited.insert(current);
    }
  }
  if (found){
    cout << ans << endl;
  }else{
    cout << "-1" << endl;
  }
  return 0;
}

Measured memory_bytes: 50376
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
vector<int> visited;
int N,M;
vector<vector<int>> G;
bool fl = false;


int main(){
    cin >> N >> M;
    G.resize(N);
    visited.resize(N);
    for(auto i:visited) i = 0;
    rep(i,M){
        int a,b;cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(auto nv:G[0]){  
        for(auto go:G[nv]){
            if(go==N-1){
                fl = true;
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 12784
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n;
    cin>>n;

    string s;
    cin>>s;

    int len = 0;
    int ans = 0;
    while( len < s.length() )
    {
        string str = s.substr(len,s.length()-len);
        vector<int> z_val = z_function(str);

        rep(i,0,z_val.size())
        {
            if ( i >= z_val[i] )
            {
                ans = max(ans,z_val[i]);
            }
        }
        len++;
    }

    cout<<ans<<endl;

}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 384
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<pair<string, int>> sps(n); cin >> sps;
    for(auto& e : sps){
        e.second *= -1;
    }
    vector<int> is(n);
    iota(is.begin(), is.end(), 0);
    sort(is.begin(), is.end(), [&](int a, int b){ return sps[a] < sps[b]; });
    for(auto& i : is){
        cout << i + 1 << '\n';
    }
}


Measured memory_bytes: 888
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
	int a,b,c;
	cin >>a>>b>>c;
	if((10*b+c)%4 == 0){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" <<endl;
	}
	
}

Measured memory_bytes: 256
// 0025 Hit and Blow
#include<iostream>
using namespace std;

int main()
{
	int a[4];
	int b[4]; 
	
	while(cin >> a[0] >> a[1] >> a[2] >> a[3]){ 
	  int hit  =0;
	  int blow =0;

	for(int i=0; i<4; i++)
		cin >> b[i];

	for(int i=0; i<4; i++)
		for(int j=0; j<4; j++)
			if(a[i]==b[j])
				if(i==j)	
					hit++;
				else
					blow++;
	cout<< hit << " " << blow << endl; 
	}
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

int main(int argc, char *argv[]){
  int n;
  while(cin >> n, n){
    vector<vector<int> > g(n, vector<int>(n, 1e9));
    for (int i = 0; i < n - 1; i++) {
      int to, from, cost;
      cin >> to >> from >> cost;
      to--;from--;
      g[to][from] = cost;
      g[from][to] = cost;
    }
    g[0][0] = 0;
    vector<pii> leaf;
    for (int i = 1; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < n; j++) {
        if(g[i][j] != 1e9)cnt++;
      }
      if(cnt == 1){
        for (int j = 0; j < n; j++) {
          if(g[i][j] != 1e9){
            leaf.push_back(pii(i, j));
          }
        }
      }
      g[i][i] = 0;
    }
    for (int i = 0; i < leaf.size(); i++) {
      int x = leaf[i].first, y = leaf[i].second;
      g[x][y] = 1e9;
      g[y][x] = 1e9;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if(g[i][j] == 1e9)continue;
        ans += g[i][j];
      }
    }
 
    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
        }
      }
    }
    int add = 0;
    for (int i = 0; i < n; i++) {
      if(g[0][i] == 1e9)continue;
      add = max(add, g[0][i]);
    }
   
    std::cout << ans - add << std::endl;
  }
  return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	map<int, int> mp;
	for(int i = 0; i < n; i++) {
		int a;
		cin >> a;
		mp[a]++;
	}
	int ans = 0;
	for(auto i : mp) {
		if(i.second >= i.first) {
			ans += i.second - i.first;
		}
		else {
			ans += i.second;
		}
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 4736
from collections import deque

s = input()
q = int(input())

d = deque()
for v in s:
    d.append(v)
r = False
for _ in range(q):
    xs = input().split()
    if xs[0] == "1":
        r = not r
    else:
        if (not r and xs[1] == "1") or (r and xs[1] == "2"):
            d.appendleft(xs[2])
        else:
            d.append(xs[2])
s = "".join(d)
print(s[::-1] if r else s)


Measured memory_bytes: 102780
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N;
  cin >> N;
  
  vector<int> A(N), B(N);
  int64_t sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> A[i] >> B[i];
    sum += A[i];
  }
  
  if (A == B) {
    cout << 0 << '\n';
    return 0;
  }
  
  int dec = numeric_limits<int>::max();
  for (int i = 0; i < N; ++i) {
    if (A[i] > B[i]) {
      dec = min(dec, B[i]);
    }
  }
  
  cout << sum - dec << '\n';
  
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
	int n,x;
	while(scanf("%d%d",&n,&x)){
	int a,b,c,cou = 0;
	if(n == 0 && x == 0) break;
	
	for(a = 1; n >= a; a++){
		for(b = 1; n >= b; b++){
			for(c = 1; n >= c; c++){
				if(a != b && a != c && b != c)
					if(a+b+c == x) cou++;
			}	
		}	
	}
	printf("%d\n", cou/6);
	}
	return 0;
}

Measured memory_bytes: 600
def bubble_sort(a):
    cnt = 0
    size = len(a)
    for i in range(size):
        for j in range(size-1, i, -1):
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                cnt += 1

    return (a,cnt)

_ = input()
l = [ int(s) for s in input().split() ]
(nl,swap) =  bubble_sort(l)

print(*nl)
print(swap)


Measured memory_bytes: 5608
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: -int(x), input().split()))

heapq.heapify(a)
for _ in range(m):
    p = heapq.heappop(a)
    heapq.heappush(a, -(-p // 2))
print(-sum(a))


Measured memory_bytes: 72088
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

char mat[8][8];

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

  rep(i, h) {
    rep(j, w) {
      cin >> mat[i][j];
      // if (mat[i][j] == '#') cnt++;
    }
  }
  int ans = 0;
  rep(s, 1 << h) {  //フラグを立てる
    rep(t, 1 << w) {
      int cnt = 0;
      rep(i, h) {
        rep(j, w) {
          if ((s & (1 << i)) && (t & (1 << j))) {
            if (mat[i][j] == '#') cnt++;
          }
        }
      }
      if (cnt == k) ans++;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int a = 0;
		int b = 0;
		
		a = n / k;
		b = n % k;
		
		if (b == 0){
			System.out.println(0);
		}
		else {
			System.out.println(1);
		}
		
		
		
		
		
	}

}


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

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  ll maximum, current;
  cin >> maximum;
  ll ans = 0;
  while (--n) {
    cin >> current;
    ll diff = maximum - current;
    ans += diff > 0 ? diff : 0;
    maximum = max(maximum, current);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <stack>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

void solve() {
	int n; cin >> n;
	string s; cin >> s;
	int ans = 1e9;
	vector<int> white(n, 0), red(n, 0);
	if (s[0] == 'W')white[0]++;
	for (int i = 1; i < n; i++) {
		white[i] = white[i - 1] + (s[i] == 'W');
	}
	if (s.back() == 'R')red.back()++;
	for (int i = n - 2; i >= 0; i--) {
		red[i] = red[i + 1] + (s[i] == 'R');
	}
	ans = min(ans, red[0]);
	ans = min(ans, white.back());
	for (int i = 0; i < n - 1; i++) {
		ans = min(ans, max(white[i], red[i + 1]));
	}
	cout << ans;

}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

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

int64_t mCum_[1000010],
        cCum_[1000010],
        mcCum_[1000010];

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    for (int i = 0; i < n; i++) {
        if (i > 0) {
            mCum_[i] += mCum_[i - 1];
            cCum_[i] += cCum_[i - 1];
            mcCum_[i] += mcCum_[i - 1];
        }
        if (s[i] == 'M') {
            mCum_[i]++;
        } else if (s[i] == 'C') {
            cCum_[i]++;
            mcCum_[i] += mCum_[i];
        }
    }

    int q;
    cin >> q;

    while (q--) {
        int k;
        cin >> k;

        int64_t ans = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] != 'D') continue;
            int r = min(n - 1, i + k - 1);

            ans += mcCum_[r] - (i > 0 ? mcCum_[i - 1] : 0);
            ans -= (i > 0 ? mCum_[i - 1] : 0) * (cCum_[r] - cCum_[i]);
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 24860
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k;
    cin >> k;
    int ans = 1;
    int cur = 7 % k;
    while (cur != 0) {
        ++ans;
        cur = (cur * 10 + 7) % k;
        if (ans > 1e7) {
            cout << -1;
            rr;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3660
import math

A,B,H,M = map(int,input().split())
tH = 30*H + 0.5*M
tM = 6*M

sa = tH - tM

if sa <0:
    sa*=-1

def cos(theta):
    hm = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(theta)))
    return hm

if sa > 180:
    print(cos(360-sa))
elif sa < 180:
    print(cos(sa))
elif sa == 180:
    print(A+B)
else:
    print(B-A)

Measured memory_bytes: 9360
#!/usr/bin/env python3


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, typ=int):
    return [typ(input()) for _ in range(n)]


def main():
    S, = read_h(str)
    flag = [False] * 26
    for c in S:
        i = ord(c) - ord('a')
        if not flag[i]:
            flag[i] = True

    ans = None
    for i, f in enumerate(flag):
        if not f:
            print(chr(i + ord('a')))
            return

    print(str(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>

int main(){
  vector<int> p(3);
  cin >> p[0] >> p[1] >> p[2];
  cout << p[0] + p[1] + p[2] - *max_element(p.begin(), p.end()) << endl;

 }





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

int main(){
    int a,b;
    cin >> a >> b;
    string s;
    if(a!=1&&b!=1&&a!=b){
        cout << (a>b?"Alice":"Bob") << endl;
    }
    else if(a==b){
        cout << "Draw" << endl;
    }
    else{
        cout << (a==1?"Alice":"Bob") << endl;
    }
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .
/// Start using lower bound !!

void solve ( int test_case )
{
    int x ;
    cin >> x ;

    if ( x >= 30 )
        cout << "Yes" ;

    else cout << "No" ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i = 1 ; i <= t ; i ++ )
    {
        solve ( i ) ;
    }

    return 0;
}


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

int main() {
	ll N,m=1000;
	cin >> N;
	vector<int> A(N);
	rep(i,N)
		cin >> A.at(i);

	rep(i,N-1)
		m += (m/A.at(i))*max(A.at(i+1)-A.at(i), 0);

	cout << m << endl;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
        int a, b;
        cin >> a >> b;
        if (a > n / 2) {
            a = n - a + 1;
        }
        if (b > n / 2) {
            b = n - b + 1;
        }
        cout << (min(a, b) - 1) % 3 + 1 << '\n';
    }
}


Measured memory_bytes: 3076
#include <stdio.h>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <utility>

using namespace std;

#define pb push_back
#define ft first
#define sd second
#define mpr make_pair
#define all(x) begin((x)), end((x))
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define max3(a, b, c) max((a), max((b), (c)))
#define max4(a, b, c, d) max(max((a), (b)), max((c), (d)))
#define min3(a, b, c) min((a), min((b), (c)))
#define min4(a, b, c, d) min(min((a), (b)), min((c), (d)))
#define isz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;

/* <------------------------------------------------------------------------------------> */

const int M = 1e9 + 7;

int d[60][3][3], n;
string s[2];

void solve()
{
    cin >> n >> s[0] >> s[1];
    forn (a, 3) forn (b, 3) d[n][a][b] = 1;
    for (int i = n - 1; i >= 0; --i) forn (a, 3) forn (b, 3)
    {
        for (int x : {0, 1, 2}) for (int y : {0, 1, 2})
        {
            if (i && s[0][i] != s[0][i - 1] && x == a) continue;
            if (i && s[0][i] == s[0][i - 1] && x != a) continue;
            if (i && s[1][i] != s[1][i - 1] && y == b) continue;
            if (i && s[1][i] == s[1][i - 1] && y != b) continue;
            if ((s[0][i] != s[1][i] && x == y) || (s[0][i] == s[1][i] && x != y)) continue;
            d[i][a][b] = (d[i][a][b] + d[i + 1][x][y]) % M;
        }
    }
    cout << d[0][0][0];
}

/* <------------------------------------------------------------------------------------> */

// #define LOCAL
// #define FILE_NAME

int main()
{
    #if defined LOCAL
        freopen("input.txt", "r", stdin);
    #elif defined FILE_NAME
        freopen(FILE_NAME".in", "r", stdin);
        freopen(FILE_NAME".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <cctype>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1 << 30
#define LLINF LLONG_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
using ll = long long;
using Pll = pair<ll,ll>;
using Pii = pair<int,int>;
using Pdd = pair<double,double>;
using dcomplex = complex<double>;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;for(ll i=1;i<=a;i++)b*=i;return b;}
ll power(ll x,ll n){ll a=1;REP(i,n)a*=x;return a;}
double inf() {return std::numeric_limits<double>::infinity();}

int main(int argc, char const *argv[]) {
  int N; cin >> N;
  int t0=0,x0=0,y0=0;
  bool flag=true;
  REP(i,N){
    int t,x,y; cin>>t>>x>>y;
    int T=t-t0;
    int D=abs(x-x0)+abs(y-y0);
    if(D>T || T%2!=D%2) {
      flag=false;
    }
    t0=t,x0=x,y0=y;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    map<int, int> A;
    REP(i, N){
        int x;
        cin >> x;
        A[x]++;
    }

    int ext = 0;
    for(auto a : A){
       ext += a.second - 1;
    }
    cout << A.size()-(ext%2) << "\n";

    return 0;
}

Measured memory_bytes: 4992
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  //cout<<fixed<<setprecision(10);
  ll n,ans=0;
  cin>>n;
  vector<ll>k;
  ll z=0;
  for(ll i=0;i>=0;i++){
    ll t=(1<<i);
    if(z+t<1000){
      k.push_back(t);
      z+=t;
    }
    else{
      k.push_back(1000-z);
      break;
    }
  }
  vector<ll>dp(n+1,0);
  vector<ll>dp2;
  dp[0]=1;
  for(ll p=0;p<6;p++){
    for(ll i=0;i<k.size();i++){
      dp2=dp;
      for(ll j=0;j<n;j++){
        ll q=(p+100)*k[i];
        if(j+q<=n&&dp[j])dp2[j+q]=1;
        if(dp[j])dp2[j]=1;
      }
      dp=dp2;
    }
  }
  if(dp[n])cout<<1<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 1792
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

void main()
{
    auto N = readln.chomp.to!long;
    auto CS = readln.split.to!(long[]);
    sort!"a > b"(CS);
    long r, d = pow(2, N*2-1);
    foreach (i; 0..N) r = (r + (CS[i] * (d + ((d * 500000004) % P * i) % P) % P) % P) % P;
    writeln(r);
}

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

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define all(a) (a).begin(),(a).end()
using ll  = long long;
using vi  = vector<ll>;
using pii = pair<ll,ll>;
#define int ll

int n;
vi a;

template<typename T> class BIT{
  vector<T> vec;
  const ll n;
  
public:
  BIT(T _n) : vec(_n + 1), n(_n) {}

  T query(ll x) { /* query for [1, x] */
    T ret = 0;
    for(ll i = x; i > 0; i -= i & (-i)) ret += vec[i];
    return ret;
  }

  void update(ll x, T k) { /* update for [1, x] */
    for(ll i = x; i <= n; i += i & (-i)) vec[i] += k;
  }
};

bool solve(int mid){
  vi s(n+1);
  map<pii,int> mp; // 転倒数は1~nでないといけない?
  rep(i,n){
    s[i+1] = (a[i] >= mid) ? 1 : -1;
    s[i+1] += s[i];
    mp[pii(s[i+1],i+1)];
  }
  { 
    int i = 1;
    for(auto &x : mp){
      x.second = i;
      i++;
    }
  }

  BIT<ll> bit(n*3);
  int inv = 0;
  rep(i,n+1){
    // cout << i << endl;
    inv += bit.query(s[i]+n*2);
    bit.update(s[i]+n*2, 1);
  }

  int tmp = (n+1) * n / 2;
  // cout << (inv >= (tmp+1)/2) << endl;
  if(inv >= (tmp+1) / 2) return true;
  else return false;
}

int bs(int _ok, int _ng){
  int ok = _ok;
  int ng = _ng;

  while(abs(ok - ng) > 1){
    int mid = (ok + ng) / 2;
    if(solve(mid)){
      ok = mid;
    }else{
      ng = mid;
    }
  }
  return ok;
}

main(){
  cin >> n;
  a.resize(n); rep(i,n) cin >> a[i];
  int ans = bs(0,1e9+1);
  cout << ans << endl;
  sort(all(a));
  //cout << *upper_bound(all(a),ans) << endl;
}

Measured memory_bytes: 10512
#include<stdio.h>
int main(void)
{
	int i,j,n,x[10000+1],y[10+1];
	scanf("%d",&n);
	while(n!=0) {
		for(j=0;j<10;j++) {
			y[j]=0;
		}
		for(i=0;i<n;i++) {
			scanf("%d",&x[i]);
			for(j=0;j<10;j++) {
				if(x[i]==j) {
					y[j]++;
				}
			}
		}
		for(j=0;j<10;j++) {
			if(y[j]!=0) {
				for(i=0;i<y[j];i++) {
					printf("*");
				}
				printf("\n");
			}
			else {
				printf("-\n");
			}
		}
	scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 608
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;



int main(){
  lll ii,jj,kk;
  lll n;
  cin >> n;
  vector<lll> a,b;
  a.resize(n+1);
  b.resize(n);
  for(ii=0;ii<n+1;ii++){
    cin >> a[ii];
  }
  for(ii=0;ii<n;ii++){
    cin >> b[ii];
  }

  lll num;
  num = 0;
  for(ii=0;ii<n;ii++){
    if(b[ii] >= a[ii]){
      num += a[ii];
      b[ii] -= a[ii];
      
    }
    else if(b[ii] < a[ii]){
      num += b[ii];
      continue;
    }

    if(b[ii] >= a[ii+1]){
      num += a[ii+1];
      a[ii+1] = 0;
    }
    else if(b[ii] < a[ii+1]){
      num += b[ii];
      a[ii+1] -= b[ii];
    }
    
  }

  cout << num << endl;
  return 0;
}


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

void solve()
{
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    int t1[n],t2[n],t3[n];
    for(int i=0;i<3*n;i++)
    {
        cin>>a[i];
        cin>>b[i];
        cin>>c[i];
    }
    t1[n-1]=a[n-1];
    t2[n-1]=b[n-1];
    t3[n-1]=c[n-1];
    for(int i=n-2;i>-1;i--)
    {
        t1[i]=a[i]+max(t2[i+1],t3[i+1]);
        t2[i]=b[i]+max(t1[i+1],t3[i+1]);
        t3[i]=c[i]+max(t1[i+1],t2[i+1]);
    }
    cout<<max(t1[0],max(t2[0],t3[0]))<<"\n";
    
}
int main()
{
    solve();
    
    
    
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<algorithm>
using namespace std;
int d[11];
int main(){
	int a,b;
	while(~scanf("%d%d",&a,&b)){
		int c=a+b;
		int ret=0;
		while(c){
			ret++;
			c/=10;
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC174B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ND = Console.ReadLine().Split(' ');
            int N = int.Parse(ND[0]);
            long D = long.Parse(ND[1]);
            long[] X = new long[N];
            long[] Y = new long[N];
            for (int i = 0; i < N; i++)
            {
                string[] XY = Console.ReadLine().Split(' ');
                X[i] = Math.Abs(int.Parse(XY[0]));
                Y[i] = Math.Abs(int.Parse(XY[1]));
            }
            int count = 0;
            for(int i = 0; i < N; i++)
            {
                if (X[i] * X[i] + Y[i] * Y[i] <= D*D)
                {
                    count += 1;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 43796