akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
int main(void){
  char s[1000],p[1000],cp[1000];

  scanf("%s %s",s,p);

  strcpy(cp,s);
  strcat(s,cp);

  if(strstr(s,p)==NULL)printf("No\n");
  else printf("Yes\n");
  
  return 0;
}



Measured memory_bytes: 2136
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  ll ans=0;
  ll A[1000100];
  for(int i=1;i<=N;i++){
    cin >> A[i];
  }
  for(int i=1;i<=N;i++){
    if(A[i]%2==1 && A[i+1]>0){
      A[i]--;
      A[i+1]--;
      ans++;
    }
    ans+=A[i]/2;
  }
  cout << ans << endl;
  return 0;
}
// AGC003_考え方


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

#define ll long long int

int main()
{
    int a, b;
    cin >> a >> b;
    if (a <= 8 && b <= 8)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;
}


Measured memory_bytes: 256
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

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

    vector<int> a(100001);

    REP(i, n) scanf("%d", &a[i]);

    ll cnt = 0;
    RREP(i, 1, n){
        if(a[i] + a[i-1] > x){
            int other = (a[i] + a[i-1]) - x;
            if(other < 0) continue;
            else if(a[i] >= other){
                a[i] -= other;
            }
            else if(a[i] < other){
                a[i-1] -= abs(other - a[i]);
                a[i] = 0;
            }
            cnt += other;
            
        }
    }

    printf("%lld\n", cnt);
        
    return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.Arrays;

class Main
{
    public static void main (String[ ] args) throws Exception
    {
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
        StringBuilder sb = new StringBuilder();
        int[][][] room = new int[4][3][10];
        
        int n = Integer.parseInt(br.readLine());

        for(int i = 0; i < n; i++)
        {
            String[] strArr = (br.readLine()).split(" ");
            int b = Integer.parseInt(strArr[0]);
            int f = Integer.parseInt(strArr[1]);
            int r = Integer.parseInt(strArr[2]);
            int v = Integer.parseInt(strArr[3]);
            
            room[b-1][f-1][r-1] += v;
        }
        
        for(int i = 0; i < 4; i++)
        {
            for(int j = 0; j < 3; j++)
            {
                for(int k = 0; k < 10; k++)
                {
                    sb.append(" ").append(room[i][j][k]);
                }
                sb.append("\n");
            }
            if(i != 3)
            {
                sb.append("####################\n");
            }
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 24608
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
        graph[b].push(a);
    }

    let mut color = vec![2; n];
    color[0] = 0;
    if dfs(0, &graph, &mut color) {
        let black: usize = color.iter().sum();
        let white = n - black;
        println!("{}", black * white - m);
    } else {
        println!("{}", n * (n - 1) / 2 - m);
    }
}

fn dfs(v: usize, graph: &Vec<Vec<usize>>, color: &mut Vec<usize>) -> bool {
    for &to in &graph[v] {
        if color[to] == 2 {
            color[to] = 1 ^ color[v];
            if !dfs(to, graph, color) {
                return false;
            }
        } else if color[to] == color[v] {
            return false;
        }
    }
    return true;
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 12924
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
struct UnionFind {
    vector<int> data;
    UnionFind(int size): data(size,-1) {
    }
    
    int root(int x){
        return (data[x] < 0)? x : data[x]=root( data[x] );
    }
    
    bool unite(int x, int y){
        x=root(x);
        y=root(y);
        if( x != y ){
            if( data[y] < data[x] ) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x!=y;
    }
    
    bool find(int x, int y){
        return root(x) == root(y);
    }
    
    int size(int x){
        return -data[ root(x) ];
    }
};

int main() {
    int n,m;
    cin>>n>>m;
    if(n-1-m>n/2) {
        cout<<"Impossible"<<endl;
        return 0;
    }
    
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    UnionFind uf(n);
    rep(i,m) {
        int x,y;
        cin>>x>>y;
        uf.unite(x,y);
    }
    
    map<int,vector<ll>> r;
    rep(i,n) {
        r[uf.root(i)].push_back(a[i]);
    }
    if(sz(r)==1) {
        cout<<0<<endl;
        return 0;
    }
    
    ll ans=0;
    int cnt=2*(n-1-m);
    priority_queue<ll,vector<ll>,greater<ll>> q;
    for(auto p:r) {
        auto &v=p.second;
        sort(all(v));
        rep(i,sz(v)) {
            if(i==0) ans+=v[i];
            else q.push(v[i]);
        }
        cnt--;
    }
    
    rep(i,cnt) {
        ans+=q.top();
        q.pop();
    }
    
    cout<<ans<<endl;
    
}


Measured memory_bytes: 7932
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,i,j,k,z;
  cin>>n;
  vector<int>a(n);
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  long long int sum=0,num=(n*(n-1)*(n-2))/6;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      vector<int>::iterator it=lower_bound(a.begin()+j,a.end(),a[i]+a[j]);
      z=a.end()-it;
      sum=sum+z;
    }
  }
  cout<<num-sum<<"\n";
  return 0;
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int A,B;
    cin>>A>>B;
    cout<<(A+B)%24<<endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, W) = readLine()!!.split(" ").map(String::toInt)

    val dp = Array(N + 1) { LongArray(W + 1) { 0 } }
    for (i in 1..N) {

        val (weight, value) = readLine()!!.split(" ").map(String::toInt)
        for (w in 0..W) {
            dp[i][w] = if (w < weight) {
                dp[i - 1][w]
            } else {
                Math.max(value + dp[i - 1][w - weight], dp[i - 1][w])
            }
        }
    }

    println(dp[N][W])
}


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

int main(){
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;

	if(x - r < 0 || y - r < 0 || x + r > W || y + r > H){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;

const int maxl=3e5+10;
const ll inf=1ll<<60;

int n,m,cas,k,cnt,totx,toty;
int st[maxl],numx[maxl],numy[maxl];
int xdis[1<<15][16],ydis[1<<15][16];
int xlen[1<<15],ylen[1<<15];
ll c[maxl],ans[maxl];
struct node
{
	int x,y,val,id;
}a[maxl],bx[maxl],by[maxl];
vector<int> tmpx,tmpy;
char s[maxl];
bool inx[maxl],iny[maxl]; 


inline void prework()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{	
		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].val);
		a[i].id=i;
		bx[i]=node{a[i].x,a[i].y,a[i].val,i};
		by[i]=node{a[i].x,a[i].y,a[i].val,i};
	}
	for(int i=0;i<=n;i++)
		ans[i]=inf;
} 

inline bool cmpx(const node &a,const node &b)
{
	return a.x<b.x;
}

inline bool cmpy(const node &a,const node &b)
{
	return a.y<b.y;
}

inline ll dis(int x,int y)
{
	return abs(x-y);
}

inline void jug(int sx,int sy)
{
	ll tmp=0;int len=xlen[sx]+ylen[sy];
	for(int i=1;i<=n;i++)
		tmp+=1ll*min(xdis[sx][i],ydis[sy][i])*a[i].val;
	ans[len]=min(ans[len],tmp);
}

inline void dfs(int k,int sx,int sy)
{
	if(k>n)
		jug(sx,sy);
	else
	{
		dfs(k+1,sx,sy);
		dfs(k+1,sx|(1<<(k-1)),sy);
		dfs(k+1,sx,sy|(1<<(k-1)));
	}
}

inline void mainwork()
{
	sort(bx+1,bx+1+n,cmpx);
	sort(by+1,by+1+n,cmpy);
	int up=1<<n;
	for(int s=0;s<up;s++)
	{
		tmpx.clear();tmpx.push_back(0);
		tmpy.clear();tmpy.push_back(0);
		for(int i=1;i<=n;i++)
		if((s>>(i-1))&1)
		{
			tmpx.push_back(a[i].x);
			tmpy.push_back(a[i].y);
		}
		sort(tmpx.begin(),tmpx.end());
		sort(tmpy.begin(),tmpy.end());
		tmpx.erase(unique(tmpx.begin(),tmpx.end()),tmpx.end());
		tmpy.erase(unique(tmpy.begin(),tmpy.end()),tmpy.end());
		int id=0;xlen[s]=tmpx.size();
		for(int i=1;i<=n;i++)
		{
			while(id+1<xlen[s] && dis(bx[i].x,tmpx[id+1])<dis(bx[i].x,tmpx[id]))
				++id;
			xdis[s][bx[i].id]=dis(bx[i].x,tmpx[id]);
		}
		id=0;ylen[s]=tmpy.size();
		for(int i=1;i<=n;i++)
		{
			while(id+1<ylen[s] && dis(by[i].y,tmpy[id+1])<dis(by[i].y,tmpy[id]))
				++id;
			ydis[s][by[i].id]=dis(by[i].y,tmpy[id]);
		}
		--xlen[s];--ylen[s];
	}
	dfs(1,0,0);
	for(int i=n;i>=0;i--)
	{	
		if(ans[i]!=inf)
			break;
		ans[i]=0;
	}
}

inline void print()
{
	for(int i=0;i<=n;i++)
		printf("%lld\n",ans[i]);
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(cas=1;cas<=t;cas++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

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

namespace ABC167
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_B();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var s = Ex.Read;
            var t = Ex.Read;

            bool b = s.Length + 1 == t.Length;
            int i = 0;
            while (b && i < s.Length)
            {
                b &= s[i] == t[i];
                i++;
            }

            (b ? "Yes" : "No").Cw();
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
            var l = Ex.ReadLongArray();
            var a = l[0];
            var b = l[1];
            var c = l[2];
            var k = l[3];
            long ans = 0;

            if (k > 0)
            {
                ans += 1 * Math.Min(k, a);
                k -= a;
            }
            if (k > 0)
            {
                k -= b;
            }
            if (k > 0)
            {
                ans -= 1 * Math.Min(k, c);
                k -= c;
            }

            ans.Cw();
        }
    }
    public class ABC_C
    {
        public ABC_C()
        {
        }
    }
    public class ABC_D
    {
        public ABC_D()
        {
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }

        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static string yesno(this bool b) { return b ? "yes" : "no"; }
        public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        public static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
#define PRINT_ENTER() cout << endl;

int main() {
    /* code */
    ll N, K;
    cin >> N >> K;
    double res = 0.0;
    for (ll n = 1; n <= N; ++n) {
        double tmp = 1.0;
        ll point = n;
        while (point < K) {
            point *= 2;
            tmp /= 2.0;
        }
        res += tmp;
    }
    cout << fixed << setprecision(10) << res / N << endl;
    return 0;
}

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

int main()
{
  int N;
  int A, B;
  int res = 0;

  cin >> N >> A >> B;

  for(int i=1; i<=N; i++){
    int a = i;
    int b = 0;
    while(a > 0){
      b +=  a % 10;
      a = a / 10;
    }
    if(b >= A && b <= B) res += i;

  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 2e5 + 100;
int a, b, c; 

int main() {
	
	cin >> a >> b >> c;
	
	
	int num = 0;
	while((a%2==0) && (b%2==0) && (c%2==0)) {
		num++;
		int x = a, y = b, z = c;
		a = (y + z) / 2;
		b = (x + z) / 2;
		c = (x + y) / 2;
		
		if(num >= N) {
			break;
		}
	}
	
	if(num >= N) puts("-1");
	else cout << num << endl;
	return 0;	
} 

Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef unsigned long long ull;
typedef pair<int, int> P;
 
int main(){
  long n;
  cin >> n;
  vector<long> a(n);
  bool IsNotUnique = false;
  
  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  sort(a.begin(), a.end()); //ソート

  a.erase(unique(a.begin(), a.end()), a.end()); //重複を削除  
  
  if(a.size()!=n){
     IsNotUnique = true;
  }
 
  if(IsNotUnique)  cout << "NO" << endl;
  else             cout << "YES" << endl;
 
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	int max;
	
	cin >> a >> b;
	
	max = (a + b);
	
	if ((a - b) >= max) {
		max = (a - b);
	}
	if ((a * b) >= max) {
		max = (a * b);
	}
	
	cout << max << "\n";
}

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

typedef long long int ll;


int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

int main(){
	int ans = 0;
	int k; scanf("%d",&k);
	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);
			}
		}
	}
	printf("%d",ans);
}



Measured memory_bytes: 3832
#include<cstdio>

int main(){
  int a, b, d, r;
  double f;
  scanf("%d %d", &a, &b);
  d = a / b;
  r = a % b;
  f = 1.0 * a / b;
  printf("%d %d %f\n", d, r, f);
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int x, y;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> x >>  y;
    cout << x + y / 2 << endl;
    return 0;
}



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

int Digitsum(int n){
  int sn=0;
  while(n>0){
    sn+=n%10;
    n/=10;
  }
  return sn;
}


int main(){
  int n;
  cin>>n;
  int tmp=n;
  int sn=Digitsum(tmp);
  if(n%sn==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



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

#define INFTY (1<<29)

int main(){
    int n,m;
    cin>>n>>m;
    int C[21],T[50001];
    for(int i=1;i<=m;i++) cin>>C[i];
    for(int i=1;i<=50000;i++) T[i]=INFTY;

    T[0]=0;
    for(int i=1;i<=m;i++){
        for(int j=0;j+C[i]<=n;j++){
            T[j+C[i]]= min(T[j+C[i]],T[j]+1);
        }
    }

    cout<<T[n]<<endl;
    return 0;
}


Measured memory_bytes: 3296
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
int x,y;
cin>>x>>y;
if(y%2==0)
{
	if(x*4>=y && x*2<=y)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
}
else
{
	cout<<"No";
}
}


Measured memory_bytes: 3580
N, M = map(int, input().split())
A = list(map(int, input().split()))  # [1, 2, 3, 4] になる

vote = sum(A)/(4*M)
judge = 0

def check(M,A,N,judge,vote):
    while 1:
        num = A.pop(A.index(max(A)))
        if num >= vote:
            judge+=1
        else:
            return 'No'
        if judge == M:
            return 'Yes'

print(check(M,A,N,judge,vote))

Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    ll s=0;
    if(n==1)
    cout<<0;
    else if(n==2)
    {
        if(a[0]<=a[1])
        cout<<0;
        else
        cout<<a[0]-a[1];
    }
    else
    {
        for(int i=0;i<n-1;++i)
        {
            if(a[i]>a[i+1])
            {
                s=s+a[i]-a[i+1];
                a[i+1]=a[i];
            }
        }
        cout<<s;
    }}

Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define NFOR(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); --i)
#define rep(i, a) for (ll i = 0; i < a; i++)
#define endl "\n"
#define fi first
#define se second
#define MOD 1000000007
#define inf 1e18
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

const int maxn = 200005;

inline ll L(ll a) {return (a << 1) + 1;}
inline ll R(ll a) {return (a << 1) + 2;}

class SegTree {
	ll T[maxn << 2];

public:
	void build()
	{
		memset(T, 0, sizeof(T));
	}

	void update(ll node, ll st, ll en, ll pos, ll val) {
		if (st > en) return;
		if (st == en) T[node] = val;
		else {
			ll mid = (st + en) >> 1;
			if (pos > mid) update(R(node), mid + 1, en, pos, val);
			else update(L(node), st, mid, pos, val);

			T[node] = max(T[L(node)], T[R(node)]);
		}
	}

	ll query(ll node, ll st, ll en, ll pos) {
		if (st > en) return -1;
		if (st == en) return T[node];
		else {
			ll mid = (st + en) >> 1;
			if (pos > mid) return max(T[L(node)], query(R(node), mid + 1, en, pos));
			else return query(L(node), st, mid, pos);
		}
	}
};

void solve() {
	SegTree st;
	st.build();

	ll n;
	cin >> n;
	vl h(n);
	rep(i, n) cin >> h[i];

	vl a(n);
	rep(i, n) cin >> a[i];

	ll ans = 0;

	ll N = *max_element(all(h)) + 1;
	// pr(N);
	rep(i, n) {
		ll temp = st.query(0, 0, N, h[i]) + a[i];
		ans = max(temp, ans);
		st.update(0, 0, N, h[i], temp);
	}

	cout << ans << endl;
}

int main()
{
    fastio;
    ll t  = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}
 

Measured memory_bytes: 9600
/*12月 30日の M 時から次の年になるまでは何時間か、求めてください。*/
//1<=M<=23
//入力は全て整数

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

int main(){
    int m;

    cin >> m;

    cout << (24-m)+24 << endl;
}


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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
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); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

signed main() {
  int W, H;
  cin >> W >> H;
  vector<P> v;
  for (int i = 0; i < W; i++) {
    int p;
    cin >> p;
    v.push_back({p, 1});
  }
  for (int i = 0; i < H; i++) {
    int q;
    cin >> q;
    v.push_back({q, 2});
  }

  sort(ALL(v));

  int ans = 0, n1 = 0, n2 = 0;
  for (auto x : v) {
    if (x.second == 1) {
      ans += (H + 1 - n1) * x.first;
      n2++;
    } else {
      ans += (W + 1 - n2) * x.first;
      n1++;
    }
  }

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


Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

int main(void){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k%2==0) cout<<a-b<<endl;
    else cout<<b-a<<endl;
}

Measured memory_bytes: 3596
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->N = $a[0];
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->A[]=$a[0];
  }
}
$len = strlen($key->N);
$res = array();
for($i=0;$i<$len;$i++) {
  if (isset($res[$key->N[$i]])) {
    $res[$key->N[$i]]+=1;
  }
  else {
    $res[$key->N[$i]]=1;
  }
}
$flg = "Yes";
foreach($res as $r) {
  if (($r % 2) != 0) {
    $flg = "No";
    break;
  }
}
printf("%s\n",$flg);


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef double dl;
#define pb push_back
#define ins insert
#define pll pair<ll,ll>
#define fi first
#define se second
#define mpr make_pair
#define vtr vector
#define itor iterator 
#define N ll(1e9+7)
#define endl '\n'
#define cont continue
#define inf ll(1e10)
using namespace std;

//ll power(ll a,ll b,ll mod)
//{
//	if(b==0)return 1;
//	ll ans=1;
//	while(b>0)
//	{
//		if(b&1)ans=(ans*a)%mod;
//		a=(a*a)%mod;
//		b>>=1;
//	}
//	return ans;
//}
int main()
{
	ios;
	ll n;
	ll i,j;
	cin>>n;vector<ll> y_th(n+1),ind(n+1);
	ll x,y;vector<ll> ans(n+1);
	for(i=1;i<=n;i++)
	{
		cin>>x>>y;
		y_th[x]=y;
		ind[x]=i;
	}
	reverse(y_th.begin()+1,y_th.end());
	ll max_co=-1;
	int pos=0,cnt;
	for(i=1;i<=n;i++)
	{
		max_co=max(max_co,y_th[i]);
		if(max_co==i)
		{
			cnt=i-pos;
			for(j=pos+1;j<=i;j++)
			{
				x=n-j+1;
				ans[ind[x]]=cnt;
			}
			pos=i;
			max_co=-1;
		}
	}
	
	for(i=1;i<=n;i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 7912
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

int N, p[100000 + 10], index, ans;

int main() {
	rd(N);
	repi(i, 0, N) rd(p[i]);

	while (1) {
		if (index == N - 2) {
			if (p[N - 2] == N - 1 || p[N - 1] == N) ans++;
			break;
		}
		else if (index == N - 1) {
			if (p[N - 1] == N) ans++;
			break;
		}
		else if (p[index] == index + 1) {
			ans++;
			index += 2;
		}
		else {
			index += 1;
		}
	}

	wrln(ans);

	return 0;
}

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

int gcd(int a, int b){
    if(a<b) swap(a, b);
    while(b!=0){
        int tmp = a%b;
        a = b;
        b = tmp;
    }
    return a;
}
int lcm(int a, int b){
    return (a*b)/gcd(a, b);
}
int main()
{
    int n;
    cin >> n;
    cout << lcm(2, n) << endl;

    return 0;
}



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

int digit_sum(int x) {
  int s = 0;
  while (0 < x) {
    s += x % 10;
    x /= 10;
  }
  return s;
}

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

  int ans = 1 + digit_sum(N-1);
  for (int i = 2; i < N/2; i++) {
    int s = digit_sum(i) + digit_sum(N - i);
    if (s < ans) {
      ans = s;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* nichijou */
template<class T,class U>
bool cmax(T & a, const U & b) {return a < b ? a = b, 1 : 0;}
template<class T,class U>
bool cmin(T & a, const U & b) {return b < a ? a = b, 1 : 0;}
/* data type */
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define F first
#define S second
/* STL container */
typedef vector<int> vi;
typedef vector<ll> vll;
#define SZ(a) ((int)(a).size())
#define ALL(a) begin(a), end(a)
#define CLR(a) (a).clear()
#define BK(a) ((a).back())
#define FT(a) ((a).front())
#define DB(a) (a).pop_back()
#define DF(a) (a).pop_front()
#define PB push_back
#define EB emplace_back
/* I gave you my heart and then you turned around. */
void _BG(const char * s) {cerr<<s<<endl;}
template<class T, class ... TT>
void _BG(const char * s,T a, TT...b)
{
    for (size_t c = 0; *s && (c || *s != ','); cerr << *s++)
        c += count(ALL("([{"),*s) - count(ALL(")]}"),*s);
    cerr << " = " << a;
    if (*s) {
        cerr << ", ";
        ++s;
    }
    _BG(s,b...);
}
#ifdef PR3PONY
#define BG(...) do { \
    cerr << __PRETTY_FUNCTION__ << ':' << __LINE__ << ": "; \
    _BG(#__VA_ARGS__,__VA_ARGS__); \
} while(0)
#else
#define BG(...)
#endif
/* Good Luck && Have Fun ! */
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    if (s.size() % 2) {
        cout << "No\n";
        return 0;
    } else {
        for (int i = 0; i < s.size(); i += 2)
            if (s[i] != 'h') {
                cout << "No\n";
                return 0;
            }
        for (int i = 1; i < s.size(); i += 2)
            if (s[i] != 'i') {
                cout << "No\n";
                return 0;
            }
    }
    cout << "Yes\n";
}


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

ll n, a[3][100005], s[3][100005];

int main()
{
	scanf("%lld",&n);
	for(int i=0;i<3;i++) {
		for(int j=1;j<=n;j++) {
			scanf("%lld",&a[i][j]);
		}
		sort(a[i]+1, a[i]+1+n);
	}
	for(int i=1;i<=n;i++) s[0][i] = i;
	for(int i=1;i<3;i++) {
		for(int j=1;j<=n;j++) {
			s[i][j] = s[i-1][lower_bound(a[i-1]+1, a[i-1]+1+n, a[i][j])-a[i-1]-1];
			s[i][j] += s[i][j-1];
		}
	}
	printf("%lld\n",s[2][n]);
}


Measured memory_bytes: 4992
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

function gcd(a,b){return b?gcd(b,a%b):a;}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var x = next();
  return 360/gcd(360,x);
}

Measured memory_bytes: 29700
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt(),m=nxt();
    
    string s;
    cin>>s;
    if(m>=n)
    {
        cout<<n<<endl;
        return 0;
    }
    vector <int> dp;
    vector <int> dp2;
    dp.resize(n+1,-1);
    dp2.resize(n+1);
    map <int, set<int> > m2;
    dp[0]=0;
    set <int> s2;
    m2[0]=s2;
    m2[0].insert(0);
    for(int i=1;i<=n;i++)
    {//cout<<i<<" "<<m2.size()<<endl;
        if(i-m-1>=0&&dp[i-m-1]!=-1)
        {//cout<<"delete\n";
            m2[dp[i-m-1]].erase(i-m-1);
            if(m2[dp[i-m-1]].size()==0)
                m2.erase(dp[i-m-1]);
        }
        if(s[i]=='0'&&m2.size()>0)
        {//cout<<"came here: "<<i<<endl;
            auto it=m2.begin();
            dp[i]=it->first+1;
            dp2[i]=*((it->second).begin());
            if(m2.find(dp[i])==m2.end())
                m2[dp[i]]=s2;
            m2[dp[i]].insert(i);

        }
        //cout<<i<<" "<<dp[i]<<" "<<dp2[i]<<endl;

    }

    if(dp[n]==-1)
    {
        cout<<"-1\n";
    }
    else
    {
        vector <int> v;
        int cur=n;
        while(cur!=0)
        {
            v.push_back(cur);
            cur=dp2[cur];
        }
        v.push_back(0);
        reverse(v.begin(),v.end());
        for(int i=0;i<v.size()-1;i++)
            cout<<v[i+1]-v[i]<<" ";
        cout<<endl;
    }



    
    
    

    return 0;   
}


 
 


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

struct Card{char suit,value;};

void bubble(struct Card A[] ,int n){
for(int i = 0; i < n; i++) {
  for(int j = n - 1; j >= i + 1; j--) {
    if(A[j].value < A[j - 1].value) {
      Card t = A[j];
      A[j] = A[j - 1];
      A[j - 1] = t;
    }
  }
}
}

void selection(struct Card A[],int n) {
  for(int i = 0; i < n; i++) {
    int minj = i;
    for(int j = i; j < n; j++) {
      if(A[j].value < A[minj].value) {
        minj = j;
      }
    }
    Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct Card A[], int n) {
  for(int i = 0; i < n; i++) {
  if(i) cout << " ";
  cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[],struct Card C2[],int n) {
  for(int i = 0; i < n ; i++) {
    if(C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main() {
  Card C1[100],C2[100];
  int n;
  cin >> n;

  for(int i = 0; i < n; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i = 0; i < n; i++) {
    C2[i] = C1[i];
  }

  bubble(C1,n);
  selection(C2,n);

  print(C1,n);
  cout << "Stable" << endl;

  print(C2,n);

  if(isStable(C1,C2,n)){
    cout << "Stable" << endl;
  }else {
    cout << "Not stable" << endl;
  }



  
}


Measured memory_bytes: 3112
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離
int d[100][100];


//移動方向のベクトル
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

//汎用
ll ans = 0;
pair<int, int> red[101], blue[101];
ll BIG = 10000000000;

//累乗
ll POW(ll a, ll b) {
ll c = 1;
for (int i = 0; i < b; ++i) {
c *= a;
}
return c;
}

//階乗
int Kaijou(int a) {
if (a < 2) return 1;
return a * Kaijou(a - 1);
}


int A[200000];
int kinds[200001];


int main() 
{
	int n,r;
	while(1){
		cin >> n>> r;
		if (n == 0&&r==0) break;

		vector<int> s(n);
		std::iota(s.begin(), s.end(), 1);
		reverse(s.begin(), s.end());

		rep(i, r) {
			int p, c;
			cin >> p >> c;
			int toU[100] = { 0 }, toD[100] = { 0 };
			rep(i, c) {
				toU[i] = s[p - 1 + i];
			}
			rep(i, p - 1) {
				toD[i] = s[i];
			}
			rep(i, c) {
				s[i] = toU[i];
			}
			rep(i, p - 1) {
				s[i + c] = toD[i];
			}
		}
	
		cout << s[0] << endl;
	}
	cin >> qqq;
}



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

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;

int main() {
  int n, m;
  cin >> n >> m;
  char a[n][n];
  char b[m][m];

  rep(y, n) {
    rep(x, n) {
      cin >> a[y][x];
    }
  }
  rep(y, m) {
    rep(x, m) {
      cin >> b[y][x];
    }
  }

  bool result = false;

  rep(ly, n) {
    rep(lx, n) {
      if (ly + m - 1 >= n or lx + m - 1 >= n) continue;

      bool match = true;

      rep(y, m) {
        rep(x, m) {
          if (a[ly + y][lx + x] != b[y][x]) match = false;
        }
      }

      if (match) result = true;
    }
  }

  if (result) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {

	int n;
	cin >> n;

	vector<int>x(n);
	vector<int>sorted(n);
	for (int i = 0; i < n; i++){
		cin >> x[i];
		sorted[i] = x[i];
	}

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

	int now = sorted[(n - 1) / 2];
	for (int i = 0; i < n; i++){
		if (x[i] <= now)
			cout << sorted[n / 2] << endl;
		else
			cout << now << endl;
	}

	return 0;
}

Measured memory_bytes: 3712
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b=map(int,input().split())
    for x in range(1,1100):
        if int(x*0.08)==a and int(x*0.1)==b:
            print(x)
            break
    else:print(-1)

if __name__=='__main__':
    main()

Measured memory_bytes: 3060
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort(reverse = True)
    ans = 0
    space = deque()
    space.append(A[0])
    for i in range(1, N):
        ans += space.popleft()
        space.append(A[i])
        space.append(A[i])
    print(ans)


    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 33404
h,w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
a = [list(map(int,input().split())) for i in range(h)]


#正方行列を読み込む

len_c = len(c)
cost = [[float('inf')]*len_c for i in range(len_c)]

for k in range(len_c):
  for i in range(len_c):
    for j in range(len_c):
      c[i][j] = min(c[i][j], c[i][k]+c[k][j])

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


Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in);) {
      int num1 = sc.nextInt();
      int num2 = sc.nextInt();

      int answer = (num2 % num1 == 0) ? num1 + num2 : num2 - num1;
      System.out.println(answer);
    }
  }
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


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


    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>

int main(void){
  int value,pay,back;

  for(;;){
    scanf("%d%d",&value,&pay);
    if(value==0&&pay==0)
      break;
    
    back=pay-value;

    {
      int sen=0,gohya=0,hya=0;
   
      for(;;){
	if(back>=1000){
	  sen++;
	  back-=1000;
	}
	else
	  break;
      }
      for(;;){
	if(back>=500){
	  gohya++;
	  back-=500;
	}
	else
	  break;
      }
      hya=back/100;
      
      printf("%d %d %d\n",hya,gohya,sen);
    }
  }
  return 0;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    v_string s(3);
    
    irep(i, 3) {
        cin >> s[i];
    }
    irep(i, 2) {
        if(s[i].back() != s[i+1].front()) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    X = read_int()
    A = 0
    B = 0
    # A > B
    while True:
        if A**5-B**5 == X:
            return '%s %s'%(A, B)
        if A**5+B**5 == X:
            return '%s %s'%(A, -B)
        if A == B:
            A += 1
            B = 0
        else:
            B += 1


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 9188