akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pinf 0x7FFFFFFF

const int N = 101;
int graph[N][N];
int dist[N][N];

int main() {
  int n, m;
  int u, v, w;
  cin >> n >> m;

  //..initialise with all disconnected
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      graph[i][j] = pinf;
    }
  }

  for (int i = 0; i < m; i++) {
    cin >> u >> v >> w;
    graph[u][v] = w;
  } 
  
  for (int i = 0; i < n; i++) {
    graph[i][i] = 0;
  } 

  //..copying the graph for processing
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dist[i][j] = graph[i][j];
    }
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (dist[i][k] != pinf && dist[k][j] != pinf && dist[i][k] + dist[k][j] < dist[i][j]) {
          dist[i][j] = dist[i][k] + dist[k][j];
        }
      } 
    }
  } 

  //..cycle present when dist[i][i] < 0
  for (int i = 0; i < n; i++) {
    if (dist[i][i] < 0) {
      cout << "NEGATIVE CYCLE" << endl;
      return 0;
    }
  }

  //..print distance from each other
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j > 0) putchar(' ');
      if (dist[i][j] == pinf) {
        cout << "INF";
      } else {
        cout << dist[i][j];
      }
    }
    putchar('\n');
  }
  return 0;
}



Measured memory_bytes: 3180
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << s1[0] << s2[1] << s3[2] << endl;

    return 0;
}


Measured memory_bytes: 888
class Node():
    def __init__(self,key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None
    def __str__(self):
        return str(self.key)
def inorder(r): ##r:root
    if (r.left != None):
        inorder(r.left)
    print(' ' + str(r.key), end ='')
    if (r.right != None):
        inorder(r.right)
def preorder(r):  ##r:root 
    print(" "+str(r.key), end ='')  ##preorder은 루트 쪽부터 print
    if (r.left != None):  ##left쪽으로 쭉감
        preorder(r.left) ##ns[i].left를 root로써 재귀함수!
    if (r.right != None):
        preorder(r.right) ##left다했으면 right으로도 똑같이 해줌 
root = None
def insert(z,root):
    y = None
    x = root
    while x != None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    
    if z.key < y.key:
        y.left = z
    else:
        y.right = z

def find(z,root):
    flag = 0
    while root != None:
        k = root.key
        if k==z:
            flag = 1
            break
        elif z>k:
            root = root.right
        elif z<k:
            root = root.left
    if flag:
        print("yes")
    else:
        print("no")
        
    

n = int(input())
command = str(input())
if command[0]=="i":
    root = Node(int(command[7:]))
else:
    print()
for i in range(n-1):
    com = str(input())
    if com[0] == "i":
        insert(Node(int(com[7:])),root)
    elif com[0]=="p":
        inorder(root)
        print()
        preorder(root)
        print()
    elif com[0] == "f":
        find(int(com[5:]),root)
    


Measured memory_bytes: 85224
def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p

a, b, c, d = map(int, input().split())
print((b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//(c*d//gcd(c, d))-(a-1)//(c*d//gcd(c, d))))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

bool num (int i) {
    int cnt = 0;
    for (int j = 1; j * j <= i; j++) {
        if (i % j == 0) {
            if (j * j != i) cnt++;
            cnt++;
        }
    }
    if (cnt == 8) return true;
    return false;
}

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i += 2) {
        if (num (i)) cnt++;
    }
    cout << cnt << "\n";
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def check_two_str(A, B):
    AtoB_dict = {}
    answer = True
    for i in range(len(A)):
        try:
            AtoB_dict[A[i]]
        except KeyError:
            AtoB_dict[A[i]] = B[i]
        else:
            if AtoB_dict[A[i]] != B[i]:
                answer = False
                break
    return answer

def main():
    S = input()
    T = input()
    if check_two_str(S, T) and check_two_str(T, S):
        print("Yes")
    else:
        print("No")
    return

if __name__ == "__main__":
    main()



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


#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) std::sort(ALL(a))
#define SORTA(a, n) std::sort(ALLA(a, n))
#define REV(a) std::reverse(ALL(a))
#define REVA(a, n) std::reverse(ALLA(a, n))
#define MAX(a, b) a = std::max(a, b)
#define MIN(a, b) a = std::min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) std::cout << i << " "; std::cout << std::endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  std::unordered_map
#define US  std::unordered_set
#define PQ  std::priority_queue

#define IO std::ios_base::sync_with_stdio(false); std::cin.tie(NULL)
/*#define IO std::ios::sync_with_stdio(0);*/

typedef long long ll;
typedef unsigned long long ull;

typedef std::string sg; 
typedef std::vector<int> vi;
typedef std::vector<double> vd;
typedef std::vector<ll> vll;
typedef std::pair<int,int> pi;
typedef std::pair<double,double> pd;
typedef std::pair<ll,ll> pll;
typedef std::queue<int> qi;
typedef std::queue<double> qd;
typedef std::queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef std::vector<vi> mi;
typedef std::vector<vd> md;
typedef std::vector<vll> mll;
typedef std::vector<pi> vpi;
typedef std::vector<pd> vpd;
typedef std::vector<pll> vpll;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
std::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(std::cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { std::cerr << std::endl; }
eni(!=) std::cerr << std::boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(std::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__) << "] "

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",a*b);
	return 0;
}	

Measured memory_bytes: 3828
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define pb push_back
    #define sz size()
     
    using namespace std;
    using ll = long long int;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;


int main(){
    ll n;
    cin >> n;
    string s = "";
    while(n){
        n--;
        s += (char)'a' + (n % 26);
        n /= 26;
    }
    reverse(ALL(s));
    cout << s << endl;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
LL dp[101][100005];
int visited[101][100005];
LL w[103],val[103];

LL fun(LL f,LL wt)
{
	if(visited[f][wt]==1)
		return dp[f][wt];
	if(wt <= 0)
		return 0;
	visited[f][wt]=1;
	if(f==0)
	{
		if(wt>=w[0]){
			dp[f][wt]=val[0];
			return val[0];
		}
		else{
			dp[f][wt]=0;
			return 0;
		}
	}
  if(w[f] > wt){

  	return dp[f][wt]=fun(f-1,wt);}
  else 
  	return dp[f][wt]=max(fun(f-1,wt-w[f])+val[f],fun(f-1,wt));

}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
LL n,wt;
cin>>n>>wt; 
for(int i=0;i<n;i++)
{
	cin>>w[i]>>val[i];
}
LL ans=fun(n-1,wt);
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 116992
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000000000000002
#define N 400003
#define endl "\n"
using namespace std;
  ll s[1000][2];
int main()
{

  ll n,w;cin>>n>>w;
    for(ll i=0;i<n;i++)
    {
        cin>>s[i][0]>>s[i][1];
    }
      ll arr[n+1][w+1];
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=w;j++)
        {
            if(i==0||j==0)
            {
                arr[i][j]=0;
            }
            else{
            if(s[i-1][0]<=j)
            {
                arr[i][j]=max(arr[i-1][j],s[i-1][1]+arr[i-1][j-s[i-1][0]]);
            }
            else

            {
                arr[i][j]=arr[i-1][j];
            }
            }
        }
    }
    cout<<arr[n][w]<<endl;;

    return 0;
}


Measured memory_bytes: 79104
import sys
input = sys.stdin.readline

def main():
    n_half = int(input()) // 2
    s = input().strip('\n')
    if n_half > 0 and s[0:n_half] == s[n_half:]:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];
ll B[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll max = 0;
    REP(i, N) {
        cin >> A[i];
        max = std::max(max, A[i]);
    }
    memset(B, 0, sizeof(B));
    REP(i, N) {
        B[A[i]]++;
    }

    ll ans = 0;
    REP(i, max + 1) {
        ll m = B[i] + B[i + 1];
        if (i > 0)
            m += B[i - 1];
        ans = std::max(ans, m);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
using namespace std;
using lint = long long;
using ld = long double;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };

const lint INF = 1ll << 60;
const int mod = 1000000007;
void speed() {
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);
	return;
}

lint h, w;

struct tr {
	lint first;
	lint second;
	lint third;
};

lint solve1() {
	lint s = w / 3;//まず縦線で切る
	lint q = s + 1;
	lint a1 = s * h;
	lint a2 = (w - s) * (h / 2);
	lint a3 = h * w - a1 - a2;
	lint b1 = q * h;//8
	lint b2 = (w - q) * (h / 2);//
	lint b3 = h * w - b1 - b2;
	return min(max({ a1,a2,a3 }) - min({ a1,a2,a3 }), max({ b1,b2,b2 }) - min({ b1,b2,b3 }));
}

lint solve2() {
	lint s = h / 3;
	lint q = s + 1;
	lint a1 = s * w;
	lint a2 = (h - s) * (w / 2);
	lint a3 = h * w - a1 - a2;
	lint b1 = q * w;
	lint b2 = (h - q) * (w / 2);
	lint b3 = h * w - b1 - b2;
	return min(max({ a1,a2,a3 }) - min({ a1,a2,a3 }), max({ b1,b2,b2 }) - min({ b1,b2,b3 }));
}

int main(void) {
	speed();
	cin >> h >> w;
	if (h % 3 == 0 || w % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	if (h == 2 || w == 2) {
		cout << 1 << endl;
		return 0;
	}
	lint ans = INF;
	ans = min({ ans,h,w });
	ans = min(ans, solve1());
	ans = min(ans, solve2());
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
using ll = long long;
using namespace std;

/*
ll GCD(ll a, ll b) {
	return b ? GCD(b, a%b) : a;
}

sort(a, a + N, greater<int>())   // descend
sort(a, a+N)                    //  ascend


** nCk
void comb(vector<vector <long long int > > &v) {
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}


** main内でnCn~nC0 生成 **
vector<vector<long long int> > v(n + 1, vector<long long int>(n + 1, 0));
	comb(v);


*/


int main() {
	string s;
	cin >> s;
	int p=0;

	rep(i, 0, 4) {
		rep(j, i + 1, 4) {
			if (s[i] == s[j])p++;
		}
	}

	if (p==2) cout << "Yes";
	else cout << "No";

}


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

int main (){
    long long X, K, D;
    cin >> X >> K >> D;
    X = abs(X);


    if (X/D - K >= 0)
    {
        cout << X - K*D << endl;
    }
    else
    {
        K -= X/D;
        X -= (X/D)*D;
        cout << abs(X - D*(abs(K)%2)) << endl;
        //cout << min(X + (K%2)*D,abs(X - D) + ((1 + K)%2)*D) << endl;
    }

    
}


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    string h;
    string t = "2019/04/30";
    cin >> h;

    if (h <= t)
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;
    ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
//typedef vector<vector<int> > matrix;
 
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
 
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
 
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=1000000007;
const int INF = 1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);
 
double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };
 
const int N=200005;

int f[N+1],inf[N+1];
int C(int n,int r)
{
    if(r>n)
    return 0;
    int ans=(f[n]*inf[r])%hell;
    return (ans*inf[n-r])%hell;
}
void pre()
{
f[0]=1;
for(int i=1;i<=N;i++)
f[i]=(f[i-1]*i)%hell;
inf[N]=power(f[N],hell-2,hell);
for(int i=N-1;i>=0;i--)
inf[i]=(inf[i+1]*(i+1))%hell;
}
bool compare(pair<int,int> p1,pair<int,int> p2)
{
    if(p1.fi!=p2.fi)
    return p1.fi<p2.fi;
    return p1.se<p2.se;
}
void solve()
{
pre();
int h,w,n;
cin>>h>>w>>n;
pair<int,int> p[n];
for(int i=0;i<n;i++)
cin>>p[i].fi>>p[i].se;
sort(p,p+n,compare);
int dp[n];
for(int i=0;i<n;i++)
{
   dp[i]=C(p[i].fi+p[i].se-2,p[i].fi-1);
   for(int j=i-1;j>=0;j--)
   {
       int z=(dp[j]*C(p[i].fi-p[j].fi+p[i].se-p[j].se,p[i].fi-p[j].fi))%hell;
       dp[i]=(dp[i]-z+hell)%hell;
   }
}
int ans=C(h+w-2,h-1);
for(int i=0;i<n;i++)
{
    int z=(dp[i]*C(h-p[i].fi+w-p[i].se,h-p[i].fi))%hell;
    ans=(ans-z+hell)%hell;
}
cout<<ans<<endl;




}

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


Measured memory_bytes: 6804
#include <bits/stdc++.h>
#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()

using namespace std;

signed main (){
  int H,W;
  cin>>H>>W;
  vector<string> a(H);
  rep(i,H){
    cin>>a[i];
  }
  vector<bool> row(H, false);
  vector<bool> col(W, false);
  rep(i,H){
    rep(j,W){
      if(a[i][j]=='#'){
        row[i]=true;
        col[j]=true;
      }
    }
  }
  rep(i,H){
    if(row[i]){
      rep(j,W){
        if(col[j]){
          cout<<a[i][j] ;
        }
      }
      cout<<endl;
    }
  }
}


Measured memory_bytes: 256
n=int(input())
ans=[]
if n%2==1:
    ans.append("1")
    n-=1
else:ans.append("0")
n//=2
while n!=0:
    ans.append("1") if n%2==1 else ans.append("0")
    n//=-2
print("".join(ans[::-1]))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define y1 A2Dalek
#define y0 Cyberman
#define yn RoseTyler
#define j1 JackHarkness
#define fs first
#define sd second
const int N=1e6;
const int oo=1e9+5;
int du[]={-1,0,0,1};
int dv[]={0,-1,1,0};
const long long mod=1e9+7;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
long long sqr(long long x) {return x*x;}
int getbit(int state, int i) {return ((state>>i)&1);}

int n;
long long res,f[N+5],t[N+5];
int main()
{
	//freopen("Infinite Sequence.inp","r",stdin);
	//freopen("Infinite Sequence.out","w",stdout);
	ios_base::sync_with_stdio(false);
    cin>>n;
    f[0]=1; f[1]=1; f[2]=1;
    t[0]=1; t[1]=2; t[2]=3;
    for (int i=3;i<=n;i++)
    {
        f[i]=(t[i-1]-f[i-2]+2*mod)%mod;
        t[i]=(t[i-1]+f[i])%mod;
    }
    for (int i=0;i<=n;i++)
    {
        if (i==n) res=(res + f[i])%mod;
        else if (i==n-1) res=(res+ f[i]*(n-1)%mod)%mod;
        else if (i==n-2) res=(res + f[i]*(n-1)%mod*n%mod)%mod;
        else res=(res+ f[i]*(n-1)%mod*(n-1)%mod +f[i]*(i+1)%mod)%mod;
    }
    cout<<res;
	return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <string>

using namespace std;

int main(){
    int n;
    cin >> n;
    int result = 0;
    for(int i = 1; i < n + 1; i++){
        if(to_string(i).length() % 2 == 1){
            result = result + 1;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int adj[205][205],sum;
int n,r,m;
vector<int>place;
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n>>m>>r;
    for(int i=0; i<r; i++)
    {
        int a;
        cin>>a;
        place.push_back(a);
    }
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            adj[i][j]=1e8;
    while(m--)
    {
        int u,v,c;
        cin>>u>>v>>c;
        adj[u][v]=min(c,adj[u][v]);
        adj[v][u]=min(c,adj[v][u]);
    }
    for(int k=1; k<=n; k++)
    {
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=n; j++)
            {
                adj[i][j]=min(adj[i][j],adj[i][k]+adj[k][j]);
            }
        }
    }
    int ans=INT_MAX;
    sort(place.begin(),place.end());
    do
    {
        int res=0;
        for(int i=0;i<r-1;i++)
        {
            res+=adj[place[i]][place[i+1]];
        }
        ans=min(ans,res);
    }
    while(next_permutation(place.begin(),place.end()));
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,x;cin>>N>>x;
  if(x==1||x==2*N-1){cout<<"No";return 0;}
  cout<<"Yes"<<endl;
  
  if(N==2){cout<<1<<endl<<2<<endl<<3;return 0;}

  vector<long>A(2*N-1,-1);
  long s=(x<=N)*2-1;
  A[N-3]=x+2*s; //x+2<=2*N-1
  A[N-2]=x-1*s; // 
  A[N-1]=x;
  A[N]=x+1*s; 
  
  long p=0;
  for(long i=1;i<=2*N-1;i++){
    while(p<2*N-1&&A[p]!=-1)p++;
    if(i==x-1*s||i==x||i==x+1*s||i==x+2*s)continue;
    A[p]=i;
  } 
  for(long x:A)cout<<x<<endl;
}



Measured memory_bytes: 4756
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

string S;
int finalAns = 700;
int cnt = 0;

int main()
{
	cin >> S;
	for(int i = 0; i < S.size(); i++) {
		if(S[i] == 'o') {
			cnt++;
		}
	}
	finalAns += 100 * cnt;
	printf("%d\n", finalAns);
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
void trace(int A[],int N){
	for(int i=0;i<N;++i){
		if(i>0) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
}
void insertionSort(int A[],int N){
	int i,prev_pos;
	for(int i=1;i<N;i++){
		int prev_pos = i-1;
		int temp_val = A[i];
		while(prev_pos >= 0 && A[prev_pos] > temp_val){
			A[prev_pos+1] = A[prev_pos];
			prev_pos--;
		}
		A[prev_pos+1] = temp_val;
		trace(A,N);
	}
}
int main(){
	int N;
	int A[100];
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	trace(A,N);
	insertionSort(A,N);
	return 0;
}


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

using namespace std;

int N, M, Q;
int L;
int A[100000];
int B[100000];
int prog[100000];
int cnt[100001];

int main()
{
    memset(prog, -1, sizeof prog);
    memset(B, -1, sizeof B);
    scanf("%d%d%d", &N, &M, &Q);
    for(int i=0; i<Q; i++)
        scanf("%d", A+i), A[i]--;
    L=0;
    cnt[0]=N;
    for(int i=Q-1; i>=0; i--)
    {
        int x=A[i];
        if(prog[x]==-1)
        {
            B[L]=x;
            prog[x]=L++;
        }
        if(cnt[prog[x]]>0)
            cnt[prog[x]]--, cnt[prog[x]+1]++;
    }
    for(int i=0; i<M; i++) if(prog[i]==-1)
    {
        B[L]=i;
        prog[i]=L++;
    }
    int idx=0;
    for(int i=L-1; i>=1; i--)
    {
        if(B[i-1]>B[i])
        {
            idx=i;
            break;
        }
    }
    for(int i=0; i<idx; i++) if(cnt[i]>0)
    {
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[5];
  for(int i=0;i<3;i++)cin>>a[i];
  sort(a,a+3);
  if(a[0]==5&&a[1]==5&&a[2]==7){
    cout<<"YES"<<endl;
  }
  else cout<<"NO"<<endl;
  return(0);
}

Measured memory_bytes: 768
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
typedef pair<int,int> pii;
#define endl '\n'
#define mod 1000000007
#define modd 998244353
#define PI 3.1415926535897932384626
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

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

int func(int arr[], int n) 
{ 
  
    unordered_set<int> s; 
    int max_ele = INT_MIN; 
    for (int i = 0; i < n; i++) { 
        s.insert(arr[i]); 
        max_ele = max(max_ele, arr[i]); 
    }  
    unordered_set<int> res; 
    for (int i = 0; i < n; i++) { 
  
        if (arr[i] != 0) { 
  
            for (int j = arr[i] * 2; j <= max_ele; j += arr[i]) { 
 
                if (s.find(j) != s.end()) 
                    res.insert(j); 
            } 
        } 
    } 
    unordered_map<int, int> mp; 
    for (int i = 0; i < n; i++) 
        mp[arr[i]]++; 
  
    unordered_map<int, int>::iterator it; 
    vector<int> ans; 
    for (it = mp.begin(); it != mp.end(); it++) { 
        if (it->second >= 2) { 
            if (res.find(it->first) == res.end()) { 
 
                int val = it->second; 
                while (val--) 
                    ans.push_back(it->first); 
            } 
        }  
        if (res.find(it->first) != res.end()) { 
            int val = it->second; 
            while (val--) 
                ans.push_back(it->first); 
        } 
    }
    return ans.size();
}

int main() 
{ 
	io();
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++) cin>>arr[i]; 
  	int k=func(arr, n); 
  	cout<<n-k;
    return 0; 
}

Measured memory_bytes: 30692
#include <iostream>
using namespace std;
int main(void){
    int a, b;
    // Your code here!
    cin >> a >> b;
    if ( b % 2 != 0 || b < 2*a || b > 4*a){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector< vector<int> > G(N);
	for(int i = 0; i < N-1; i++) {
		int a, b;
		cin >> a >> b;
		G[--a].push_back(--b);
		G[b].push_back(a);
	}
	vector<int> part(N, -1);
	part[0] = 0;
	queue<int> q;
	q.push(0);
	while(!q.empty()) {
		for(auto v : G[q.front()]) if(part[v] == -1) {
			part[v] = 1-part[q.front()];
			q.push(v);
		}
		q.pop();
	}
	int cnt[2] = {0, 0};
	for(int i = 0; i < N; i++) cnt[part[i]]++;
	int cnt_P[3] = {0, 0, 0};
	for(int i = 0; i < N; i++) cnt_P[(i+1)%3]++;
	for(int k = 0; k < 2; k++) if(cnt[k] >= cnt_P[1] && cnt[1-k] >= cnt_P[2]) {
		vector<int> ans(N, 0);
		for(int i = 0; i < N; i++) {
			if(part[i] == k && cnt_P[1]) cnt_P[1]--, ans[i] = 1;
			if(part[i] == 1-k && cnt_P[2]) cnt_P[2]--, ans[i] = 2;
		}
		int cur[3] = {1, 0, 0};
		for(int i = 0; i < N; i++) ans[i] += (cur[ans[i]]++) * 3;
		for(int i = 0; i < N; i++) cout << ans[i] << ((i == N-1) ? "\n" : " ");
		return 0;
	}
	for(int k = 0; k < 2; k++) if(cnt[k] >= cnt_P[1]+cnt_P[2]) {
		vector<int> ans(N, 0);
		for(int i = 0; i < N; i++) {
			if(part[i] == k && cnt_P[1]) cnt_P[1]--, ans[i] = 1;
			else if(part[i] == k && cnt_P[2]) cnt_P[2]--, ans[i] = 2;
		}
		int cur[3] = {1, 0, 0};
		for(int i = 0; i < N; i++) ans[i] += (cur[ans[i]]++) * 3;
		for(int i = 0; i < N; i++) cout << ans[i] << ((i == N-1) ? "\n" : " ");
		return 0;
	}
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 15344
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef pair<int,int> pa;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
const int N=1e5+5,M=5e7+5,INF=1e9,mod=998244353;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int n;
struct P{
	int x,y;
	il P(){}
	il P(int x,int y):x(x),y(y){}
	il bool operator<(const P&o)const{if(x==o.x)return y<o.y;return x<o.x;}
	il int operator*(const P&o)const{return x*o.y-y*o.x;}
	il P operator-(const P&o)const{return P(x-o.x,y-o.y);}
}p[N];
ll pw[N];
il int bad(int i,int j,int k){
	if((p[j]-p[i])*(p[k]-p[i])==0)return 1;
	return 0;
}
int main(){
	read(n);rep(i,1,n)read(p[i].x,p[i].y);
	pw[0]=1;rep(i,1,n)pw[i]=pw[i-1]*2%mod;
	sort(p+1,p+1+n);
	ll qaq=0;
	rep(i,1,n)rep(j,i+1,n){
		int ok=1;
		rep(k,1,j)
			if(k!=i&&k!=j)
				if(bad(i,j,k))ok=0;
		if(ok){
			int res=2;
			rep(k,j+1,n)res+=bad(i,j,k);
			(qaq+=pw[res]-res-1)%=mod;
		}
	}
	qaq=pw[n]-qaq-n-1;
	cout<<qaq<<endl;
}

Measured memory_bytes: 256
import itertools

N, M, X = map(int, input().split())
C = list()
A = list()
for _ in range(N):
    line = list(map(int, input().split()))
    C.append(line[0])
    A.append(line[1:])

combi = list()
for i in range(N):
    combi += itertools.combinations(range(N), i+1)

ok = list()
for books in combi:
    money = 0
    rikai = [0] * M
    for book in books:
        money += C[book]
        for i in range(M):
            rikai[i] += A[book][i]

    for r in rikai:
        if r < X:
            break
    else:
        ok.append(money)

result = min(ok) if len(ok) != 0 else -1
print(result)


Measured memory_bytes: 9672
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,T,X,Y,t=0,x=0,y=0,i;cin>>N;
  for(i=0;i<N;i++){
    cin>>T>>X>>Y;
    if(abs(X-x)+abs(Y-y)>T-t||(T+X+Y-t-x-y)%2==1)break;
    t=T,x=X,y=Y;
  }
  if(i==N)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

string helper(string x, string y, int n){

    for(int i=0;i<n;i++){
	   if(x[i]<y[i])
	      return x;
	   else if(x[i]>y[i])
	      return y;
	   else if(x[i]==y[i])
	      continue;
	     
	}
	return x;
}
int main() {
	int a,b,sum1=0,sum2=0;
	cin>>a>>b;
	for(int i=0;i<b;i++){
	    sum1 = sum1*10+a;
	}
	for(int j=0;j<a;j++){
	    sum2 = sum2*10+b;
	}
	string x = to_string(sum1);
	string y = to_string(sum2);
	int n = min(x.size(),y.size());
	string ans = helper(x,y,n);
	
	for(int i=0;i<ans.size();i++){
	    cout<<ans[i];
	}
	
	return 0;
}

Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
AB = [lr() for _ in range(N-1)] # 0-indexed
edges = [[] for _ in range(N+1)] # 1-indexed
for a, b in AB:
    edges[a].append(b)
    edges[b].append(a)

order = [] # 頂点１を根とした時、上からの頂点の順番
parent = [0] * (N+1) # 1-indexed
stack = [1]
while stack:
    x = stack.pop()
    order.append(x)
    for y in edges[x]:
        if parent[x] == y:
            continue
        parent[y] = x
        stack.append(y)

color = [-1] * (N+1) # 1-indexed 頂点iの親方向への辺の色
for o in order:
    ng = color[o]
    c = 1
    for z in edges[o]:
        if z == parent[o]:
            continue
        if c == ng:
            c += 1
        color[z] = c
        c += 1

answer = []
for i in range(N-1):
    a, b = AB[i]
    if a == parent[b]:
        answer.append(color[b])
    else:
        answer.append(color[a])

print(max(answer))
print('\n'.join(map(str, answer)))
# 12

Measured memory_bytes: 44748
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<pair<int, int> > > vvp;
typedef vector<pair<int,int> > vp;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<vector<bool> > vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define mod 1000000007
#define intmax 2147483647
#define intmin -2147483648
#define longmax 9223372036854775807
#define longmin -9223372036854775808
#define nil -1
int main() {
	int n, m;
	cin >> n >> m;
	vs A(n);
	vs B(m);
	rep(i, 0, n)cin >> A[i];
	rep(i, 0, m)cin >> B[i];
	int d = n - m;
	bool f;
	for (int i = 0; i < d+1; i++)
	{
		for (int j = 0; j < d+1; j++)
		{
			f = true;
			for (int k = 0; k < m; k++)
			{
				string w = A[k + j].substr(i,m);
				if (w != B[k])f = false;
			}
			if (f)break;
		}
		if (f)break;
	}
	cout << Yn(f) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	int X;
	cin >> X;
	for (int A = -120; A <= 120; A++)
		for (int B = -120; B <= 120; B++) {
			if (A * A * A * A * A - B * B * B * B * B == X) {
				cout << A << " " << B << endl;
				return 0;
			}
		}
	return 0;
}

Measured memory_bytes: 3596
import  math
def C(n,r):
    return math.factorial(n)//(math.factorial(r)*math.factorial(n-r))
n,m=input().split()

ans = 0
if int(n)>=2:
    ans+=C(int(n),2)
if int(m)>=2:
    ans+=C(int(m),2)
print(ans)

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

int count_Si(int *S,int n,int x){
	int count=0;
	for(int i=0;i<n;i++){
		if(S[i]==x){
			count++;
		}
	}
	return count;
}

int check_finish(int *S,int *P,int n){
	for(int i=0;i<n;i++){
		if(S[i]!=P[i]){
			return -1;
		}
	}
	return 1;
}

void calc(int *S,int n){
	int *P=(int*)malloc(sizeof(int)*n);
	int count=0;

	while(1){
		for(int i=0;i<n;i++){
			P[i]=count_Si(S,n,S[i]);
		}
		if(check_finish(S,P,n)==1){
			break;
		}
		count++;
		for(int i=0;i<n;i++){
			S[i]=P[i];
		}
	}
	printf("%d\n",count);
	for(int i=0;i<n;i++){
		printf("%d",P[i]);
		if(i==(n-1)){
			printf("\n");
		}else{
			printf(" ");
		}
	}
}

int main(){
	int n;
	int *S;

	while(scanf("%d",&n)){
		if(n==0){break;}
		S=(int*)malloc(sizeof(int)*n);
		for(int i=0;i<n;i++){
			scanf("%d",&S[i]);
		}

		calc(S,n);
	}

	return 0;
}


Measured memory_bytes: 2040
S = input()

# print(S)

flag = True
for i in range(len(S)):
    # print(S[i])
    
    if (i + 1) % 2 == 1:
        if not (S[i] == 'R' or S[i] == 'U' or S[i] == 'D'):
            flag = False
    else:
        if not(S[i] == 'L' or S[i] == 'U' or S[i] == 'D'):
            flag = False
            
            
# print(flag)

if flag:
    print('Yes')
else:
    print('No')

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

// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  vector<ll> x(n), y(n);
  vector<pair<ll, ll>> t1(n), t2(n);
  REP(i, n) {
    cin >> x[i] >> y[i];
    t1[i] = {x[i] + y[i], i};
    t2[i] = {-x[i] + y[i], i};
  }
  sort(ALL(t1));
  sort(ALL(t2));
  ll i1 = t1[n - 1].second, i2 = t1[0].second, i3 = t2[n - 1].second,
     i4 = t2[0].second;

  cout << max(abs(x[i1] - x[i2]) + abs(y[i1] - y[i2]),
              abs(x[i3] - x[i4]) + abs(y[i3] - y[i4]))
       << endl;
  return 0;
}


Measured memory_bytes: 12644
import Data.List
import Data.Char
import qualified Data.ByteString.Char8 as B
import Data.Array
import Data.Array.ST
import Control.Monad
import Control.Monad.ST
main=B.interact$B.pack.show.f.unfoldr (B.readInt.B.dropWhile isSpace)
f (_:c:stcs)=runST $ do
    ar<-newArray ((0,0),(c,100001)) 0::ST s (STUArray s (Int,Int) Int)
    forM_ (pack stcs) $ \(s,t,c) -> do
        writeArray ar (c,s) =<< succ <$> readArray ar (c,s)
        writeArray ar (c,t+1) =<< pred <$> readArray ar (c,t+1)
    forM_ [(i,t)|i<-[1..c],t<-[1..100000]] $ \(i,t)->
        writeArray ar (i,t) =<< (+) <$> readArray ar (i,t-1) <*> readArray ar (i,t)
    forM_ [(i,t)|i<-[1..c],t<-[1..100000]] $ \(i,t)-> do
        u<-readArray ar (i,t)
        when (u/=0) $ writeArray ar (0,t) =<< succ <$> readArray ar (0,t)
    maximum <$> forM [1..100000] (\t->readArray ar (0,t))
    where
        pack [] = []
        pack (s:t:c:r) = (s,t,c):pack r

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

int main() {
  int n;
  cin >> n;
  vector<string>a(n);
  for(int i=0;i<n;i++){
  cin >> a.at(i);
  }
  int m=1;
  sort(a.begin(),a.end());
  for(int i=0;i<n-1;i++){
  if(a.at(i)!=a.at(i+1)){
  m++;  
  }
  }
    cout << m << endl;  
}

Measured memory_bytes: 9600
import collections
N = int(input())
arr = list(map(int, input().split()))
cum = [0]*N
cum[0] = arr[0]
for i in range(1,N):
    cum[i] = arr[i] + cum[i-1]
c = collections.Counter(cum)
ans = c[0]
tmp = 0
for i in range(N-1):
    c[cum[i]] -= 1
    tmp += arr[i]
    ans += c[tmp]
print(ans)

Measured memory_bytes: 41680
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c;
  while(true){
  cin>>a>>b;
  if(a==0&&b==0){
    break;
  }
  if(a>b){
    c=a;
    a=b;
    b=c;
  }
  cout<<a<<" "<<b<<"\n";
  }
  return(0);
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
const ll MOD=1e9+7;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    vector<ll> a(3);
    ll ans = LLONG_MAX;
    for(ll i=0;i<3;i++)cin>>a[i];
    sort(a.begin(),a.end());
    do{
        ll sum = abs(a[1]-a[0]) + abs(a[2]-a[1]);
        ans=min(ans , sum);
    }while(next_permutation(a.begin(),a.end()));
    cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int n, K;
int xl[50], yl[50], zl[50], xr[50], yr[50], zr[50];
int sortedX[100];
int sortedY[100];
int sortedZ[100];

bool bet(double a, double b, double c) {
	return (a <= b && b <= c);
}

//leader point(x, y, z)
bool check(double x, double y, double z) {
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (bet(xl[i], x, xr[i]) && bet(yl[i], y, yr[i]) && bet(zl[i], z, zr[i])) {
			cnt++;
		}
	}
	return (cnt >= K);
}

signed main() {
	int i, j, k;
	
	cin >> n >> K;
	for (i = 0; i < n; i++) cin >> xl[i] >> yl[i] >> zl[i] >> xr[i] >> yr[i] >> zr[i];
	for (i = 0; i < n; i++) {
		sortedX[2 * i] = xl[i]; sortedX[2 * i + 1] = xr[i];
		sortedY[2 * i] = yl[i]; sortedY[2 * i + 1] = yr[i];
		sortedZ[2 * i] = zl[i]; sortedZ[2 * i + 1] = zr[i];
	}
	sort(sortedX, sortedX + 2 * n);
	sort(sortedY, sortedY + 2 * n);
	sort(sortedZ, sortedZ + 2 * n);
	
	int ans = 0;
	for (i = 0; i < 2 * n - 1; i++) {
		for (j = 0; j < 2 * n - 1; j++) {
			for (k = 0; k < 2 * n - 1; k++) {
				if (check(sortedX[i] + 0.5, sortedY[j] + 0.5, sortedZ[k] + 0.5)) {
					int szX = sortedX[i+1] - sortedX[i];
					int szY = sortedY[j+1] - sortedY[j];
					int szZ = sortedZ[k+1] - sortedZ[k];
					ans += szX * szY * szZ;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1180
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int rows=3;
    vector<string> mat(rows);
    for(int r=0; r<rows; ++r){ cin >> mat[r]; }
    
    for(int i=0; i<rows; ++i){ cout << mat[i][i]; } cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
A = sorted(A,reverse = True)
alice = []
bob = []
for i in range(N):
    if i % 2 == 0:
        alice.append(A[i])
    else:
        bob.append(A[i])
print(sum(alice) - sum(bob))

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int cnt = 0;
    while(true){
        int even = 0;
        rep(j, n) if(a[j]%2 == 0) even++;
        
        if(even == n){
            cnt++;
            rep(k,n) a[k] /= 2;
        }
        else break;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
from collections import deque

N, X, Y = map(int, input().split())


def node_search(i):
    node_list = []
    if i != 1:
        node_list.append(i-1)
    if i != N:
        node_list.append(i+1)
    if i == X:
        node_list.append(Y)
    if i == Y:
        node_list.append(X)
    return node_list


def bfs(k):
    q = deque()
    dist = [N]*(N+1)
    q.append(k)
    check = [0]*(N+1)
    check[k] = 1
    dist[k] = 0
    while q:
        now_node = q.pop()
        check[now_node] = 1
        next_nodes = node_search(now_node)
        for node in next_nodes:
            if check[node] == 0:
                dist[node] = min(dist[now_node]+1, dist[node])
                q.appendleft(node)
    return dist


ans = [0]*N
for k in range(1, N+1):
    dist_list = bfs(k)
    for i in range(k+1, N+1):
        ans[dist_list[i]] += 1

for i in range(1, N):
    print(ans[i])


Measured memory_bytes: 58076
#include<iostream>
#include<math.h>
using namespace std;

#define ll long long
int main(){

string s;
cin>>s;

int arr[26]{0};
for (char c:s){
    arr[c-'a']++;
}
for(int i=0;i<26;i++){
    if(arr[i]%2!=0)
    {
        cout<<"No";
        return 0;
    }
}
cout<<"Yes";

}


Measured memory_bytes: 3124
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(n):
    if a[i] < 0:
        count = count + 1

if count % 2 == 0:
    ans = 0
    for i in range(n):
        ans = ans + abs(a[i])
    print(ans)
else:
    ans = 0
    for i in range(n):
        ans = ans + abs(a[i])
    l = []
    for i in range(n):
        l.append(ans - 2*abs(a[i]))
    print(max(l))

Measured memory_bytes: 14452
A, B, K = (int(i) for i in input().split())  


for i, k in enumerate(range(K)):
    if i % 2 == 0:
        if A % 2 == 1:
            A -= 1
        B += A / 2
        A = A / 2
    
    if i % 2 == 1:
        if B % 2 == 1:
            B -= 1
        A += B / 2
        B = B / 2

print('{} {}'.format(int(A), int(B)))

 





Measured memory_bytes: 3060