akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    int cnt = 0;
    int mae = 0, ushiro = 0;
    rep(i, n) {
        if(s[i] == '(') {
            cnt++;
        }
        else {
            cnt--;
            if(cnt < 0) {
                mae++;
                cnt++;
            }
        }
    }
    if(cnt > 0) {
        ushiro = cnt;
    }
    
    rep(i, mae) {
        cout << '(';
    }
    cout << s;
    rep(i, ushiro) {
        cout << ')';
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<string, ll>> v(n);
    for(int i=0;i<n;++i) {
        cin >> v[i].first >> v[i].second;
    }
    string s;
    cin >> s;

    ll ans = 0LL;
    bool to_add = false;
    for(int i=0;i<n;++i) {
        if(to_add) ans += v[i].second;
        if(v[i].first == s) {
            to_add = true;
        }
    }
    cout << ans << endl;
}


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

long long n,ans,k,l,r;
int main()
{
	cin>>n>>k;
	if (k==0)
	{
		printf("%lld\n",n*n);
		return 0;
	}
	for (int i=k+1;i<=n;i++)
	{
		ans+=(n/i)*(i-k);
		if (n%i!=0)ans+=max(0ll,n-(n-n%i+k-1));
		// cout<<ans<<endl;
	}
	cout<<ans;
}


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

int main() {
  int H, W, A, B, N;
  int y=0;
  long int x=0;
  string S;
  cin >> N;
  vector<int> vec(N);

  for ( int i=0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  for ( int i=0; i < N; i++) {
    for (int j=1; j<N-i; j++) {
      x += vec.at(i)*vec.at(i+j);
    }
  }
  cout << x << endl;

    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	while(a >= b) {
		b *= 2;
		k--;
	}
	while(b >= c) {
		c *= 2;
		k--;
	}
	yorn(k >= 0);
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;


int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    string s;
    cin>>s;
    int i, j;
    int len = s.length();
    int maxlen = 0;
/*     fo(i, len) {
        if(s[i] == 'A') {
            Fo(j, i, len) {
                if(s[j] == 'Z'){
                    if( (j-i+1) > maxlen )
                        maxlen = (j-i+1);
                }
            }
        }
    } */
    int beg, end;
    for(i=0; i<len; i++) {
        if(s[i] == 'A') {
            beg = i;
            break;
        }
    }
    for(i=len-1; i>=0; i--) {
        if(s[i] == 'Z') {
            end = i;
            break;
        }
    }

    cout<<end-beg+1;

return 0;
}

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

int main(){
    string S;
    char before;
    long count = 0;
    cin >> S;
    before = S[0];
    for(int i=1;i<S.length();i++){
        if(before == S[i]){
            count++;
        }
        // cout << count << " " << before << " " << S[i] << endl;
        if(before == '0'){
            before = '1';
        }
        else{
            before = '0';
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int a[100000],box[100000-1];
int main(){
	int n,t;
	cin >> n >> t;
	for(int i=0;i<n;i++) cin >> a[i];
	int maxnum=a[n-1];
	int ans=0;
	int maxbox=0;
	for(int i=n-2;i>=0;i--){
		box[i]=maxnum-a[i];
		if(a[i]>maxnum) maxnum=a[i];
		if(box[i]>maxbox){
			maxbox=box[i];
			ans=1;
		}else if(box[i]==maxbox) ans++;
	}	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {

	int coin[] = { 500, 100, 50, 10, 5, 1 };

	for (;;) {

		int N, ans = 0;

		scanf("%d", &N);
		if (!N) break;

		N = 1000 - N;

		for (int i = 0; N > 0; i++) {
			while (N >= coin[i]) {
				N -= coin[i];
				ans++;
			}
		}

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

	return 0;
}

Measured memory_bytes: 2576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
int a[100005];
int main()
{
    ll a,b;
    cin>>a>>b;
    ll t=__gcd(a,b);
    int ans=0;
    for(int i=2;i<=sqrt(t);i++)
    {
        bool x=0;
        while(t%i==0)
        {
            t=t/i;
            x=1;
        }
        if(x) ans++;
    }
    if(t>1) ans++;
    cout<<ans+1<<'\n';
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            checked
            {
                string[] s;
#if true
                int N = int.Parse(Console.ReadLine());
#else
                s = Console.ReadLine().Split(' ');
                int N = int.Parse(s[0]);
                int K = int.Parse(s[1]);
#endif

                int[] v = new int[N];

#if true
                s = Console.ReadLine().Split(' ');
                for (int i = 0; i < N; i++)
                {
                    v[i] = int.Parse(s[i]);
                }

#else
                for (int i = 0; i < N; i++)
                {
                    v[i] = int.Parse(Console.ReadLine());
                }
#endif

                for (int i = 1; i < N; i++)
                {
                    if(v[i-1] < v[i] && v[i] > 1)
                    {
                        v[i]--;
                    }
                }

                for (int i = 1; i < N; i++)
                {
                    if ( v[i-1] > v[i])
                    {
                        Console.WriteLine("No");
                        return;
                    }

                }

                Console.WriteLine("Yes");
            }
        }
    }
}


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

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

    int ans = INT_MAX;
    int A;
    for (int i = 0; i < N; i++)
    {
        cin >> A;
        int power = 0;
        while (A % 2 == 0)
        {
            power++;
            A /= 2;
        }
        ans = min(ans, power);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
judge = [True] * N
edge = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a, b = a-1,b-1
    edge[a].append(b)
    edge[b].append(a)

for i in range(N):
    for v in edge[i]:
        if H[i] <= H[v]:
            judge[i] = False

print(sum(judge))


Measured memory_bytes: 93576
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include <vector>
#include <map>
using namespace std;
int main() {
    char str[1010],s=0;
    cin>>str;
    for(int i=0; i<strlen(str); i++) {
        if(s==0) {
            if(str[i]!='C') continue;
            if(str[i]=='C') {
                s+=1;
                continue;
            }
        }
        if(s==1) {
            if(str[i]!='F') continue;
            if(str[i]=='F') {
                s+=1;
                continue;
            }
        }
    }    
    if(s==2) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
n=int(input())
D = [list(map(int,input().split())) for i in range(n)]
for i in range(n-2):
  if D[i][0] == D[i][1] and D[i+1][0] == D[i+1][1] and D[i+2][0] == D[i+2][1]:
    print("Yes")
    break
else:
  print("No")

Measured memory_bytes: 9188
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
using namespace std;
const int moddy=1e9+7;
long long n,m,ans;
int main()
{
	//freopen("std.in","r",stdin);
	cin>>n>>m;
	if(n==m)
		ans=2;
	else if((n==m+1)||(n==m-1))
		ans=1;
	for(long long i=1;i<=n;i++)
	{
		ans*=i;
		ans%=moddy;
	}
	for(long long i=1;i<=m;i++)
	{
		ans*=i;
		ans%=moddy;
	}
	cout<<ans;
	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;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	int n , m; cin >> n >> m;
	if(n==1 && m==0){
		cout<<0;
		return;
	}
	int s , c;
	vector<int> hash(n,0);
	vector<int> arr(n,0);
	for(int i = 0 ; i < m ; i++){
		cin >> s >> c;
		s--;
		if(hash[s] != 0 && arr[s] != c){
			cout<<"-1";
			return;
		}
		hash[s] = 1;
		arr[s] = c;
	}
	string res = "";
	if(hash[0] == 0){
		arr[0] = 1;
	}
	for(int i = 0 ; i < n ; i++){
		res += arr[i]+'0';
	}
	if((int)res.size() != n || (res[0]=='0' && n!=1)){
		cout<<"-1";
		return;
	}
	cout<<res;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

template<class V, int ME> class BIT {
public:
    V bit[1<<ME];
    V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
    void update(int e, V val) {e++; while(e<=1<<ME) bit[e-1]+=val,e+=e&-e;}
};

int main(){
    int N, tmp;
    cin >> N;
    vector<int> inputs(N), rank(N);
    vector<pii> x(N);
    REP(i, N){
        cin >> x[i].first;
        x[i].second = i;
    }
    sort(x.begin(), x.end());
    REP(i, N){
        rank[x[i].second] = i+1;
    }

    REP(i, N){
        inputs[--rank[i]] = i;
    }

    BIT<int, 19> bit;
    ll res = 0;
    REP(i, N){
        bit.update(inputs[i], 1);
        //cout << bit.total(N) - bit.total(inputs[i]) << endl;
        res += (bit.total(N) - bit.total(inputs[i]));
    }
    cout << res << endl;
    return 0;
}


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

#define ll long long 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);


int main()
{
    int n;
    cin >> n;
    int ar[n];
    for(int i=0;i<n;i++) cin >> ar[i];
    int mn=INT_MAX;
    int tmp=0;
    for(int i=-100;i<=100;i++)
    {
        for(int j=0;j<n;j++)
        {
            tmp=tmp+pow((i-(ar[j])),2);
        }
        mn=min(mn,tmp);
        tmp=0;
    }
    cout << mn << endl;
}

Measured memory_bytes: 3564
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  llong ans = 0;
  while(x > 0 || y > 0){
    if(x == 0 && y == 0){
      break;
    }else if(y == 0){
      ans += min(a, 2 * c);
      x--;
    }else if(x == 0){
     ans += min(b, 2 * c);
     y--;
    }else{
      ans += min(2 * c, a + b);
      x--; y--;
    }
  }

  cout << ans << "\n";
  return 0;
}



Measured memory_bytes: 256
use proconio::input;

const MOD: usize = 1_000_000_007;
fn create_pascal() -> Vec<Vec<usize>> {
  let n = 2000;
  let mut result: Vec<Vec<usize>> = vec![vec![0;n+1];n+1];
  result[0][0] = 1;
  for i in 0..n {
    for ii in 0..n {
      result[i+1][ii] = (result[i+1][ii] + result[i][ii]) % MOD;
      result[i+1][ii+1] = (result[i+1][ii+1] + result[i][ii]) % MOD;
    } 
  }
  result
}

fn main() {
  input! {
    n: usize,
    blue: usize,
  }

  let pascal = create_pascal();
  
  let culc = |n: usize, k: usize| {
    if n < k { return 0 }
    if n == 0 && k == 0 { return 1 }
    if k < 1 { return 0 }
    pascal[n - 1][k - 1]
  };
  
  let red = n - blue;
  for i in 1..=blue {
    let blue_p = culc(blue, i) % MOD;
    let mut red_p = culc(red, i-1) % MOD;
    red_p = (red_p + culc(red, i)) % MOD;
    red_p = (red_p + culc(red, i)) % MOD;
    red_p = (red_p + culc(red, i+1)) % MOD;
    println!("{}", blue_p * red_p % MOD);
  }
}

Measured memory_bytes: 33400
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
#define l long long
#define pb push_back
#define mem(a,n) memset(a,n,sizeof(a))
#define find(v,n) find(v.begin(),v.end(),n)
#define sort1(v) sort(v.begin(),v.end())
#define lb(v,n) lower_bound(v.begin(),v.end(),n)-v.begin()
#define ub(v,n) upper_bound(v.begin(),v.end(),n)-v.begin()
#define mod 1000000007
#define reverse(s) reverse(s.begin(),s.end())
//#define pi pair<l,l> 
const double pi=3.141592653589793;
bool isprime(l n)
{
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
/*bool fact(l n)
{
	vector<l> v;
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(i%2==1||(n/i)%2==1)
			{
				return true;
			}
		}
	}
	return false;
}*/
l power(l a,l b)
{
	l ans=1;
	while(b>0)
	{
		if(b&1)
		{
			ans=(ans*a);
		}
		b>>=1;
		a=(a*a);
	}
	return ans;
}//prefixsums
void frooty()
{
	l n;
	cin>>n;
	l a;
	l ans=0;
	for(l i=0;i<n;i++)
	{
		cin>>a;
		if(i%2==0&&a%2==1)
			ans++;
	}
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q=1;
	//cin>>q;
	while(q--)
	{
		frooty();
	}
}

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;
int n;
vector<int> a(100001);
vector<int> b(100001);
vector<int> edge[100001];
map<P, int> mp;

void dfs(int pre, int v, int d) {
    int idx = 1;
    REP(i, edge[v].size()){
        if(edge[v][i] == pre) continue; 
        if(idx == d) idx++;
        if(v > edge[v][i]) {
            mp[make_pair(edge[v][i], v)] = idx;
        } else {
            mp[make_pair(v, edge[v][i])] = idx;
        }
        dfs(v, edge[v][i], idx);
        idx++;
    }
}

int main(){
    cin >> n;
    REP(i, n-1) {
        cin >> a[i] >> b[i];
        edge[a[i]].push_back(b[i]);
        edge[b[i]].push_back(a[i]);
    }
    int ans = 0;
    REP(i, n) {
        int size = edge[i].size();
        ans = max(ans, size);
    }

    dfs(0, 1, 0);

    cout << ans << endl;
    REP(i, n-1) {
        cout << mp[make_pair(a[i], b[i])] << endl;
    }
    

    return 0;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
int cnt=1,K;
typedef long long ll;
ll ans=0;
int a[12],len;
void MADE(int x){
	for (int i=x-1;i>=0;i--) a[i]=max(0,a[i+1]-1);
}
int main(){
	for (int i=0;i<12;i++) a[i]=0;
	a[0]=1,len=1;
	cin>>K;
	while (cnt<K){
		cnt++;
		bool ok=0;
		int pos=0,res=0;
		for (;pos<len;pos++){
			for (int j=a[pos]+1;j<10;j++) if (pos==len-1 || abs(j-a[pos+1])<=1){
				res=j,ok=1;break;
			}
			if (ok) break;
		}
		if (!ok){
			len++;
			a[len-1]=1;
			MADE(len-1);
		}else{
			a[pos]=res;
			MADE(pos);
		}
	}
	for (int i=len-1;i>=0;i--) ans=ans*10+a[i];
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
template<class T> inline void YES(T condition) { 
    if(condition) cout << "YES" << endl;
    else cout << "NO" << endl;
}
template<class T> inline void Yes(T condition) {
    if(condition) cout << "Yes" << endl;
    else cout << "No" << endl;
}
template<class T> T gcd(T a, T b) {
    if(a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); }
    else { return a; }
}
template<class T> T lcm(T a, T b){
    return a / gcd(a, b) * b;
}
long long qpow(long long a, long long b, int MOD) {
    if (b == 0) return 1;
    long long res = 1;
    while (b) {
        if (b & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}

const int MOD = 998244353;
const int maxn = 2e6;
int fac[maxn + 5];
int invfac[maxn + 5];
void init() {
    fac[0] = 1;
    for (int i = 1; i <= maxn; i++) fac[i] = 1LL * fac[i - 1] * i % MOD;
    invfac[maxn] = (int)(qpow(fac[maxn], MOD - 2, MOD));
    for (int i = maxn - 1; i >= 0; i--) invfac[i] = 1LL * invfac[i + 1] * (i + 1) % MOD;
}
int C(int n, int k) {
    assert(0 <= k && n >= k);
    int tmp = (int)(1LL * invfac[k] * invfac[n - k] % MOD);
    return (int)(1LL * fac[n] * tmp % MOD);
}

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

    int n, m, k;
    cin >> n>> m >> k;
    LL ans = 0;
    init();
    for (int i = 0; i <= k; i++) {
        ans += (1LL * m * C(n - 1, i) % MOD) * qpow(m - 1, n - i - 1, MOD) % MOD;
        ans %= MOD;
        // cout << i << ":" << ans << '\n';
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 19240
from collections import defaultdict
def prime_factorization(n):
  if n==1:
    return {}
  res=defaultdict(int)
  for f in range(2,n):
    if f*f>n:
      break
    while n%f==0:
      n=n//f
      res[f]+=1
  if n>1:
    res[n]+=1
  return res

def cnt_ope(n):
  return min(k for k in range(n+1) if (k+2)*(k+1)//2>n)

def main():
  fac=prime_factorization(int(input()))
  return sum(cnt_ope(cnt) for cnt in fac.values())
print(main())

Measured memory_bytes: 66100
m,n=map(int,raw_input().split())
a=[]*m
b=[]*n
p=0
q=0
while(q<m):
	q+=1
	a.append(raw_input())
while(p<n):
	p+=1
	b.append(raw_input())
flag=False
# print a
# print b
for i in xrange(n):
	if not b[i] in (a[i]):
		flag=True
		break
if flag:
	print "No"
else:
	print "Yes"

Measured memory_bytes: 2568
N = gets.strip.to_i
A = gets.split.map(&:to_i)
res = Array.new
res << A.join(' ') + "\n"
for i in 1..(N-1)
  key = A[i]
  j = i - 1
  while j >= 0 and A[j] > key
    A[j+1] = A[j]
    j -= 1
  end
  A[j+1] = key
  res << A.join(' ') + "\n"
end
print res.join

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

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
typedef long long ll;


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

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    rep(i, ty - sy) {
        cout << "U";
    }
    rep(i, tx - sx) {
        cout << "R";
    }
    rep(i, ty - sy) {
        cout << "D";
    }
    rep(i, tx - sx) {
        cout << "L";
    }
    cout << "L";
    rep(i, ty - sy + 1) {
        cout << "U";
    }
    rep(i, tx - sx + 1) {
        cout << "R";
    }
    cout << "D";
    cout << "R";
    rep(i, ty - sy + 1) {
        cout << "D";
    }
    rep(i, tx - sx + 1) {
        cout << "L";
    }
    cout << "U" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int n,i,c=0;
	while(scanf("%d",&n),n){
		c=0;
		for(i=1;i<=n;i++){
			if(i%15625==0)c+=6;
			else if(i%3125==0)c+=5;
			else if(i%625==0)c+=4;
			else if(i%125==0)c+=3;
			else if(i%25==0)c+=2;
			else if(i%5==0)c+=1;
		}
		printf("%d\n",c);
	}
	return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 575;

// dp[見てるとこ][重さ]
ll dp[MAX_N][MAX_N * MAX_N];

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

  CIN(N, W);
  vector< ll > w(N);
  vector< ll > v(N);
  REP(i, N) {
    cin >> w[i] >> v[i];
  }
  vector< ll > diff_w(N);
  REP(i, N) {
    diff_w[i] = w[i] - w[0];
  }

  ll sm = 0;
  // 見ているとこ
  REP(i, N) {
    RREP(j, N) {
      if (j > i) {
	// iまでで作るので
	continue;
      }
      RREP(k, sm + 1) {
	dp[j + 1][k + diff_w[i]] = max(dp[j + 1][k + diff_w[i]],
				       dp[j][k] + v[i]);
      }
    }
    sm += diff_w[i];
  }

  ll ans = 0ll;
  REP(i, N + 1) {
    REP(j, 3 * N) {
      if (w[0] * i + j > W) {
	// 重さがWを超えた時には入れない
	continue;
      }
      debug(dp[i][j]);
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 205056
x = int(input())
list = [500, 5,100, 50, 10, 1]
ans_list = [0, 0, 0, 0, 0]
for i in range(5):
    ans_list[i] = int(x / list[i])
    x -= (list[i] * ans_list[i])
ans = ans_list[0] * 1000 + ans_list[1] * 5
print(ans)

Measured memory_bytes: 38256
def calculate_mean(num,data):

	mean = sum(data) / num
	#print('{:.5f}'.format(mean))

	return mean

def find_difference(num,data):

	#平均を求める
	mean = calculate_mean(num,data)
	diff = []
	for num1 in data:
		diff.append(num1-mean)
	return diff

def calculate_variance(num,data):
	#平均との差を求める
	diff = find_difference(num,data)

	#差の二乗を求める
	squared_diff = []

	for d in diff:
		squared_diff.append(d**2)

	#分散を求める
	sum_squared_diff = sum(squared_diff)
	variance = sum_squared_diff/num

	return variance

if __name__ == '__main__':

	while True:
		num = int(input())

		if num == 0:
			break
		data_s = input().split(" ")
		data = [int(i) for i in data_s]

		#分散を求める
		variance = calculate_variance(num,data)

		#標準偏差
		std = variance**0.5
		print('{:.5f}'.format(std))





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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

//main
//------------------------------------------
signed main(){
  int A ,B, C;
  cin >> A >> B >> C;

  int mini=min(A, B);
  int maxi=max(A, B);
  if(mini<C&&maxi>C) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

N = int(stdin.readline().rstrip())
H = [int(x) for x in stdin.readline().rstrip().split()]

flg = True

maxn = -INF

for i in range(N-1):
    diff = H[i+1] - H[i]

    if diff >= 0:
        if diff == 0:
            pass
        else:
            H[i] = H[i] - 1
            maxn = max(H[i], maxn)
        continue

    if diff == -1:
        if H[i] - 1 >= maxn:
            H[i] = H[i] - 1
            maxn = max(H[i], maxn)
        else:
            flg = False
            break
    # diff < -1
    else:
        flg = False
        break


if flg:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 89580
z = [int(i) for i in input().split()]
x = z[2] - z[0]
y = z[3] - z[1]
x_3 = [z[2]-y,z[3]+x]
x_4 = [x_3[0]-x,x_3[1]-y]
square = x_3+x_4
for i in square:
    print(i,end=" ")

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

struct UnionFind {
    vector<ll> par;  // par[i]: parent of i
    vector<ll> siz;

    UnionFind(ll N) : par(N + 1), siz(N + 1, 1ll) {  // initialize by making every node a root node
        for (int i = 0; i <= N; i++) par[i] = i;
    }

    ll root(ll x) {  // find the root of a given node
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        return;
    }

    bool issame(ll x, ll y) {  // return true if x and y belong to the same tree
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

unordered_set<int> friends_adj[100100];

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uftree(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uftree.unite(a, b);
        friends_adj[a].insert(b);
        friends_adj[b].insert(a);
    }
    rep(i, k) {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        if (uftree.issame(c, d)) {
            friends_adj[c].insert(d);
            friends_adj[d].insert(c);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << uftree.size(i) - friends_adj[i].size() - 1 << " ";
    }
    cout << endl;
}


Measured memory_bytes: 26752
def solve():
    j = 1
    for i in s:
        if i != 1:
            print(i)
            exit()
        if j==K:
            print(i)
            exit()
        j += 1
    print(1)

if __name__=="__main__":
    S = input()
    K = int(input())
#    d = 5*10**15
    s = [int(c) for c in S]
#    print(s)
    solve()


Measured memory_bytes: 9124
import java.util.*;
public class Main{
	public static void main(String args[]){

		Scanner ob = new Scanner(System.in);
		int N = ob.nextInt();
		int count = 0;
		int[] a = new int[N];

		for (int i = 0; i < N; i++) {
			a[i] = ob.nextInt();
		}

		for (int j = 0; j < N; j++) {
			
			if ((a[j] % 2 != 0) && ((j + 1) % 2 != 0)) {
				++count;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 35560
n = int(input())
N = n

ans = ""

while n != 0:
    if n % 2 == 1:
        ans += "1"
        n = n - 1
        n //= -2
    else:
        ans += "0"
        n //= -2

print(ans[::-1] if N != 0 else 0)

Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
char c[200000+5];
int main()
{
//	gets(c);
	scanf("%s",c);
	int len=strlen(c);
	stack<char>ans;
	for(int i=0;i<len;++i){
		if(ans.empty()){
			ans.push(c[i]);
			continue;
		}
		if(ans.top()=='S'&&c[i]=='T'){
			ans.pop();
		}
		else{
			ans.push(c[i]);
		}
	}
	cout<<ans.size()<<endl;
	return 0;
 } 

Measured memory_bytes: 640
#include<stdio.h>
main()
{
	int n, i, j, s, x;
	scanf("%d", &n);
	if (n<105)
	{
		x=0;
	}
	else
	{
		for (i=105, x=0; i<=n; i=i+2)
		{
			for (j=1, s=0; j<=i; j++)
			{
				if (i%j==0)
				{
					s++;
					if (j==i && s==8)
					{
						x++;
					}
				}
			}
		}
	}
	printf("%d\n", x);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

char c[3][4];

int main(){
    for(int i = 0 ; i < 3; i++)
        for(int j = 0; j < 4; j++) scanf("%c", &c[i][j]);
    for(int i = 0; i < 3; i++) printf("%c", c[i][i]);
}


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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> a(n),dp(n+1,IINF);
    REP(i,n)cin >> a[i];
    REP(i,n){
        *lower_bound(dp.begin(),dp.end(),a[i]) = a[i];
    }
    cout << lower_bound(dp.begin(),dp.end(),IINF)-dp.begin() << endl;
    return 0;
}



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

// templates -------------------------------------

#define ULL unsigned long long
#define LL long long
#define LLD long long double
#define REP(i, n) for(LL i = 0; i < n; i++)
#define INV_REP(i, n) for(LL i = n; 0 <= i; i--)

LL sumOfDigits(LL n)
{
  LL sum = 0;
  while(0 < n)
  {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

LL combination(LL n, LL m)
{
  LL nume = 1;
  REP(i, m) nume *= (n-i);
  LL demo = 1;
  for(int i = 1; i <= m; i++) demo *= i;
  return nume / demo;
}

template<class T>
class UnionFind
{
private:
  vector<T> par;
  vector<T> rank;
  vector<T> size;

public:
  UnionFind(T N) :
    par(N, T()), rank(N, T()), size(N, T())
  {
    REP(i, N)
    {
      par[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }

  inline T root(T x)
  {
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  inline bool same(T x, T y)
  {
    return root(x) == root(y);
  }

  inline T getSize(T x)
  {
    return size[root(x)];
  }

  void unite(T x, T y)
  {
    T r1 = root(x);
    T r2 = root(y);
    if(r1 == r2) return;

    if(rank[r1] < rank[r2]) swap(r1, r2);
    if(rank[r1] == rank[r2]) rank[r1]++;
    par[r2] = r1;
    size[r1] += size[r2];
  }
};

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

int a, b;

void input()
{
  cin >> a >> b;
}

void solve()
{
  cout << (b%a == 0 ? a+b : b-a);
}

int main()
{
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>
#include <unordered_map>

using namespace std;


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

    int n;
    cin>>n;
    vector<string> g(n);
    for (int i=0; i<n; i++) cin>>g[i];
    int ans = -1;
    for (int i=0; i<n; i++) {
        vector<string> gg = g;
        queue<int> q;
        vector<int> v(n, -1);
        v[i] = 0, q.push(i);
        int cur = 0;
        bool valid = true;
        while (!q.empty()) {
            int size = q.size();
            while (size--) {
                int now = q.front();
                q.pop();
                for (int j=0; j<n; j++) {
                    if (gg[now][j] == '1') {
                        if (v[j] != -1 && v[j] != cur + 1) {
                            valid = false;
                            break;
                        }
                        gg[now][j] = '0', gg[j][now] = '0', v[j] = cur + 1;
                        q.push(j);
                    }
                }
                if (!valid) break;
            }
            if (!valid) break;
            cur++;
        }
        for (int j=0; j<n; j++) {
            if (v[j] == -1) {
                valid = false;
                break;
            }
        }
        if (valid) ans = max(ans, cur);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

struct osak{
    vector<int> d;
    osak(int n) :d(n+1, 1) {
        for(int i = 2; i <= n; i++){
            if (d[i] != 1) continue;
            for(int j = i; j <= n; j += i){
                if (d[j] == 1) d[j] = i;
            }
        }
    }
    vector<P> factorize(int x){
        vector<P> res;
        int y = d[x];
        int cnt = 1;
        while(x != 1){
            x /= y;
            if (d[x] != y){
                res.push_back(P(y, cnt));
                cnt = 0;
            }
            y = d[x];
            cnt++;
        }
        return res;
    }
};

int main(){
    int n;
    cin >> n;
    osak o(n+1);

    ll ans = 0;
    for(int c = 1; c < n; c++){
        int x = n -c;
        auto res = o.factorize(x);
        ll sum = 1;
        rep(i, res.size()){
            sum *= res[i].second + 1;
        }
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7040
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int D = nextInt();
		int[][] space = new int[N][D];
		for(int i=0;i<N;i++) {
			space[i]=nextIntArray(D);
		}
		int cnt = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			}
		}
		out.println(cnt);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}

Measured memory_bytes: 23764
/*  -*- coding: utf-8 -*-
 *
 * b.cc: D: Xor Sum 2
 */
 
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<stdio.h>
 
using namespace std;
 
/* constant */
 
const int MAX_N = 200000;
 
/* typedef */
 
typedef long long ll;
 
/* global variables */
 
ll as[MAX_N];
 
/* subroutines */
 
/* main */
 
int main() {
  int n;

  scanf("%ld", &n);
 
  for (int i = 0; i < n; i++) scanf("%ld", &as[i]);
 
  ll cnt = 0, x = 0;
  long  sum,xxor;
  sum = xxor = 0;
  int j;
  j = 0;

  for (int i = 0; i < n; i++) {

    while (j < n ){
	  //cout << "j:" << j << "x:" << x << endl;
	  //if((x & as[j]) != 0){
	  //	break;
	  //}
	  if((sum+as[j]) != (x xor as[j])){
		break;
	  }
	  sum = sum + as[j];
	  x = x xor as[j];
	  j++;
	}
	
	//cout << "i:" << i << "j:" << j << endl;
    cnt += j - i;
	//cout << "before x:" << x << endl;
	sum = sum - as[i];
    x = x xor as[i];
	//cout << "after x:" << x << endl;
  }
 
  printf("%lld\n", cnt);
  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>

int main(){
    int H,W;
    for(int i = 0;; i++){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0){
            break;
        }
        for(int j = 1; j <= H; j++){
            for(int k = 1; k <= W; k++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N - 1);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
  }
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N - 1; i++) cin >> C[i];

  int total = 0;
  for (int i = 0; i < N; i++) {
    total += B[A[i]];
    if (i > 0) {
      if (A[i] == A[i - 1] + 1) {
	total += C[A[i - 1]];
      }
    }
  }
  cout << total << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int X;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> X;
    if (X == 3 or X == 5 or X == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	int i;
	int d;
	set<int> D;
	for (i=0;i<N;i++){
		cin>>d;
		D.insert(d);
	}
	cout<<D.size()<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v, y, m; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

vector<string> p;
vector< vector<bool> > vis;
bool stable;

i_i dfs(int x, int y) {
	char c = p[y][x];
	vis[y][x] = true;
	int cnt = 0, sum = 0;
	int l = INT_MAX, r = INT_MIN;
	stack<i_i> s;
	s.push(i_i(x, y));
	while (s.size()) {
		i_i xy = s.top(); s.pop();
		int x = xy.first, y = xy.second;
		cnt++; sum += x;
		for (int k = 0; k < 4; k++) {
			int _x = x + dx[k], _y = y + dy[k];
			if (!vis[_y][_x] && p[_y][_x] == c) {
				vis[_y][_x] = true;
				s.push(i_i(_x, _y));
			}
			if (k == 1 && !vis[_y][_x] && p[_y][_x] != '.' && p[_y][_x] != c) {
				i_i z = dfs(_x, _y);
				cnt += z.first;
				sum += z.second;
			}
			if (k == 3 && p[_y][_x] != '.' && p[_y][_x] != c) {
				l = min(l, _x);
				r = max(r, _x + 1);
			}
		}
	}
	double xg = (double)sum / cnt + 0.5;
	if (xg <= l + EPS || xg >= r - EPS)
		stable = false;
	return i_i(cnt, sum);
}

int main() {
	for (;;) {
		int w, h; cin >> w >> h;
		if (w == 0) break;
		p = vector<string>(h + 2);
		p[0] = string(w + 2, '.');
		p[h + 1] = string(w + 2, '#');
		for (int y = 1; y <= h; y++) {
			string s; cin >> s;
			p[y] = '.' + s + '.';
		}
		for (int x = 1; x <= w; x++)
			if (p[h][x] != '.') {
				vis = vector< vector<bool> >(h + 2, vector<bool>(w + 2));
				stable = true;
				dfs(x, h);
				break;
			}
		cout << (stable ? "STABLE" : "UNSTABLE") << endl;
	}
}

Measured memory_bytes: 1252
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;

//マクロ
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<long long, long long> 
#define vin(v,N) for(int i=0;i<N;i++) cin>>v.at(i)
#define pb push_back
#define vl vector<long long>
#define vvl vector<vector<long long>>

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(ll x,ll N){
  ll ret=1;
  for(int i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//素因数分解(mapで返す)
map<ll,ll> factor(ll p){
  ll p1=p;
  map<ll,ll>ret;
  for(ll i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  string s,t;cin>>s>>t;
  ll N,M;N=s.size();M=t.size();
  
  vvl dp(N+1,vl(M+1,0));
  //cout<<dp[N+1][M+1]<<endl;
  
  rep(i,N){
    rep(j,M){
      if(s[i]==t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
      chmax(dp[i+1][j+1], dp[i+1][j]);
      chmax(dp[i+1][j+1], dp[i][j+1]);
    }
  }
  
  string res="";
  ll i=N; ll j=M;
  while(i>0 && j>0){
    if(dp[i][j]==dp[i-1][j])
      i--;
    else if(dp[i][j]==dp[i][j-1])
      j--;
    else{
      res=s[i-1]+res;
      i--; j--;
    }
  }
  
  cout<<res<<endl;
  //cout<<dp[N][M];
}

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

#define REP(i, n) for(int i; i<n; i++)

using namespace std;

unsigned long long gcd(unsigned long long a, unsigned long long b){
    if(a<b){
        unsigned long long tmp = a;
        a = b;
        b = tmp;
    }
    unsigned long long r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(){
    int n;
    cin >> n;
    vector<unsigned long long> t;
    
    REP(i, n){
        unsigned long long ct;
        cin >> ct;
        t.push_back(ct);
    }

    unsigned long long a;
    unsigned long long r = t[0];
    for(int i=1; i<t.size(); i++){
        a = t[i];
        unsigned long long b = gcd(a, r);
        r = a*(r/b);
    }
    cout << r << endl;
}


Measured memory_bytes: 256
n = int(input())

cnt=[[0,0,0,0,0,0,0,0,0,0] for _ in range(10)]
ans = 0


for i in range(n+1):
    i = list(str(i))
    cnt[int(i[0])][int(i[-1])] += 1

for i in range(1, 10):
    for j in range(1, 10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)


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

int main(){
    string s;
    cin >> s;
    bool ans = (s[2]==s[3])&&(s[4]==s[5]);
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

const ll MAXV = 1e18;

int main() {
    int n;
    ll ans = 1;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    
    for (int i = 0; i < n; i++)
    {
        if (a[i] > MAXV / ans) {
            ans = -1;
            break;
        }
        ans *= a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4004