akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long 
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000009
using namespace std;
bool isprime(ll n)
{
    //if(n<2)
    //return false;
    if(n==1)
    return true;
    if(n==2 || n==3)
    return true;
    if(n%2==0)return false;
    for(ll i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        return false;
        
    }
    return true;
}
int gcd(ll a,ll b)
{
    if(a==0)
    return b;
    return gcd(b%a,a);
}
int lcm(ll a,ll b)
{
    return a*(b/gcd(a,b));
}
 set<ll> fac;
void allFactors(ll n)
{
   // set<ll> fac;
    for(ll i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            fac.insert(i);
            if(i!=n/i)
            {
                fac.insert(n/i);
               
            }
        }
    }
    //return fac.size();
}
bool threefactors(ll n)//when you have need of a no which is divisible by 1,itself,any other one no.
{
    ll p=sqrt(n);
    if(p*p==n)
    {
        if(isprime(p))
        return 1;
        else
        return 0;
    }
    else
    return 0;
}
unsigned int countSetBits(unsigned int n) //no. of 1's in a binary representation of a number
{ 
    unsigned int count = 0; 
    while (n) { 
        count += n & 1; 
        n >>= 1; 
    } 
    return count; 
} 
int main()
{
     IOS
     int testcases;
    // cin>>testcases;
     //while(testcases--)
     {
       
            int n;
            cin>>n;
           int h[n];
           for(int i=0;i<n;i++)
           {
               cin>>h[i];
           }
           ll dp[n];
           for(int i=0;i<n;i++)
           {
               dp[i]=mod;
           }
           dp[0]=0;
           for(int i=0;i<n;i++)
           {
               if(i+1<n)
               {
               if(dp[i+1]>0)
               dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
              // else
               //dp[i+1]=dp[i]+abs(h[i]-h[i+1]);
               }
               if(i+2<n)
               {
               if(dp[i+2]>0)
               dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
               //else
               //dp[i+2]=dp[i]+abs(h[i]-h[i+2]);
               }
           }
           cout<<dp[n-1];
     }
     return 0;
} 
//ascii of a=97
//ascii of A=65
//ascii of 0=48

Measured memory_bytes: 4852
#include <stdio.h>
#include <string.h>
 
int main(void){
	char s[128];
  	scanf("%s",s);
  	if(strcmp(s,"Sunny")==0){
		printf("Cloudy");
    }else if(strcmp(s,"Cloudy")==0){
		printf("Rainy");
    }else if(strcmp(s,"Rainy")==0){
		printf("Sunny");
    }
             }
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

int main() {
    //ifstream cin("f.in");

    int n, m; cin >> n >> m; 
    
    vector<vector<int>> mat(n, vector<int> (n, 0));
    vector<int> b(n, 0);

    for(int i = 0; i < m; ++i) {
        int x, y; cin >> x >> y;
        x -= 1, y -= 1;
        mat[x][y] = 1;
        b[x] |= (1 << y);
    }
    
    auto add = [&] (int &a, int b) {
        a += b;
        while(a >= MOD) {
            a -= MOD;
        }
        while(a < 0) {
            a += MOD;
        }
    };

    vector<vector<int>> dp(16, vector<int> ((1 << n), 0));
    vector<int> set_bits((1 << 15), 0);
    
    for(int i = 1; i < (1 << 15); ++i) {
        set_bits[i] = set_bits[i >> 1] + (i & 1);
    }

    for(int mask = 0; mask < (1 << n); ++mask) {
        int ways = 1;
        if((mask & 1) and (mask & 2))
            continue;
        for(int i = 0; i < n; ++i) {
            if((1 << i) & mask)
                continue;
            int who = set_bits[(b[i] & mask)];
            ways = 1LL * ways * ((1 << who) - 1) % MOD;
        }

        for(int i = 0; i < n; ++i) {
            if((1 << i) & mask) {
                int many = set_bits[b[i] & ((1 << n) - mask)];
                ways = 1LL * ways * ((1 << many)) % MOD;
            }
        }

        dp[0][mask] = ways;
    }

    for(int nimber = 1; nimber < 16; ++nimber) {
        for(int mask = 0; mask < (1 << n); ++mask) {
            for(int sub = mask - 1; sub > 0; sub = ((sub - 1) & mask)) {
                if((sub & 1) and (sub & 2))
                    continue;
                if(dp[nimber - 1][mask - sub] == 0)
                    continue;

                int ways = 1;
                for(int i = 0; i < n; ++i) {
                    if((1 << i) & mask)
                        continue;
                    int who = set_bits[(b[i] & sub)];
                    ways = 1LL * ways * ((1 << who) - 1) % MOD;
                    if(ways == 0) {
                        break;
                    }
                }
                
                if(ways == 0) {
                    continue;
                }

                for(int i = 0; i < n; ++i) {
                    if((1 << i) & sub) {
                        int many = set_bits[b[i] & ((1 << n) - mask)];
                        ways = 1LL * ways * (1 << many) % MOD;
                    }
                }

                int prv = dp[nimber - 1][mask - sub];
                add(dp[nimber][mask], 1LL * prv * ways % MOD);
            }
        }
    }

    int ans = 0;
    for(int nimber = 1; nimber < 16; ++nimber)
        add(ans, dp[nimber][(1 << n) - 1]);

    cout << ans << "\n";
}

Measured memory_bytes: 2556
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;


const int mod=1000000007;
//const int mod=998244353;



int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,d,y,l,r;
    cin >> n >> k;
    vi v(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    vi vv(k+1,0);
    for(int i=0; i<v[0]; i++){
        vv[i]=0;
    }
    for(int i=0; i<=k; i++){
        for(int j=0; j<n; j++){
            if(i-v[j]>=0&&vv[i-v[j]]==0){
                vv[i]=1;
                break;
            }
        }
    }
    cout << (vv[k]==1?"First":"Second") << el;
    return 0;
}


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

using namespace std;
using vi = vector<int>;


#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"
const int INF = 1e9;

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

  IN(N);
  vi A(N);
  REP(i, N)
    cin >> A[i];

  int ans = INF;
  FOR(x, -100, 100+1) {
    int cost = 0;
    REP(i, N) {
      cost += (A[i] - x) * (A[i] - x);
    }
    ans = min(ans, cost);
  }
  OUT(ans);

  return 0;
}


Measured memory_bytes: 896
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	Map<Long, ArrayList<Long>> m = new HashMap<Long ,ArrayList<Long>>();

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long W = sc.nextLong();


		long w0=0;
		ArrayList<ArrayList<Long>> wv = new ArrayList<ArrayList<Long>>();
		for(int i=0; i<4; i++) {
			wv.add(new ArrayList<Long>());
		}
		for(int i=0; i<n; i++) {
			int w=sc.nextInt();
			long v=sc.nextLong();
			if(i==0) w0=w;
			wv.get((int)(w-w0)).add(v);
		}
		for(int i=0; i<4; i++) {
			Collections.sort(wv.get(i), (x,y)->Long.compare(y, x));
		}
		long s[][] = new long[4][n+1];
		for(int i=0; i<4; i++) {
			s[i][0]=0;
		}
		for(int i=0; i<4; i++) {
			for(int j=0; j<wv.get(i).size(); j++) {
				s[i][j+1] = s[i][j] + wv.get(i).get(j);
			}
		}

		long max = 0;
		for(int i=0; i<=wv.get(0).size(); i++) {
			for(int j=0; j<=wv.get(1).size(); j++) {
				for(int k=0; k<=wv.get(2).size(); k++) {
					for(int l=0; l<=wv.get(3).size(); l++) {
						if((w0*i + (w0+1)*j + (w0+2)*k + (w0+3)*l)>W) continue;
						max = Math.max(max, s[0][i] + s[1][j] + s[2][k] + s[3][l]);
					}
				}
			}
		}
		System.out.println(max);
		sc.close();
	}


}




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

void print(vector<int> &v){
    int i = 0;
    vector<int>::iterator ite = v.begin();
    while(ite != v.end()){
        if(i++ != 0)
            cout << " ";
        cout << *ite;
        ite++;
    }
    cout << endl;
}

int bubbleSort(vector<int> &v){
    int size = v.size(), i, cnt = 0;
    bool changed = true;
    while(changed){
        changed = false;
        for(i = 0; i < size-1; i++){
            if(v[i] > v[i+1]){
                int tmp = v[i];
                v[i] = v[i+1];
                v[i+1] = tmp;
                changed = true;
                cnt++;
            }
        }
    }
    return cnt;
}

int main(){
    int n, x, i;
    vector<int> v;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> x;
        v.push_back(x);
    }
    int cnt = bubbleSort(v);
    print(v);
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1220
def main():
    m = int(input())
    s = set()
    for _ in range(m):
        a,b = map(int,input().split())
        if a == 0:
            s.add(b)
            print (len(s))
        elif a == 1:
            if b in s:print (1)
            else     :print (0)
        elif b in s:s.remove(b)


if __name__ == '__main__':
    main()




Measured memory_bytes: 23360
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <functional>
#include <algorithm>
using namespace std;
typedef tuple<int,int,int> tiii;

typedef struct{
	int x;
	int y;
}dir;
vector<dir>D={
	{-1,-1},{0,-1},{1,-1},
	{-1,0},{1,0},
	{-1,1},{0,1},{1,1},
};

const int H=8,W=8;
vector<function<bool(tiii,tiii)> >sorter={ //{num,x,y}
	[](tiii a,tiii b)->bool{
		if(get<0>(a)<get<0>(b))return true;
		if(get<0>(a)>get<0>(b))return false;
		if(get<2>(a)>get<2>(b))return true;
		if(get<2>(a)<get<2>(b))return false;
		if(get<1>(a)>get<1>(b))return true;
		if(get<1>(a)<get<1>(b))return false;
		return false;
	},
	[](tiii a,tiii b)->bool{
		if(get<0>(a)<get<0>(b))return true;
		if(get<0>(a)>get<0>(b))return false;
		if(get<2>(a)<get<2>(b))return true;
		if(get<2>(a)>get<2>(b))return false;
		if(get<1>(a)<get<1>(b))return true;
		if(get<1>(a)>get<1>(b))return false;
		return false;
	}
};

int check2(int color,dir&d,int x,int y,vector<string>&m){
	if(x<0||W<=x||y<0||H<=y||m[y][x]=='.')return -1;
	if(m[y][x]==color)return 0;
	int r=check2(color,d,x+d.x,y+d.y,m);
	if(r<0)return r;
	return r+1;
}
int check1(int color,int x,int y,vector<string>&m){
	int R=-1;
	for(auto &d:D){
		int r=check2(color,d,x+d.x,y+d.y,m);
		if(r>0){
			if(R<0)R=0;
			R+=r;
		}
	}
	return R;
}

int fill2(int color,dir&d,int x,int y,vector<string>&m){
	if(x<0||W<=x||y<0||H<=y||m[y][x]=='.')return -1;
	if(m[y][x]==color)return 0;
	int r=fill2(color,d,x+d.x,y+d.y,m);
	if(r<0)return r;
	m[y][x]=color;
	return r+1;
}
void fill1(int color,int x,int y,vector<string>&m){
	for(auto &d:D)fill2(color,d,x+d.x,y+d.y,m);
}

int main(){
	string color="ox";
	vector<string>m(H);
	for(int h=0;h<H;h++)cin>>m[h];
	int turn=0,pass=0;
	for(;;turn^=1){
		vector<tiii>v;
		for(int y=0;y<H;y++)for(int x=0;x<W;x++)if(m[y][x]=='.'){
			int r=check1(color[turn],x,y,m);
			if(r>0)v.push_back(make_tuple(r,x,y));
		}
		if(v.empty()){
			pass++;
			if(pass>1)break;
		}else{
			pass=0;
			sort(v.begin(),v.end(),sorter[turn]);
			tiii &t=*v.rbegin();
			int x=get<1>(t),y=get<2>(t);
			fill1(color[turn],x,y,m);
			m[y][x]=color[turn];
		}
	}
	for(int h=0;h<H;h++)cout<<m[h]<<endl;
	return 0;
}

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

int N,K;
int ans = 0;
vector<int> V;
long long dp[10][10010] = {1};

int main()
{
    scanf("%d%d",&N,&K);
    for(int i = 0; i < N; i++)
    {
        int a;
        scanf("%d",&a);
        if(a < K)
        {
            V.push_back(a);
        }
    }
    N = V.size();
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j <= K * 2; j++)
        {
            if(dp[0][j] != 0)
            {
                dp[1][j] += dp[0][j];
                if(j + V[i] <= K * 2)dp[1][j + V[i]] += dp[0][j];
            }
        }
        for(int j = 0; j <= K * 2; j++)
        {
            dp[0][j] = dp[1][j] % 1000000007;
            dp[1][j] = 0;
        }
    }
    for(int i = 0; i < N; i++)
    {
        int now = V[i];
        long long mem[10010] = {0};
        for(int j = 0; j <= K; j++)
        {
            if(j == K)ans++;
            if((dp[0][j] - mem[j] + 1000000007) % 1000000007 > 0)
            {
                mem[j + now] += dp[0][j] - mem[j];
                mem[j + now] %= 1000000007;
                mem[j] += dp[0][j] - mem[j];
                mem[j] %= 1000000007;
                if(j >= K - now)
                {
                    break;
                }
            }
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 512
N, M = map(int, input().split())
X = []
for i in range(M):
    a, _ = map(int, input().split())
    c = list(map(int, input().split()))
    key = sum(1 << (v - 1) for v in c)
    X.append([key, a])

INF = 10 ** 9 + 7
dp = [[INF] * (2 ** N) for _ in range(M + 1)]
dp[0][0] = 0
for i in range(M):
    for j in range(2 ** N):
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
        dp[i + 1][j | X[i][0]] = min(dp[i + 1][j | X[i][0]],
                                     dp[i][j] + X[i][1])

if dp[-1][-1] == INF:
    print(-1)
else:
    print(dp[-1][-1])


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

int main() {
  vector<int> x(3);
  cin >> x.at(0) >> x.at(1) >> x.at(2);
  sort(x.begin(), x.end());
  reverse(x.begin(), x.end());
  cout << x.at(0) * 10 + x.at(1) + x.at(2) <<endl;
}


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

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

using namespace std;
typedef unsigned long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> a(n+2, 0);
    vector<int>cumSum(n+2, 0);

    int init;
    cin >> init;
    cumSum[0] = 0;
    cumSum[1] = abs(init);
    a[1] = init;

    FOR(i, 2, n+1) {
        cin >> a[i];
        cumSum[i] = cumSum[i-1]+ abs(a[i] - a[i-1]);
    }
    cumSum[n+1] = cumSum[n] + abs(a[n]);

    FOR(i, 1, n+1){
        cout << cumSum[i-1] + (cumSum[n+1] - cumSum[i+1]) + abs(a[i+1] - a[i-1]) << endl;
        //  cout << cumSum[i-1] << '+' << (cumSum[n+1] - cumSum[i+1]) << '+' << abs(a[i+1] - a[i-1]) << endl;
    }

    
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

V<V<int>> g;
V<bool> checked;
int n1;
int n2;

void dfs(int v) {
  checked[v] = true;
  for (auto n : g[v]) {
    if (checked[n]) continue;
    if ((v == n1 && n == n2) || (v == n2 && n == n1)) continue;
    dfs(n);
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  V<int> a(m), b(m);
  rep(i, m) {
    int ai, bi;
    cin >> ai >> bi;
    a[i] = --ai;
    b[i] = --bi;
  }
  g.resize(n);
  checked.resize(n);
  rep(i, m) {
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }

  int ans = 0;
  rep(i, m) {
    fill(checked.begin(), checked.end(), false);
    n1 = a[i];
    n2 = b[i];
    dfs(0);
    bool ok = true;
    V<bool> t = checked;
    rep(i, n) if (!checked[i]) ok = false;
    if (!ok) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
while True:
    a = raw_input().split()
    if a.count('0') == 4:
        break
    b = zip(a, map(int, a))

    def f(b):
        if len(b) == 1:
            return b[0][0] if b[0][1] == 10 else 0

        for i in range(len(b)):
            for j in range(i + 1, len(b)):

                c = [b[k] for k in range(len(b)) if k != i and k != j]
                c.append(('({} * {})'.format(b[i][0], b[j][0]), b[i][1] * b[j][1]))
                d = f(c)
                if d:
                    return d

                c = [b[k] for k in range(len(b)) if k != i and k != j]
                c.append(('({} + {})'.format(b[i][0], b[j][0]), b[i][1] + b[j][1]))
                d = f(c)
                if d:
                    return d

                c = [b[k] for k in range(len(b)) if k != i and k != j]
                c.append(('({} - {})'.format(b[i][0], b[j][0]), b[i][1] - b[j][1]))
                d = f(c)
                if d:
                    return d

                c = [b[k] for k in range(len(b)) if k != i and k != j]
                c.append(('({} - {})'.format(b[j][0], b[i][0]), b[j][1] - b[i][1]))
                d = f(c)
                if d:
                    return d
        return 0
    print f(b)

Measured memory_bytes: 4348
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <algorithm> 
#include <set>
#include <sstream>
#include <bit>
#include <bitset>
#include <iomanip>
#include <queue>
typedef long long int ll;
using namespace std;
int main() {
	string S; cin >> S;
	for (int i = 0; i < S.size(); i++) {
		S[i] = 'x';
	}
	cout << S << endl;
}

Measured memory_bytes: 2968
import java.util.Scanner;

public class Main {

	static int count = 0;

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] S = new long[n];

		for(int i = 0; i < n; i++) {
			S[i] = sc.nextLong();
		}

		int q = sc.nextInt();

		for(int j = 0; j < q; j++) {

			long T = sc.nextLong();
			binarySearch(S, T);
		}
		System.out.println(count);
	}
	
	public static void binarySearch(long[] S, long T) {
		int left = 0;
		int right = S.length;
		
		while(left < right) {
			int mid = (left + right) / 2;
			if(S[mid] == T) {
				count++;
				return;
			} else if(S[mid] > T) {
				right = mid;
			} else if(S[mid] < T) {
				left = mid + 1;
			}
		}
	}

}


Measured memory_bytes: 69192
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> A;
#define int long long
int N,M;
pair<int , int> K[100001];
signed main() {
    cin >> N >> M;
    vector<A>vec[100001];
    for(int i = 0; i < M; i++) {
        int P,Y;
        cin >> P >> Y;
        vec[P].push_back(A(Y,i));
    }
    for(int i = 1; i <= N; i++) {
        sort(vec[i].begin(),vec[i].end());
        for(int j = 0; j < vec[i].size(); j++){
        	K[vec[i][j].second].first = i;
       	    K[vec[i][j].second].second = j+1;
        }
    }
    for(int i = 0; i < M; i++) {
        printf("%06d" "%06d\n",K[i].first,K[i].second);
    }
}

Measured memory_bytes: 8576
#include<stdio.h>
int main()
{
	int sougaku=0,sum=0,money=0,amari[100]={0},k=0;
	scanf("%d",&sougaku);
	while(sougaku!=0){
		for(int i=0;i<9;i++){
			scanf("%d",&money);
			sum=sum+money;
		}
		amari[k]=sougaku-sum;
		k++;
		sum=0;
		scanf("%d",&sougaku);
	}
	for(int i=0;i<k;i++){
		printf("%d\n",amari[i]);
	}
	return 0;
}

Measured memory_bytes: 1028
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections

mod = 10 ** 9 + 7
a, b, x = list(map(int, input().split()))
if (a * a * b / 2 >= x):
    print(90. - np.rad2deg(np.arctan(2*x/(a*b*b))))
else:
    print(np.rad2deg(np.arctan(2*b/a - 2*x/(a**3))))


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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<long long> v{2, 1};
  
  for (int i=2; i<=n; i++) {
    v.push_back(v[i-1]+v[i-2]);
  }

  printf("%lld\n", v.back());
  return 0;
}

Measured memory_bytes: 256
// Try diverta 2019 Programming Contest
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let r = get!();
    let g = get!();
    let b = get!();
    let n = get!();
    
    let mut ans = 0;
    
    for i in 0..n/r+1 {
    	let rem = n - i * r;
    	for j in 0..rem/g+1 {
        	let rem = rem - j * g;
            if rem >= 0 && rem % b == 0 {
            	ans += 1;
            }
        }
    }
    
    println!("{}", ans);
}

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

typedef long long ll;

void solve(){
	int n;
	cin>>n;
	vector<int> a(n+1);
	for(int i= 1; i <= n; ++i){
		cin>>a[i];
	}
	vector<ll> dp(n+1,0);
	dp[1] = 0;
	vector<ll> prefix(n+1);
	prefix[1] = a[1];
	for(int i=3;i<=n;i+=2){
		prefix[i] = prefix[i-2]+a[i];
	}
	for(int i=2;i<=n;i++){
		if(i&1){
			dp[i]=max(dp[i-1],dp[i-2]+a[i]);
		}else{
			dp[i] = a[i] + dp[i-2];
			dp[i] = max(dp[i],prefix[i-1]);
		}
	}
	cout<<dp[n]<<endl;
}

int main() {
	//freopen("input.txt","r",stdin);

	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL); 
	
	solve();

	/*if(){

		ll dp[n];
		fill(dp, dp+n, 0LL);

		// normal cases
		ll sum = 0;
		for(int i = 0; i < n; i += 2){
			sum += a[i];
		}
		ans = sum;
		sum = 0;
		for(int i = n-1; i >= 1; i -= 2){
			sum += a[i];
			dp[i] = sum;
		}
		ans = max(ans, sum);

		//abnormal case
		sum = 0;
		for(int i = 0; i+3 < n; i += 2){
			sum += a[i];
			ans = max(ans, sum + dp[i+3]);
		}
	}*/

}



Measured memory_bytes: 7152
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////


int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,A,B; cin >> N >> A >> B;
    cout << max(0LL,(N-2)*B - (N-2)*A + 1) << ln;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX 2000

int A[MAX];
int n;

int solve(int m,int j) {
	if(!m)  return 1;
	if(j>n) return 0;
	int res=solve(m,j+1)||solve(m-A[j],j+1);
	return res;
}

int main() {
	int q,i,m;
	cin >> n;
	for(i=0; i<n; i++) {
		cin>>A[i];
	}
	cin>>q;
	for(i=0; i<q; i++) {
		cin>>m;
		if(solve(m,0))  printf("yes\n");
		else printf("no\n");
	}

	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<ll, ll>
#define PLL pair<ll, ll>
#define PLI pair<ll, ll>
#define PIL pair<ll, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m,k,pro;
ll a[100010],pre[100010];
ll res;
int main()
{
	cin >>n>>m>>k>>pro;
	for (ll i=0;i<n;i++) cin >>a[i],a[i]=-a[i];
	sort(a,a+n);
	for (ll i=0;i<n;i++) pre[i+1]=pre[i]-a[i];
	ll ok=pro-1;
	while (a[ok+1]==a[pro-1] && ok<n) ok++;
	for (ll i=0;i<n;)
	{
		//cout <<i<<" "<<res<<" #########\n";
		bool fl=0;
		if (i<=ok) fl=1;
		else if (n-i>=k)
		{
			ll it=lower_bound(a,a+n,a[i]-m)-a;
			if (it<pro) fl=1;
			//cout <<-a[i]<<" "<<it<<" ##\n";
		}
		else
		{
			ll ki=k-(n-i),ni=i;
			ll it=lower_bound(a,a+n,a[i]-m)-a;
			ki-=it,ni-=it;
			ki*=m;
			ll l=0,r=ni,mid;
			while (l<r)
			{
				mid=(l+r)>>1;
				//cout <<l<<" "<<r<<" "<<mid<<" --- "<<mid*m+(ni-mid)*(-a[i]+m-1)-(pre[i]-pre[i-(ni-mid)])<<" "<<ki<<" ##\n";
				if (mid*m+(ni-mid)*(-a[i]+m)-(pre[i]-pre[i-(ni-mid)])>=ki)
					r=mid;
				else l=mid+1;
			}
			//cout <<ki<<" "<<i<<" "<<-a[i]<<" "<<l<<" ##\n";
			ll jt=lower_bound(a+it+l,a+n,a[i]-m)-a;
			if (jt<pro) fl=1;
		}
		if (!fl) break;
		ll j=i;
		while (a[i]==a[j] && i<n) res++,i++;
	}
	cout <<res;
	return 0;
}

Measured memory_bytes: 1792
def printboard( board )
	8.times{ |y|
		8.times{ |x|
			print board[ y ][ x ] 
		}
		puts
	}
end

def min( x , y)
	if x > y 
		y
	else
		x
	end
end
def max( x, y )
	if x > y
		x
	else
		y
	end
end

def bomb( board, sx, sy )
	chain = Array.new
	chain << [sx - 1,sy - 1]

	while chain.size > 0
		temp = chain.shift	
		tx = temp[ 0 ] 
		ty = temp[ 1 ]

		board[ ty ][ tx ] = 0

		lx1 = max( 0, tx - 3)
		lx2 = min( 7, tx + 3)
		lx1.upto( lx2 ){ |tempx|
			if board[ ty ][ tempx ] == 1
				chain << [tempx, ty ]
				board[ ty ][ tempx ] = 0
			end
		}

		ly1 = max( 0, ty - 3 )
		ly2 = min( 7, ty + 3 )
		ly1.upto( ly2 ){ |tempy|
			if board[ tempy ][ tx ] == 1
				chain << [tx, tempy ]
				board[ tempy ][ tx ] = 0
			end
		}
	end
	return board
end

def main

	answers = Array.new
	num = $stdin.gets.chomp.to_i

	num.times{|n|
		$stdin.gets #if n > 0

		board = Array.new( 8 ){ Array.new( 8 )}
		8.times{ |i|
			line = $stdin.gets
			temp = line.chomp.split(//).map{|n| n.to_i}
			8.times{ |j|
				board[ i ][ j ] = temp[ j ]
			}
		}
		x = $stdin.gets.chomp.to_i
		y = $stdin.gets.chomp.to_i
		b = bomb( board, x ,y )
		answers << b.dup
	}

	answers.each_with_index{ |b,i|
		print "Data #{i+1}:\n"
		printboard( b )
	}
	
end
main


Measured memory_bytes: 6116
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 1000000000
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 12
int k;
int dp[MN][MN][MN];
int sm[MN][MN];
int calc(int st, int nd){
    //memset(dp, 0, sizeof dp);
    //cout << "doing " << st << " " << nd << "\n";
    dp[1][st][st] = 1;
    FOR(i, 2, nd){
        F0R(d, 10){
            if(d != 0) dp[i][st][d] += dp[i-1][st][d-1];
            dp[i][st][d] += dp[i-1][st][d];
            if(d != 9) dp[i][st][d] += dp[i-1][st][d+1];
        }
    }
    FOR(i, 1, nd){
        F0R(j, 10){
            //cout << dp[i][st][j] << " ";
            sm[i][st] += dp[i][st][j];
        }
        //cout << "\n";
    }
}

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

    cin >> k; --k;
    F0R(j, 10){
        calc(j, 10);
    }
    /*FOR(i, 1, 10){
        F0R(j, 10){
            cout << sm[i][j] << " ";
        }
        cout << "\n";
    }*/
    int nd = 1;
    int std = -1;
    while(nd != 0){
        bool ok = false;
        F0R(i, 10){
            if(std == -1 && i == 0) continue;
            else if(std != -1 && abs(std-i)>1) continue;
            if(sm[nd][i] > k){
                cout << i;
                //cout << "pairing " << i << "\n";
                --nd;
                ok = true;
                std = i;
                break;
            } else{
                k -= sm[nd][i];
            }
        }
        if(!ok){ ++nd; }
        //cout << "now k " << k << "\n";
    }

    return 0;
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(min(d,b)-max(a,c) > 0){
        cout << min(d,b)-max(a,c) << endl;
    }else cout << 0 << endl;
}

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

using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	
	t.erase(t.size()-1);
	if(s==t){
	    cout<<"Yes";
	}else{
	    cout<<"No";
	}
}


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

int main() {
  int N, M;
  cin >> N >> M;
  string A[N], B[M];
  for (int i=0; i<N; i++)
    cin >> A[i];
  for (int i=0; i<M; i++)
    cin >> B[i];
  for (int i=0; i<=N-M; i++) {
    for (int j=0; j<=N-M; j++) {
      bool check = true;
      for (int k=0; k<M; k++)
        for (int l=0; l<M; l++)
          if (B[k][l] != A[i+k][j+l])
            check = false;
      if (check) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
blood_hash = [[:A, 0],[ :B, 0], [:AB, 0], [:O, 0]].to_h
while tmp = gets
  # break if tmp == ""
  tmp = tmp.chomp.split(",")
  blood_hash[tmp[1].to_sym] +=  1
end

blood_hash.each{|k,_|
  puts blood_hash[k]
}


Measured memory_bytes: 6856
#include <iostream>

using namespace std;

int main(){
    int n;
    bool f = false;
    cin >> n;
    for(int i = 0; i < 3; i++){
        if(n % 10 == 7){
            f = true;
            break;
        }
        n /= 10;
    }
    if(f) cout << "Yes" << endl;
    else  cout << "No" << endl;
    
}

Measured memory_bytes: 3580
//When Can We Meet?
#include <stdio.h>
#include <string.h>
int N, M, Q, i, D[100], t;
int main(void)
{
    for(;scanf("%d%d",&N,&Q),N;)
    {
        memset(D,0,sizeof(D));
        for(i=0;i<N;i++)
            for(scanf("%d",&M);M--;)
            {
                scanf("%d",&t);
                D[t]++;
            }
        for(i=0,t=-1;i<100;i++)
            if ((t==-1&&D[i]>=Q)||(t!=-1&&D[i]>D[t]))
                t=i;
                printf ("%d\n", t == -1 ? 0 : t);
    }
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N;
    cin >> N;
    vector<int> A(N);
    ll res = 0;
    REP(i, N) {
        cin >> A[i];
        res += A[i];
    }
    int Q;
    cin >> Q;
    vector<int> B(Q), C(Q);
    REP(i, Q) cin >> B[i] >> C[i];

    vector<ll> num(100001, 0);
    for(int i = 0; i < N; i++) {
        num[A[i]]++;
    }

    for(int i = 0; i < Q; i++) {
        res += num[B[i]] * (C[i] - B[i]);
        num[C[i]] += num[B[i]];
        num[B[i]] = 0;
        cout << res << endl;
    }





    // ll res = 0;
    // for(int i = 0; i < N; i++) {
    //     res += A[i];
    // }
    
    // for(int i = 0; i < Q; i++) {
    //     for(int j = 0; j < N; j++) {
    //         if (A[j] == B[i]) {
    //             A[j] = C[i];
    //             res += C[i] - B[i];
    //         }
    //     }
    //     cout << res << endl;
    // }

    return 0;
}

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

int main()
{
	int a,b,c,x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	for (int i = 0; i <= a; ++i)
	{
		for (int j = 0; j <= b; ++j)
		{
			for (int k = 0; k <= c; ++k)
			{
				if (500*i + 100*j + 50*k == x) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int n;
	cin >> n;
	if (n % 2 == 0)
	{
		cout << 0.5;
	}
	else
	{
		float res = (n / 2 + 1) / (float)n;
		cout << res;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
int a[100000],b[50000],A,B,i,C=0;
int min,max,mid;

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

scanf("%d",&B);
for(i=0;i<B;i++){
scanf("%d",&b[i]);

min=0; max=A;
while(min<max){
 mid=(min+max)/2;
  if(a[mid]==b[i]){
    C++;
    break;
   }
  else if(b[i]<a[mid])
    max=mid;
  else
    min=mid+1;
}

}

printf("%d\n",C);
return 0;
}



Measured memory_bytes: 2272
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n), y(m);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> y[i];
    }

    int xm = *max_element(x.begin(), x.end());
    int ym = *min_element(y.begin(), y.end());

    if (Y - X >= 1 && ym - xm >= 1 && xm < Y && X < ym) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
vector<int> O[10];
P sg[10];
int d[1005][1005]={};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int fi[1005][1005];
int ans[1005][1005]={};
bool graph[55][55];
bool visited[55];
int a[55],b[55];

signed main(){
    string  s;cin>>s;
    int to=0;
    rep(i,s.length()-1){
        if(s[i]!=s[i+1])to++;
    }
    cout<<to<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N-1);
  for(int i=0;i<N-1;i++) cin>>b[i];
  a[0]=b[0];
  for(int i=1;i<N-1;i++){
    a[i]= min(b[i],b[i-1]);
  }
  a[N-1]=b[N-2];
  int ans =0;
  for(int i=0;i<N;i++) ans += a[i];
  cout<<ans<<endl;

}


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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int x; cin >> x;
	if(x >= 30){
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


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

int linerSearch( std::vector<int> arr, int n )
{
    arr.push_back( n );
    int idx = 0;
    while( arr[idx++] != n );  idx--;

    return idx!=arr.size()-1;   //exist: True, not exist: False
}

int main()
{
    int n, q;

    std::cin >> n;
    std::vector<int> S(n);
    for( auto &s: S){ std::cin >> s; }
    
    std::cin >> q;
    std::vector<int> T(q);
    for( auto &t: T){ std::cin >> t; }

    int ans = 0;
    for( int i = 0; i < T.size(); i++ ){
        ans += linerSearch( S, T[i] );
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int s, f, n;
    vector<int> a;
    cin >> s;
    a.push_back(s);
    for(int i=0; i<1000;i++){
        if(a[i]%2==0){
            f = a[i]/2;
        }else{
            f = 3*a[i]+1;
        }
        a.push_back(f);
        for(int j=0; j<i+1; j++){
            if(a[j] == a[i+1]){
                cout << i+2;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int N;
  cin >> N;
  ll ans = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      for (int k = 1; k <= N; ++k) {
        int tmp = gcd(i, j);
        ans += gcd(tmp, k);
        // printf("%d\n", gcd(tmp, k));
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
 using namespace std;
 int main()
 {
     char x, y;
     cin >> x >> y;
     if(x > y)
        printf(">\n");
     else if(x == y)
        printf("=\n");
     else
        printf("<\n");
     return 0;
 }


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

int main(){
    string s;
    cin >> s;
    int counter = 0;
    char a = s[0];
    for(int i=1;i<s.size();i++){
        char b = s[i];
        if(a != b) counter ++;
        a = b;
    }
    cout << counter << endl;
}

Measured memory_bytes: 636
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  string s,t;
  cin>>s>>t;
  int count=0;
  int n=s.size();
  while(count<n){
    char tmp=s[n-1];
    // cout<<tmp<<endl;
    s=tmp+s;
    s.pop_back();
    // cout<<s<<endl;
    if(s==t){
      cout<<"Yes"<<endl;
      break;
    }
    if(count==n-1){
      cout<<"No"<<endl;
    }
    count++;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] ana = new String[6];
		char[] c = new char[3];
		ana=line.split(" ");
		for(int i=0;i<3;i++){
		c[i]=ana[i].charAt(0);
		System.out.print(Character.toUpperCase(c[i]));
		}

	}
}

Measured memory_bytes: 21076
from collections import Counter

def prime_factorize(n):
    res = []
    while n % 2 == 0:
        res.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            res.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        res.append(n)
    return res

n = int(input())
prime_numbers = prime_factorize(n)
prime_counter = Counter(prime_numbers)

ans = 0
for v in prime_counter.values():
    i = 1
    while v >= i:
        ans += 1
        v -= i
        i += 1

print(ans)

Measured memory_bytes: 9452
#include <iostream>

using namespace std;

int info[22];

int main()
{
    int n, a, v;
    int max_idx = 0;

    cin >> n;
    
    info[max_idx] = -10;
    for (int i = 0; i < n; i++) {
        cin >> a >> v;
        info[a] = v;
    }
    
    for (int i = 1; i <= n; i++)
        if (info[max_idx] < info[i])
            max_idx = i;
    cout << max_idx << " " << info[max_idx] << endl;
    
    return 0;
}

Measured memory_bytes: 1168
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

int main() {
	int n, m;
	while (cin >> n >> m, n) {
		vector<pair<int, int>> v(m);
		for (int i = 1; i <= m; ++i) {
			v[i - 1].second = -i;
		}
		for (int i = 0; i<n; ++i) {
			for (int j = 0; j<m; ++j) {
				int k; cin >> k;
				v[j].first += k;
			}
		}
		stable_sort(v.rbegin(), v.rend());
		for (int i = 0; i<m; ++i) {
			if(i!=m-1)cout << -v[i].second << " ";
			else cout << -v[i].second;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3012
K, A, B = map(int, input().split())

if K - 2 < A-1 or B - A <= 2 :
    print(K+1)
    exit(0)

ans = 1
ans += A-1
K -= A-1
if K & 1 == 1:
    ans += 1
    K -= 1

ans += (B-A)*(K//2)
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll L,A[200001],B[200001][5],dp[200001][5],inf=1e18;
int main(){
    cin>>L;
    rep(i,L) cin>>A[i];
    rep(i,L){
        B[i][0]=A[i];
        B[i][4]=A[i];
        if(A[i]==0) B[i][1]=2;
        else B[i][1]=A[i]%2;
        B[i][3]=B[i][1];
        B[i][2]=(A[i]+1)%2;
    }
    rep(i,L)rep(j,5) dp[i][j]=inf;
    rep(i,5) dp[L][i]=0;
    for(int i=L-1;i>=0;i--)rep(j,5)rep(k,j+1) dp[i][j]=min(dp[i][j],dp[i+1][k]+B[i][j]);
    cout<<min({dp[0][0],dp[0][1],dp[0][2],dp[0][3],dp[0][4]})<<"\n";
}

Measured memory_bytes: 17408
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
constexpr int MAXN = (1 << 20) + 5;
constexpr int MOD = 1e9 + 7;
constexpr double eps = 1e-6;
constexpr int INF = 1e9 + 7;
int dir[4][2] = { { -1,0 },{ 0,1 },{ 1,0 },{ 0,-1 } };


int main()
{
	//freopen("in.in", "r", stdin);&
	//freopen("out.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);

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

	if (a + b >= c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	//system("pause");
	return 0;
}

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

#define ll long long

int main(){
    int n,a[1000];
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> a[i];
        if(a[i]%2==0 && a[i]%3!=0 && a[i]%5!=0){
            cout << "DENIED";
            return 0;
        }
    }
    cout << "APPROVED";
}


Measured memory_bytes: 3560
N = int(input())
monsters = list(map(int,input().split()))
monsters = sorted(monsters)

def gcd(a,b):
    if b==0:
        return a
    return gcd(b, a%b)

if N == 1:
    print(monsters[0])
else:
    ans = gcd(monsters[0], monsters[1])
    if N == 2:
        print(ans)
    else:
        for i in range(2, N):
            ans = gcd(ans,monsters[i])
        print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int bs[101];
int rs[101];
int ts[101];
int main(){

  int n;
  int y;
  while(cin>>n&&n){
    cin>>y;
    for(int i=0;i<n;i++)
      cin>>bs[i]>>rs[i]>>ts[i];
    double opt=-1;
    int res=0;
    for(int i=0;i<n;i++){
      double a=1;
      if(ts[i]==1)a*=(1+y*1.0*rs[i]/100);
      else{
	for(int j=0;j<y;j++)a*=(1+1.0*rs[i]/100);
      }
      if(opt<a){
	opt=a;
	res=bs[i];
      }
    }
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;
#include <queue>

int main(void){
    Cin(int, n, d);
    int k = 2*d+1;
    Cout((n+k-1)/k);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
using namespace std;
 
const int N = 100;
const int INF = 100000000;
 
int n, data[N][N], yoko[N][N], tate[N];
 
main(){
  cin >> n;
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin >> data[i][j];
  for(int i=0;i<n;i++){
    yoko[i][0] = data[i][0];
    for(int j=1;j<n;j++) yoko[i][j] = yoko[i][j-1] + data[i][j];
  }
  int ans = -INF;
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      ans = max(ans, data[i][j]);
      if(i == 0) for(int k=0;k<n;k++) tate[k] = yoko[k][j];
      else for(int k=0;k<n;k++) tate[k] = yoko[k][j] - yoko[k][i-1];
      int tmp[N];
      tmp[0] = tate[0];
      for(int k=1;k<n;k++) tmp[k] = tmp[k-1] + tate[k];
      int valm = 0, valM = -INF;
      for(int k=0;k<n;k++){
        valM = max(valM, tmp[k]);
        if(valm > tmp[k]){
          valm = tmp[k];
          valM = tmp[k];
        }
        if(valm != valM) ans = max(ans, valM - valm);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1236
#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() {
    double R;
    cin >> R;
    cout << 2 * R * 3.14 << endl;
    return 0;
}

Measured memory_bytes: 3784
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define vi vector<ll>
#define pii pair<ll,ll>
#define bc __builtin_popcountll
#define vvi vector<vi> 
#define vpii vector<pair<ll,ll>>
#define mll unordered_map<ll,ll>
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define fo(i,a,b) for(ll i=a;i<=b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()-->returns an iterator to the k-th largest element (counting from zero)
//X.order_of_key()-->the number of items in a set that are strictly smaller than our item.
struct cmp
{
	bool operator() (ll a,ll b){
		return (a>b);
	}
};
ll mod=1000000007;
const ll N=100005;
int main()
{
fast;
    ll n;
    cin>>n;
    ll a[n];
    ll pre[n];
    f(i,n)
        cin>>a[i];
    pre[0]=a[0];
    f1(i,n-1)
    {
        pre[i]=pre[i-1]+a[i];
    }
    ll sum=0;
    f(i,n)
    {
        sum=(sum%mod+(a[i]%mod*((pre[n-1]%mod-pre[i]%mod+mod)%mod))%mod)%mod;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 6716