akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,pair<int,int>> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
ll digitsum(ll n){
    ll sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}
int main(){
    int n;cin>>n;
    if(n%digitsum(n)==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int main() {
  int N;
  ll mx = -INF;
  ll mn = INF;

  cin >> N;
  REP(i, N) {
    ll in;
    cin >> in;
    mx = max(mx, in);
    mn = min(mn, in);
  }

  cout << mx - mn << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
static const int N=100;
int main(){
  int n,p[N+1],m[N+1][N+1],i,j,l,a;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d %d",&p[i-1],&p[i]);
  for(i=1;i<=n;i++)
    m[i][i]=0;
  for(j=2;j<=n;j++){
    for(i=0;i<=n-j+1;i++){
      a=i+j-1;
      m[i][a]=(1<<21);
      for(l=i;l<=a-1;l++)
	m[i][a]=min(m[i][a],m[i][l]+m[l+1][a]+p[i-1]*p[l]*p[a]);
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}

int min(int a,int b){
  return a < b ? a : b;
}
    



Measured memory_bytes: 2108
# -*- coding: utf-8 -*-

import sys

def gcd(a, b):

    c = min(a, b)
    d = max(a, b)
    r = 0    
    while True:
        r = d % c
        if r == 0:
            break
        d = c
        c = r

    return c

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        for line in sys.stdin:
            lines.append(line)
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    # 出力
    nm = lines[0].split(" ")
    n = int(nm[0])

    rows = []
    for i in range(1, 2):
        rows.append([int(e) for e in lines[i].split(" ")])

    return (n, rows[0])

def solve(n, monsters):

    g = monsters[0]
    for i in range(1, n):
        g = gcd(g, monsters[i])


    return g

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()


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

int main(){
    int n; cin>>n;
    vector<int> a(n);

    int ans = 1e9;

    for(int i=0; i<n; i++){
        int count =0;
        cin>>a[i];
        while(a[i] % 2 == 0){
            a[i] /= 2;
            count++;
        }

        ans = min(ans,count);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<cmath>
#include <string>
#include<map> 
#include<deque>  
#include<vector>
#include<bitset>
#include<string>  
#include<cstring> 
#include<stack>  
#include<set>
#include<functional>
#define mst(x,y) memset(x,y,sizeof x)
#define mp(x,y) make_pair((x),(y))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
int x,a,b,dis[203],hed[202],K,v[202],ans=1234567890;
priority_queue<pii,vector<pii>,greater<pii> > q;
struct edge{
	int v,next,w;
}e[200005];
void adde(int u,int v,int w){
	e[K].w=w;
	e[K].v=v;
	e[K].next=hed[u];
	hed[u]=K++;
}
void g(int vl){
	q.push(mp(0,0));int u;
	dis[0]=0;
	while(!q.empty()){
		u=q.top().second;q.pop();
		for(int i=hed[u];~i;i=e[i].next){
		/*	if(vl<=v[e[i].v]&&vl+m>=v[e[i].v]&&dis[e[i].v]>dis[u]+e[i].w)
			{dis[e[i].v]=dis[u]+e[i].w;
			q.push(mp(dis[e[i].v],e[i].v));}//printf("%d:%d\n",e[i].v,dis[e[i].v])*/;
		}
	}
	return;
}
int main()
{
	scanf("%d%d%d",&x,&a,&b);
	cout<<(x-a)%b<<endl;
	return 0;
}                    

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    ll a[2][n];
    rp(i,2) rp(j,n) {
      cin >> a[i][j];
    }
    ll dp[2][n];
    rp(i,n){
        if(i == 0) dp[0][i] = a[0][0];
        else dp[0][i] = dp[0][i-1] + a[0][i];
    }
    rp(i,n){
      if(i == 0) dp[1][i] = a[0][0] + a[1][0];
      else dp[1][i] = max(dp[0][i],dp[1][i-1]) + a[1][i];
    }
    cout << dp[1][n-1]<<endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

// ソート対象の配列を出力
void printA(vector<int> A, int N)
{
    for(int i = 0; i < N; i++)
    {
        if(i == N-1) cout << A[i] << endl;
        else cout << A[i] << " ";
    }
}

// 挿入ソート
vector<int> insertionSort(vector<int> A, int N)
{
    for(int i = 1; i < N; i++)
    {
        int v = A[i];
        int j = i-1;
        while(j >= 0 && A[j] > v)
        {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        printA(A, N); // ステップごとの状態を出力
    }
    return A;
}

int main()
{
    // 入力
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    // 初期状態の配列を出力
    printA(A, N);
    // 挿入ソートを実行
    A = insertionSort(A, N);
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,k;
  cin >> a >> b >> k;
  
  int small = min(a,b);
  
  int cnt=0;
  for(int i=small;i>0;i--){
    if(a%i==0 && b%i==0){
      cnt++;
    }
    if(cnt == k){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
  
}

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

int main()
{
  int x;
  cin >> x;
  int score = 0;
  score += 1000 * (x / 500);
  x %= 500;
  score += 5 * (x / 5);
  cout << score << '\n';
  return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let k: i32 = iter.next().unwrap().parse().unwrap();
    let x: i32 = iter.next().unwrap().parse().unwrap();

    let from = x - k + 1;
    let to = x + k - 1;
    println!("{}", (from..to+1).map(|x| x.to_string()).collect::<Vec<_>>().join(" "));
    
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

#define N 200000
#define M 100

int main() {
	int d, n, i, j,cnt = 0;
	double x[N], y[N]; 

	cin >> n >> d;

	for (i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		if (sqrt(x[i] * x[i] + y[i] * y[i]) <= d) {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 6872
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("4");
            WillReturn.Add("1 2 3 4");
            //4 2 1 3
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3");
            WillReturn.Add("1 2 3");
            //3 1 2
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("1");
            WillReturn.Add("1000000000");
            //1000000000
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("6");
            WillReturn.Add("0 6 7 6 7 0");
            //0 6 6 0 7 7
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        int UB = AArr.GetUpperBound(0);
        var sb = new System.Text.StringBuilder();

        for (int I = UB; 0 <= I; I -= 2) {
            if (sb.Length > 0) sb.Append(" ");
            sb.Append(AArr[I]);
        }

        int StaInd = (UB % 2 == 0 ? 1 : 0);
        for (int I = StaInd; I <= UB; I += 2) {
            if (sb.Length > 0) sb.Append(" ");
            sb.Append(AArr[I]);
        }
        Console.WriteLine(sb.ToString());
    }
}


Measured memory_bytes: 49208
use std::io;
use std::str::FromStr;

fn main() {
    let (a,b) = {let t = reads::<i32>(); (t[0], t[1])};
    println!("{}", (a - 1) * (b - 1))
}



#[allow(dead_code)]
fn getline() -> String {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().to_string()
}

#[allow(dead_code)]
fn read<T>() -> T where T : FromStr {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn reads<T>() -> Vec<T> where T : FromStr {
    let mut ln = String::new();
    io::stdin().read_line(&mut ln).ok();
    ln.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}



Measured memory_bytes: 4352
global Q
global N
def deque():
    global head
    x=Q[1][head]
    if head+1==maxn:
        head=0
    else:
        head=head+1
    return x
def enque(i,a):
    global tail
    Q[0][tail]=Q[0][i]
    Q[1][tail]=a
    if tail+1==maxn:
        tail=0
    else:
        tail=tail+1
n,q=map(int,input().split())
Q=[[0 for j in range(n)] for i in range(2)]
N=[[0 for j in range(n)] for i in range(2)]
head=0
tail=0
for i in range(0,n):
    a,b=input().split()
    Q[0][i]=a
    Q[1][i]=(int(b))
maxn=n
i=0
k=0
time=0
while 1:
    if Q[1][i]>q:
        time=time+q
        l=deque()-q
        enque(i,l)
        i=i+1
        if i==maxn:
            i=0
    else:
        time=time+deque()
        N[0][k]=Q[0][i]
        N[1][k]=time
        i=i+1
        if tail==head and k==n-1:
            time=time+Q[1][head]
            break
        if i==maxn:
            i=0
        k=k+1
for i in range(0,n):
    print(N[0][i],end=" ")
    print(N[1][i])
        
        



Measured memory_bytes: 13444
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main(){
    unsigned long long x, a;
    cin >> x;
    int i;
    a = 100;
    for(i=1;i<4000;i++){
        a += a / 100;
        if(a>=x){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3632
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s1,s2;
    cin >>  s1 >> s2;
    int i = 0;
    int j = 0;
    int ans = s2.size();
    for(int size = 0; size <= s1.size()-s2.size(); size++){
        int count = 0;
        for(int i = 0; i < s2.size();i++){
            if(s2[i] != s1[size + i] ){
                count++;
            }
        }
        ans = min(ans,count);
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;
typedef pair<int, int> P;
using edge = struct
{
    int to;
    ll cost;
};

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

long long combination[10001][10001];

//void initC(int n);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

int ans = 0;

void solve()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i, h) cin >> s[i];
    int ans = 0;
    REP(si, h) REP(sj, w) {
        if(s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x) {
            if(dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i, j));
        };
        update(si, sj, 0);
        while(!q.empty()) {
            int i = q.front().first;
            int j = q.front().second; 
            q.pop();
            REP(dir, 4) {
                int ni = i+di[dir], nj = j+dj[dir];
                if(ni < 0||ni >= h || nj < 0|| nj >= w) continue;
                if(s[ni][nj] == '#') continue;
                update(ni, nj, dist[i][j]+1);
            }
        }
        REP(i, h) REP(j, w) {
            if(dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << "\n";
}

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

Measured memory_bytes: 256
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
HUGE_NUM = 999999999999999
MOD = 1000000007
EPS = 0.00000000001
sys.setrecursionlimit(10000)

len_A = int(input())
A = list(map(int, input().split()))

len_B = int(input())
B = list(map(int, input().split()))

B_Bigger = False

for i in range(min(len_A, len_B)):
    if A[i] != B[i]:
        B_Bigger = B[i] > A[i]
        break

    if i == len_A - 1 and i != len_B - 1:
        B_Bigger = True

if B_Bigger == True:
    print('1')
else:
    print('0')



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

using namespace std;

const int N = 1005;

int a[N], n, k;

int main(){
    scanf("%d%d", &n, &k);
    for(int i=1;i<=n;++i){
        scanf("%d",a+i);
    }

    sort(a+1,a+n+1);
    int res=0;
    for(int i=1;i<=k;++i)res+=a[i];

    printf("%d",res);
    return 0;
}


Measured memory_bytes: 3784
#include <iostream>

using namespace std;
 
int gcd(int x, int y){
  return y ? gcd(y, x%y) : x;
}

int main(){
  int x, y;
  cin >> x >> y;
  cout << (x+y)-(gcd(x, y)-1) << endl;
  return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

vector<vi> g;
vi color;
bool dfs(int v, int c = 0) {
    color[v] = c;
    for (int t : g[v]) {
        if (color[t] == 1-c) continue;
        if (color[t] == c) return false;
        if (!dfs(t, 1-c)) return false;
    }
    return true;
}

int main(){
    int n, m;
    cin >> n >> m;
    g = vector<vi>(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].pb(b);
        g[b].pb(a);
    }
    color = vi(n, -1);
    if (dfs(0)) {
        int b = 0, w = 0;
        rep(i, n) {
            if (color[i] == 1) ++w;
            else ++b;
        }
        cout << ((ll)b * w - m) << endl;
    }
    else cout << ((ll)n * (n-1) / 2 - m) << endl;
    return 0;
}


Measured memory_bytes: 9400
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

int main(int argc, char *argv[])
{
    int num, ttl, temp;
    char c;
    vector<char> v;
    map<char, int> left, right;

    cin >> num;
    ttl = num;

    left['E'] = left['W'] = 0;
    right['E'] = right['W'] = 0;

    for(int i = 0; i < num; i++){
        cin >> c;
        v.push_back(c);
        right[c]++;
    }
    for(int i = 0; i < num; i++){
        right[v[i]]--;

        temp = left['W'] + right['E'];
        if(temp < ttl){
            ttl = temp;
        }
        left[v[i]]++;
    }
    cout << ttl << '\n';
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
 
    int N, A, B; cin >> N >> A >> B;
    cout << min(N*A, B) << endl;
 
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;

int a[5];
bool used[5];
int ans;

void dfs(int time, int cur){
    if(cur == 5){
        ans = min(ans, time);
        return;
    }
    rep(i, 5)if(used[i]){
        used[i] = false;
        if(cur != 0) time = ((time-1)/10 + 1) * 10;
        dfs(time+a[i], cur+1);
        used[i] = true;
    }
}

int main(){
    rep(i, 5) cin >> a[i];
    rep(i, 5) used[i] = true;
    ans = 1000000000;
    dfs(0, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
int main() {
int h,w,i,x,y,z;
for(z=0;1;z++){
scanf("%d%d",&h,&w);
if(w==0 && h==0)break;
for(y=0;y<h;y++){
         if(y%2==0){
         for(x=0;1;x++){
         if(i<w){
         printf("#");
         i = i+1;
         }
         if(i<w){
         printf(".");
         i = i+1 ;
         }
         if(i==w) break;
         }
         }
 if(y%2==1){
         for(x=0;1;x++){
         if(i<w){
         printf(".");
         i = i+1;
         }
         if(i<w){
         printf("#");
         i = i+1 ;
         }
         if(i==w) break;
         }
         }

i=0;
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n, m;
  cin >> n >> m;
  int x = 0;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    x += a;
  }
  if (n-x < 0) cout << -1 << endl;
  else cout << n-x << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
    ll n;
    cin>>n;
    if(n==0){cout<<0<<endl;return 0;}
    string ans="";
    int odd=0;
    while(abs(n)){
        if(n%2){
            ans="1"+ans;
            if(odd)n++;
            else n--;
        }
        else ans="0"+ans;
        n/=2;
        odd=1-odd;
    }
    cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 };

long long n;
int main() {
	cin >> n;
	vector<long long>k(n + 1), l(n + 1);
	for (int i = 1; i <= n; ++i) { cin >> k[i]; }
	for (int i = 1; i <= n; ++i) { l[i] = l[i - 1] + k[i]; }
	long long ans = INF;
	for (long long i = 2; i <= n - 2; ++i) {
		long long mon = lower_bound(l.begin() + 1, l.end(), l[i] / 2) - l.begin(), monn = lower_bound(l.begin() + 1, l.end(), (l[i] + l[n]) / 2) - l.begin();
		for (long long j = max((long long)0, mon - 1); j <= min(i - 1, mon + 1); ++j) {
			for (long long kk = max(i + 1, monn - 1); kk <= min(n, (long long)monn + 1); ++kk) {
				vector<long long>v = { l[j],l[i] - l[j],l[kk] - l[i],l[n] - l[kk] };
				sort(v.begin(), v.end());
				ans = min(ans, v[3] - v[0]);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3328
// ABC177D - Friends

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<int> count;

	// n要素で初期化
	UnionFind(int n) {
		par.resize(n);
		rank.resize(n);
		count.resize(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
			count[i] = 1;
		}
	}

	// 木の根を求める。
	int find(int x) {
		if (par[x] == x) {
			return x;
		} else {
			return par[x] = find(par[x]);
		}
	}

	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) {
			return;
		}
		
		count[x] += count[y];
		count[y] = count[x];
		if (rank[x] < rank[y]) {
			par[x] = y;
		} else {
			par[y] = x;
			if (rank[x] == rank[y]) {
				rank[x]++;
			}
		}
	}

	// xとyが同じ集合に属するか否か
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// xと同じ集合の要素数を返す。
	int getCount(int x) {
		return count[x];
	}
};

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

	UnionFind tree(N);
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		tree.unite(A-1, B-1);
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans = max(ans, tree.getCount(i));
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5540
import java.util.Scanner;

public class Main {
	static char[] chars;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		chars = s.toCharArray();
		boolean bool = true;
		for(char c : chars){
			if( ! check(c)){
				bool = false;
			}
		}
		System.out.println(bool ? "Yes" : "No");
	}
	static boolean check(char c){
		int count = 0;
		for(char c1 : chars){
			if(c ==c1) {
				count++;
			}
		}
		return count == 2;
	}
}


Measured memory_bytes: 21844
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    ans = [0] * (N+1)
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                val = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if 1 <= val <= N:
                    ans[val] += 1
    for i in range(1, N+1):
        print(ans[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 69076
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int _=2e5+5,yl=1e9+7;
void inc(int &x,int y){x+=y;if(x>=yl)x-=yl;}
int  n,a[_],g[_],f[_];
int main(){
	ios::sync_with_stdio(false);
	cin>>n;f[0]=1;
	for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=1;i<=n;++i){
		f[i]=f[i-1];
		if(a[i]!=a[i-1])inc(f[i],g[a[i]]);
		g[a[i]]=f[i];
	}
	
	cout<<f[n]<<endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
	map<string,int> mp;
	string s;
	int n,maxn=-1;
	cin >> n;
	vector<string>ve(n+1);
	for(int i=0;i<n;i++)
	{
		cin >> s;
		ve[i]=s;
		mp[ve[i]]++;
		maxn=max(mp[ve[i]],maxn);
	}
	sort(ve.begin(),ve.end());
	int i=0;
	while(i<=n)
	{
		if(mp[ve[i]]==maxn) 
		{
			cout<<ve[i]<<endl;
			i+=maxn;
		}
		else i++;	
	}
}

Measured memory_bytes: 26880
import java.util.Scanner;
   
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    if (a < b && b < c) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 26104
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int cnt = 0;
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j < s.length(); j++) {
                if (i != j && s.charAt(i) == s.charAt(j)) {
                    cnt++;
                }
            }
        }
        if (cnt > 0)
            System.out.println("no");
        else
            System.out.println("yes");
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#define pb push_back
#define mp make_pair
using namespace std;

const long long INF = 2e18 + 18;

vector<long long> dp, cost;
vector<vector<long long> > c; 

void solve() {
	int n; cin >> n;
	c.resize(n, vector<long long>(n));
	dp.resize((1 << n), -INF);
	cost.resize((1 << n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> c[i][j];
		}
	}
	for (int mask = 0; mask < (1 << n); mask++) {
		long long res = 0;
		for (int i = 0; i < n; i++) {
			if (mask & (1 << i)) {
				for (int j = i + 1; j < n; j++) {
					if (mask & (1 << j)) {
						res += c[i][j];
					}
				}
			}
		}
		cost[mask] = res;
	}
	dp[(1 << n) - 1] = 0;
	for (int mask = (1 << n) - 1; mask >= 0; mask--) {
		for (int submask = mask; ; submask = (submask - 1) & mask) {
			dp[mask - submask] = max(dp[mask - submask], dp[mask] + cost[submask]);
			if (submask == 0) break;
		}
	}
	cout << dp[0] << endl;
}

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

Measured memory_bytes: 1280
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a.copy()
cost = sum(s_cost)
for k in range(1,N):
    for i in range(N):
        if s_cost[i] > a[(i-k)%N] :
            s_cost[i] = a[(i-k)%N]
    if cost > k*x + sum(s_cost):
        cost = k*x + sum(s_cost)
    else:
        break

print(cost)


Measured memory_bytes: 3316
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int w = sc.nextInt();
      int h = sc.nextInt();
      int n = sc.nextInt();
      int x1 = 0;
      int x2 = w;
      int y1 = 0;
      int y2 = h;
      int[] x = new int[n];
      int[] y = new int[n];
      int[] a = new int[n];
      for(int i = 0;i < n;i++){
      	x[i] = sc.nextInt();
        y[i] = sc.nextInt();
        a[i] = sc.nextInt();
        if(a[i]==1) x1 = Math.max(x[i],x1);
        else if(a[i]==2) x2 = Math.min(x[i],x2);
        else if(a[i]==3) y1 = Math.max(y[i],y1);
        else if(a[i]==4) y2 = Math.min(y[i],y2);
      }
      if(x1 < x2 && y1 < y2)System.out.println((x2-x1)*(y2-y1));
      else System.out.println(0);
    }
}

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

string S;
void input(){
	cin >> S;
}

int solve(){
	int i, max_cnt, cnt;
	for(i=0, cnt=0, max_cnt=0; i<S.length(); i++) {
		switch(S[i])
		{
			case 'A':
			case 'C':
			case 'G':
			case 'T':
				cnt++;
				max_cnt = max_cnt<cnt ? cnt : max_cnt;
				break;
			default:
				cnt = 0;
		}
	}
	return max_cnt;
}

int main(){
	input();
	cout << solve() << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
        char x[1000]={0};
        int i;

        scanf("%s",x);

        for(i = 0; i < 1000; i++){
                if(x[i] == NULL)
                        break;


                if(x[i] == 'A'){
                        x[i] = 'X';
                }else if(x[i] == 'B'){
                        x[i] = 'Y';
                }else if(x[i] == 'C'){
                        x[i] = 'Z';
                }else{
                        x[i] = x[i] - 3;
                }
        }


        printf("%s\n",x);


        return 0;
}

Measured memory_bytes: 524
import java.io.IOException;

public class Main {
    public static void main(String[] args) {
        StringBuilder builder = new StringBuilder();
        int l = readInt(builder), r = readInt(builder), d = readInt(builder), count = 0;
        for (int i = l; i <= r; i++) {
            if (i % d == 0) count++;
        }
        System.out.print(count);
    }
    private static int readInt(StringBuilder builder) {
        builder.setLength(0);
        while (true) {
            try {
                int b = System.in.read();
                if (b == ' ' || b == '\n' || b == -1) {
                    break;
                } else {
                    builder.appendCodePoint(b);
                }
            } catch (IOException e) {
                break;
            }
        }

        return Integer.parseInt(builder.toString());
    }
}


Measured memory_bytes: 32136
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const double pi = acos(-1.0);
const long long inf = 100000000000LL;

int main() {
	LL n; cin >> n;
	VL a(5); rep(i, 5)cin >> a[i];
	sort(all(a));

	LL min = a[0];
	LL ans = (n + a[0] - 1) / a[0] + 4;
	Cout(ans);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MAX_DIST 1LL<<50
#define NMAX 1003

ll dist[NMAX] = {0,};

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(m), b(m), c(m);

    for(int i = 0; i < m; i++){
        int at, bt ,ct;
        cin >> at >> bt >> ct;
        at--; bt--; ct = -ct;
        a[i] = at; b[i] = bt; c[i] = ct;
    }

    for(int i = 1; i < NMAX; i++){
        dist[i] = MAX_DIST;
    }

    for(int i = 0; i < n-1; i++){
        for(int j = 0; j < m; j++){
            if(dist[a[j]] == MAX_DIST){continue;}
            if(dist[b[j]] > dist[a[j]] + c[j]){
                dist[b[j]] = dist[a[j]] + c[j];
            }
        }
    }
    ll ans = -dist[n-1];

    bool negative[NMAX] = {false,};
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(dist[a[j]] == MAX_DIST){continue;}
            if(dist[b[j]] > dist[a[j]] + c[j]){
                dist[b[j]] = dist[a[j]] + c[j];
                negative[b[j]] = true;
            }
            if(negative[a[j]]){
                negative[b[j]] = true;
            }
        }
    }
    if(negative[n-1]){cout << "inf" << endl;}
    else{cout << ans << endl;}

    return 0;
}


Measured memory_bytes: 256
fun main() {
    val n = readLine()?.toInt() ?: return
    val a = readLine()?.split(" ")?.map(String::toInt) ?: return
    val colors = Array(9) { 0 }
    a.forEach {
        val i = when (it) {
            in 1..399 -> 0
            in 400..799 -> 1
            in 800..1199 -> 2
            in 1200..1599 -> 3
            in 1600..1999 -> 4
            in 2000..2399 -> 5
            in 2400..2799 -> 6
            in 2800..3199 -> 7
            else -> 8
        }
        colors[i]++
    }
    val rainbow = colors.last()
    val min = 0.until(8).count { colors[it] > 0 }
    if (min == 0) {
        println("1 $rainbow")
        return
    }
    val max = rainbow + min
    println("$min $max")
}

Measured memory_bytes: 40776
#include<bits/stdc++.h>
using namespace std;
const long long N=1<<19;
long long a[N];
long long n,pp;
struct re{
	long long num;
	long long id;
}x[5],dp[N][2];
long long maxer;
short p[N];
bool cmp(re x,re y){return x.num<y.num;}
int main()
{	

	ios::sync_with_stdio(0);
	cin>>n;
	pp=(1<<n)-1;
	for(long long i=0;i<=pp;i++){
	long long c;
	cin>>a[i];
	dp[i][0].num=a[i];
	dp[i][0].id=i;
	dp[i][1].id=-100;
	}
	for(long long i=1;i<pp;i++){
		for(long long j=0;j<n;j++)if((1<<j)&i){
		long long k=(1<<j)^i;
		x[1]=dp[k][0];
		x[2]=dp[k][1];
		x[3].num=a[i];
		x[4].num=a[1<<j];
		x[3].id=i;
		x[4].id=1<<j;
		sort(x+1,x+1+4,cmp);
		int az=0,s;
		for(int l=4;l>=1;l--)
			if(x[l].num>dp[i][0].num){
			az=1;
			re ax=dp[i][0];
			dp[i][0]=x[l];
			x[l]=ax;
			break;}
		for(int l=4;l>=1;l--)
			if(x[l].num>dp[i][1].num&&dp[i][0].id!=x[l].id)
			{dp[i][1]=x[l];}	
		}
		maxer=max(maxer,dp[i][1].num+dp[i][0].num);
		cout<<maxer<<endl;
	}
	long long i=pp;
	for(long long j=0;j<n;j++)if((1<<j)&i){
		long long k=(1<<j)^i;
		x[1]=dp[k][0];
		x[2]=dp[k][1];
		x[3].num=a[i];
		x[4].num=a[1<<j];
		x[3].id=i;
		x[4].id=1<<j;
		sort(x+1,x+1+4,cmp);
		int az=0,s;
		for(int l=4;l>=1;l--)
			if(x[l].num>dp[i][0].num){
			az=1;
			re ax=dp[i][0];
			dp[i][0]=x[l];
			x[l]=ax;
			break;}
		for(int l=4;l>=1;l--)
			if(x[l].num>dp[i][1].num&&dp[i][0].id!=x[l].id)
			{dp[i][1]=x[l];}	
		}
		maxer=max(maxer,dp[i][1].num+dp[i][0].num);
		cout<<maxer<<endl;
	return 0;
}

Measured memory_bytes: 16384
#include<bits/stdc++.h>
using namespace std;
int n[6];
int main()
{
	cin>>n[1]>>n[2]>>n[3]>>n[4];
	sort(n+1,n+4+1);
	if (n[1]==1 && n[2]==4 && n[3]==7 && n[4]==9) puts("YES");
	else puts("NO");
}

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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)

using namespace std;

using ll = long long;
using pii = pair<int, int>;

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    set<pii> ab;
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        ab.insert(pii(a, b));
    }

    vector<ll> result(10, 0);
    set<pii> used;
    for (pii p: ab) {
        int a, b;
        tie(a, b) = p;
        FOR(top, max(a - 2, 0), min(a + 1, H - 2)) {
            FOR(left, max(b - 2, 0), min(b + 1, W - 2)) {
                if (used.count(pii(top, left))) {
                    continue;
                }
                used.insert(pii(top, left));
                int n_blacks = 0;
                FOR(i, top, top + 3) {
                    FOR(j, left, left + 3) {
                        if (ab.count(pii(i, j))) {
                            ++n_blacks;
                        }
                    }
                }
                assert(n_blacks > 0);
                ++result[n_blacks];
            }
        }
    }
    result[0] = (ll)(H - 2) * (W - 2) - accumulate(result.begin() + 1, result.end(), 0ll);

    REP(j, 10) cout << result[j] << endl;

    return 0;
}

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

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; int k; cin >> n >> k;
	string s; cin >> s;
	int tmp = 0;
	rep(i, n - 1) {
		if (s[i] == s[i + 1])tmp++;
	}
	cout << min(tmp + 2 * k, n - 1) << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    VL a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];
    sort(all(a));
    sort(all(b));
    if (n % 2 == 1){
        int ni = n / 2;
        ll mx = b[ni];
        ll mn = a[ni];
        ll ans = (mx - mn) + 1;
        cout << ans << endl;
    }else{
        int nileft = (n-1) / 2, niright = n / 2;
        ll mx = (b[nileft] + b[niright]) / 2;
        ll mn = ceil((a[nileft] + a[niright]) / 2.0);
        ll ans = (mx - mn) + 1;
        ans += mx - mn;
        if ((b[nileft] + b[niright]) % 2 == 1) ans++;
        if ((a[nileft] + a[niright]) % 2 == 1) ans++;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6284
#include<bits/stdc++.h>
using namespace std;
vector<int> G[1<<11];
int d[1<<11],N,X,Y;
void bfs(int s){
  fill(d,d+(1<<11),1<<30);
  d[s]=0;
  queue<int>q;
  q.push(s);
  while(q.size()){
    int v=q.front();q.pop();
    for(auto e:G[v]){
      if(d[e]>d[v]+1){
        d[e]=d[v]+1;
        q.push(e);
      }
    }
  }
}
int main(void){
  cin>>N>>X>>Y;
  X--;Y--;
  for(int i=0;i<N-1;i++){
    G[i].push_back(i+1);
    G[i+1].push_back(i);
  }
  G[X].push_back(Y);
  G[Y].push_back(X);
  map<int,int>cnt;
  for(int i=0;i<N;i++){
    bfs(i);
    for(int j=i+1;j<N;j++)cnt[d[j]]++;
  }
  for(int k=1;k<N;k++)cout<<cnt[k]<<endl;
}


Measured memory_bytes: 512
//============================================================================
// Name        : template.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <vector>
#include <string.h> // for memset in CF judge.
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n; cin >> n;
	ll a[n];
	forn(i, n) cin >> a[i];

	ll start = 0;
	forn(i, n) {
		start ^= a[i];
	}
	forn(i, n) {
		cout <<  (start ^ a[i]) << " ";
	}


	return 0;
}


Measured memory_bytes: 5168
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0, cnt = 0;
    rep(i,s.size()){
        if(s[i] == 'S') ++cnt;
        else --cnt;
        if(cnt < 0){
            ++ans;
            cnt = 0;
        }
    }
    ans += cnt;
    cout << ans << endl;
    return 0;
}


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

int a[100];
int main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	reverse(a, a + n);
	rep(i, n) {
		if (i)cout << ' ';
		cout << a[i];
	}
	cout << endl;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

// 1825

int main() {
  int n, k;
  cin >> n >> k;
  vl v(n);
  rep (i, n) cin >> v[i];

  ll ans = 0;
  rep (l, n + 1) {
    rep (r, n + 1) {
      if (l + r > n) break;
      if (l + r > k) break;
      vi a;
      rep (i, l) a.push_back(v[i]);
      rep (i, r) a.push_back(v[n - 1 - i]);
      sort(all(a));
      reverse(all(a));
      rep (i, k - (l + r)) {
        if (a.size() > 0 and a.back() < 0) a.pop_back();
        else break;
      }

      ll sum = 0;
      rep (i, a.size()) sum += a[i];
      chmax(ans, sum);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s:String = read();
    let p:String = read();
    let ring = s.repeat(2);
    println!("{}", if ring.contains(&p) {"Yes"} else {"No"});

}



Measured memory_bytes: 5040
#include <iostream>
using namespace std;
int dp[10000][31];
int Over(int k, int l)
{
	while(l>=1)
	{
		if(dp[k][l]>=2) break;
		else l--;
	}
	return l;
}
int main()
{
	while(1)
	{
		int n; cin >> n;
		if(!n) break;
		dp[0][0]=1; dp[0][1]=n;
		int s=1; int k=0;
		while(n!=1 && s>0)
		{
			int sum=0;
			for(int i=1;i<s;i++) dp[k+1][i]=dp[k][i], sum+=dp[k][i];
			dp[k+1][s]=dp[k][s]-1; sum+=dp[k+1][s];
			dp[k+1][s+1]=n-sum;
			while(dp[k+1][s+1]>dp[k+1][s])
			{
				dp[k+1][s+1]=dp[k+1][s]; sum+=dp[k+1][s+1];
				dp[k+1][s+2]=n-sum; s++;
			}
			dp[k+1][0]=s+1; k++;

			s=Over(k,dp[k][0]);
		}
		
		for(int j=0;j<=k;j++)
		{
			for(int i=1;i<=dp[j][0];i++)
			{
				if(i!=1) cout << ' ' ;	cout << dp[j][i] ;
			}
			cout << '\n' ;
		}
		
	}
}

Measured memory_bytes: 1716
#include<vector>
#include <iostream>
#include<algorithm>
#include <unordered_map>
//#include <bits/stdc++.h>

using namespace std;


int main(){
    int n;

    cin >> n;

    vector<string> s(n);

    for(int i = 0; i < n; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }

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

    int cnt = 0;
    long long a = 0;
    for(int i = 1; i < n; i++){
        if(s[i] == s[i-1]){
            //cout << s[i-1] << endl;
            cnt++;
            a += cnt;
        }else{
            cnt = 0;
        }
    }

    cout << a << endl;
}


Measured memory_bytes: 7296