akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

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


long long GCD(long long x, long long y) {
    return y ? GCD(y, x%y) : x;
}

int main() {
    long long A, B;
    cin >> A >> B;
    long long G = GCD(A, B);
    auto pf = prime_factorize(G);
    cout << pf.size() + 1 << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
N=int(input())
a_list=list(map(int,input().split()))

counter=defaultdict(int)

for a in a_list:
    counter[a]+=1

ans=0
prob=defaultdict(int)
for k,v in counter.items():
    p=v*(v-1)//2
    ans+=p
    if v>1:
        p2=(v-1)*(v-2)//2
        prob[k]=p2-p

for a in a_list:
    print(ans+prob[a])

Measured memory_bytes: 100044
def checker(ded, da):
  for i in range(3):
    for j in range(2):
      if da[i][j] - ded[j] != da[i][2] - ded[2]:
        return False
  return True

def ma(da):
  for i in range(-100, 101):
    for j in range(-100, 101):
      for k in range(-100, 101):
        if checker([i, j, k], da):
          return False
  return True

da = [list(map(int,input().split())) for i in range(3)]
if not ma(da):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 41324
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		List<Integer> res = new ArrayList<>();
		res.add(1);
		for (int i = 2; i <= (int)Math.sqrt(n * 1.0) + 1; i++) {
			int num = i;
			int temp = 1;
			while (temp < n) {
				temp *= num;
				if (temp <= n) {res.add(temp);}
			}
		}
		
		Collections.sort(res);
		System.out.println(res.get(res.size()-1));
	}

    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 21204
import java.util.Scanner;
	public class Main{
		public static void main(String args[]){
			Scanner sc = new Scanner(System.in);
			while(sc.hasNext()){
				int n = sc.nextInt();
				int x = 1;	
				for(int i = 1 ; i <= n ; i++){
					x += i ;
				}
				System.out.println(x);
			}
	}
}

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) {
        cin >> s[i];
    }
    sort(all(s));
    int maxstr = 0;
    int nowstr = 1;
    for(int i = 1; i < n; i++) {
        if(s[i] == s[i - 1])
            nowstr++;
        else
            nowstr = 1;
        if(nowstr > maxstr) maxstr = nowstr;
    }
    nowstr = 1;
    if(maxstr == 1) cout << s[0] << endl;
    for(int i = 1; i < n; i++) {
        if(s[i] == s[i - 1])
            nowstr++;
        else
            nowstr = 1;
        if(nowstr == maxstr) cout << s[i] << endl;
    }

    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    i64 n;
    cin >> n;
    vector<i64> a(n);
    map<i64, i64> c;
    i64 ans = 0;
    for (auto& e : a) {
        cin >> e;
        ans += c[e]++;
    }

    for (auto& e : a) {
        cout << ans - (c[e] - 1) << endl;
    }
}


Measured memory_bytes: 11008
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <queue>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;

int main()
{
    //freopen("in.txt", "r", stdin);
    ll n, a, b;
    cin >> n >> a >> b;
    cout << ((a % 2) == (b % 2) ? "Alice" : "Borys");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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; }

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	vector<int> l(n);
	rep(i, n)
	{
		cin >> l[i];
	}

	sort(l.begin(), l.end());
	ll ans = 0;
	for (int i = 0; i < n - 2; i++)
	{
		for (int j = i + 1; j < n - 1; j++)
		{
            if(l[n-1]<l[i]+l[j])
            {
                ans+=n-(j+1);
            }
            else
			for (int k = j + 1; k < n; k++)
			{
				if (l[k] < l[i] + l[j])
				{
					ans++;
				}
				else
				{
					break;
				}
			}

		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable: 4244) // 最悪をします
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <sstream>
#define BIT(nr) (1UL << (nr))
#define int long long
//#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }


using namespace std;

//デバッグ用カッコの有無
#ifdef DEBUG
template <class T>ostream &operator<<(ostream &o, const vector<T>&v)
{
	o << "{"; for (int i = 0; i<(int)v.size(); i++)o << (i>0 ? ", " : "") << v[i]; o << "}"; return o;
}
#endif // DEBUG

template <class T>ostream &operator<<(ostream &o, const vector<T>&v)
{
	for (int i = 0; i<(int)v.size(); i++)o << (i>0 ? " " : "") << v[i]; return o;
}

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int dxp[4] = { 0, 1 }; // x軸方向への変位(正のみ)
int dyp[4] = { 1, 0 }; // y軸方向への変位(負のみ)

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;

	// libalgo のものに追加、メンバを追加するだけなので互換性は崩さないはず、逆辺のG[e.dstの]インデックスを保持
	int rev;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph& g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph& g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

void solve() {

}

int dp[30][50010];

signed main() {
	int q;
	cin >> q;

	rep(_, q) {
		string s, t;
		cin >> s >> t;
		int sl = s.length();
		int tl = t.length();

		s = "*" + s;
		t = "*" + t;

		vector<vector<int>> dp(sl + 1, vector<int>(tl + 1, 0));

		REPS(i, sl) {
			REPS(j, tl) {
				if (s[i] == t[j]) {
					chmax(dp[i][j], dp[i - 1][j - 1] + 1);
				}
				chmax(dp[i][j], dp[i - 1][j]);
				chmax(dp[i][j], dp[i][j - 1]);

			}
		}

		cout << dp[sl][tl] << "\n";
	}

}



Measured memory_bytes: 10776
N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Measured memory_bytes: 25716
#!/usr/bin/env python
from operator import mul
from functools import reduce

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

# INF = 10**9+7
N, K = map(int, input().split())
for i in range(1, K+1):
    ans = cmb(N-K+1, i, mod) * cmb(K-1, i-1, mod) % mod
    print(ans)


Measured memory_bytes: 5224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}


int main(){
  int n, X; cin >> n >> X;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  rep(i, n) x[i] = abs(x[i] - X);

  int g = x[0];
  rep(i, n) g = gcd(x[i], g);

  cout << g << endl;

  return 0;
}


Measured memory_bytes: 640
#include <cstdio>

int main()
{
	int sum = 0;
	while(1) {
		char c;
		c = getchar();
		if (c >= '0' && c <= '9')
			sum += c - '0';
		else
			break;
	}
	printf("%s\n", sum % 9 == 0 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 1532
// project1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

using namespace std;

class operate{
public:
    operate(int x,int y,char a) {
        varA = x;
        varB = y;
        ope = a;
    };

    int cal() {
        switch (ope)
        {
        case '+':
            return varA + varB;
            break;
        case '-':
            return varA - varB;
            break;
        default:
            break;
        }

    };

private:
    double varA;
    double varB;
    char ope;
};

int main()
{
    int bufA = 0, bufB = 0;
    char ope;

    cin >> bufA;
    cin >> ope;
    cin >> bufB;
    
    operate question1(bufA, bufB, ope);

    cout << question1.cal();

    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

bool isPreMeiji(int year, int month, int day) {
    if (year < 1868) return true;
    if (year == 1868) {
        if (month < 9) return true;
        if (month > 9) return false;
        return day < 8;
    }
    return false;
}

bool isMeiji(int year, int month, int day) {
    if (year < 1912) return true;
    if (year == 1912) {
        if (month < 7) return true;
        if (month > 7) return false;
        return day < 30;
    }
    return false;
}

bool isTaisho(int year, int month, int day) {
    if (year < 1926) return true;
    if (year == 1926) {
        if (month < 12) return true;
        if (month > 12) return false;
        return day < 25;
    }
    return false;
}

bool isShowa(int year, int month, int day) {
    if (year < 1989) return true;
    if (year == 1989) {
        if (month < 1) return true;
        if (month > 1) return false;
        return day < 8;
    }
    return false;
}

int getMeijiYear(int year) {
    return year - 1868 + 1;
}

int getTaishoYear(int year) {
    return year - 1912 + 1;
}

int getShowaYear(int year) {
    return year - 1926 + 1;
}

int getHeiseiYear(int year) {
    return year - 1989 + 1;
}

int main() {
    int year;
    int month;
    int day;
    while(cin>>year>>month>>day) {
        if (isPreMeiji(year,month,day)) {
            cout << "pre-meiji" << endl;
        }else if (isMeiji(year,month,day)) {
            cout << "meiji " << getMeijiYear(year) << " ";
            cout << month << " " << day << endl;
        }else if (isTaisho(year,month,day)) {
            cout << "taisho " << getTaishoYear(year) << " ";
            cout << month << " " << day << endl;
        }else if (isShowa(year,month,day)) {
            cout << "showa " << getShowaYear(year) << " ";
            cout << month << " " << day << endl;
        }else {
            cout << "heisei " << getHeiseiYear(year) << " ";
            cout << month << " " << day << endl;
        }
    }
    return 0;
}

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

int main(){
    int x[5];
    for(int i = 0; i < 5; i++) cin >> x[i];

    for(int i = 0; i < 5; i++){
        if(x[i] == 0){
            cout << i+1 << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3640
def makedic(array):
    dic = {str(i): '' for i in range(10)}
    for v in array:
        dic[v[1]] += v[0]
    return dic


def main():
    n = int(input())
    origin = [v for v in input().split()]
    dic_origin = makedic(origin)

    a = origin[:]
    for i in range(n - 1):
        last = n - i - 1
        for j in range(last):
            if int(a[j][1]) > int(a[j + 1][1]):
                a[j], a[j + 1] = a[j + 1], a[j]

    print(' '.join(a))
    print('Stable' if makedic(a) == dic_origin else 'Not Stable')

    b = origin[:]
    for i in range(n):
        m = i
        for j in range(i + 1, n):
            if int(b[j][1]) < int(b[m][1]):
                m = j

        if not m == i:
            b[m], b[i] = b[i], b[m]

    print(' '.join(b))
    print('Stable' if makedic(b) == dic_origin else 'Not stable')


if __name__ == '__main__':
    main()








Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> PPI;
typedef pair<LL, LL> PL;
typedef long long LL;
// LLONG_MIN, INT_MIN
#define xx first
#define yy second

// int seg[810000];
// void build(int id=1, int l=0, int r = n){
//   if(l==r-1){
//     seg[id] = da[l];
//   }
//   int mid = (l+r)/2;
//   build(id*2, l, mid);
//   build(id*2+1,mid, r);
//   s[id] = max(s[id*2],s[id*2+1]);
// }
// void mx(int x, int y, int id=1, int l=0, int r = n){
//   if(x>=r||y<=l) return -1;
//   if(l>=x&&r<=y)return seg[id];
//   int mid = (l+r)/2;
//   return max(mx(x,y,id*2,l,mid),mx(x,y,id*2+1,mid, r));
// }

const int MOD = 1e9 + 7;
LL dp[2100][2100];
int main()
{
  //freopen("input", "r", stdin);
  // freopen("output", "w", stdout);
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  LL n,m;
  cin>>n>>m;
  LL a[2100], b[2100];
  for(LL i=0;i<n;i++)
    cin>>a[i];
  for(LL i=0;i<m;i++)
    cin>>b[i];

  memset(dp, 0, sizeof(dp));
  // for(LL i=0;i<=n;i++)
  //   for(LL j=0;j<=n;j++)
  //     if(i==0||j==0)
  //       dp[i][j] = 1;
  for(LL i=1;i<=n;i++)
    for(LL j=1;j<=m;j++){
      if(a[i-1]==b[j-1]){dp[i][j] += dp[i-1][j-1]+1;}
      dp[i][j] += dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1];
      // cout<<dp[i][j]<<endl;
      dp[i][j]%=LL(1e9+7);

    }
    // for(LL i=1;i<=n;i++)
    //   {for(LL j=1;j<=n;j++)
    //     cout<<dp[i][j]<<" ";
    //   cout<<endl;
    //   }
  cout<<(dp[n][m]+1+MOD)%LL(1e9+7)<<endl;

}


Measured memory_bytes: 34688
#include <stdio.h>

#define MAX 10000
#define NIL -1

typedef struct node {
    int p;
    int L;
    int r;
} Node;

Node T[MAX];
int n;

void Preorder( int u );
void Inorder( int u );
void Postorder( int u );

int main() {
    int i, v, L, r, root;
    
    scanf( "%d", &n );
    for ( i = 0; i < n; i++ ) {
        T[i].p = NIL;
    }
    
    for ( i = 0; i < n; i++ ) {
        scanf( "%d%d%d", &v, &L, &r );
        T[v].L = L;
        T[v].r = r;
        if ( L != NIL ) T[L].p = v;
        if ( r != NIL ) T[r].p = v;
    }
    
    for ( i = 0; i < n; i++ ) {
        if ( NIL == T[i].p ) {
            root = i;
        }
    }
    
    printf( "Preorder\n" );
    Preorder( root );
    printf( "\n" );
    printf( "Inorder\n" );
    Inorder( root );
    printf( "\n" );
    printf( "Postorder\n" );
    Postorder( root );
    printf( "\n" );
    
    return 0;
}

void Preorder( int u ) {
    if ( NIL == u ) return;
    printf( " %d", u );
    Preorder( T[u].L );
    Preorder( T[u].r );
}

void Inorder( int u ) {
    if ( NIL == u ) return;
    Inorder( T[u].L );
    printf( " %d", u );
    Inorder( T[u].r );
}

void Postorder( int u ) {
    if ( NIL == u ) return;
    Postorder( T[u].L );
    Postorder( T[u].r );
    printf( " %d", u );
}

/*
9
0 1 4
1 2 3
2 -1 -1
3 -1 -1
4 5 8
5 6 7
6 -1 -1
7 -1 -1
8 -1 -1
 */

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int cnt = 0;
    for(int i = 0; i < 3; i++){
        if(S[i] == 'R' && cnt == 0) cnt++;
        if(i > 0 && S[i - 1] == 'R' && S[i] == 'R') cnt++;

    }
    cout << cnt << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 123;
 
int n;
int a[maxn];
string s, t;
int main () { 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    cin >> t;
    set <string> q;


    int m = t.size();
    n = s.size();
    for(int i = 0; i + m - 1 < n; i++){
	    bool bad = 0;
		for(int j = 0; j < m; j++)
			if(s[i + j] == '?' or s[i + j] == t[j]) {}
			else bad = 1;
		if(bad) continue;
		string cur = s;
		for(int j = 0; j < i; j++)
			if(s[j] == '?') cur[j] = 'a';
		for(int j = 0; j < m; j++)
			cur[i + j] = t[j];

		for(int j = i + m; j < n; j++)
			if(s[j] == '?')
			cur[j] = 'a';
		q.insert(cur);
	}
	if(q.size()) {
		cout << *(q.begin());
	}else cout << "UNRESTORABLE";
	return 0;
}




Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn =  new Scanner(System.in);
        
        while(stdIn.hasNext()){
            int b = stdIn.nextInt();
            int r = stdIn.nextInt();
            int g = stdIn.nextInt();
            int c = stdIn.nextInt();
            int s = stdIn.nextInt();
            int t = stdIn.nextInt();
            
            if(b + r + g + c + s + t == 0){
                break;
            }
            
            System.out.println(100 + (r * 3 + b * 5) * 13 + c * 2  + (r + b) * 15 + g * 7 -((t - s - r * 3 - b * 5) * 3));
        }
    }
}



Measured memory_bytes: 28796
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

pair<int, int> solve(string s) {
	int tot = 0;
	int mn = 0;
	for (auto x : s) {
		if (x == '(') tot++;
		else tot--;
		mn = min(mn, tot);
	}
	return {tot, mn};
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
		
	int n;
	cin >> n;
	vector<string> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	vector<pair<pair<int, int>, string>> pb;
	vector<pair<pair<int, int>, string>> nb;
	for (int i = 0; i < n; i++) {
		int tot, mn;
		tie(tot, mn) = solve(a[i]);
		if (tot >= 0) {
			pb.push_back({{(mn + 0 * tot), tot}, a[i]});
		} else {
			nb.push_back({{-(tot - mn), tot}, a[i]});
		}
	}
	sort(pb.rbegin(), pb.rend());
	sort(nb.begin(), nb.end());
	string res;
	for (auto t : pb) {
		res += t.second;
		// cerr << t.second << endl;
	}
	for (auto t : nb) {
		res += t.second;
		// cerr << t.second << endl;
	}
	{
		int tot, mn;
		tie(tot, mn) = solve(res);
		if (tot == 0 && mn >= 0) {
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
	}
}


Measured memory_bytes: 59908
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    O = input().strip()
    E = input().strip()
    answer = [None]*(len(O)+len(E))
    for i in range(len(O)):
        answer[2*i] = O[i]
    for i in range(len(E)):
        answer[2*i+1] = E[i]
    return ''.join(answer)


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 61764
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, W = map(int, input().split())
    wv = [list(map(int, input().split())) for i in range(N)]

    INF = int(1e18)
    dp = np.full(1000 * N + 1, INF, dtype=int)
    dp[0] = 0

    max_v = 0
    for i in range(N):
        w, v = wv[i]
        dp[v:max_v + v + 1] = np.minimum(dp[v:max_v + v + 1], dp[:max_v + 1] + w)
        max_v += v
    
    print(np.where(dp <= W)[0].max())

if __name__ == "__main__":
    main()

Measured memory_bytes: 15168
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

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

	if (x == 1) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>

int hikaku(const void* x,const void* y) {
	if(*((int*)x)>*((int*)y))return -1;
	if(*((int*)x)<*((int*)y))return 1;
	return 0;
}

int main(void) {
	int kyaku[10000];
	int kyakunum;
	int i;
	unsigned long long sum;
	while(1) {
		scanf("%d",&kyakunum);
		if(kyakunum==0)break;
		for(i=0;i<kyakunum;i++) {
			scanf("%d",&kyaku[i]);
		}
		qsort(kyaku,kyakunum,sizeof(int),hikaku);
		sum=0;
		for(i=0;i<kyakunum;i++) {
			sum+=kyaku[i]*i;
		}
		printf("%llu\n",sum);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
vector<vector<int> >ed;
vector<vector<int> >dd;
vector<int> v;
vector<int> X;
int dfs(int a, int p) {
	v[a] = 1;
	for (int i = 0; i < ed[a].size(); i++) {
		if (v[ed[a][i]] == 0) {
			X[ed[a][i]] = X[a] + dd[a][i];
			dfs(ed[a][i], a);
		}
	}

}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> L(M);
	vector<int> R(M);
	vector<int> D(M);
	ed.resize(N);
	dd.resize(N);
	v.resize(N, 0);
	X.resize(N, 0);
	int res = 0;
	for (int i = 0; i < M; i++) {
		cin >> L[i] >> R[i] >> D[i];
		L[i]--;
		R[i]--;
		ed[L[i]].push_back(R[i]);
		dd[L[i]].push_back(D[i]);
		ed[R[i]].push_back(L[i]);
		dd[R[i]].push_back(-D[i]);
	}
	for (int i = 0; i < N; i++) {
		if (v[i] == 0) {
			X[i] = 0;
			dfs(i, -1);
		}
	}
	bool f = true;
	for (int i = 0; i < M; i++) {
		if (X[L[i]] + D[i] != X[R[i]]) {
			f = false;
		}
	}
	if (f) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 26368
function main(input){
  var _input = input.split('\n')
  var N = parseInt(_input[0])
  var strArr = _input[1].split(' ')
  var numArr = []
  for (var i = 0; i < strArr.length; i++){
  	var num = parseInt(strArr[i])
    if (num % 2 === 1) {
    	console.log(0)
      	return
    }else numArr.push(num / 2)
  }
  
  var result = 1
  while (true) {
    for (var i = 0; i < numArr.length; i++){
      var num = numArr[i]
      if (num % 2 === 1) {
          console.log(result)
          return
      } else numArr[i] = num / 2
    }
    result++
  }
  
  
}

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

Measured memory_bytes: 11468
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

LL dp[304][304][304];

int main(){
    fastcin();

    int n, K;
    cin >> n >> K;
    vector<int> h(n+1, 0);
    rep(i, n) cin >> h[i+1];
    rep(i, 302)rep(j, 302)rep(k, 302) dp[i][j][k] = LLINF;
    dp[0][0][0] = 0;
    rep(i, n)rep(j, K+1)rep(k, i+1){
        // 高さをa[k]に合わせる
        chmin(dp[i+1][j+1][k], dp[i][j][k]);
        // 高さを変えない
        chmin(dp[i+1][j][i+1], dp[i][j][k]+max(h[i+1]-h[k], 0));
    }
    LL ans = LLINF;
    rep(j, K+1){
        rep(k, n+1){
            chmin(ans, dp[n][j][k]);
            // cout << dp[n][j][k] << " ";
        }
        // cout << endl;
    }
    cout << ans << endl;

}

Measured memory_bytes: 219392
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize);
    let mut count = 0;
    let mut div = 1;
    loop {
        if n / div >= 1 {
            if n < div * 10 {
                count += (n % ((div) * 10)) - div + 1;
            } else {
                count += div * 9;
            }
        } else {
            break;
        }
        div *= 100;
    }
    println!("{}", count);
}


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

using namespace std;



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

	string s0, s1, s = "";
	cin >> s0 >> s1;
	int i;
	for (i = 0; i < 100; i++) {
		if (i < s0.length()) s = s + s0[i];
		if (i < s1.length()) s = s + s1[i];
	}

	cout << s << "\n";

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()
	t := nextStr()

	for i := 0; i < len(s); i++ {
		if s == t {
			fmt.Println("Yes")
			return
		}
		s = s[1:] + string(s[0])
	}

	fmt.Println("No")

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

static const int MAX = 10;
static const ll INFTY = (1LL << 32);

int n=10;
ll d[MAX][MAX];

// ワーシャルフロイド（全点対間最短経路(動的計画法)）
void floyd() {
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			if (d[i][k] == INFTY) continue;
			for (int j = 0; j < n; j++) {
				if (d[k][j] == INFTY) continue;
				// 頂点 k を経由する場合としない場合の最小コストを求める
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			d[i][j] = ((i == j) ? 0 : INFTY);
		}
	}
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			ll c; cin >> c;
			if(i==j) continue;
			d[i][j] = min(d[i][j], c);
		}
	}
	floyd();
	
	vector<vector<int>> A(H);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int a; cin >> a;
			A[i].push_back(a);
		}
	}

	int ans=0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if(A[i][j]==-1) continue;
			//cout << A[i][j] <<" "<< d[A[i][j]][1] << endl;
			ans += d[A[i][j]][1];
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MN 1<<20
#define inf 0x3f3f3f3f
using namespace std;
int n,a[MN],tmp[10],f[MN][2],ans;
bool cmp(int x,int y){return a[x]<a[y];}
int main(){
	scanf("%d",&n);
	for(int i=0;i<(1<<n);i++)scanf("%d",&a[i]);f[0][0]=0,f[0][1]=1<<n,a[1<<n]=-inf;
	for(int i=1;i<(1<<n);i++){
		f[i][0]=i,f[i][1]=1<<n;
		for(int j=0;j<n;j++)if(i&(1<<j)){
			tmp[0]=f[i][0],tmp[1]=f[i][1],tmp[2]=f[i^(1<<j)][0],tmp[3]=f[i^(1<<j)][1];
			sort(tmp,tmp+4,cmp);
			f[i][0]=tmp[3],f[i][1]=tmp[3]==tmp[2]?tmp[1]:tmp[2];
		}
	}
	for(int i=1;i<(1<<n);i++)ans=max(ans,a[f[i][0]]+a[f[i][1]]),printf("%d\n",ans);
}


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

int main() {
  int k;
  string s;
  
  cin >> k >> s;
  
  size_t len = s.length();
  
  if (len <= k) cout << s << endl;
  else {
    for (int i=0;i<k;i++) {
      cout << s[i];
    }
    cout << "..." << endl;
  }
    
}


Measured memory_bytes: 3628
import java.util.*;
class P
{
	String name;
	int point;
	P(String name, int point)
	{
		this.name = name;
		this.point = point;
	}
}

public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			if(n == 0)
			{
				break;
			}
			List<P> data = new ArrayList<P>();
			boolean[][] point = new boolean[21][31];
			for(int i = 0; i < n; ++i)
			{
				String name = stdIn.next();
				data.add(new P(name, 0));
				int m = stdIn.nextInt();
				while(m-- != 0)
				{
					int d = stdIn.nextInt();
					point[i][d] = true;
				}
			}
			for(int i = 0; i < 31; ++i)
			{
				int count = 0;
				for(int j = 0; j < n; ++j)
				{
					if(point[j][i])
					{
						++count;
					}
				}
				for(int j = 0; j < n; ++j)
				{
					if(point[j][i])
					{
						data.get(j).point += n - count + 1;
					}
				}
			}
			Collections.sort(data, new Comparator<P>() 
				{
				    public int compare(P obj0, P obj1) 
				    {
				        return obj0.name.compareTo(obj1.name);
				    }
				}
			);

			int minIndex = 0;
			int min = 999999999;
			for(int i = 0; i < n; ++i)
			{
				if(min > data.get(i).point)
				{
					min = data.get(i).point;
					minIndex = i;
				}
			}
			System.out.println(data.get(minIndex).point + " " + data.get(minIndex).name);
		}
	}
}

Measured memory_bytes: 12000
x,n = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
k = True
if not x in p:
    print(x)
else:
    y = x
    z = x
    while k:
        y -= 1
        if not y in p:
            print(y)
            break
        z += 1
        if not z in p:
            print(z)
            break

Measured memory_bytes: 9168
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      string a, b, c;
      cin >> a >> b >> c;
      if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) cout << "YES" << endl;
      else cout << "NO" << endl;
    }

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}



const int MAX_N = 100010;




signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	cout << n * (n - 1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
vector<ll> t;
int main(){
  int n,a;
  cin >> n >> a;
  cout << n * n - a << endl;
  return 0;
}

Measured memory_bytes: 256
from fractions import gcd

A, B, C, D = map(int, input().split())

lcm = (C * D) // gcd(C, D)


print((B-A+1) - ((B//C - (A-1)//C) + (B//D - (A-1)//D) - (B//lcm - (A-1)//lcm)))

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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;
ll sum =0;
ll dfs(ll h){

	if(h ==1){
		return 0;
	}

	sum = dfs(h/2)+1;
	sum *=2;

/*	cout<<sum<<endl;*/

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

	 ll n;cin>>n;

	 writeln(dfs(n)+1);
}


Measured memory_bytes: 256
n = int(input())
ans = (0, n)
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        ans = min(ans, (i, n // i), key=lambda x: abs(x[0] - x[1]))
print(ans[0] - 1 + ans[1] - 1)

Measured memory_bytes: 9296
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    int a,i;
    char b[4];
    scanf("%d %s",&a,b);
    a=a*pow(10,strlen(b))+atoi(b);
    if((double)(sqrt(a)-(int)sqrt(a))==0)
        puts("Yes");
    else
        puts("No");
    return 0;
}

Measured memory_bytes: 128
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    n = int(input())
    a = list(map(int, input().split()))
    ra = []
    for i in range(n):
        ra.append((i+1)*30000)
    rb = []
    c = 1
    for i in range(n):
        rb.append((n-i)*30000)
    for i in a:
        rb[i-1] += c
        c += 1
    print(' '.join(map(str,ra)))
    print(' '.join(map(str,rb)))


f()


Measured memory_bytes: 9792
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int N, T, L, B;

int next(int cur, int dice) {
    int ret = cur + dice;
    if (N < ret) ret = N - (ret - N);
    return ret;
}

int main() {
    ios::sync_with_stdio(false);

    while (cin >> N >> T >> L >> B && ( N || T || L || B )) {
        string LB = "                                                                                                     ";
        int k;
        for (int i=0; i<L; ++i) {
            cin >> k;
            LB[k] = 'L';
        }
        for (int i=0; i<B; ++i) {
            cin >> k;
            LB[k] = 'B';
        }

        double p[101][101][2] = {0};
        p[0][0][0] = 1.0;
        for (int i=0; i<T; ++i) {
            for (int j=0; j<N; ++j) {
                for (int k=1; k<=6; ++k) {
                    int ne = next(j, k);
                    if (LB[ne] == 'B') ne = 0;
                    p[i+1][ne][LB[ne] == 'L'] += p[i][j][0] / 6.0;
                }
                p[i+1][j][0] += p[i][j][1];
            }
        }

        double ans = 0;
        for (int i=0; i<=T; ++i) ans += p[i][N][1] + p[i][N][0];
        cout << setprecision(6) << fixed << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1444
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define mod 1000000007
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int count=0;
    int i=0;
    for(i=0; i<n-1; i++)
    {
        count++;
        if(s[i]==s[i+1])
        {
            int i1=i+1;
            while(i1<n && s[i1]==s[i1-1])
                i1++;
            i=i1-1;
        }
    }
    if(i==n-1 && s[i]!=s[i-1])
        count++;
    cout<<count<<"\n";
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int K = nextInt();
  int ans = (K/2) * ((K+1)/2);
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
int n;
ld a[3000],dp[3000][3000];
ld recurs(int pos,int h)
{
	int t=pos-h;
	if(pos>=n) return 1;
	if(dp[pos][h]!=-1) return dp[pos][h];
	if(t>=(n/2))
	{
		dp[pos][h]=a[pos]*recurs(pos+1,h+1);
	}
	else
	{
		dp[pos][h]=a[pos]*recurs(pos+1,h+1)+(1-a[pos])*recurs(pos+1,h);
	}
	return dp[pos][h];
}
int main()
{
    ios_base::sync_with_stdio(false);//this works only
    cin.tie(NULL);// when first all inputs are from user
    cout.tie(NULL);//you will see all outputs afterwards
 //   memset(dp,-1,sizeof(dp));
   // cout<<dp[0]<<endl;
    for (int i = 0; i < 3000; ++i)
    {
    	for (int j = 0; j < 3000; ++j)
    	{
    		dp[i][j]=-1;
    	}
    }
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    }
   // cout<<a[0]<<endl;
    ld ans=recurs(0,0);
    cout<<setprecision(9)<<fixed<<ans<<endl;
    return 0;
}

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

vector<int> four(int n, int size) {
  vector<int> res(size);

  for(int i=size-1;i>=0;i--) {
    res[i] = n / (int)pow(4, i);
    n %= (int)pow(4, i);
  }

  return res;
}

int main() {
  int n;
  int a, b, c;
  cin >> n >> a >> b >> c;
  vector<int> l(n);
  for(int i=0;i<n;i++) cin >> l[i];

  sort(l.begin(), l.end());

  int min = INT_MAX;
  int lastp = 0;
  int lastq = 0;
  int lastr = 0;
  do {
    int s = n - 3;
    for(int i=0;i<pow(4, s); i++) {
      vector<int> f = four(i, s);
      int p = l[0];
      int q = l[1];
      int r = l[2];
      if(lastp == p && lastq == q && lastr == r) break;
      int ans = 0;
      for(int j=0;j<f.size();j++) {
        if(f[j] == 0) {
          p+= l[j+3];
          ans += 10;
        }
        if(f[j] == 1) {
          q+= l[j+3];
          ans += 10;
        }
        if(f[j] == 2) {
          r+= l[j+3];
          ans += 10;
        }
      }

      ans += abs(p - a) + abs(q - b) + abs(r - c);

      if(ans < min) min = ans;
    }

    lastp = l[0];
    lastq = l[1];
    lastr = l[2];
  } while (next_permutation(l.begin(), l.end()));

  cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define lim 100010
#define mod 1e9+7
#define INF 1e9
#define REP(i,n) for(int i=0;i<n;i++)



int main() {
	ll N,K;
	scanf("%lld%lld",&N,&K);
	ll A[N],F[N];
	REP(i,N) scanf("%lld",&A[i]);
	REP(i,N) scanf("%lld",&F[i]);
	sort(A, A+N);
	sort(F, F+N, greater<ll>());
	ll l = -1;
	ll r = A[N-1] * F[0];
	while(l+1 < r){
		ll m = l + (r-l)/2;
		ll cost = 0;
		REP(i,N){
			ll e = m/F[i];
			if(e >= A[i])continue;
			cost += A[i] - e;
		}
		if(cost<=K)r = m;
		else l = m;
	}
	printf("%lld\n",r);
	return 0;
}

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

int main() {
    int n, q;
    cin >> n >> q;
    long long ans = 1LL * (n-2) * (n-2);
    int h = n, w = n;;
    vector<int> a(n+1, n), b(n+1, n);
    while (q--) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            if (x < w) {
                for (int i = x; i < w; ++i) a[i] = h;
                w = x;
            }
            ans -= a[x] - 2;
        } else {
            if (x < h) {
                for (int i = x; i < h; ++i) b[i] = w;
                h = x;
            }
            ans -= b[x] - 2;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int mod = 1e9 + 7;
int Mod(int x){x%=mod;if(x<0)x+=mod;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(), x.end()

int comb(int n,int r,vi &fact) {
	if(n==r or r==0) return 1;
	int num=fact[n];
	int denom=Mod(fact[r]*fact[n-r]);
	denom = Pow(denom,mod-2);
	return Mod(num*denom);
}

int__ main() {
	fast;

	int n,k; cin >> n >> k;

	vi fact(n+1,1);
	for(int i=1;i<=n;i++) fact[i] = Mod(i * fact[i-1]);

	int ans = 0;
	vi a(n);
	for(int i=0;i<n;i++) cin >> a[i];

	sort(all(a));

	for(int i=0;i+k-1<n;i++) {
		int no = comb(n-i-1,k-1,fact);
		ans = Mod(ans - no*a[i]);
	}

	for(int i=n-1;i-k+1>=0;i--) {
		int no = comb(i,k-1,fact);
		ans = Mod(ans + no*a[i]);
	}

	cout << ans << endl;
}	

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <memory.h>
#include <bitset>
#include <stack>
#include <assert.h>
#include <ctime>
#include <unordered_set>
using namespace std;
#define ll long long
#define ppi pair<int, int>
#define mp make_pair
const int N = 2e5 + 11, K = 20;
const int mod = 1e9 + 7;
set<ll> ans;
vector<ll> getDiv(ll n)
{
	vector<ll> arr;
	for (ll i = 1; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			if (i != 1) arr.push_back(i);
			if (n / i != i)
				arr.push_back(n / i);
		}
	}
	return arr;
}
int main()
{
#ifndef ONLINE_JUDGE
	//freopen("inp.txt", "r", stdin);
#endif

	ll n; cin >> n;
	vector<ll> nn = getDiv(n);
	vector<ll> n1 = getDiv(n - 1);
	for (int i = 0; i < nn.size(); i++)
	{
		ll v = n;
		while (v % nn[i] == 0)
			v /= nn[i];
		if (v % nn[i] == 1)
			ans.insert(nn[i]);
	}
	for (int i = 0; i < n1.size(); i++)
		ans.insert(n1[i]);
	cout << ans.size();
}


Measured memory_bytes: 384