akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

string calcAddition( string a, string b )
{
    int as = a.size(), bs = b.size(), d = as > bs ? as - bs : bs - as;
    string s = "0", t = "0";
    for( int i = 0; i < d; i++ )
        as > bs ? t += "0" : s += "0";
    s += a; t += b;

    for( int i = s.size() - 1; i >= 1; i-- )
    {
        s[i] += t[i] - '0';
        if( s[i] > '9' )
        {
            s[i] -= 10;
            s[i-1]++;
        }
    }

    bool j = true;
    for( int i = 0; i < s.size(); i++ )
        if( s[i] != '0' )
            j = false;
    if( j )
        return "0";
    return s[0] == '0' ? s.substr( 1, s.size() ) : s;
}

string calcSubtraction( string a, string b )
{
    int as = a.size(), bs = b.size(), d = as - bs;
    string s = "", t = "";
    for( int i = 0; i < d; i++ )
        t += "0";

    s += a;
    t += b;

    for( int i = s.size() - 1; i >= 0; i-- )
    {
        if( s[i] < t[i] )
        {
            s[i] += 10;
            if( s[i-1] >= '1' )
                s[i-1]--;
            else
            {
                int j = i - 1;
                while( s[j] == '0' )
                    s[j--] += 9;
                s[j]--;
            }
        }
        s[i] -= ( t[i] - '0' );
    }

    if( s.size() == 1 )
        return s;

    for( int i = 0; i < s.size(); i++ )
    {
        if( '1' <= s[i] && s[i] <= '9' )
            return s.substr( i, s.size() );
    }

    return "0";
}

int main()
{
    string a, b, c;

    cin >> a >> b;

    c = b;
    int as = a.size(), bs = b.size(), cs, d = as - bs;
    for( int i = 0; i < d - 1; i++ )
        c += "0";
    cs = c.size();

    while( c != b )
    {
        while( as > cs || as == cs && a >= c )
        {
            a = calcSubtraction( a, c );
            as = a.size();
        }
        c = c.substr( 0, c.size() - 1 );
        cs = c.size();
    }

    while( as > bs || as == bs && a >= b )
    {
        a = calcSubtraction( a, b );
        as = a.size();
    }

    cout << a << endl;


    return 0;
}



Measured memory_bytes: 3228
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
total = 0
sum_sqr = 0
sqr_sum = 0
for i in range(n):
    sum_sqr = (sum_sqr + a[i])
sum_sqr = (sum_sqr * sum_sqr)
for i in range(n):
    sqr_sum = (sqr_sum + ((a[i] * a[i])))
# print(sqr_sum, sum_sqr)
total = (sum_sqr - sqr_sum) // 2
print(total%mod)

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


int main() {
  string S;
  cin >> S;
  int N = S.size();
  int ans = 999;
  for(int i = 0; i < N-2; i++){
    int num = (S[i]-'0')*100+(S[i+1]-'0')*10+S[i+2]-'0';
    ans = min(ans, abs(num-753));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
import java.io.InputStream;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.ArrayList;

public class Main {
	public static void main(String args[]) {
		MyInput in = new MyInput();
		int a,b;
		int ap = 0;
		int bp = 0;

		int kai = in.nextInt();

		while(kai != 0) {
			ap = 0;
			bp = 0;
			for(int i = 0; i < kai; i++) {
				a = in.nextInt();
				b = in.nextInt();
				if(a < b) {
					bp += a + b;	
				}else if(a > b) {
					ap += a + b;	
				}else {
					ap += a;	
					bp += b;
				}
			}
			System.out.println(ap + " " + bp);
			kai = in.nextInt();
		}
	}
}

class MyInput {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr= 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if(ptr < buflen) {
			return true;
		}else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch(IOException e) {
				e.printStackTrace();
			}
			if(buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	public int readByte() { 
		if (hasNextByte()) return buffer[ptr++];
		else return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <=126;
	}

	private void skipUnprintable() {
		while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if(!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if(!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if(b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true) {
			if('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			}else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 26204
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
vector<vector<int>> vec(30);
int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size();
	s = s + s;
	for (int i = 0; i < s.size(); i++) {
		vec[int(s[i] - 'a')].emplace_back(i);
	}
	long long ans = 0;
	int now = -1;
	for (int i = 0; i < t.size(); i++) {
		auto itr = upper_bound(vec[int(t[i] - 'a')].begin(), vec[int(t[i] - 'a')].end(), now);
		if (itr == vec[int(t[i] - 'a')].end()) {
			cout << "-1" << endl;
			return 0;
		}
		ans += *itr - now;
		now = *itr % n;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4684
from bisect import bisect_left

n = int(input())
li = list(map(int, input().split()))

li.sort()

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        a = li[i]
        b = li[j]
        idx = bisect_left(li, a+b)
        ans += idx - (j+1)
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <stdio.h>
#include <ctime>
#include <cstdio>
using namespace std;
int main(){
    unsigned long long x,y;
    cin>>x>>y;
    int cnt=0;
    while(x<=y){
        x*=2;
        cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  char pre[4];
  char rslt[4];
  int cnt = 0;
  
  scanf("%s", pre);
  scanf("%s", rslt);
  
  int i;
  for(i=0; i < 3; i++){
    if(pre[i] == rslt[i]){
      cnt++;
    }
  }
  
  printf("%d", cnt);
}

Measured memory_bytes: 128
n,m,c = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
count = 0
n.times do
  a = gets.split.map(&:to_i)
  sum = 0
  m.times do |i|
    sum += a[i] * b[i]
  end
  if sum + c > 0
    count += 1
  end
end
puts count	

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;
const double EPS = 1e-10;

// _
typedef complex<double> P;

namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b)-EPS : imag(a) < imag(b)-EPS;
  }
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L(){}
};

P line_cross(const L& l, const L& m) {
  double num = cross(m[1]-m[0], m[0]-l[0]);
  double denom = cross(m[1]-m[0], l[1]-l[0]);
  return P(l[0] + (l[1]-l[0])*num/denom);
}

bool intersectSS(const L &s, const L &t) {
  set<P> se;
  REP(i,2)se.insert(s[i]);
  REP(i,2)se.insert(t[i]);
  if (se.size()!=4) return false; // [_ð¤LµÄ¢éê
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

int main() {
  int n;
  
  while(cin>>n,n) {
    L ls[n];
    int res = 1;
    REP(i,n) {
      int x1,y1,x2,y2;
      cin>>x1>>y1>>x2>>y2;
      ls[i] = L(P(x1,y1),P(x2,y2));
      set<P> se;
      REP(j,i) {
        if (intersectSS(ls[i], ls[j])) {
          se.insert(line_cross(ls[i],ls[j]));
        }
      }
      res += 1+se.size();
    }
    cout << res << endl;
  }
}

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

	

int main() {
	
	int N, K;
	cin >>N >>K;
	
	vector<int> vec(N);
	for(int i=0; i<N; i++){
		
		cin >>vec.at(i);
		
	}
	
	int count=0;
	for(int i=0; i<N; i++){
		
		if(vec.at(i)>=K){
			
			count++;
			
		}
		
	}
	
	cout <<count <<endl;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		StringBuffer sb=new StringBuffer();

		int max=0;
		String maxString="";
		Map<String, Integer> val=new HashMap<String, Integer>();
		Map<Integer, String> key=new HashMap<Integer, String>();
		Set<String> set=new HashSet<String>();
		String[] st=s.split("\\s");
		ArrayList<String> list=new ArrayList<String>();
		for (int i = 0; i < st.length; i++) {
			list.add(st[i]);
			set.add(st[i]);
		}
		int i=0;
		for (String string : set) {
			val.put(string, i);
			key.put(i, string);
			int l=string.length();
			if(max<l){
				max=l;
				maxString=string;
			}
			i++;
		}

		int[] a=new int[set.size()];

		for (int j = 0; j < list.size(); j++) {
			a[val.get(list.get(j))]++;
		}
		int maxFreq=0;
		String maxFreqString="";
		for (int j = 0; j < a.length; j++) {
			if(a[j]>maxFreq){
				maxFreq=a[j];
				maxFreqString=key.get(j);
			}
		}

		System.out.println(maxFreqString+" "+maxString);


	}

}

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

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"
#define sq(x)           ((x)*(x))
#define pi              acos(-1.0)
#define NUM             1000005

typedef long long ll;


int main()
{
    FastRead

    ll n,cnt=0;
    
    cin>>n;
    
    vector<ll>v(n);
    
    for(ll i=0;i<n;i++)
    {
        cin>>v[i];
        
        if(v[i]%2)
            cnt++;
    }
    
    if(cnt%2)
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
}


Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

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

//********************************template END****************************************//

void solve(void){
	int D, G;
	cin >> D >> G;
	int ans = INF;
	vec ps(D), cs(D);
	rep(D, i)
	{
		cin >> ps[i] >> cs[i];
	}
	rep((1<<D), bit)
	{
		int res = 0, cnt = 0;
		rep(D, d)
		{
			if (bit >> d & 1)
			{
				res += ps[d] * (d+1) * 100 + cs[d];
				cnt += ps[d];
			}
		}
		if (res >= G)
		{
			ans = min(ans, cnt);
			continue;
		}
		repr(D, d)
		{
			if (bit >> d & 1)
			{
				continue;
			}
			if (res + ps[d] * (d+1) * 100 + cs[d] <= G)
			{
				res += ps[d] * (d+1) * 100 + cs[d];
				cnt += ps[d];
				continue;
			}
			ans = min(ans, cnt + (G-res-1) / 100 / (d+1) + 1);
			break;
		}
	}

	cout << ans << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())

ans = 0
if (A + B) >= 2*C:
    minv = min(X, Y)
    ans += minv * 2*C
    X -= minv
    Y -= minv
    ans += min(A*X, X*2*C) + min(B*Y, Y*2*C)
    print(ans)

else:
    print(min(A*X + B*Y, max(X, Y)*2*C))

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

int main()
{
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    if (B/A<=C)
    {
        printf("%d", B/A);
    }
    else
    {
        printf("%d", C);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
ll a,b;
cin>>a>>b;
cout<<lcm(a,b)<<endl;
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String result = "Three";
		for(int i = 0; i < N; i++) {
			String S = sc.next();
			if("Y".equals(S)) {
				result = "Four";
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 21844
while True:

    a,op,b = input().split()
    a = int(a)
    b = int(b)

    if op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(int(a/b))
    elif op == "?":
        break


Measured memory_bytes: 5596
import java.util.*;
class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int K = scan.nextInt();

//aを固定, 
long ans = 0;
for(int B=K+1;B<=N;++B){
ans += (long)((N+1)/B)*(B-K)+Math.max(0,(N+1)%B-K);
if(K==0)--ans;
}
System.out.println(ans);
}}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
int n;
ll a[N],b[N],du[N],pre[N],bk[N];
vector<int>v;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]),b[i]=a[i]*-2;
    pre[1]=1;
    for(int i=2;i<=n;i++)
    {
        pre[i]=1;
        if(b[i-1]<=b[i])
        {
            ll s=b[i];
            while(s*4>=b[i-1])
                s*=4,du[i-1]++;
            if(du[i-1]) v.push_back(i-1);
        }
        else
        {
            ll s=b[i-1];
            while(s>b[i])
            {
                s*=4;
                int low=0;
                if(v.size())
                {
                    low=v.back();
                    du[v.back()]--;
                    if(!du[v.back()]) v.pop_back();
                }
                pre[i]+=2*(i-1-low);
            }
        }
        pre[i]+=pre[i-1];
    }
    v.clear();
    memset(du,0,sizeof(du));
    for(int i=n-1;i>=1;i--)
    {
        if(a[i]<=a[i+1])
        {
            ll s=a[i];
            while(s*4<=a[i+1])
                s*=4,du[i]++;
            if(du[i]) v.push_back(i);
        }
        else
        {
            ll s=a[i+1];
            while(s<a[i])
            {
                s*=4;
                int up=n;
                if(v.size())
                {
                    up=v.back();
                    du[v.back()]--;
                    if(!du[v.back()]) v.pop_back();
                }
                bk[i]+=2*(up-i);
            }
        }
        bk[i]+=bk[i+1];
    }
    ll ans=1e18;
    for(int i=1;i<n;i++)
        ans=min(ans,pre[i]+bk[i+1]);
    ans=min(ans,pre[n]);
    ans=min(ans,bk[1]);
    printf("%lld\n",ans);
}


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

int main(){
    int n;
    cin >> n;
    vector<int> ans(n);
    rep(i,n-1){
        int a;
        cin >> a;
        ans[a-1]++;
    }

    for (int x : ans){
        cout << x << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3988
a = int(input())
b = int(input())
c = int(input())
x_origin = int(input())
i = 0
ans = 0
while i <= a:
    x_aftera = x_origin - 500 * i
    if x_aftera < 0:
        break
    j = 0
    while j <= b:
        x_afterb = x_aftera - 100 * j
        if x_afterb < 0:
            break
        if x_afterb // 50 <= c:
            ans += 1
        j += 1
    i += 1
print(ans)


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

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

    int ans = 0;
    int active = 0;

    for (int i = 0; i < N; i++) {
        if (active >= h[i]) {
            active = h[i];
        } else {
            ans += h[i] - active;
            active = h[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
A = [list(map(int, input().split())) for h in range(H)]

ans = []
# 先ずは各行に注目して奇数を右端に寄せる
for h in range(H):
  for w in range(W-1):
    if A[h][w] % 2: # A[h][w]が奇数
      A[h][w] -= 1
      A[h][w+1] += 1
      ans.append([h+1, w+1, h+1, w+2])

# 最も右の列に注目して(それ以外の列は全て偶数)奇数を下に寄せる
for h in range(H-1):
  if A[h][-1] % 2: # A[h][-1]が奇数
    A[h][-1] -= 1
    A[h+1][-1] += 1
    ans.append([h+1, W, h+2, W])

print(len(ans))
for a in ans:
  print(*a)

Measured memory_bytes: 30288
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
 

 class Main{

     static int[] dens=new int[10];
     public static void main(String args[]){
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         try{
             String line;String hit="A";
             while((line=br.readLine())!= null){if(line.isEmpty())break;
                 String split[] = line.split(",");
                 String a =split[0];//val
                 String b = split[1];//num
                 if(a.equals(hit))hit=b;
                 else if(b.equals(hit))hit=a;
             }
                 System.out.println(hit);
             
         }catch(Exception e){}         
     }
    
 }

Measured memory_bytes: 16908
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;



int main() {
    string s; cin >> s;
    int n = s.size();
    int A,Z;
    rep(i,n){
        if(s[i] == 'A'){
            A = i;
            break;
        }
    }
    for(int i = n-1; i >= 0; i--){
        if(s[i] == 'Z') {
            Z = i;
            break;
        }
    }
    cout << Z - A + 1 << endl;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e3 + 5;

char c[MAXN][MAXN];

int cnt_v[MAXN][MAXN], cnt_e[MAXN][MAXN];

int cnt_e_g[MAXN][MAXN], cnt_e_v[MAXN][MAXN];

void solve(){
	int n, m, q, i1, j1, i2, j2;
	scanf("%d%d%d", &n, &m, &q);
	REPN(i, 1, n){
		scanf("%s", &c[i][1]);
	}
	REPN(i, 1, n){
		REPN(j, 1, m){
			cnt_v[i][j] = cnt_v[i][j - 1] + cnt_v[i - 1][j] - cnt_v[i - 1][j - 1];
			if (c[i][j] == '1'){
				cnt_v[i][j]++;
			}
			cnt_e[i][j] = cnt_e[i][j - 1] + cnt_e[i - 1][j] - cnt_e[i - 1][j - 1];
			if (c[i][j] == '1' && c[i - 1][j] == '1'){
				cnt_e[i][j]++;
			}
			if (c[i][j] == '1' && c[i][j - 1] == '1'){
				cnt_e[i][j]++;
			}
			
			cnt_e_g[i][j] = cnt_e_g[i][j - 1];
			if (c[i][j] == '1' && c[i + 1][j] == '1'){
				cnt_e_g[i][j]++;
			}
		}
	}
	
	REPN(j, 1, m){
		REPN(i, 1, n){
			cnt_e_v[i][j] = cnt_e_v[i - 1][j];
			if (c[i][j] == '1' && c[i][j + 1] == '1'){
				cnt_e_v[i][j]++;
			}
		}
	}
	
	while(q--){
		scanf("%d%d%d%d", &i1, &j1, &i2, &j2);
		
		//printf("%d %d %d %d\n", i1, j1, i2, j2);
		
		int v = cnt_v[i2][j2] - cnt_v[i1 - 1][j2] - cnt_v[i2][j1 - 1] + cnt_v[i1 - 1][j1 - 1];
		int e = cnt_e[i2][j2] - cnt_e[i1 - 1][j2] - cnt_e[i2][j1 - 1] + cnt_e[i1 - 1][j1 - 1];
		
		int add_e = (cnt_e_g[i1 - 1][j2] - cnt_e_g[i1 - 1][j1 - 1]) + (cnt_e_v[i2][j1 - 1] - cnt_e_v[i1 - 1][j1 - 1]);
		e -= add_e;
		
		//printf("%d %d %d\n", v, e, add_e);
		
		printf("%d\n", v - e);
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 68480
import heapq
import sys

input = sys.stdin.readline

inf = 10**13

N,M,S = map(int,input().split())

data = [[] for _ in range(N)]

sumA = 0

for i in range(M):
    U,V,A,B = map(int,input().split())
    sumA += A
    U -= 1
    V -= 1
    data[U].append((B,V,A))###(距離, 行き先, 費用)
    data[V].append((B,U,A))###(距離, 行き先, 費用)

P = sumA

C = [0]*N
D = [0]*N

for i in range(N):
    C[i],D[i] = map(int,input().split())

dist = [[inf]*(P+1) for _ in range(N)]
#visit = [[0]*(P+1) for _ in range(N)]
###heapにぶち込んだことがあるかないか

q = [(0,0,min(S,P))]###(仮の最短距離, 頂点番号, 所持金)
heapq.heapify(q)

while q:
    v = heapq.heappop(q)
    if v[0] >= dist[v[1]][v[2]]:
        continue
    dist[v[1]][v[2]] = v[0]

    if v[2] + C[v[1]] <= P:
        if dist[v[1]][v[2]+C[v[1]]] == inf:
            heapq.heappush(q,(v[0]+D[v[1]],v[1],v[2]+C[v[1]]))

    for x in data[v[1]]:
        if x[2] > v[2]:
            continue
        if dist[x[1]][v[2]-x[2]] == inf:
            heapq.heappush(q,(v[0]+x[0],x[1],v[2]-x[2]))
    
    ###
    #print(P)
    #print(q)
    #print(v)
    ###

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



Measured memory_bytes: 116320
#include <stdio.h>

int main(void)
{
	int count[4][3][10] = {0};
	int n, b, f, r, v;
	int B, R, F;
	scanf("%d", &n);
	while (n--)
	{
		scanf("%d %d %d %d", &b, &f, &r, &v);
		count[b - 1][f - 1][r - 1] += v;
	}
	
	for (B = 0; B < 4; B++)
	{
		for (F = 0; F < 3; F++)
		{
			for (R = 0; R < 10; R++)
			{
				printf(" %d", count[B][F][R]);
			}
			putchar('\n');
		}
		if (B != 3)
			printf("####################\n");
	}
	return 0;
}

Measured memory_bytes: 612
n = gets.to_i
vs = gets.split.map(&:to_i)

evens = {}
odds = {}
0.upto(n-1) do |i|
  v = vs[i]
  # puts "vs[#{i}] = #{v}"
  if i % 2 == 0
    evens[v] = (evens[v] || 0) + 1
  else
    odds[v] = (odds[v] || 0) + 1
  end
end

evens = evens.map{|num,count| [num, count]}.sort_by{|arr| arr[1]*-1 }
odds = odds.map{|num,count| [num, count]}.sort_by{|arr| arr[1]*-1 }

# puts evens.to_s
# puts odds.to_s

if evens[0][0] != odds[0][0]
  evens_already = evens[0][1]
  odds_already = odds[0][1]
else
  evens_next_diff = evens[0][1] - (evens[1] || [0,0])[1]
  odds_next_diff = odds[0][1] - (odds[1] || [0,0])[1]
  # puts [evens_next_diff, odds_next_diff].to_s
  if evens_next_diff > odds_next_diff
    evens_already = evens[0][1]
    odds_already = odds[0][1] - odds_next_diff
  else
    evens_already = evens[0][1] - evens_next_diff
    odds_already = odds[0][1]
  end
end
# puts "[#{evens_already}, #{odds_already}]"
puts n - (evens_already + odds_already)


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

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

template<class... Args>
auto nvect(size_t n, Args&&... args) {
	if constexpr(sizeof...(args) == 1)
		return vector(n, args...);
	else
		return vector(n, nvect(args...));
}


int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	auto dp = nvect<ll>(n+1, 2, 2, 0);
	dp[0][0][0] = 1;
	rep(i, n)rep(j, 2)rep(k, 2)rep(d, 10){
		int nj = int(d == 0 or j);
		int nk = int(d == 9 or k);
		dp[i+1][nj][nk] += dp[i][j][k];
		dp[i+1][nj][nk] %= MOD;
	}
	cout << dp[n][1][1];
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef string::const_iterator State;

set<int> expression(State &);
set<int> number(State&);
set<int> factor(State&);


set<int> number(State &begin){
  int ret = 0;
  while(isdigit(*begin)){
    ret *= 10;
    ret += *begin - '0';
    begin++;
  }
  set<int> res;
  res.insert(ret);
  return res;
}

// 括弧か数をパースして、その評価結果を返す。
set<int> factor(State &begin) {
    if (*begin == '(') {
        begin++;
        auto ret = expression(begin);
        begin++;
        return ret;
    } else {
        return number(begin);
    }
}


set<int> expression(State &begin){
  vector<set<int>> nums;
  vector<char> ops;
  nums.push_back(factor(begin));
  while( *begin == '+' || *begin == '-' ||
         *begin == '*' || *begin == '/' ) {

    ops.push_back(*begin);
    begin++;
    nums.push_back(factor(begin));
  }

  int n = ops.size();
  vector<int> perm(n);
  //next perm で回すためのvector配列
  rep(i,n) perm[i] = i;
  set<int> ret;
  do{
    vector<set<int>> buff = nums;
    bool ng = false;
    rep(i,n){
      int L = perm[i];
      int R = L+1;
      char op = ops[perm[i]];
      while(L >= 0 && buff[L].size() == 0){
        L--;
      }
      if(L < 0){
        ng = true;
        break;
      }
      set<int> to;
      for(auto el1: buff[L]){
        for(auto el2: buff[R]){
          if(op == '+') to.insert(el1 + el2);
          if(op == '-') to.insert(el1 - el2);
          if(op == '*') to.insert(el1 * el2);
          if(op == '/' && el2 != 0) to.insert(el1 / el2);
        }
      }
      buff[L] = to;
      buff[R].clear();
    }
    if( !ng ){
      for(int el: buff[0]){
        ret.insert(el);
      }
    }
  } while (next_permutation(all(perm)));
  return ret;
}

void solve(const string & s){
  State begin = s.begin();
  auto ans = expression(begin);
  cout << ans.size() << endl;
}

int main(){
  string s;
  while(cin >> s){
    if( s=="#") break;
    solve(s);
  }
  return 0;
}



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

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

  if (A >= 500) {
    cout << "Yes" << endl;
  } else if ((N % 500) <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  } 
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

const PI: f64 = std::f64::consts::PI;

#[fastout]
fn main() {
    input! {
        a: f64,
        b: f64,
        h: f64,
        m: f64,
    }

    let angle = ((h * 5.0 + m / 60.0 * 5.0) / 60.0 - m / 60.0).abs() * 2.0 * PI;
    let hoge = a * a + b * b - 2.0 * a * b * angle.cos();
    let ans = hoge.sqrt();
    println!("{}", ans);
}


Measured memory_bytes: 3008
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, M, ABs):
    ans = 0
    schedule = [0] * M
    max_start_day = [M - i for i in range(M + 1)]
    ABs.sort(key=lambda x: x[1], reverse=True)
    for A, B in ABs:
        if A > M:
            continue
        work_day = max_start_day[A]
        if work_day < 0:
            continue
        flg = False
        while schedule[work_day] != 0:
            work_day -= 1
            if work_day < 0:
                flg = True
                break
        if flg:
            max_start_day[A] = work_day
            continue
        ans += B
        schedule[work_day] = B
        max_start_day[A] = work_day - 1
    print(ans)


if __name__ == '__main__':
    N, M = map(int, input().split())
    ABs = [[int(i) for i in input().split()] for _ in range(N)]

    # from random import randint
    # N, M = 10 ** 5, 10 ** 5
    # ABs = [[randint(1, 10 ** 5), randint(1, 10 ** 4)] for _ in range(10 ** 5)]

    solve(N, M, ABs)

Measured memory_bytes: 96620
/*
把A从小到大排序，可以写出如下两个B是合法的中位数序列的必要条件：
(1)B[i]是A中的数 
(2)A[i] <= B[i] <= A[2N - i]。B[i]的下界就是A[1] ~ A[2i - 1]的中位数A[i]，B[i]的上界就是A[2N - 2i + 1] ~ A[2N - 1]的中位数A[2N - i]
(3)不存在任意一对i < j < N，满足B[j] < B[i] < B[j + 1]或B[j] > B[i] > B[j + 1]
   注意按照题目所给出的每次加入2个数的过程，分情况讨论：
   (1)加入的2个数在中位数的两边，那么中位数不变
   (2)加入的2个数都在中位数的左边，那么中位数往左边移动1个位置。即找到当前中位数左边最靠右的点，就是新的中位数
   (3)加入的2个数都在中位数的右边，那么中位数往右边移动1个位置。即找到当前中位数右边最靠左的点，就是新的中位数
   那么显然，如果出现了B[j] < B[i] < B[j + 1]或B[j] > B[i] > B[j + 1]的情况，可以通过反证证明不合法
同时，这3个条件也是B是合法的中位数序列的充分条件，因为可以按照从后往前的顺序贪心构造
*/
/*
考虑从后往前填入B中的数，显然(2)限制中的区间越来越松。同时当前限制区间的两个端点都是可以被填的
dp这个过程。F[i][a][b]表示，从后往前填到了第i个数，第i - 1个数可以填的数中有a个< B[i]，有b个> B[i]，同时B[i]也是可以填的。转移分为3种：
(1)B[i - 1] = B[i]，转移到F[i - 1][a][b]
(2)B[i - 1] < B[i]，也就是说B[i - 1]是a个< B[i]中的。填上该数后，B[i]和B[i - 1]都可以填，但是B[i - 1] < v < B[i]的数不可以填了
   转移到F[i - 1][(x <= a) - 1][1 + b]
(3)B[i - 1] > B[i]，也就是说B[i - 1]是b个> B[i]中的，填上该数后，B[i]和B[i - 1]都可以填，但是B[i] < v < B[i - 1]的数不可以填了
   转移到F[i - 1][1 + a][(x <= b) - 1]
每次转移之前要把当前新增的限制区间的端点加进去
*/

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long int LL;
const int MOD(1000000000 + 7);
const int Max_N(55);

constexpr int Mult(int a, int b)
{
	return a * 1LL * b % MOD;
}

constexpr int Add(int a, int b)
{
	return a + b >= MOD ? a + b - MOD : a + b;
}

constexpr int Sub(int a, int b)
{
	return a - b < 0 ? a - b + MOD : a - b;
}

int N, A[Max_N << 1], L[Max_N], R[Max_N], F[Max_N << 1][Max_N << 1][Max_N << 1], G[Max_N << 1][Max_N << 1];

int main()
{
	scanf("%d", &N);
	for (int i = 1;i <= 2 * N - 1;++i)
		scanf("%d", A + i);
	sort(A + 1, A + 1 + (2 * N - 1));
	for (int i = 1;i <= N;++i)
		L[i] = A[i], R[i] = A[2 * N - i];
	F[N][0][0] = 1;
	for (int i = N - 1;i >= 1;--i)
	{
		memset(G, 0, sizeof(G));
		for (int a = 0;a <= 2 * N - 1;++a)
			for (int b = 0;b <= 2 * N - 1;++b)
				if (F[i + 1][a][b])
					G[a + (L[i] != L[i + 1])][b + (R[i] != R[i + 1])] = F[i + 1][a][b];
		for (int a = 0;a <= 2 * N - 1;++a)
			for (int b = 0;b <= 2 * N - 1;++b)
				if (G[a][b])
				{
					F[i][a][b] = Add(F[i][a][b], G[a][b]);
					for (int x = 1;x <= a;++x)
						F[i][x - 1][1 + b] = Add(F[i][x - 1][1 + b], G[a][b]);
					for (int x = 1;x <= b;++x)
						F[i][1 + a][x - 1] = Add(F[i][1 + a][x - 1], G[a][b]);
				}
	}
	int Ans(0);
	for (int a = 0;a <= 2 * N - 1;++a)
		for (int b = 0;b <= 2 * N - 1;++b)
			Ans = Add(Ans, F[1][a][b]);
	printf("%d", Ans);
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
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; }

string s;
int x, y;
bool dp[8080][16010];

int main() {
    cin >> s >> x >> y;
    int slen = s.length();
    vector<int> Fsum(slen+1, 0);
    for(int i = 0; i < slen; ++i) if(s[i] == 'F') Fsum[i+1]++;
    for(int i = 0; i < slen; ++i) Fsum[i+1] += Fsum[i];

    vector<int> Fd;
    int pre = 0;
    for(int i = 0; i < slen; ++i) {
        if(s[i] == 'T' || i == slen-1) {
            int fadd = Fsum[i+1] - Fsum[pre];
            Fd.emplace_back(fadd);
            pre = i;
        }
    }

    // Tの間のFの数が管理できている
    // 偶数番目の区間がx, 奇数番目の区間がy
    vector<int> Feven;
    vector<int> Fodd;
    for(int i = 0; i < (int)Fd.size(); ++i) {
        if(i % 2 == 0) Feven.emplace_back(Fd[i]);
        else Fodd.emplace_back(Fd[i]);
    }

    x += 8000; y += 8000;
    // xについて計算する
    memset(dp, 0, sizeof(dp));
    dp[0][8000] = true;
    int Femax = Feven.size();
    for(int i = 0; i < Femax; ++i) {
        for(int j = 0; j <= 16000; ++j) {
            if(i == 0) {
                if(j-Feven[i] >= 0) dp[i+1][j] = dp[i][j-Feven[i]];
            }
            else {
                if(j-Feven[i] >= 0) dp[i+1][j] = dp[i][j-Feven[i]];
                if(j+Feven[i] <= 16000) {
                    if(!dp[i+1][j]) dp[i+1][j] = dp[i][j+Feven[i]];
                }
            }
        }
    }

    bool flgx = dp[Femax][x];
    /*if(flgx) cout << "true" << endl;
    else cout << "false" << endl;*/

    // yについて計算する
    memset(dp, 0, sizeof(dp));
    dp[0][8000] = true;
    int Fomax = Fodd.size();
    for(int i = 0; i < Fomax; ++i) {
        for(int j = 0; j <= 16000; ++j) {
            if(j-Fodd[i] >= 0) dp[i+1][j] = dp[i][j-Fodd[i]];
            if(j+Fodd[i] <= 16000) {
                if(!dp[i+1][j])dp[i+1][j] = dp[i][j+Fodd[i]];
            }
        }
    }

    bool flgy = dp[Fomax][y];
    /*if(flgy) cout << "true" << endl;
    else cout << "false" << endl;*/

    if(flgx && flgy) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 130072
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vint a(n);
	rep(i, n) {
		cin >> a[i];
	}
	llint now = 0, cnt = 0;
	rep(i, n) {
		now += a[i];
		if (i % 2 == 0) {
			if (now <= 0) {
				cnt -= now;
				cnt++;
				now = 1;
			}
		}
		else {
			if (now >= 0) {
				cnt += now;
				cnt++;
				now = -1;
			}
		}
	}
	llint ans = cnt;
	cnt = 0;
	now = 0;
	rep(i, n) {
		now += a[i];
		if (i % 2 != 0) {
			if (now <= 0) {
				cnt -= now;
				cnt++;
				now = 1;
			}
		}
		else {
			if (now >= 0) {
				cnt += now;
				cnt++;
				now = -1;
			}
		}
	}
	cout << min(ans, cnt) << endl;
	return 0;
}

Measured memory_bytes: 640
def s_sort(A,N):

   for i in range(N):
       min_j = i
       for j in range(i,N):
           if A[j][1:] < A[min_j][1:]:
               min_j = j

       if i != min_j:
           temp = A[i]
           A[i] = A[min_j]
           A[min_j] = temp

   return A

def b_sort(A,N):
    for i in range(N):
        for j in range(N - 1,i,-1):
            if A[j][1:] < A[j-1][1:]:
                A[j],A[j-1] = A[j-1],A[j]
        
    return A

if __name__ == '__main__':
    n = int(input())
    R = list(map(str,input().split()))
    C = R[:]
    Sr = s_sort(R,n)
    Br = b_sort(C,n)

    fstable = Sr == Br

    print(" ".join(map(str,Br)))
    print("Stable")
    print(" ".join(map(str,Sr)))
    if(fstable == True):
       print("Stable")
    else:
       print("Not stable")



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

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


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

ll n, k, t, d;
vector<pair<ll, int>> sushi;

int main() {
    cin >> n >> k;
    
    for(int i = 1; i <= n; i++) {
        cin >> t >> d;
        //おいしさを第一要素、ネタを第二要素としてsushiに入れる
        sushi.push_back({d, t});
    }

    map<int, ll> m;
    sort(sushi.begin(), sushi.end());

    ll ans = 0, sum = 0, cnt = 0, r = 0;
    for(int i = n-1; i >= 0; i--) {
        if(i >= n-k) {
            m[sushi[i].second]++;
            sum += sushi[i].first;

            if(i == n-k) {
                ll s = m.size();
                ans = sum + s*s;
                r = n-k;
            }
        }
        else {
            if(!m.count(sushi[i].second)) {
                m[sushi[i].second]++;

                while(r <= n-1 && m[sushi[r].second] == 1) {
                    r++;
                }

                if(r == n) {
                    break;
                }

                sum += sushi[i].first - sushi[r].first;
                m[sushi[r].second]--;
                r++;
                ll s = m.size();
                ans = max(ans, sum + s*s);
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5744
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

int main()
{
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 4) {
    if (s[i]=='2') ans++;
  }
  pr(ans);
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>

using namespace std;

int main() {
	int A,B;
	cin >> A >> B;
	
	if (A == B) {
		cout << A * 2 << endl;
	} else {
		cout << max(A,B) * 2 - 1 << endl;
	}
	
	return 0;
}


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

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

use std::cmp::{max, min};
use std::collections::HashMap;

fn gcd(a: i64, b: i64) -> i64 {
  if a % b == 0 {
    b
  } else {
    gcd(b, a % b)
  }
}

fn lcm(a: i64, b: i64) -> i64 {
  a * b / gcd(a, b)
}

fn main() {
  let n = read::<i64>();
  let mut vec: Vec<Vec<i64>> = vec![];
  let mut s_x = 0;
  let mut s_y = 0;
  let mut time = 0;
  let mut ans = "Yes";

  for _ in 0..n {
    let t = read::<i64>();
    let x = read::<i64>();
    let y = read::<i64>();
    vec.push(vec![t, x, y]);
  }

  for i in vec {
    let t = i[0];
    let x = i[1];
    let y = i[2];
    let d_x = (s_x - x).abs();
    let d_y = (s_y - y).abs();
    let d_time = (time - t).abs();

    if (d_x + d_y) % 2 != d_time % 2 || d_time < d_x + d_y {
      ans = "No";
      break;
    }
    s_x = x;
    s_y = y;
    time = t;
  }

  println!("{}", ans);
}


Measured memory_bytes: 10492
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int n, m;
double l[20], a[20], b[20];

vector<int> use;

// idx以降でk個選ぶときの最大値
double dfs(int idx, int k){
    double res = 0;
    if (k == 0){
        for (int i = 0; i < use.size(); i++)
        {
            for (int j = 0; j < i; j++)
            {
                double dl = l[use[i]] - l[use[j]];
                double da = a[use[i]] - a[use[j]];
                double db = b[use[i]] - b[use[j]];
                res += dl*dl + da*da + db*db;
            }
        }
    }
    else
    {
        for (int i = idx; i < n - k + 1; i++)
        {
            use.push_back(i);
            res = max(res, dfs(i+1, k - 1));
            use.pop_back();
        }
    }
    return res;
}

int main(){
    while (cin >> n >> m && n | m)
    {
        for (int i = 0; i < n; i++)
        {
            cin >> l[i] >> a[i] >> b[i];
        }
        cout << fixed << setprecision(20) << dfs(0, m) << endl;
    }
}

Measured memory_bytes: 1304