akhauriyash/Code-Regression huggingface dataset:
use std::collections::BinaryHeap;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let a: Vec<u64> = sc.vec(n);
    let mut b: Vec<u64> = sc.vec(n);
    if (0..n).any(|i| b[i] < a[i]) {
        println!("-1");
        return;
    }

    let mut heap = BinaryHeap::new();
    for i in 0..n {
        try_push(&mut heap, &a, &b, i);
    }

    let mut ans = 0;
    while let Some((_, i)) = heap.pop() {
        let prev = b[(i + n - 1) % n];
        let next = b[(i + 1) % n];
        let diff = b[i] - a[i];
        let count = diff / (prev + next);
        ans += count;
        b[i] -= count * (prev + next);
        try_push(&mut heap, &a, &b, (i + 1) % n);
        try_push(&mut heap, &a, &b, (i + n - 1) % n);
    }
    if a == b {
        println!("{}", ans);
    } else {
        println!("-1");
    }
}

fn try_push(heap: &mut BinaryHeap<(u64, usize)>, a: &[u64], b: &[u64], i: usize) {
    let n = a.len();
    let prev = b[(i + n - 1) % n];
    let next = b[(i + 1) % n];
    let diff = b[i] - a[i];
    let count = diff / (prev + next);
    if count > 0 {
        heap.push((count, i));
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10492
#include<bits/stdc++.h>
using namespace std;
int a[10][10];
int main()
{
	int h,w,m,n,s=0;
	cin>>h>>w;
	int b[h][w];
	for(int i=0;i<10;i++)
	for(int j=0;j<10;j++)
	{
		cin>>m;
		a[i][j]=m;
	}
	for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	{
		cin>>n;
		b[i][j]=n;
	}
	for(int k=0;k<10;k++)
	for(int i=0;i<10;i++)
	for(int j=0;j<10;j++)
	a[i][j]=min(a[i][k]+a[k][j],a[i][j]);
	for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	if(b[i][j]!=-1)
	s+=a[b[i][j]][1];
	cout<<s;
}

Measured memory_bytes: 384
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#include <random>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

int main() {
    int N; vector<int> v(3);
    cin >> N;
    for(int i=0; i<3; i++) cin >> v[i];

    vector<string> vs(N);
    for(int i=0; i<N; i++) cin >> vs[i];
    
    string pat = "ABC", ans = "";
    for(int i=0; i<N; i++) {
        string s = vs[i];
        int p = pat.find(s[0]), q = pat.find(s[1]);
        if(!v[p] and !v[q]) {
            puts("No");
            return 0;
        }
        if(v[p] == 1 and v[q] == 1 and i+1<N) {
            string t = vs[i+1];
            int x = pat.find(t[0]), y = pat.find(t[1]);
            if(p == x or p == y) {
                ans += pat[p];
                v[p]++; v[q]--;
            }
            else {
                ans += pat[q];
                v[q]++; v[p]--;
            }
        }
        else if(v[p] > v[q]) {
            ans += pat[q];
            v[q]++; v[p]--;
        }
        else {
            ans += pat[p];
            v[p]++; v[q]--;
        }
    }
    puts("Yes");
    for(auto c : ans) cout << c << endl;
    return 0;
}


Measured memory_bytes: 6692
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

struct node
{
    int x,y,id;
};
struct edge
{
    int u,v;
    double cost;
    edge() {}
    edge(int x,int y,double z)
    {
        u=x;
        v=y;
        cost=z;
    }
    bool operator <(const edge& a) const
    {
        return cost>a.cost;
    }
};

edge es[50010];
int par[10010];
node p[10010];
int n,m;
void init()
{
    for(int i=1;i<=n;i++) par[i]=i;
}

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

void unite(int x,int y)
{
    x=find(x);
    y=find(y);
    if(x!=y) par[x]=y;
}

double dis(int a,int b)
{
    return sqrt(1.0*(p[a].x-p[b].x)*(p[a].x-p[b].x)+1.0*(p[a].y-p[b].y)*(p[a].y-p[b].y));
}

double kruskal()
{
    sort(es,es+m);
    //for(int i=0;i<m;i++) printf("%d %d %lf\n",es[i].u,es[i].v,es[i].cost);
    double s=0;
    for(int i=0;i<m;i++)
    {
        edge e=es[i];
        if(find(e.u)!=find(e.v))
        {
            unite(e.u,e.v);
        }
        else
        {
            s+=e.cost;
        }
    }
    return s;
}
int main()
{
    //freopen("a.txt","r",stdin);
    int a,b;
    double c,sum;
    while(~scanf("%d%d",&n,&m))
    {
        init();
        sum=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&p[i].x,&p[i].y);
        }
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&a,&b);
            c=dis(a,b);
            es[i]=edge(a,b,c);
        }
        printf("%.3lf\n",kruskal());
    }
    return 0;
}

Measured memory_bytes: 3296
#include<bits/stdc++.h>
#define fori(x,a,b) for (int x=a;x<=b;x++)
#define fi first
#define se second
using namespace std;
const int K = 1e5+10;
int a[110],n,k;
bool f[K];
int main()
{
    cin>>n>>k;
    fori(i,1,n) cin>>a[i];
    fori(s,1,k)
    {
        fori(i,1,n)
        {
            if (s>=a[i] && !f[s-a[i]])
            {
                f[s] = true;
            }
        }
    }
    if (f[k]) cout<<"First";
    else cout<<"Second";
}


Measured memory_bytes: 3688
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        String s = stdIn.next();
        String p = stdIn.next();
        s += s;
        boolean flag;

        for (int i = 0; i < s.length() / 2; i++) {
            if (s.charAt(i) == p.charAt(0)) {
                flag = true;
                for (int j = i + 1, k = 1; k < p.length(); j++, k++) {
                    if (s.charAt(j) != p.charAt(k)) {
                        flag = false;
                    }
                }
                if (flag) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}





Measured memory_bytes: 26236
def main():
    import bisect
    n, m, *py = map(int, open(0).read().split())
    d = [[] for _ in range(n+1)]
    for i,j in zip(*[iter(py)]*2):
        d[i].append(j)

    for i in d:
        i.sort()

    ans = ''
    for i, j in zip(*[iter(py)] * 2):
        k = bisect.bisect_right(d[i], j)
        ans += str(i).zfill(6) + str(k).zfill(6) + '\n'

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26460
import sys
from collections import defaultdict
def dfs(d,y,x,f):
    global ans
    if d >= 10:
        return
    f_ = defaultdict(int)
    for i in f.keys():
        f_[i] = f[i]
    for t,s in vr[(y,x)]:
        if a[t][s] == 3:
            ans = min(ans,d+1)
            break
        elif f[(t,s)]:
            if s == x+1:
                break
            f_[(t,s)] = 0
            dfs(d+1,t,s-1,f_)
            f_[(t,s)] = 1
            break

    for t,s in vl[(y,x)]:
        if a[t][s] == 3:
            ans = min(ans,d+1)
            break
        elif f[(t,s)]:
            if s == x-1:
                break
            f_[(t,s)] = 0
            dfs(d+1,t,s+1,f_)
            f_[(t,s)] = 1
            break

    for t,s in vd[(y,x)]:
        if a[t][s] == 3:
            ans = min(ans,d+1)
            break
        elif f[(t,s)]:
            if t == y+1:
                break
            f_[(t,s)] = 0
            dfs(d+1,t-1,s,f_)
            f_[(t,s)] = 1
            break

    for t,s in vu[(y,x)]:
        if a[t][s] == 3:
            ans = min(ans,d+1)
            break
        elif f[(t,s)]:
            if t == y-1:
                break
            f_[(t,s)] = 0
            dfs(d+1,t+1,s,f_)
            f_[(t,s)] = 1
            break
    return
while 1:
    w,h = map(int, sys.stdin.readline()[:-1].split())
    if w == h == 0:
        break
    a = [list(map(int, sys.stdin.readline()[:-1].split())) for i in range(h)]
    vr = defaultdict(list)
    vl = defaultdict(list)
    vd = defaultdict(list)
    vu = defaultdict(list)
    f = defaultdict(int)
    for y in range(h):
        for x in range(w):
            if a[y][x] == 1:
                f[(y,x)] = 1
            if a[y][x] in [1,3]:
                for x_ in range(x):
                    vr[(y,x_)].append((y,x))
            elif a[y][x] == 2:
                sy,sx = y,x
    for y in range(h):
        for x in range(w)[::-1]:
            if a[y][x] in (1,3):
                for x_ in range(x+1,w):
                    vl[(y,x_)].append((y,x))
    for x in range(w):
        for y in range(h):
            if a[y][x] in (1,3):
                for y_ in range(y):
                    vd[(y_,x)].append((y,x))
    for x in range(w):
        for y in range(h)[::-1]:
            if a[y][x] in (1,3):
                for y_ in range(y+1,h):
                    vu[(y_,x)].append((y,x))
    ind = [[[0]*4 for i in range(w)] for j in range(h)]
    ans = 11
    dfs(0,sy,sx,f)
    ans = ans if ans < 11 else -1
    print(ans)



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

using namespace std;

int main(){
	int n, k;
	cin>>k>>n;
	vector<int> a(n);
	for(int i = 0; i<n; i++){
		cin>>a[i];
		}
	int m = -1;
	for(int i = 0; i<n-1; i++){
		m = max(m, a[i+1]-a[i]);
		}
		
	m = max(m, abs(a[0]+k - a[n-1]));
	cout<<k-m;
	return 0;
	}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define mt make_tuple
#define s second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eps 1e-7
#define endl "\n"
#define ll long long int
#define mp make_pair
#define p_q priority queue

using namespace std;
     

     int a[100005];
int vis[100005]={0};
 vector< int > adj[100005];

    
// int power(int x, unsigned int y) 
// { 
//     int temp; 
//     if( y == 0) 
//         return 1; 
//     temp = power(x, y/2); 
//     if (y%2 == 0) 
//         return temp*temp; 
//     else
//         return x*temp*temp; 
// } 
     

bool vowl(char c)
{
  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}
 
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;    
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 
bool check(ll n, ll p) 
{ 
    if (power(n, (p-1)/2, p) == 1) 
       return true; 
  
    return false; 
} 

int dfs(int source,int vertex_covered)
{
  vis[source]=1;
  if(adj[source].size()==1)
  {
    int v=adj[source][0];
    if(vis[v])
    {
      a[source]=1; 
      return 1;// means i cannot remove that edge
    }
  }

  for(int j=0;j<adj[source].size();j++)
  {
    if(!vis[adj[source][j]])
    {
      vertex_covered+=dfs(adj[source][j],1);
    }
  }
  //cout<<source<<"--->"<< vertex_covered<<endl;
   
   a[source]= vertex_covered;
   return vertex_covered;

    

}
 
 
int main()
{
    fast;
    int t=1;
   // cin>>t;
    while(t--)
    {
      int n;
      cin>>n;
      int a,b,c1=0,c2=0,c3=0;
      cin>>a>>b;
      for(int i=0;i<n;i++)
      {
        int x;
        cin>>x;
        if(x<=a)
        {
          c1++;
        }
        else if(x>=a+1 && x<=b)
        {
          c2++;
        }
        else if(x>=b+1)
        {
          c3++;
        }
      }
      int ans=min(min(c1,c2),c3);
      cout<<ans<<endl;
      
    }




    return 0;  
}

Measured memory_bytes: 2560
n,m = map(int,input().split())
a = [int(input()) for i in range(m)]
#print(n,m,a)

ans = [0]*(n+1)
ans[0] = 1
for i in range(m):
  ans[a[i]] = -1
for i in range(1,n+1):
  if i > 1:
    if ans[i] != -1:
      if ans[i-2] != -1:
        ans[i] += ans[i-2]
      if ans[i-1] != -1:
        ans[i] += ans[i-1]
  else:
    if ans[i] != -1:
      ans[i] = ans[i-1]
#print(ans)
print(ans[n]%1000000007)

Measured memory_bytes: 462708
#include <stdio.h>
#define N 25
#define NIL -1

struct Node{
  int parent,left,right;
};
struct Node T[10000];
int n,D[10000],H[10000];
int setHeight(int);
void setDepth(int,int);
//節点uの兄弟を返す
int brosend(int);
void print(int);

int main(){
  int n,i,v,l,r;
  int root=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    T[i].parent=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL)T[l].parent=v;
    if(r!=NIL)T[r].parent=v;
  }
  for(i=0;i<n;i++){
    if(T[i].parent==NIL)
      root=i;
  }
  setDepth(root,0);
  setHeight(root);
  for(i=0;i<n;i++)
    print(i);
  return 0;
}
int setHeight(int k){
  int h1=0,h2=0;
  if(T[k].left!=NIL)
    h1=setHeight(T[k].left)+1;
  if(T[k].right!=NIL)
    h2=setHeight(T[k].right)+1;
  return H[k]=(h1>h2?h1:h2);
}
void setDepth(int k,int g){
  if(k==NIL) return;
  D[k]=g;
  setDepth(T[k].left,g+1);
  setDepth(T[k].right,g+1);
}
int brosend(int k){
  if(T[k].parent==NIL)
    return NIL;
  if(T[T[k].parent].left!=k&&T[T[k].parent].left!=NIL)
    return T[T[k].parent].left;
  if(T[T[k].parent].right!=k&&T[T[k].parent].right!=NIL)
    return T[T[k].parent].right;
  return NIL;
}
void print(int k){
  printf("node %d: ",k);
  printf("parent = %d, ",T[k].parent);
  printf("sibling = %d, ",brosend(k));
  int deg=0;
  if(T[k].left!=NIL)deg++;
  if(T[k].right!=NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[k]);
  printf("height = %d, ",H[k]);

  if(T[k].parent==NIL){
    printf("root\n");
  }
  else if(T[k].left==NIL&&T[k].right==NIL){
    printf("leaf\n");
  }
  else {
    printf("internal node\n");
  }
}
  
  



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


int main(){
  int val1, val2;
  vector<pair<int,int> >v;
  while(cin >> val1 >> val2 && (val1 || val2)){
    if(val1 > val2){
      swap(val1, val2);
    }
    v.push_back(make_pair(val1, val2));
  }
  for(int i=0;i<(int)v.size();i++){
    cout << v[i].first << " " << v[i].second << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int a, v; cin >> a >> v;
    int b, w; cin >> b >> w;
    int t; cin >> t;
    if (abs(a-b) <= (ll)t*(v-w)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <limits>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <array>
#include <tuple>
#include <utility>
#include <cctype>
#include <typeinfo>
using namespace std;

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define ii(n)    ff(i, n)
#define kk(n)    ff(k, n)
#define mm(n)    ff(m, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define iii(a, b) fff(i, a, b)
#define kkk(a, b) fff(k, a, b)
#define mmm(a, b) fff(m, a, b)
#define xx first
#define yy second
#define bb begin()
#define ee end()
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#define zz(array, byte)   memset(array, byte, sizeof(array));

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


const LL INF = 9223372036854775807LL;
//const int INF = 2147483647;
   
const LL MOD = LL(1e9) + 7;



LL expmod(LL a, LL b) {
    if (0 == b) return 1LL;
    LL rr = expmod(a, b >> 1);
    rr = (rr * rr) % MOD;
    if (b & 1)
        return (rr * a) % MOD;
    return rr;
}

const int MAXCOMB = 1007;
LL factorial[MAXCOMB];
LL inverse[MAXCOMB];


LL choose(int n, int k) {
    LL rr = (factorial[n] * inverse[n-k]) % MOD;
    return (rr * inverse[k]) % MOD;
}

int N, A, B, C, D;

LL cache[1007][1007];
LL dp(int remaining, int nextsize) {
    if (remaining == 0)
        return 1LL;
    if (nextsize > B)
        return 0;
    if (nextsize > remaining)
        return 0;
    LL &entry = cache[remaining][nextsize];
    if (-1LL != entry)
        return entry;

    LL rr = dp(remaining, nextsize+1);
    fff (gcount, C, D+1) {
        if (gcount*nextsize > remaining)
            break;
        LL further = dp(remaining - gcount*nextsize, nextsize+1);
        if (0 == further)
            continue;
        int rem = remaining;
        ii (gcount) {
            further = (further * choose(rem, nextsize)) % MOD;
            rem -= nextsize;
        }
        further = (further * inverse[gcount]) % MOD;
        rr = (rr + further) % MOD;
    }       
    //printf("Putting %d for %d %d\n", int(rr), remaining, nextsize);

    return entry = rr;
}


int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout << '\n';
    
    zz(cache, -1);
    factorial[0] = 1LL;
    iii (1, MAXCOMB)
        factorial[i] = (factorial[i-1] * LL(i)) % MOD;
    ii (MAXCOMB)
        inverse[i] = expmod(factorial[i], MOD-2);

    cin >> N >> A >> B >> C >> D;

    
    LL rr = dp(N, A);


    cout << rr << '\n';

    return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll MOD = 1000000007;
ll INF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
ll power_mod(ll x, ll y, ll m){
  ll res = 1;
  if(y>0){
    res = power_mod(x,y/2,m);
    if(y%2==0) res = (res*res)%m;
    else res = (((res*res)%m)*x)%m;
  }
  return res;
}
//-----------------------------------------

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  cin >> n;

  ll ans1 = power_mod(10, n, MOD);
  ll ans2 = power_mod(9, n, MOD);
  ll ans3 = power_mod(8, n, MOD);
  cout << (ans1 - 2 * ans2 + ans3 + MOD * MOD )% MOD << endl;

    
    
  return 0;
}



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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int A, B;

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

  std::cin >> A >> B;

  int res = std::max({A + B, A - B, A * B});
  std::cout << res << std::endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)
N = int(input())
a = list(map(int, input().split()))
suma = [0, a[0]]
for i in range(1, N):
    suma.append(suma[-1] + a[i])
inf = float("inf")
dp = [[-1 for i in range(N+1)] for j in range(N+1)]
# dp[i][j]は区間[i, j)での最小のコスト

# メモ化再帰
def rec(l, r):
    if r - l == 0:
        dp[l][r] = 0
        return 0
    elif r - l == 1:
        dp[l][r] = a[l]
        return a[l]

    if dp[l][r] != -1:
        return dp[l][r]

    # r - l >= 2である
    # iを媒介にdpを貪欲に探索する。
    res = inf
    for pos in range(l+1, r):
        tmp = 0
        if pos - l > 1:
            tmp += rec(l, pos) + suma[pos] - suma[l]
        else:
            tmp += rec(l, pos)
        if r - pos > 1:
            tmp += rec(pos, r) + suma[r] - suma[pos]
        else:
            tmp += rec(pos, r)
        res = min(res, tmp)
    dp[l][r] = res
    return res

print(rec(0, N))

Measured memory_bytes: 76016
#include <stdlib.h>
#include <iostream>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int gcd(int x, int y)
{
    if (y == 0)
    {
        return x;
    }
    return gcd(y, x % y);
}

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

    ll ans = 0;
    for (int a = 1; a <= K; a++)
    {
        for (int b = 1; b <= K; b++)
        {
            for (int c = 1; c <= K; c++)
            {
                ans += gcd(gcd(a, b), c);
            }
        }
    }

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

Measured memory_bytes: 3632
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
using namespace std;
const ll INF = 1e10;
int a,b,c,x,y,tmp;
vector<int> m(105);
int main(){
  cin>>a>>b>>c>>x>>y;
  
  if(x>y){
    tmp=y;
    y=x;x=tmp;
    tmp=b;
    b=a;a=tmp;
  }
    
  cout<<min(min(y*2*c,x*a+y*b),x*2*c+(y-x)*b)<<endl;
  
  return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    vector<int> a(4);
    vector<int> t = {1,4,7,9};

    cin>>a[0]>>a[1]>>a[2]>>a[3];

    sort(all(a));
    //cout <<fixed<<setprecision(16)<< << endl;



    if(a == t)cout << "YES" <<endl;
    else cout << "NO" <<endl;

    return 0;
}


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

typedef long long ll;
#define pii pair<pii , pii>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 200005

int n , m;
int s = 0;
bool used[MAXX];
vector<int> adj[MAXX];
void DFS(int node){
    used[node] = true;
    s++;
    for(int i = 0; i < adj[node].size(); i++){
        int to = adj[node][i];
        if(!used[to]){
            DFS(to);
        }
    }
}

int main()
{
    _FastIO;

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x , y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    memset(used , false , sizeof(used));
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(!used[i]){
            s = 0;
            DFS(i);
            ans = max(ans , s);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 20912
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
using namespace std;
#define t_max 10000001
char M[1001][1001];
short S[1001][1001];
int P[1001][1001];
char table[t_max];
vector<pair<short,short> >m(t_max);
int m_rev[t_max];
pair<short,int> dfs(int x,int y){
	if(y==1001)return make_pair(0,0);
	if(S[x][y]>=0)return make_pair(S[x][y],P[x][y]);
	int m=0,m_place=0,i=-1;
	for(;i<2;i++){
		if(x+i<0||1000<x+i)continue;
		pair<short,int> p=dfs(x+i,y+1);
		if(m<p.first||(m==p.first&&m_place<p.second))m=p.first,m_place=p.second;
	}
	if(m==0){
		if(M[x][y])return make_pair(S[x][y]=1,P[x][y]=m_rev[x*1001+y]);
		return make_pair(S[x][y]=0,P[x][y]=0);
	}else{
		return make_pair(S[x][y]=m+M[x][y],P[x][y]=m_place);
	}
}
main(){
	int k=1,z,x,y,i,n,s;
	m[k]=make_pair(x=500,y=500),m_rev[x*1001+y]=k,k++;
	for(z=2;z<=1000;z+=2){
		x++,y++;
		for(i=0;i<z;i++)m[k]=make_pair(x,--y),m_rev[x*1001+y]=k,k++;
		for(i=0;i<z;i++)m[k]=make_pair(--x,y),m_rev[x*1001+y]=k,k++;
		for(i=0;i<z;i++)m[k]=make_pair(x,++y),m_rev[x*1001+y]=k,k++;
		for(i=0;i<z;i++)m[k]=make_pair(++x,y),m_rev[x*1001+y]=k,k++;
	}
	table[0]=table[1]=1;
	for(x=2;x<t_max;x++)if(!table[x])for(y=x*2;y<t_max;y+=x)table[y]=1;
	for(;scanf("%d%d",&n,&s),n;){
		memset(M,0,sizeof(M));
		memset(S,0xff,sizeof(S));
		memset(P,0,sizeof(P));
		for(i=1;i<=n;i++)if(!table[i])M[m[i].first][m[i].second]=1;
		pair<short,int> p=dfs(m[s].first,m[s].second);
		printf("%d %d\n",p.first,p.second);
	}
}

Measured memory_bytes: 60948
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> c(H);
	for (int i = 0; i < H; i++)
		cin >> c[i];

	int ans = 0;
	for (int bitH = 0; bitH < (1 << H); bitH++) {
		for (int bitW = 0; bitW < (1 << W); bitW++) {
			int black = 0;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if ((((bitH >> i) & 1) == 0)  && (((bitW >> j) & 1) == 0) && c[i][j] == '#') {
						black++;
					}
				}
			}
			if (black == K) {
				ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <locale>
#include <list>
using namespace std;
#define FORN(i,m,n) for(ll i=m; i<ll(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
#define p_b(x) push_back(x)
#define m_p(a,b) make_pair(a,b)
typedef long long ll;
typedef long double ld;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n; cin>>n;
  string s; cin>>s;
  bool flag = !(n & 1);
  int m = n >> 1;
  FORN(i,0,m){
    if(s[i] != s[i+m]) flag = false;
  }
  cout<<(flag?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

int main()
{
    long long N, K;
    cin >> N >> K;
    deque<long long> D;
    rep(i, N)
    {
        long long V;
        cin >> V;
        D.push_back(V);
    }

    long long ans = 0;
    for (long long l = 0; l < min(N, K) + 1; l++)
    {
        for (long long r = 0; r < min(N, K) + 1; r++)
        {
            if (l + r > K)
                continue;
            deque<long long> d = D;
            priority_queue<long long, vector<long long>, greater<long long>> dust;
            rep(i, l)
            {
                if (d.size() == 0)
                    break;

                dust.push(d.front());
                d.pop_front();
            }

            rep(i, r)
            {
                if (d.size() == 0)
                    break;

                dust.push(d.back());
                d.pop_back();
            }

            rep(i, K - (l + r))
            {
                if (dust.size() == 0)
                    break;

                if (dust.top() < 0)
                    dust.pop();
            }

            long long cost = 0;

            while (dust.size())
            {
                cost += dust.top();
                dust.pop();
            }

            //cout << l << ", " << r << ":" << cost << endl;
            ans = max(cost, ans);
        }
    }

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef unsigned long long ll;

const ll M = 1000000007;

ll power(ll x, int n)
{
    if(n == 0) return 1;
    if(n%2 == 0) return power((x*x) % M, n/2) % M;
    if(n%2) return (power((x*x) % M, n/2) * x) % M;
}

int main()
{
    ll x;
    int n;
    cin >> x >> n;
    cout << power(x, n) << endl;
}



Measured memory_bytes: 3092
def solve(n,y)
0.upto(n) do |i|
0.upto(n-i) do |j|
k=n-i-j
return  [i,j,k] if 10000*i+5000*j+1000*k==y
end
end
[-1,-1,-1]
end
puts solve(*gets.split.map(&:to_i))*" "

Measured memory_bytes: 1916
#include <iostream>

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

    long long X;
    std::cin >> X;
    constexpr int RANGE_MAX = 178;
    long long pow5[RANGE_MAX];
    for (int i = 0; i < RANGE_MAX; i++)
    {
        long x = i;
        pow5[i] = x * x * x * x * x;
    }

    for (int A = 0; A < RANGE_MAX; A++)
    {
        for (long long B = 0; B < A; B++)
        {
            if (pow5[A] - pow5[B] == X)
            {
                std::cout << A << " " << B << std::endl;
                return 0;
            }
            else if (pow5[A] + pow5[B] == X)
            {
                std::cout << A << " " << -B << std::endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;

typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

lint mod = 998244353;

lint pow(lint a, lint n){
    lint ans = 1;
    lint base = a;
    while(n>0){
        if (n%2) ans = ans*base%mod;
        n = n/2;
        base = base*base%mod;
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);



    lint n; cin>>n;
    vector<pll> rt(n);
    for (int i=0; i<n; ++i) cin>>rt[i].first>>rt[i].second;
    sort(rt.begin(), rt.end());

    vl last(n);
    stack<pll>  seg;

    last[n-1] = n-1;
    seg.push({n-1, n-1});
    for (int id = n-2; id >=0; --id){
        lint r = rt[id].first + rt[id].second;
        while(!seg.empty()){
            pll left = seg.top();
            if (r > rt[left.first].first){
                seg.pop();
            } else {
                break;
            }
        }
        lint rid = n-1;
        if (!seg.empty()){
            rid = seg.top().first - 1;
        }
        seg.push({id, rid});
        last[id] = rid;

    }

    vl ans(n+1, -1);
    ans[n] = 1;
    for (int i= n-1; i>=0; --i){
        ans[i] = ans[last[i]+1];
        ans[i] = (ans[i+1] + ans[i])%mod;
    }
    cout<<ans[0];

}


Measured memory_bytes: 8192
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
int main() {
	int a, b;
	cin >> a >> b;
	cout << (a * 3 + b) / 2 << endl;
}

Measured memory_bytes: 4992
// doot diddly donger cuckerino Hahahahahah


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")

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

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vi = vector<int>;

template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = acos(-1);

template <typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

class CGeTAC {
public:
  
  void solve(std::istream& cin, std::ostream& cout) {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> dp(n + 1);
    for (int i = 0; i < n; ++i) {
      dp[i + 1] = dp[i] + (s[i] == 'A' and s[i + 1] == 'C');
    }
    while (q--) {
      int l, r;
      cin >> l >> r;
      cout << (dp[r - 1] - dp[l - 1]) << '\n';
    }
  }
};

int32_t main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
	CGeTAC solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3860
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 R, G, B, N;
  cin >> R >> G >> B >> N;

  i64 ans = 0;
  rep(r,(N/R)+1) rep(g,((N-r*R)/G)+1){
    if((N-r*R-g*G)%B==0) ans++;
  }
  cout << ans << "\n";



}

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

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) begin(c), end(c)
template<class T> void read(T& x){ cin>>x; }
void read(int& x){ scanf("%d", &x); }
void read(int64_t& x){ scanf("%lld", &x); }
void read(double& x){ scanf("%lf", &x); }
template<class T, class U, class... V>
void read(T& x, U& y, V&... z){ read(x); read(y, z...); }

int main(){
    int n,y; read(n,y);
    y/=1000;
    int i,j,k;
    for(i=0; 10*i<=y; ++i){
        for(j=0; 10*i+5*j<=y; ++j){
            k=y-10*i-5*j;
            if(i+j+k==n){
                printf("%d %d %d",i,j,k);
                return 0;
            }
        }
    }
    printf("-1 -1 -1");
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstdio>

using namespace std;

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

struct Edge {int to, dis, c;};

struct Status{
  double cost;
  int pos, pre, v;
  bool operator<(const Status &s) const {return cost > s.cost;}
};

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) break;
    int s, g;
    cin >> s >> g;
    --s, --g;
    vector<Edge> edge[n];
    rep (i, m) {
      int x, y, d, c;
      cin >> x >> y >> d >> c;
      --x, --y;
      edge[x].push_back((Edge){y, d, c});
      edge[y].push_back((Edge){x, d, c});
    }
    priority_queue<Status> que;
    que.push((Status){0, s, 39, 0});
    double dis[40][40][40];
    rep (i, 40) rep (j, 40) rep (k, 40) dis[i][j][k] = 1e99;
    while (!que.empty()) {
      Status now = que.top();
      que.pop();
      if (dis[now.pos][now.pre][now.v] < now.cost + 1e-8) continue;
      dis[now.pos][now.pre][now.v] = now.cost;
      if (now.pos == g && now.v == 1) break;
      rep (i, edge[now.pos].size()) {
	int to = edge[now.pos][i].to;
	double dis = edge[now.pos][i].dis;
	if (to == now.pre) continue;
	if (now.v > 0 && now.v <= edge[now.pos][i].c) que.push((Status){now.cost + dis / now.v, to, now.pos, now.v});
	if (now.v > 1 && now.v - 1 <= edge[now.pos][i].c) que.push((Status){now.cost + dis / (now.v - 1), to, now.pos, now.v - 1});
	if (now.v < edge[now.pos][i].c) que.push((Status){now.cost + dis / (now.v + 1), to, now.pos, now.v + 1});
      }
    }
    double res = 1e99;
    rep (i, 40) res = min(res, dis[g][i][1]);
    if (res == 1e99) puts("unreachable");
    else printf("%.4lf\n", res);
  }
}

Measured memory_bytes: 21796
while True:
    n,x = map(int,input().split())
    if n==x==0:
        break
    count = 0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    count += 1
    print(count)


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 1; i <= n; i++) cin >> a[i];
  
  int count = 0, now = 1;
  // n回以内に見つからないならループしてるので不可能
  while (count < n && now != 2) {
    count++;
    now = a[now];
  }
  
  cout << (count == n ? -1 : count) << endl;
}

Measured memory_bytes: 3780
#include<stdio.h>
void CS(long *,long *,long *,long,long);
#define N 2100000
int main(){
  long A[N],B[N],C[N];
  long i,k=0,j,n;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
    if(k<A[i]){
      k=A[i];
    }
  }
  CS(A,B,C,k,n);
  return 0;
}


void CS(long *A,long *B,long *C,long k,long n){
  long i,j;
  for(i=0;i<=k;i++){
    C[i]=0;
  }
  for(j=1;j<=n;j++){
    C[A[j]]++;
  }
  for(i=1;i<=k;i++){
    C[i]=C[i]+C[i-1];
  }
  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<=n; i++){
    printf("%d",B[i]);
    if(i != n) printf(" ");
  }
  printf("\n");

}



Measured memory_bytes: 33040
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
	   String s = sc.next();
	   String year =("2018");
	   String month = s.substring(4);
	   System.out.println(year + month);	
	}
}

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

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

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

  vector<int> ans;
  reverse(s.begin(), s.end());
  for(int i = 0; i < n;){
    int mx_j = 0;
    for(int j = 1; j <= m; ++j){
      if(i + j > n) continue;
      if(s[i + j] == '0'){
        mx_j = j;
      }
    }
    if(mx_j == 0){
      cout << -1 << endl;
      return 0;
    }
    i += mx_j;
    ans.push_back(mx_j);
  }

  reverse(ans.begin(), ans.end());
  for(int i = 0; i < ans.size(); ++i){
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}


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

int main()
{
	ll t1,t2,a1,a2,b1,b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	if (a1*t1 + a2*t2 == b1*t1 + b2*t2)
	{
		cout << "infinity" << endl;
		return 0;
	}

	if (a1 < b1)
	{
		swap(a1,b1);
		swap(a2,b2);
	}

	if (a1*t1 + a2*t2 > b1*t1 + b2*t2)
	{
		cout << "0" << endl;
	}
	else
	{
		ll diff = (b1*t1 + b2*t2) - (a1*t1 + a2*t2);
		ll ans = 1 + (a1*t1 - b1*t1) / diff * 2;
		if ((a1*t1 - b1*t1) %  diff == 0) ans--;
		cout << ans << endl;
	}
	return 0;
}

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

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N;
int cnt[4];
double dp[301][301][301];

double solve(int a,int b,int c){
    double ret=0;
    if(dp[a][b][c]!=-1)return dp[a][b][c];
    if(a)ret+=(solve(a-1,b,c))*(a);
    if(b)ret+=(solve(a+1,b-1,c))*(b);
    if(c)ret+=(solve(a,b+1,c-1))*(c);
    ret+=N;
    ret=(double)ret/(a+b+c);
    return dp[a][b][c]=ret;
}

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>N;
    rep(i,0,N){
        int a;
        cin>>a;
        cnt[a]++;
    }
    rep(i,0,301)rep(j,0,301)rep(k,0,301)dp[i][j][k]=-1;
    dp[0][0][0]=0;
    printf("%.10lf",solve(cnt[1],cnt[2],cnt[3]));
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}

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

int main(){

    int a,b,c,d;
    cin >> a >> b >> c >> d;

    cout << "U";
    for(int i=c-a-1;i>0;i--){
        cout << "R";
    }
    for(int j=d-b-1;j>0;j--){
        cout << "U";        
    }
    cout << "R";
    cout << "D";
    for(int i=d-b-1;i>0;i--){
        cout << "D";
    }
    for(int j=c-a-1;j>0;j--){
        cout << "L";
    }
    cout << "L";
    cout << "D";
    for(int i=c-a+1;i>0;i--){
        cout << "R";
    }
    for(int j=d-b+1;j>0;j--){
        cout << "U";
    }
    cout << "L";
    cout << "U";
    for(int i=c-a+1;i>0;i--){
        cout << "L";
    }
    for(int j=d-b+1;j>0;j--){
        cout << "D";
    }
    cout << "R";

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main( void )
{
	char sentence[1200] = {};
	int moji_cou[26] = {};
	int convert, char_cou;
	int len;
	
	//?¨??????\??????????????????????????????
	while( gets( sentence ) != NULL )
	{
		//???????????????????????????
		len = strlen( sentence );
		
		//?????????????????????????????°?????????
		for( char_cou = 0; char_cou < len; char_cou++ )
		{
			if( sentence[char_cou] >= 'a' && sentence[char_cou] <= 'z' || sentence[char_cou] >= 'A' && sentence[char_cou] <= 'Z' )
			{
				//??¨????°??????????????????????????????????????????§?????°????????´???
				convert = tolower( sentence[char_cou] ) - 'a';
				//??????????????????????????°?????°???????¢???????
				moji_cou[convert]++;
			}
		}
	}
	//???????????¨???
	for( char_cou = 0; char_cou < 26; char_cou++ )
	{
		printf( "%c : %d\n", char_cou + 'a', moji_cou[char_cou] );
	}
	return 0;
}

Measured memory_bytes: 524
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        while(true){
            int x = sc.nextInt();
            int y = sc.nextInt();
            if(x == 0 && y ==0){
                break;
            }
            for(int k=0;k<x;k++){
               for(int j=0;j<y;j++){
                    System.out.print("#");
                }
               System.out.println();
            }
            System.out.println();
        }
        sc.close();
    }
}


Measured memory_bytes: 34984
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define f first
#define s second
#define ff find_first_of
#define fl find_last_of
#define all(s) (s).begin(),(s).end()
#define rall(s) (s).rbegin(),(s).rend()
#define bs(x) (bitset<18>(x)).to_string()
#define sep ios::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef long long ll;
int main()
{
	sep;
	ll x,p=0;
	cin>>x;
	p=x/500*1000;
	x%=500;
	p+=x/5*5;
	cout<<p;
	
}

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

Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var N, a, r int
	fmt.Scan(&N)
	m := map[int]int{}
	for i := 0; i < N; i++ {
		fmt.Scan(&a)
		m[a]++
	}
	for k, v := range m {
		if k == v {
			continue
		} else if k < v {
			r += v - k
		} else {
			r += v
		}
	}
	fmt.Println(r)
}

Measured memory_bytes: 8064