akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>

using namespace std;

#define MAX 2000001
#define VMAX 10000

int main () {
	unsigned short *inputArray, *outputArray;

	int buckets[VMAX + 1];

	int n;
	scanf("%d", &n);

	inputArray = new unsigned short[n];
	outputArray = new unsigned short[n + 1];

	for (int i = 0; i <= VMAX; i++) {
		buckets[i] = 0;
	}



	for (int i = 0; i < n; i++) {
		scanf("%hu", &inputArray[i]);
		buckets[inputArray[i]]++;
	}

	//Accumulating the count, making bucket as cumulative array
	for (int i = 1; i <= VMAX; i++) {
		buckets[i] = buckets[i] + buckets[i - 1];
	}

	for (int i = 0; i < n; i++) {
		outputArray[buckets[inputArray[i]]] = inputArray[i];
		buckets[inputArray[i]]--;
	}

	for (int i = 1; i < n + 1; i++) {
		if (i > 1) printf(" ");

		printf("%d",outputArray[i]);

	}

	cout << endl;

	return 0;
}



Measured memory_bytes: 11140
#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
char buf[200];
int Make(int a,int b,int c,int d,int e,int f,int g)
{
    return g*64+f*32+e*16+d*8+c*4+b*2+a;
}
int s[22];
bool dfs(int depth)
{
    if(depth==12)
    {
        for(int i=0;i<128;i++)
        {
            int b[8]={0};
            for(int j=0;j<7;j++)
            {
                if(i>>j&1) b[j]=1;
                else b[j]=0;
            }
            int c[8]={0};
            c[0]=buf[Make(s[0],s[1],s[11],b[0],b[1],b[2],b[3])];

            c[1]=buf[Make(s[1],s[2],b[0],b[1],s[3],b[3],b[4])];

            c[2]=buf[Make(s[11],b[0],s[10],b[2],b[3],s[9],b[5])];

            c[3]=buf[Make(b[0],b[1],b[2],b[3],b[4],b[5],b[6])];

            c[4]=buf[Make(b[1],s[3],b[3],b[4],s[4],b[6],s[5])];

            c[5]=buf[Make(b[2],b[3],s[9],b[5],b[6],s[8],s[7])];

            c[6]=buf[Make(b[3],b[4],b[5],b[6],s[5],s[7],s[6])];

            int t=buf[Make(c[0],c[1],c[2],c[3],c[4],c[5],c[6])];

            if(t!=c[3]) return true;
        }
        return false;
    }
    s[depth]=0;
    if(dfs(depth+1))
        return true;
    s[depth]=1;
    if(dfs(depth+1))
        return true;
    return false;
}
int main()
{
    while(1)
    {
        scanf("%s",buf);
        if(buf[0]=='#') break;
        for(int i=0;i<128;i++)
        {
            buf[i]-='0';
        }
        if(dfs(0)){
            printf("no\n");
        }
        else
            printf("yes\n");
    }

    return 0;
}

Measured memory_bytes: 1112
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main(){
  ll n ; cin>>  n;  ll ans=0 ;ll p=0 ;
   rep(i,n+50){
     ll x= i*(i+1)/2 ;
     if(x>=n){
       ans = i ;
       p = x-n ;
       break ;
     }
   }
  
   rep2(i,1,ans){
     if(i!=p) cout<< i<<endl ;
   }
      return 0;
  }
  

Measured memory_bytes: 3608
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()

a,b = 1,n-(n%2)
for i in range(m):
    if n%2 == 0 and i == (m+1)//2:
        a += 1
    print(a,b)
    a,b = a+1, b-1

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define fly ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define ll long long
#define pb push_back
#define inf 100000000000
using namespace std;

ll n,m;
vector<ll>g[100010];
ll vis[100010];

ll dfs(ll n){
  if(g[n].size() == 0)return 1;
  if(vis[n] != 0)return vis[n];
  ll cnt = 0;
  for(auto x: g[n]){
    cnt = max(cnt,dfs(x));
  }
  return vis[n] = cnt + 1;
}


int main(int argc, char const *argv[]) {
  fly;
  cin >> n >> m;
  set<ll>st;
  for(int i = 0;i<m;i++){
    ll u,v;
    cin >> u >> v;
    st.insert(u);
    st.insert(v);
    g[u].pb(v);
  }
  ll k = -1;
  for(auto x: st){
    if(vis[x] == 0){
      k = max(k, dfs(x));
    }
  }
  cout << k-1 << endl;



  return 0;
}


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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

int main()
{
    _upgrade
    int n; cin >> n;
    n = sqrt(n);
    cout << n * n << "\n";
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  long long int a=2, b=1;
  for (int i = 1; i<n; ++i) {
    long long int tmp = b;
    b = a + b;
    a = tmp;
  }
  cout << b << endl;
  return 0;
}

Measured memory_bytes: 3628
import itertools
N = int(input())
A = list(map(int,input().split()))

ans = 0
for ptn in itertools.product(range(-1,2),repeat=N):
    m = 1
    for a,d in zip(A,ptn):
        m *= (a+d)
        if m%2==0:
            ans += 1
            break
print(ans)

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

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[0] != s[1] || s[0] != s[2] || s[1] != s[2]){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
N, nums = int(input()), list(map(int, input().split()))

score = [[(-1 if N % 2 == 0 else 1)*x for x in nums]]
for i in range(1, N):
    temp = []
    for j in range(N - i):
        func, sign = (min, -1) if i % 2 == N % 2 else (max, 1)
        temp.append(func(sign*nums[j] + score[-1][j + 1], sign*nums[j + i] + score[-1][j]))
    score.append(temp)

print(score[-1][-1])


Measured memory_bytes: 80732
sx, sy, tx, ty = map(int, input().split())
dx, dy = tx - sx, ty - sy
print('U' * dy + 'R' * dx + 'D' * dy + 'L' * dx +
      'L' + 'U' * (dy + 1) + 'R' * (dx + 1) +\
      'DR' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U')


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

int main(){
	int num[2] = {0};
	int n; cin >> n;
	string in; cin >> in;
	for(int i = 0; i < in.size(); ++i){
		if(in[i] == '('){
			num[0]++;
		}else{
			num[1]++;
		}
		if(num[0] < num[1]){
			in.insert(0, "(");
			--num[1];
			++i;
		}
	}
	num[0] = num[1] = 0;
	for(int i = 0; i < in.size(); ++i){
		if(in[i] == '('){
			num[0]++;
		}else{
			num[1]++;
		}
	}
	for(int i = 0; i < num[0] - num[1]; ++i){
		in+= ")";
	}
	cout << in << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
   int a, b,w;
   
   scanf("%d %d %d",&w, &a, &b);
   	
   	if (a+w<b)
   	{
   		printf("%d",b-(a+w));
   	}
   	else if (a>b+w)
   	{
   		printf("%d",a-(b+w));
   	}
   	else
   	printf("0");
}

Measured memory_bytes: 128
#include <stdio.h>

int main (){

	char ha;
	scanf("%c", &ha);
	if(ha >= 'a' && ha <= 'z')
	{
		printf("a");
	}
	else if (ha >= 'A' && ha <= 'Z')
	{
		printf("A");
	}	

	return 0;
}

Measured memory_bytes: 1572
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class ARingring {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int a, b, c;
	    in >> a >> b >> c;
	    vector<int> v{a, b, c};
	    sort(v.begin(), v.end());
	    out << v[0] + v[1] << endl;
	}
};


int main() {
	ARingring solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main()
{
	int N;
	std::cin >> N;
	int A,B;
	std::cin >> A;
	std::cin >> B;

	int num_a=0, num_b=0, num_c=0;
	//Pi
	std::vector<int> P(N+1);
	P[0] = 9999;//miss防止
	for (int i = 1; i < N+1; ++i) {
		std::cin >> P[i];
		if (P[i] < A + 1) {
			num_a++;
		}
		else if (P[i] < B + 1) {
			num_b++;
		}
		else {
			num_c++;
		}
	}

	if (num_a <= num_b && num_a <= num_c) {
		std::cout << num_a;
	}
	else if (num_b < num_c) {
		std::cout << num_b;
	}
	else {
		std::cout << num_c;
	}


}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int N, M, Q;

lint mx = -1;
void dfs(int i, vector<int> &A, vector<vector<int>> &V) {
    if (i == N) {
        // dump(A);
        lint sum = 0;
        for (int i = 0; i < Q; i++) {
            if (A[V[i][1] - 1] - A[V[i][0] - 1] == V[i][2]) { sum += V[i][3]; }
        }
        // d(sum);
        mx = max(mx, sum);
        return;
    }
    for (int x = A[i - 1]; x <= M; x++) {
        A[i] = x;
        dfs(i + 1, A, V);
    }
}

int main() {
    cin >> N >> M >> Q;
    vector<vector<int>> V(Q, vector<int>(4, -1));
    rep(i, Q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        V[i][0] = a;
        V[i][1] = b;
        V[i][2] = c;
        V[i][3] = d;
    }
    vector<int> A(N, 0);
    for (int x = 1; x <= M; x++) {
        A[0] = x;
        dfs(1, A, V);
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
long long int dp[101][100000];
int main() 
{
	long long int n,w;cin>>n>>w;
	vector<long long int> W(n);
	vector<long long int> V(n);
	long long int sum=0;
	for(long long int i=0;i<n;i++)
	{
	    cin>>W[i];
	    cin>>V[i];
	    sum+=V[i];
	}
	for(long long int i=0;i<=n;i++)
	{
	    for(long long int j=0;j<=sum;j++)
	    {
	        dp[i][j]=INT_MAX;
	    }
	} 
	for(long long int i=0;i<101;i++)
	{
	    dp[i][0]=0;
	}
	// for(long long int i=0;i<n;i++)
	// {
	//     cout<<W[i]<<" "<<V[i]<<endl;
	// }
	for(long long int i=1;i<=n;i++)
	{
	    for(long long int j=1;j<=sum;j++)
	    {
	        if(V[i-1]>j)
	        {
	            dp[i][j]=dp[i-1][j];
	        }
	        else
	        {
	            dp[i][j]=min(dp[i-1][j],dp[i-1][j-V[i-1]]+W[i-1]);
	        }
	    }
	}
	// for(long long int i=0;i<=n;i++)
	// {
	//     for(long long int j=0;j<=sum;j++)
	//     {
	//     	if(dp[i][j]==INT_MAX)
	//     	{
	//     		cout<<-1<<" ";
	//     		continue;
	//     	}
	//         cout<<dp[i][j]<<" ";
	//     }
	//     cout<<endl;
	// }   
	//cout<<dp[n][90]<<endl;
	for(int j=sum;j>=0;j--)
	{
	    if(dp[n][j]<=w)
	    {
	        cout<<j;
	        return 0;
	    }
	}
	
}

Measured memory_bytes: 79104
#include<iostream>
using namespace std;
int memo[50];
int fib(int n){
  if(memo[n] >= 0)return memo[n];
  if(n <= 1)return 1;
  return memo[n] = fib(n-1) + fib(n-2);
}

int main(){
  int n;
  cin >> n;
  fill(memo,memo+50,-1);
  cout << fib(n) << endl;
}

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

int main(void){
    int n, q, Number, count;
    bool Exist;
    vector<int> S;
    
    std::cin >> n;
    S.clear();
    for(int i = 0; i < n; i++){
        std::cin >> Number;
        if(S.empty()){
            S.push_back(Number);
        } else{
            Exist = false;
            for(int j = 0; j < S.size(); j++){
                if(Number == S[j]) Exist = true;   
            }
            if(Exist == false)  S.push_back(Number);
        }
    }
    
    std::cin >> q;
    count = 0;
    for(int i = 0; i < q; i++){
        std::cin >> Number;
        for(int j = 0; j < S.size(); j++){
            if(Number == S[j])  count++;
        }
    }
    
    std::cout << count << std::endl;
    
}

Measured memory_bytes: 1224
import sys
from collections import deque

N = int(input())
H = deque(list(map(int, input().split())))

if N == 1:
    print("Yes")
    sys.exit()

h1 = max(H.popleft()-1, 0)
h2 = H.popleft()

if h1 - h2 > 0:
    print("No")
    sys.exit()

if N == 2:
    print("Yes")
    sys.exit()

def h2_can_be_decreased(h1, h2, h3):
    if h1 == h2:
        return False
    else:
        return True

for i in range(N-2):
    h3 = H.popleft()
    if h2 - h3 > 1:
        print("No")
        sys.exit()
    elif (h2 - h3 == 1):
        if h2_can_be_decreased(h1, h2, h3):
            h2 = max(h2-1, 0)
        else:
            print("No")
            sys.exit()
    else:
        if h2_can_be_decreased(h1, h2, h3):
            h2 = max(h2-1, 0)
            pass
        pass
    
    h1 = h2
    h2 = h3

print("Yes")


Measured memory_bytes: 63984
import collections 
N = int(input())
A = [int(i) for i in input().split()]
A = collections.Counter(A)
A = sorted(A.items(), key=lambda x:x[0],reverse = True)
e = []

for k,v in A:
  if v >= 4:
    e.append(k)
    e.append(k)
  elif v >= 2:
    e.append(k)
  if len(e) >= 2:
    break
if len(e) < 2:
  ans = 0
else:
  ans = e[0]*e[1]
print(ans)

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

int main(void) {
  int N, T;
  cin >> N >> T;
  vector<P> v(N);
  vector<P> filtered;

  for (int i = 0; i < N; i++) {
    cin >> v[i].first >> v[i].second;
  }
  copy_if(v.begin(), v.end(), back_inserter(filtered),
          [=](P e) { return e.second <= T; });

  sort(filtered.begin(), filtered.end());
  cout << (filtered.size() == 0 ? "TLE" : to_string(filtered[0].first)) << endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
A, B = [], []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a if N & 1 else 2 * a)
    B.append(b if N & 1 else 2 * b)

a, b = int(np.median(A)), int(np.median(B))
if a > b:
    a, b = b, a
print(b - a + 1)

Measured memory_bytes: 45836
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n-1):
  j = 0
  if a[i+1] - a[i] == 1:
    j = a[i]
    ans += c[j-1]
    
for i in range(n):
  ans += b[i]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \
  cout << #v << "=(" << v[0];                                                  \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; }                     \
  cout << ")" << endl;
#define mdebug(m)                                                              \
  cout << #m << "=" << endl;                                                   \
  REP(i_debug, m.size()) {                                                     \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \
    cout << endl;                                                              \
  }
#define Lower_bound(v, x)                                                      \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

ll mod = 1000000007;

int main() {

  string N;
  cin >> N;
  ll L = N.size();
  vec n;
  for (auto a : N) {
    n.push_back(a - '0');
  }

  ll dp[L + 1][2][2][2][2];

  REP(x, L + 1) {
    REP(i, 2) {
      REP(j, 2) {
        REP(k, 2) {
          REP(l, 2) { dp[x][i][j][k][l] = 0; }
        }
      }
    }
    dp[x][1][0][0][0] = 1;
  }
  dp[0][1][0][0][0] = 0;
  dp[0][0][0][0][0] = 1;
  vec Nlist(3, -1);
  Nlist[0] = 3;
  Nlist[1] = 5;
  Nlist[2] = 7;
  //   vdebug(n);
  REP(x, L) {
    REP(i, 2) {
      REP(j, 2) {
        REP(k, 2) {
          REP(l, 2) {
            REP(m, 3) {
              ll y = Nlist[m];
              if (i == 0 && y > n[x]) {
                // cout << "next" << y << n[x] << endl;
                continue;
              }
              dp[x + 1][i || y < n[x]][j || y == 3][k || y == 5][l || y == 7] +=
                  dp[x][i][j][k][l];
            }
          }
        }
      }
    }
  }
  cout << dp[L][0][1][1][1] + dp[L][1][1][1][1] << endl;

  return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
delrow = []
delline = []
for i in range(w):
  whiteline = 0
  for j in range(h):
    if a[j][i] == ".":
      whiteline += 1
    if whiteline == h:
      delline.append(i)
for i in range(h):
  whiterow = 0
  for j in range(w):
    if a[i][j] == ".":
      whiterow += 1
    if whiterow == w:
      delrow.append(i)
for i in range(h):
  if i in delrow:
    continue
  else:
    ans = ""
    for j in range(w):
      if j in delline:
        continue
      else:
        ans += a[i][j]
  print(ans)

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }


/*
--------------------------------------------

	type

--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

/*
--------------------------------------------

	container

--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

/*
--------------------------------------------

	repetition

--------------------------------------------
*/
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

/*
--------------------------------------------

	constant

--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

/*
--------------------------------------------

	Optimizer

--------------------------------------------
*/
//#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
--------------------------------------------
 
	Utility Algorithm

-------------------------------------------- 
*/

template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}
 
template <typename T1>
T1 euclideanAlgorithm(T1 a, T1 b) {
    T1 a_tmp = a;
    T1 b_tmp = b;
 
    if (a_tmp > b_tmp) {
        swapAlgorithm<T1>(a_tmp, b_tmp);
    }
 
    T1 r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

template <typename T2>
T2 getLCM(T2 a, T2 b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int N;
LL a[10][10];

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;
    

    for(int k=1; k<=N; k++) {
        a[to_string(k).front() - '0'][to_string(k).back() - '0']++;
    }

    LL ans = 0;
    for(int k=1; k<=N; k++) {
        ans += a[to_string(k).back() - '0'][to_string(k).front() - '0'];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

const int MAX_N = 1e3 + 5;
const int INF = 1e9 + 5;

typedef long long ll;

int arr [MAX_N];

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

  int n;
  cin >> n;

  int mx = -INF;
  ll odds = 0;
  ll evens = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    mx = max(mx, arr[i]);

    if (arr[i] > 0) {
      if (i % 2 == 1) {
        odds += arr[i];
      } else {
        evens += arr[i];
      }
    }
  }

  if (mx <= 0) {
    int pos = 0;
    for (int i = 1; i <= n; i++) {
      if (arr[i] == mx) {
        pos = i;
        break;
      }
    }

    cout << mx << '\n';
    cout << n - 1 << '\n';
    for (int i = n; i > pos; i--) {
      cout << i << '\n';
    }
    for (int i = 1; i < pos; i++) {
      cout << 1 << '\n';
    }
    return 0;
  }
  
  vector<int> ops;
  if (evens > odds) {
    ops.push_back(1);
    for (int i = 1; i < n; i++) {
      arr[i] = arr[i + 1];
    }
    n--;
    odds = evens;
  }

  vector<int> to_keep;
  for (int i = 1; i <= n; i++) {
    if (arr[i] > 0 && i % 2 == 1) {
      to_keep.push_back(i);
    }
  }

  while (n > to_keep.back()) {
    ops.push_back(n);
    n--;
  }

  while ((int) to_keep.size() >= 2) {
    int v = to_keep.back();
    int u = *next(to_keep.rbegin());
    
    while (v > u + 2) {
      v -= 2;
      n -= 2;
      ops.push_back(u + 2);
    }

    n -= 2;
    ops.push_back(u + 1);
    to_keep.pop_back();
  }

  for (int i = 1; i < to_keep[0]; i++) {
    ops.push_back(1);
  }

  cout << odds << '\n';
  cout << (int) ops.size() << '\n';
  for (int u : ops) {
    cout << u << '\n';
  }
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
	char a,b;
	scanf("%c %c",&a,&b);
	if(a>b)
    {
	printf(">\n");
    }
    else if(a<b)
    {
      printf("<\n");
    }
    else
    {
      printf("=\n");
    }  
	return 0;
} 

Measured memory_bytes: 128
#include<iostream>

#define f first
#define s second

using namespace std;

typedef pair<int,int> P;
P now,ans;


P getans(P p1, P p2){
  int sq1 = p1.f*p1.f+p1.s*p1.s;
  int sq2 = p2.f*p2.f+p2.s*p2.s;

  if(sq1 == sq2){
    if(p1.f > p2.f) return p1;
    return p2;
  }else if(sq1 > sq2) return p1;
  else if(sq1 < sq2) return p2;
}

void init(){
  now = ans = P(0,0);
}

int main(){
  int n;
  while(cin >> n && n){

    while(n--){
      init();
      while(1){
	P p;
	cin >> p.f >> p.s;
	if(p == P(0,0)) break;
	now.f += p.f;
	now.s += p.s;
	ans = getans(ans,now);
      }

      cout << ans.first << " " << ans.second << endl;
    }
  }
  return 0;

}

Measured memory_bytes: 1160
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	int n, m;
	cin >> n;
	int x[2020];
	for (int i = 1; i <= n; i++){
		cin >> x[i];
	}
	cin >> m;
	int a[2020];
	for (int j = 1; j <= m; j++){
		cin >> a[j];
		x[a[j]] += 1;
		if (x[a[j]] == 2020)x[a[j]]--;
		if (x[a[j]] == x[a[j] + 1])x[a[j]]--;
	}
	for (int l = 1; l <= n; l++){
		cout << x[l] << endl;
	}
	return 0;
}


Measured memory_bytes: 3120
q=int(input())
a=0
b=0
g,l,ans=map(int,input().split())
r=l
now=1
from heapq import heappop, heappush
le,ri=[],[]
for i in range(q-1):
    cin=tuple(map(int,input().split()))
    if cin[0]==2:
        print(l,ans)
    else:
        x=cin[1]
        ans+=cin[2]
        if not(l<=x<=r):
            ans+=min(abs(x-l),abs(r-x))
        now+=1
        if now%2:
            heappush(le,-min(l,r,x))
            heappush(ri,max(l,r,x))
            l=l+r+x-max(l,r,x)-min(l,r,x)
            r=l
        else:
            if l<=x:
                heappush(ri,x)
                r=heappop(ri)
            else:
                heappush(le,-x)
                l,r=-heappop(le),l


Measured memory_bytes: 16816
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define mt make_tuple
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define forn(i, a) for(int i=0; i<a; i++)
#define Forn(i, a) for(int i=1; i<=a; i++)
#define read(x) ((scanf("%s", &_), (x) = _))
#define INF 1e9
#define memINF 127
#define inf 1e18
#define all(x) x.begin(), x.end()
#define MOD 1e9+7 
#define HASH 1543 

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

using namespace std;

inline int in() 
{
    int x=0, c;
    for(; (uint)((c=getchar())-'0')>=10;) 
	{ 
		if(c=='-') 
			return -in(); 
		if(!~c)
			throw ~0; 
	}
    do 
	{ 
		x=(x<<3)+(x<<1)+(c^48); 
	} 
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int gcd(int a, int b){if(a>b) swap(a, b); return a==0?b:gcd(b%a, a);}
inline int lcm(int a, int b){return a*b/gcd(a, b);}

int N, M, par[1000010], ranks[1000010], a, b, c, dist[1000010], all, newNode[1000010];
vector<pi> e[1000010];
vi adj[1000010];
bool used[1000010];

inline int find(int x)
{
	return par[x]==x?x:par[x]=find(par[x]);
}

inline void unite(int x, int y)
{
	x=find(x), y=find(y);
	if(x==y)
		return;
	if(ranks[x]<ranks[y])
		par[x]=y;
	else
	{
		par[y]=x;
		if(ranks[x]==ranks[y])
			ranks[x]++;
	}
}

int main()
{
	while(~scanf("%d %d",&N,&M))
	{
		while(M--)
		{
			a=in(), b=in();
			e[in()].eb(mp(a, b));
		}
		all=N;
		Forn(i, 1000000)
		{
			if(!e[i].size())
				continue;
			int pa;
			foreach(it, e[i])
	        {
	            used[it->f]=used[it->s]=false,
	            newNode[it->f]=newNode[it->s]=-1,
	            ranks[it->f]=ranks[it->s]=0;
	            par[it->f]=it->f;
				par[it->s]=it->s;
	        }
			foreach(it, e[i])
				unite(it->f, it->s);
			foreach(it, e[i])
	        {
	            if(!used[it->f])
	            {
	                used[it->f]=true;
	                pa=find(it->f);
	                if(newNode[pa]<=0)
	                    newNode[pa]=++all;
	                adj[it->f].eb(newNode[pa]);
	                adj[newNode[pa]].eb(it->f);
	            }
	            if(!used[it->s])
	            {
	                used[it->s]=true;
	                pa=find(it->s);
	                if(newNode[pa]<=0)
	                    newNode[pa]=++all;
	                adj[it->s].eb(newNode[pa]);
	                adj[newNode[pa]].eb(it->s);
	            }
	        }
		}
		queue<int> q;
		q.push(1);
		memset(dist, -1, sizeof(dist));
		dist[1]=0;
		while(!q.empty())
		{
			int cur=q.front();
			q.pop();
			foreach(it, adj[cur])
				if(dist[*it]<0)
					dist[*it]=dist[cur]+1, q.push(*it);
		}
		if(dist[N]<0)
			puts("-1");
		else
			printf("%d\n", dist[N]>>1);
		forn(i, all+1)
	    {
	    	e[i].clear();
	    	adj[i].clear();
	    	used[i]=0;
	    	newNode[i]=0;
	    }
	}
	return 0;
}

Measured memory_bytes: 72960
#include<bits/stdc++.h>
    using namespace std;
    #define PAIN___ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define ll long long int
    #define fi first
    #define se second
    #define pb push_back
    #define pii pair < ll, ll >
    #define mp make_pair
    #define vec vector < ll >
    #define vecp vector < pii  >
    #define forl(i,q1,n,q2) for(ll i=q1;i<q2;i++)
    #define null NULL
    #define mm 1000005



    vec v[mm];
    int main()
    {
        PAIN___;
        ll t;
        t=1;
        while(t--)
        {
            ll n;
            cin>>n;
            ll a[n];
            forl(i,0,n,n)cin>>a[i];
            ll sum[n];
            sum[0]=a[0];
            forl(i,0,n,n)sum[i+1]=sum[i]+a[i+1];
          ll ans=9999999999;
          forl(i,0,n,n)
          {
              ans=min(ans,abs(sum[i]-(sum[n-1]-sum[i])));
          }
          cout<<ans<<endl;





    }
    }



Measured memory_bytes: 23680
# データ構造queueを用いて解く問題となっている.
from collections import deque
k = int(input())

def solve(k):
    q = deque()
    ans = 0
    for i in range(1,10):
        q.append(i)
    count = 0
    while count < k:
        val = q.popleft()
        tmp = val % 10
        if tmp != 0:
            q.append(10*val + tmp - 1)
        q.append(10*val + tmp)
        if tmp != 9:
            q.append(10*val + tmp + 1)
        ans = val
        count += 1
    return ans
print(solve(k))

Measured memory_bytes: 11948
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String st;
		int a, b, c;
		int paper[][];
		int count = 0, max = 0;

		paper = new int[10][10];
		while (sc.hasNext()) {
			a = 0;
			b = 0;
			c = 0;
			st = sc.next();
			count = 0;
			max = 0;
			for (int i = 0; i < st.length(); i++) {
				a *= 10;
				a += st.charAt(i) - '0';
				if (st.charAt(i + 1) == ',') {
					for (int j = i + 2; j < st.length(); j++) {
						b *= 10;
						b += st.charAt(j) - '0';
						if (st.charAt(j + 1) == ',') {
							for (int k = j + 2; k < st.length(); k++) {
								c *= 10;
								c += st.charAt(k) - '0';
							}
							break;
						}
					}
					break;
				}
			}

			paper[a][b]++;
			if (0 <= a - 1) paper[a - 1][b]++;
			if (a + 1 < 10) paper[a + 1][b]++;
			if (0 <= b - 1) paper[a][b - 1]++;
			if (b + 1 < 10) paper[a][b + 1]++;
			if (2 <= c) {
				if (0 <= a - 1 && 0 <= b - 1) paper[a - 1][b - 1]++;
				if (0 <= a - 1 && b + 1 < 10) paper[a - 1][b + 1]++;
				if (a + 1 < 10 && 0 <= b - 1) paper[a + 1][b - 1]++;
				if (a + 1 < 10 && b + 1 < 10) paper[a + 1][b + 1]++;
				if (c == 3) {
					if (0 <= a - 2) paper[a - 2][b]++;
					if (a + 2 < 10) paper[a + 2][b]++;
					if (0 <= b - 2) paper[a][b - 2]++;
					if (b + 2 < 10) paper[a][b + 2]++;
				}
			}
		}
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (max < paper[i][j]) {
					max = paper[i][j];
				}
				if (paper[i][j] == 0) {
					count++;
				}
			}
		}
		System.out.println(count);
		System.out.println(max);
	}
}

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

int main(int argc, const char * argv[]) {
    int a;
    int b;
    string op;
    
    cin >> a >> op >> b;
    if (op == "+") {
        cout << a + b << endl;
    } else if (op == "-") {
        cout << a - b << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AOJ.Volume1
{
    public class MilkShop
    {
        public static void Main()
        {
            while (true)
            {
                int cust_num = int.Parse(Console.ReadLine());
                if (cust_num == 0) { break; }

                var wait_time = new List<int>();
                for (int i = 0; i < cust_num; i++) { wait_time.Add(int.Parse(Console.ReadLine())); }

                wait_time.Sort();
                long ans = 0;
                long tmp = 0;
                for (int i = 0; i < wait_time.Count; i++)
                {
                    ans += tmp;
                    tmp += wait_time[i];
                }
                Console.WriteLine(ans);
            }
        }
    }
}

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

const long long MOD = 1000000007;



string k;
int D;
int dp[10001][101][2];

long long dfs(int pos, int d, int lower){
    if( pos == k.size() ) return d == 0;
    if( dp[pos][d][lower] != -1) return dp[pos][d][lower];

    long long ans = 0;
    if( lower ){
        for(int i = 0 ; i < 10 ; i++){
            ans += dfs(pos+1, (d+i) % D, true);
        }
    }else{
        for(int i = 0 ; i < k[pos] - '0' ; i++){
            ans += dfs(pos+1, (d+i) % D, true);
        }
        ans += dfs(pos+1, (d+k[pos]-'0') % D, false);
    }

    return dp[pos][d][lower] = ans % MOD;
}
void solve(string K, long long D){
    k = K;
    ::D = D;
    memset(dp, -1, sizeof(dp));
    cout << (dfs(0, 0, 0) - 1 + MOD) % MOD << endl;
}

int main(){
    string K;
    cin >> K;
    long long D;
    scanf("%lld",&D);
    solve(K, D);
    return 0;
}


Measured memory_bytes: 8960
#include<iostream>

using namespace std;

int main() {
	int N = 0;	//N 焼きたいNタコ焼きの数
	int X = 0;		//X 一度に焼けるタコ焼きの数
	int T = 0;		//T かかる時間
	int total_time = {};
	int t_num=1;
	cin >> N >> X >> T;	//タコ焼きの数

	t_num = (N / X);
	total_time = (N % X);
	if (total_time != 0) {
		t_num++;
	}
	total_time = t_num * T;
	cout << total_time << endl;
	return 0;
}


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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if ((a+b+c)>21) {
        cout << "bust" << endl;
    } else cout << "win" << endl;

    return 0;
}


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

int main(){
 int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;
}

Measured memory_bytes: 3640
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

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

def readInts():
  return list(map(int,input().split()))
def main():
    X = int(input())
    sum = 0
    i = 1
    while sum <= 10**9:
        sum += i
        if sum >= X:
            print(i)
            exit()
        i += 1

if __name__ == '__main__':
  main()


Measured memory_bytes: 5148
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1010


int main(){
  int n, c, d[SIZE][SIZE], a[SIZE][SIZE];

  int counter[3][SIZE] = {};
  
  cin >> n >> c;

  for(int i=0;i<c;i++)
    for(int j=0;j<c;j++)
      scanf("%d", d[i]+j);

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      scanf("%d", a[i]+j);
      counter[(i+1+j+1)%3][a[i][j]-1]++;
    }
  }
  ll ans = LLINF;


  
  for(int i=0;i<c;i++){
    for(int j=0;j<c;j++){
      for(int k=0;k<c;k++){
        if(i == j || j == k || i == k) continue;

        int col[3] = {i, j, k};
        ll calc = 0;
        
        for(int p=0;p<c;p++){
          calc += d[p][col[0]] * counter[0][p];
          calc += d[p][col[1]] * counter[1][p];
          calc += d[p][col[2]] * counter[2][p];
        }
        
        ans = min(ans, calc);
      }
    }
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4480
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        int[][] nums = new int[3][3];
        for (int i = 0; i < 3; i ++)
            for (int j = 0; j < 3; j ++)
                nums[i][j] = scan.nextInt();
        int n = scan.nextInt();
        boolean[][] found = new boolean[3][3];
       // int ans = 0;
        for (int k = 0; k < n; k ++){
            int t = scan.nextInt();
            for (int i = 0; i < 3; i ++){
                for (int j  = 0; j < 3; j ++){
                    if (nums[i][j] == t){
                       // ans ++;
                        found[i][j] = true;
                    }
                }
            }
        }
        if ((found[0][0] && found[0][1] && found[0][2]) || (found[1][0] && found[1][1] && found[1][2]) || (found[2][0] && found[2][1] && found[2][2])
        || (found[0][0] && found[1][0] && found[2][0]) || (found[0][1] && found[1][1] && found[2][1]) || (found[0][2] && found[1][2] && found[2][2])
        || (found[0][0] && found[1][1] && found[2][2]) || (found[0][2] && found[1][1] && found[2][0]))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000009;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double bin;

  cin >> bin;
  while(bin >= 0){
    string ans;
    int bin_s = (int)bin;
    
    // 整数部
    while(bin_s != 0){
      ans += bin_s % 2 == 0? "0" : "1";
      bin_s /= 2;
    }    
    for(int i = ans.size();i < 8;i++){
      ans += "0";
    }
    
    reverse(ans.begin(), ans.end());
    ans += ".";

    // 小数部
    int cnt = 0;
    double bin_m = bin - (int)bin;
    
    while(cnt < 100 && bin_m != 0){
      cnt++;
      bin_m *= 2;
      ans += (int)bin_m == 1? "1" : "0";
      bin_m -= (int)bin_m;
    }
    
    for(int i = cnt;i < 4;i++){
      ans += "0";
    }

    if(cnt <= 4){
      cout << ans << endl;
    }else{
      cout << "NA" << endl;
    }
    cin >> bin;
  }
  return 0;
}




Measured memory_bytes: 3064
#include <iostream>

int main(){

    int ans=0;
    int r,D;
    int x[11];
    std::cin>>r>>D>>x[0];

    for(int i=1;i<=10;i++){
        x[i]=r*x[i-1]-D;
    }
    
    for(int i=1;i<=10;i++){
        std::cout<<x[i]<<std::endl;
    }
    return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

ll solve(vector<ll> &a, vector<bool> &sw) {
    ll ans = 0;
    ll sum = 0;

    ll n = a.size();
    rep(i, n) {
        sum += a[i];
        if (sw[i]) {
            if (sum <= 0) {
                ans += abs(sum - 1);
                sum = 1;
            }
        } else {
            if (sum >= 0) {
                ans += abs(sum + 1);
                sum = -1;
            }
        }
    }
    return ans;
}

int main() {
source:
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) { cin >> a[i]; }
    ll ans = 0;
    bool positive = true;
    vector<bool> sw0(n), sw1(n);
    rep(i, n) {
        if (i % 2 == 0) {
            sw0[i] = true;
        } else {
            sw0[i] = false;
        }
    }
    rep(i, n) {
        if (i % 2 == 0) {
            sw1[i] = false;
        } else {
            sw1[i] = true;
        }
    }

    ans = min(solve(a, sw0), solve(a, sw1));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, cnt = 0, ans = 1;
    cin >> n;
    while(1){
        cnt = 1;
        for(int i=2;i<=ans;i++){
            if(ans%i==0){
                cnt++;
            }
        }
        if(cnt==n){
            cout << ans << endl;
            break;
        }
        else{
            ans++;
        }
    }


    return 0;
}


Measured memory_bytes: 3104
/*
操作后距离仍然是等差数列

首项：

1. 删除编号为 $1,2$ 的，首项为 $d+2x$
2. 删除编号为 $2,3$ 的，首项为 $3d+3x$ 
3. 其他情况都不变

$d'=\frac{1}{2n}\times (d+2x)+\frac{1}{2n}\times (3d+3x)+\frac{2n-2}{2n}\times d=\frac{5x+2nd+2d}{2n}$

公差：

1. 没有取，长度为 $x$
2. 取走了，长度为 $3x$

$x'=\frac{(n+2)\times x}{2n}$

*/
#include <bits/stdc++.h>
using namespace std;
#define ld long double
int main (){
	ld n,a,x,ans=0;
	cin>>n>>a>>x;
	for (;n;n--){
		ans+=a+(2*n-1)/2*x;
		a=((2*n+2)*a+5*x)/(2*n);
		x=(n+2)*x/n;
	}
	printf ("%.13Lf",ans);
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

ll dp[100001];

int main(){
  ll N,W;cin>>N>>W;
  vector<ll>w(N),v(N);
  rep(i, N)cin>>w[i]>>v[i];

  rep(i, N){
    rrep1(j, W){
      if(j-w[i]>=0) dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
    }
//  rep(i, W+1)cout<<dp[i]<<' ';cout<<endl;  
  }

  cout<<dp[W]<<endl;


  return 0;
}

Measured memory_bytes: 1024
using System;

namespace abc96_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = Console.ReadLine().Split(' ');
            int month = int.Parse(array[0]);
            int day = int.Parse(array[1]);
            if (month <= day)
            {
                Console.WriteLine(month);
            }
            else
            {
                Console.WriteLine(month - 1);
            }
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const ll MOD = 1e9 +7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[100010];
    cin>>n;
    rep(i,n) cin>>a[i];
    bool flag =false;
    ll cnt=0;
    rep(i,n){
        if(a[i]==0){
            flag=true;
        }
        else if(a[i]<0){
            cnt++;
        }
    }
    if(cnt%2==0) flag=true;
    ll sum=0,m=INF;
    rep(i,n){
        sum +=abs(a[i]);
    }
    rep(i,n){
        m=min(m,abs(a[i]));
    }
    if(flag){
        cout<<sum<<endl;
    }
    else{
        cout<<sum-2*m<<endl;
    }
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
 
constexpr LL INF = 1e18;
LL dp[100001], dp2[100001];
LL N, T, E;
LL x[100001];
 
int main() {
    scanf("%lld %lld %lld", &N, &E, &T);
    for(int i = 1; i<=N; ++i) scanf("%lld", x+i);
    int now = 1;
    LL mn = -2*x[1];
    for(int i = 1; i<=N; ++i) {
        if( 2*(x[i] - x[1]) <= T ) {
            dp[i] = T;
            continue;
        }
        while( 2*(x[i]-x[now+1]) > T ) {
            mn = min(mn, dp[now]-2*x[now+1]);
            ++now;
        }
        dp[i] = min(dp[now]+T, mn+2*x[i]);
    }
    printf("%lld\n", dp[N]+E);
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>

int bubble_sort(int A[], int n) {
  bool flag = 1;
  int cnt = 0;
  int i = 0;
  while (flag) {
    flag = 0;
    for (int j = n - 1; 0 < j; j--) {
      if (A[j] < A[j - 1]) {
        std::swap(A[j - 1], A[j]);
        cnt++;
        flag = 1;
      }
    }
    i++;
  }
  return cnt;
}

int main() {
  int n;
  scanf("%d", &n);

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

  int cnt = bubble_sort(A, n);

  for (int i = 0; i < n; i++) {
    if (i != 0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");

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

  return 0;
}



Measured memory_bytes: 2724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n; cin>>n;
    string s; cin>>s;
    ll mod=1e9+7;
    map<char,ll> m;
    rep(i,n){
        m[s[i]]++;
    }
    ll res=1;
    rep(i,26){
        res*=m[i+'a']+1;
        res%=mod;
    }
    res--;
    if(res<0) res+=mod;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int main() {
	while (1) {
		int a, b;
		cin >> a >> b;
		if (a == 0 && b == 0) { break; }
		for (int i = 0; i < a; ++i) {
			for (int j = 0; j < b; ++j) {
				if (i == 0 || j == 0 || i == a - 1 || j == b - 1) { cout << "#"; }
				else { cout << "."; }
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3096