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

int main() {
	int result = 0;
	int n,x,t;
	cin >> n >> x >> t;

	for(int i=1; i<10000; i++) {
		if(n<=(x*i)) {
			result = t*i;
			break;
		}
	}

	cout << result << "\n";
}


Measured memory_bytes: 3620
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, A[1000], B[1000], C[1000];
	cin >> N;
	for(int i = 1; i <= N; i++) {
		cin >> A[i];
	} 
	for(int i = 1; i <= N; i++) {
		cin >> B[i];
	} 
	for(int i = 1; i <= N - 1; i++) {
		cin >> C[i];
	}
	int sum = 0;
	for(int i = 1; i <= N; i++) {
		sum = sum + B[A[i]];
		if(A[i + 1] - A[i] == 1) {
			sum = sum + C[A[i]];
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int n,x,y,t,xi,yi,ti,dx,dy,dt;
bool test;

int main()
{
    cin>>n;
    xi=0,yi=0,ti=0,test=true;
    for(int i=1;i<=n;i++){
      cin>>t>>x>>y;
      dx=abs(x-xi),dy=abs(y-yi),dt=abs(t-ti);
      //cout<<(dt-dx-dy)<<'\n';
      if(dx+dy>dt)test=false;
      else if((dt-dx-dy)%2==1)test=false;
      xi=x,yi=y,ti=t;
    }
    if(test)cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
N ,L  = map(int,input().split())

sum = 0
for n in range(1,N+1):
    sum += n + L - 1

if N + L - 1  < 0 :
   print(sum - (N + L - 1))
   exit(0)
elif 1 + L - 1 <= 0 :
    print(sum)
else:
    print(sum - (1 + L - 1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,m; cin >> n >> m;
  int a[m];
  REP(i,m) cin >> a[i];
  int sum = 0;
  REP(i,m) sum += a[i];
  if (n >= sum) COUT(n-sum);
  else COUT(-1);

  return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using u32 = uint32_t;

int main() {
	u32 N, R;
	cin >> N >> R;
	
	if(N < 10) {
		cout << R + 100 * (10 - N);
	} else {
		cout << R;
	}
	
	return 0;
}

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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define REP(i,n) for(ll i = 1; i < (n); i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")

using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1; 


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

  int n;
  cin >> n;
  map<int, int> mp;
  rep(i,n){
    int a;
    cin >> a;
    mp[a]++;
  }
  int ans = 0;
  for(auto it = mp.begin(); it != mp.end(); it++){
    if((*it).first <= (*it).second) ans += (*it).second - (*it).first;
    else ans += (*it).second;
  }
  cout << ans << endl;

}

Measured memory_bytes: 4736
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
using namespace std;
using ll =long long;
int main() {
	int A[3][3];
	int N;
	vector<int>b;
	int c;
	for (int i=0; i < 3; i++) {

		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];

		}
	}
	cin >> N;
	for (int i = 0; i < N; i++){
		cin>>c;
		for (int i=0; i < 3; i++) {

			for (int j = 0; j < 3; j++) {
				if (A[i][j] == c) {

					A[i][j] = 0;

				}

			}
		}
	}
	for (int i=0; i < 3; i++) {
		if (A[i][0] == A[i][1] && A[i][1] == A[i][2]) {
			cout << "Yes";
			return 0;
		}
		if (A[0][i] == A[1][i] && A[1][i] == A[2][i]) {
			cout << "Yes";
			return 0;
		}
		if (A[0][0] == A[1][1] && A[1][1] == A[2][2]) {
			cout << "Yes";
			return 0;
		}
		if (A[0][2] == A[1][1] && A[1][1] == A[2][0]) {
			cout << "Yes";
			return 0;
		}

	}
	cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define bg(x) (x).begin()
#define ed(x) (x).end()
#define ar array
#define ll long long int

const ll mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        string s;
        cin >> s;
        if (s.back() == 's') {
            cout << s + "es";
        }
        else {
            cout << s + "s";
        }
    }
    

    return 0;
}

Measured memory_bytes: 3664
H, N = map(int, input().split())
INF = 10**9
dp= [INF for _ in range(H+1)]

dp[0] = 0

for i in range(N):
  a, b = map(int, input().split())
  for j in range(H):
    if j+a > H:
      dp[H] = min(dp[H], dp[j] + b)
    else:
      dp[j+a] = min(dp[j+a], dp[j] + b)
print(dp[H])

Measured memory_bytes: 75004
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int N, ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++)ans += i + 1;
	cout << ans;
}


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

int main() {
  int A,B,C; cin >>A >>B >>C;
  if (A==B) cout <<C <<endl;
  else if (A==C) cout <<B <<endl;
  else cout <<A <<endl;
  return 0;
}


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

int main()
{
    int64_t N;
    int n;
    cin >> N;
    string Alf = "";
    string Ans = "";
    for(char a = 'a' ; a <= 'z' ; a++)
    {
        Alf += a;
    }

    while(N > 0){
        n = N % 26; 

        N /= 26;
        if( n != 0 )
        {
            Ans = Alf.at(n-1) + Ans;
        } else {
            N --;
          	Ans = Alf.at(25) + Ans;
        }

    }
    cout << Ans;
    
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(void)
{
    int i, n, sum=0, min;

    scanf("%d", &n);

    int w[n], c[n-1], s1[n-1], s2[n-1];

    for(i=0; i<n; i++){
        scanf("%d", &w[i]);
    sum += w[i];
    }

    s1[0] = w[0];
for(i=0; i<n-2; i++) s1[i+1] = s1[i] + w[i+1];

for(i=0; i<n-1; i++) s2[i] = sum - s1[i];

for(i=0; i<n-1; i++){
c[i] = s1[i] - s2[i];
if(c[i]<0) c[i]=c[i]*(-1);
}

min = c[0];
for(i=1; i<n-1; i++) if(c[i]<min) min = c[i];

printf("%d\n", min);

return 0;
}

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

int main() {
    int N, sum = 0;
    cin >> N;
    vector<int> A(N);
    vector<pair<int, int>> ans;
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);
    sort(A.begin(), A.end());
    
    if (A[0] <= 0) {
        vector<bool> use(N, false);
        int now = A[0];
        for (int i = 1; i < N-1; i++) if (A[i] >= 0) {
            ans.emplace_back(now, A[i]);
            now -= A[i];
            use[i] = true;
        }
        A[0] = now;
        sum = A[N-1];
        for (int i = 0; i < N-1; i++) if (!use[i]) {
            ans.emplace_back(sum, A[i]);
            sum -= A[i];
        }
    } else {
        sum = A[0];
        for (int i = 1; i < N-1; i++) {
            ans.emplace_back(sum, A[i]);
            sum -= A[i];
        }
        ans.emplace_back(A[N-1], sum);
        sum = A[N-1] - sum;
    }
    
    printf("%d\n", sum);
    for (auto e : ans) printf("%d %d\n", e.first, e.second);
    return 0;
}

Measured memory_bytes: 3192
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	long long int N, M;
	cin >> N >> M;
	vector<P> v;
	for(int i = 0; i < N; i++){
		long long int A, B;
		cin >> A >> B;
		v.push_back(P(A, B));
	}
	sort(v.begin(), v.end());
	long long int ans = 0;
	for(int i = 0; i < N; i++){
		if(v[i].second < M){
			M -= v[i].second;
			ans += v[i].first * v[i].second;
		}else{
			ans += v[i].first * M;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		int z1, z2;
		int umax = 0;
		int dmax = 0;
		for (int j = 0; j < t; j++) {
			cin >> z2;
			if (j == 0) {
			} else {
				if (z1 > z2) {
					dmax = max(dmax, z1-z2);
				} else {
					umax = max(umax, z2-z1);
				}
			}
			z1 = z2;
		}
		cout << umax << ' ' << dmax << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>

int main() {
   
   int A, B, C;
   std::cin >> A >> B >> C;
   
   int max = 0;
   max = std::max(A, B);
   max = std::max(max, C);
   std::cout << max * 9 + A + B + C << std::endl;
   return 0;
}


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

int a[50];
int main(){
  int n;cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  double ans=a[0];
  for(int i=0;i<n;i++){
    ans=(ans+a[i])/2;
  }
  cout<<setprecision(6);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n,i;
    scanf("%d\n",&n);
    int a[n];
    for(i=n-1;i>=0;i--){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        printf("%d",a[i]);
        if(i<n-1){
            printf(" ");
        }
    }
    printf("\n");
    return 0; /*0?????????*/
}

Measured memory_bytes: 600
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define N 1000005
#define ll long long
#define debug(a) cout<<#a<<": ";for(auto i:a)cout<<i<<" ";cout<<endl;
#define trace(a) cout<<#a<<": "<<a<<endl;
#define int ll
// int a[N];
signed main() {
	ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
	int i,j,k,l,m,n,t;
	cin >> t;
	while(t--) {
		ll a,b;
		cin >> a >> b;
		if(a > b) swap(a,b);

		if(a*b == 1) {
			cout << "0" << endl;
			continue;
		}

		ll sq = sqrtl(a*b-1  + 0.1);
		ll an = 0;
		
		an += sq;
		an *= 2;
		an--;
		if((a*b - 1)/sq == sq) {
			an--;
		}
		else if(sq * (sq+1) >= a*b) {
			an-=2;
		}
		if(a == b || a == b-1)
			an = 2LL*a-2;
		cout << an << endl;
	}
}

Measured memory_bytes: 256
// use std::ops::{Index, IndexMut};
// use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) 
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator, 
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

fn main() {
    let (x, y) = readl!(usize, usize);
    // let n = 100;
    // let mut dp = vec![vec![false; x+y]; x+y];
    // for sum in 0..x+y {
    //     for i in 0..sum+1 {
    //         debug!(sum);
    //         debug!(i);
    //         for k in 1..i+1 {
    //             if k*2 <= i && k*3 <= sum {
    //                 dp[sum][i] = dp[sum][i] || !dp[sum-k][i-2*k];
    //             }
    //         }
    //         for k in 1..sum+1 {
    //             if i+k < x+y && sum-k >= i+k {
    //                 dp[sum][i] = dp[sum][i] || !dp[sum-k][i+k];
    //             }
    //         }
    //     }
    // }
    // for i in 0..x+y {
    //     for j in 0..x+y {
    //         if dp[i][j] {
    //             print!("1 ");
    //         } else {
    //             print!("{} ", 0);
    //         }
    //     }
    //     println!("");
    // }
    let sum = x+y;
    if sum <= 1 {
        println!("Brown");
    } else {
        if x == (sum+1)/2 || y == (sum+1)/2 {
            println!("Brown");
        } else {
            println!("Alice");
        }
    }

}



Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);

        boolean keepGoing = true;

        while(keepGoing){
            double m = inp.nextInt();
            double f = inp.nextInt();
            double r = inp.nextInt();

            if (m == -1 && f == -1 && r == -1) {
                keepGoing = false;
            } else {
                if (r != -1) {
                    System.out.println(gradeWithMakeup(m, f, r));
                } else {
                    System.out.println(gradeWithoutMakeup(m, f));
                }
            }
        }
    }

    public static String gradeWithMakeup(double m, double f, double r) {
        if (m == -1 || f == -1) {
            return "F";
        }

        /*
        if (m != -1) {
            mf += m;
            mfTotal += mTotal;
        }

        if (f != -1) {
            mf += f;
            mfTotal += fTotal;
        } */

        //System.out.println(mf + " " + mfTotal);
        //System.out.println("---____");

        double grade = ((m + f)/100) *100;

        if (grade >= 80) {
            return "A";
        } else if (grade >= 65) {
            return "B";
        } else if (grade >= 50) {
            return "C";
        } else if (grade >= 30) {
            if (r >= 50) {
                return "C";
            }
            return "D";
        } else {
            return "F";
        }
    }

    public static String gradeWithoutMakeup(double m, double f) {
        if (m == -1 || f == -1) {
            return "F";
        }

        //System.out.println(mf + " " + mfTotal);
        //System.out.println("---");

        double grade;

        grade = ((m + f)/100)*100;

        if (grade >= 80) {
            return "A";
        } else if (grade >= 65) {
            return "B";
        } else if (grade >= 50) {
            return "C";
        } else if (grade >= 30) {
            return "D";
        } else {
            return "F";
        }
    }
}



Measured memory_bytes: 26304
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define ll long long
#define mp map<int,int>
using namespace std;
int a[20][20];
int main() {
	int n,d;
	cin>>n>>d;
	ll ans=0;
	rep(i,1,n) rep(j,1,d)cin>>a[i][j];
	rep(i,1,n) rep(j,i+1,n) {
		double t=0;
		rep(k,1,d)t+=pow(a[i][k]-a[j][k],2);
		t=sqrt(t);
		if(t==floor(t))ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
# def gcd(a, b):
#     if b == 0:
#         return a
#     return gcd(b, a % b)

from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
ans = 1001001001
g = a[0]
for i in range(1,n):
    g = gcd(a[i], g)
    ans = min(ans, g)

print(ans)


Measured memory_bytes: 16284
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<min(a,b)+min(c,d);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var a     = int.Parse(spl[0]);
        var b     = int.Parse(spl[1]);
        var c     = int.Parse(spl[2]);

        int tmp;

        tmp = a;
        a = b;
        b = tmp;

        tmp = a;
        a = c;
        c = tmp;

        return a + " " + b + " " + c;
    }
}

Measured memory_bytes: 11092
def get_GCD(a, b)
  while ((r = a%b) != 0) do
    a = b
    b = r
  end
  b
end

def get_LCM(a, b, gcd)
  a * b / gcd
end

while s = gets do
  a, b = s.split(/\s/).map(&:to_i)

  gcd = get_GCD(a, b)
  lcm = get_LCM(a, b, gcd)
  puts "#{gcd} #{lcm}"
end

Measured memory_bytes: 6108
#include <iostream>
#include <cstdlib>
#include<vector>
#include<string>
#include<cmath>
#include <algorithm>
#include<complex>

using namespace std;
typedef long long LL;


int main() {
	LL N, A;
	cin >> N >> A;
	cout << (N*N) - A << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

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

using namespace std;

int main()
{
    int X, Y, Z; cin >> X >> Y >> Z;

    X -= Z;

    int i = 0;
    while(X >= 0)
    {
        X -= Y;
        X -= Z;
        i++;
    }

    cout << i - 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

#define rep(s, e) for(int i(s); i < e; ++i)

int main() {
    int n(0);
    cin >> n;

    int *R = new int[n];
    rep(0, n) {
        cin >> R[i];
    }

    int minv(R[0]);
    int maxv(R[1] - R[0]);

    rep(1, n) {
        if(maxv < R[i] - minv) {
            maxv = R[i] - minv;
        }
        if(minv > R[i]) {
            minv = R[i];
        }
    }
    cout << maxv << "\n";
    return 0;
}


Measured memory_bytes: 3876
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)

inline int read() {
    int x; scanf("%d", &x); return x;
}

inline vector<int> reads(int n) {
    vector<int> v(n);
    for (auto& i : v) scanf("%d", &i);
    return v;
}

vector<pair<int, int>> get_mode(vector<int> v) {
    map<int, int> mp;
    for (auto i : v) mp[i]++;
    vector<pair<int, int>> mode;
    for (auto i : mp) mode.emplace_back(i.second, i.first);
    sort(mode.rbegin(), mode.rend());
    return mode;
}

int main() {
    int n = read();
    vector<int> v = reads(n);
    vector<int> e, o;
    rep(i, n) {
        if (i % 2 == 0) e.emplace_back(v[i]);
        else o.emplace_back(v[i]);
    }

    auto mode1 = get_mode(e);
    auto mode2 = get_mode(o);

    if (mode1[0].second != mode2[0].second) {
        int cnt = 0;
        for (int i : e) cnt += (i != mode1[0].second);
        for (int i : o) cnt += (i != mode2[0].second);
        cout << cnt << "\n";
        return 0;
    }

    if (mode1.size() == 1 && mode2.size() == 1) {
        cout << n / 2 << "\n";
        return 0;
    }

    int cnt = 0;
    rep(i, n) {
        cnt += (i % 2 == 0 && v[i] != mode1[0].second);
        cnt += (i % 2 == 1 && v[i] != mode2[1].second);
    }
    int cnt1 = 0;
    rep(i, n) {
        cnt1 += (i % 2 == 0 && v[i] != mode1[1].second);
        cnt1 += (i % 2 == 1 && v[i] != mode2[0].second);
    }
    cout << min(cnt, cnt1) << "\n";

    return 0;
}

Measured memory_bytes: 4748
import itertools

N, M, Q = map(int, input().split())
A = [list(map(int, input().split())) for i in range(Q)]

comb = list(itertools.combinations_with_replacement(range(1, M + 1), N))

saidai = 0
for c in comb:
    score = 0
    for a in A:
        if (c[a[1] - 1] - c[a[0] - 1] == a[2]):
            score += a[3]
    saidai = max(saidai, score)

print(saidai)

Measured memory_bytes: 21508
import sys
from heapq import*
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0
 H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:
    F[v]=t
    heappush(H,(t,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
  else:
   c,d,e=map(int,f[2:].split())
   E[c]+=[(e,d)];E[d]+=[(e,c)]
if'__main__'==__name__:
 for e in iter(r,'0 0\n'):s(*map(int,e.split()))


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }
  vector<int> visited(n+1, 0);
  int tmp = 1;
  int ans = 0;
  while(visited[tmp] == 0 && tmp != 2){
    visited[tmp] = 1;
    tmp = a[tmp];
    ans++;
  }
  if(tmp == 2){
    cout << ans << endl;
  }else{
    cout << -1 << endl;
  }
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include<assert.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MRE assert(0);
#define Yay puts("Yay");
const int inf = 1e17;
const int mod =998244353;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int a[50005], b[50005], c[50005];
int dp[200005][2];
int d0[200006], d1[2][200006], d2[2][200006];
map<P, int>M;

int modpow(int a, int x) {
	int res = 1;
	while (x) {
		if (x & 1)res = res*a%mod;
		a = a*a%mod;
		x >>= 1;
	}
	return res;
}

signed main() {
	int n, m; cin >> n >> m;
	rep(i, 2 * n)d0[i] = d1[0][i] = d1[1][i] =d2[0][i]=d2[1][i]= -1;
	int flg = 0;
	int fr = (n*n - 5 * n + 6)/2;
	rep(i, m) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
		if (a[i] == b[i])d0[a[i]] = c[i];
		else if (b[i] - a[i] == 1) {
			d1[0][b[i]] = c[i];
		}
		else if (a[i] - b[i] == 1) {
			d1[1][a[i]] = c[i];
		}
		else if (abs(a[i] - b[i]) == 2) {
			int mi = (a[i] + b[i]) / 2;
			if (a[i] < b[i])d2[0][mi] = c[i];
			else d2[1][mi] = c[i];
		}
		else {
			P p = make_pair(min(a[i], b[i]), max(a[i], b[i]));
			if (M[p] == 0) {
				M[p] = c[i] + 1;
				fr--;
			}
			else {
				int C = M[p] - 1;
				if (C + c[i] == 1)flg++;
				else M[p] = 0;
			}
		}
	}

	if (flg) {
		cout << 0 << endl; return 0;
	}
	dp[0][0]++; dp[0][1]++;
	if (d0[0] >= 0)dp[0][1 - d0[0]]--;

	for(int i=1;i<n;i++) {
		int C1 = 0;
		if (d1[0][i] >= 0)C1++; if (d1[1][i] >= 0)C1++;
		if (C1 == 2) {//両方確定
			int s = d1[0][i] ^ d1[1][i];
			dp[i][s] = (dp[i-1][0]+dp[i][s])%mod;
			dp[i][s ^ 1] = (dp[i-1][1] + dp[i][s ^ 1]) % mod;

		}
		else if (C1 == 1) {//片方確定
			rep(j, 2)rep(k, 2)dp[i][k] = (dp[i-1][j] + dp[i][k]) % mod;
		}
		else {
			rep(j, 2)rep(k, 2)dp[i][k] = (dp[i][k] + dp[i-1][j] * 2) % mod;
		}

		if (d0[i] >= 0)dp[i][d0[i] ^ 1] = 0;

		if (i == n - 1)break;
		int C2 = 0;
		if (d2[0][i] >= 0)C2++; if (d2[1][i] >= 0)C2++;
		if (C2 == 2) {
			int s = d2[0][i] ^ d2[1][i];
			dp[i][s ^ 1] = 0;
		}
		else if (C2 == 0) {
			rep(j, 2)dp[i][j] = dp[i][j] * 2 % mod;
		}
	}
	int sum = (dp[n - 1][0] + dp[n - 1][1])*modpow(2, fr) % mod;

	cout << sum << endl;
}

Measured memory_bytes: 14720
#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 k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int d = a[0] + k - a[n-1];
  rep(i, n-1) d = max(d, a[i+1] - a[i]);
  int ans = k - d;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4024
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vii vector<ii>
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define pin(n) in(n.first) >> n.second
#define vin(a, n) for (int i=0; i<n; ++i) in(a[i])
#define viin(a, n) for (int i=0; i<n; ++i) in2(a[i].first, a[i].second);
#define out(n) cout << n
#define outs(n) out(n) << ' '
#define outn(n) out(n) << '\n'
#define out2(n, m) cout << n << ' ' << m
#define out2s(n, m) out2(n, m) << ' '
#define out2n(n, m) out2(n, m) << '\n'
#define pout(n) out2(n.first, n.second)
#define pouts(n) pout(n) << ' '
#define poutn(n) pout(n) << '\n'
#define vout(a) for (auto i : a) outs(i)
#define viout(a) for (auto i : a) out2n(i.first, i.second)
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pp(a, b) emplace_back(make_pair(a, b))
#define fori(i, n) for (int i=0; i<n; ++i)
#define foris(i, a, b) for (int i=a; i<b; ++i)
#define ford(i, n) for (int i=n-1; i>=0; --i)
#define fords(i, a, b) for (int i=a; i>=b; --i)
#define forr(i, a) for (auto i : a)
const int mod = (int)(1e9) + 7;
//endregion

int n;

int main() {
    io();
    in(n);
    vector<double> a(n);
    vin(a, n);
    qsort(a);
    foris (i, 1, n) {
        a[i] = (a[i-1]+a[i])/2;
    }
    out(a[n-1]);
}


Measured memory_bytes: 256
def main():
    input()
    cc = map(int, raw_input().split())
    s = 0
    pre = -1
    cont = 0
    for c in cc:
        if c == pre:
            cont += 1
        else:
            s += cont / 2
            pre = c
            cont = 1
    s += cont / 2
    print s


if __name__ == '__main__':
    main()

Measured memory_bytes: 28012
n, k = gets.split.map(&:to_i)
v = gets.split.map(&:to_i)

m = [n, k].min
max = 0
0.upto(m) do |i|
  0.upto(m - i) do |j|
    sum = 0
    w = []
    i.times do |x|
      t = v[x]
      sum += t
      w.push t if t < 0
    end
    j.times do |x|
      t = v[-1 - x]
      sum += t
      w.push t if t < 0
    end
    sw = w.sort
    limit = [sw.size, k - i - j].min
    sum -= sw[0..(limit - 1)].reduce(:+) if !sw.empty? && limit > 0
    if max < sum
      max = sum
    end
  end
end
puts max


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


vector<vector<P>> g(100005);


//vector<vector<int>> g(10005);

vector<int> ans(100005);

int dfs(int a){

	//cout<<a<<endl;
	for (auto t:g[a]){
		int to=t.first;
		int dist=t.second;
		if (ans[to]!=INF)continue;
			ans[to]=(dist+ans[a])%2;
			dfs(to);

		}


	return 0;
}


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

	rep(i,n-1){
		ll u,v,w;
		cin>>u>>v>>w;
		u--;v--;
		g[u].push_back(make_pair(v,w%2));
		g[v].push_back(make_pair(u,w%2));

	}

	rep(i,100005)ans[i]=INF;
	ans[0]=0;
	dfs(0);
	rep(i,n){
		cout<<ans[i]%2<<endl;
	}

return 0;

}


Measured memory_bytes: 7680
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
const long long inf1=10000000000ll,inf2=100000,inf3=2155;
long long n,m,i,j,x,ans,p[inf3],c;
map<long long,long long> mp;
bool check(int x)
{
	int i;
	for(i=2;i*i<=x;i++){
		if(x%i==0)return 0;
	}
	return 1;
}
void init()
{
	int i;
	for(i=2;i<=inf3;i++){
		if(check(i)){
			p[++c]=i;
		}
	}
}
long long d3(long long x)
{
	int i;
	for(i=1;i<=c;i++){
		long long t=p[i]*p[i]*p[i];
		while(x%t==0){
			x/=t;
		}
	}
	return x;
}
long long f(long long x)
{
	int i;
	long long s=1;
	for(i=1;i<=c;i++){
		if(x%(p[i]*p[i])==0){
			x/=p[i]*p[i];
			s*=p[i];
		}
		else if(x%p[i]==0){
			x/=p[i];
			s*=p[i]*p[i];
		}
		if(s>inf1) return -1;
	}
	long long t=sqrt(x);
	if(t*t<x) t++;
	if(t*t>x) t--;
	if(t*t==x){
		s*=t;if(s>inf1) return -1;
	}
	else{
		if(inf1/x<s) return -1;
		s*=x;if(s>inf1) return -1;
		if(inf1/x<s) return -1;
		s*=x;if(s>inf1) return -1;
	}
	return s;
}
int main()
{
	init();
	scanf("%lld",&n);
	fz1(i,n){
		scanf("%lld",&x);
		x=d3(x);mp[x]++;
//		cerr<<x<<endl;
	}
	ff(mp,it)if(it->second){
		long long t=f(it->first);
//		cerr<<it->first<<' '<<t<<endl;
		if(it->first==t){
			ans++;
			continue;
		}
		if(mp.count(t)){
			ans+=max(it->second,mp[t]);
			mp[t]=it->second=0;
		}
		else{
			ans+=it->second;
			it->second=0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8576
import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def slv(S, K):
    d = set([])
    for i in range(len(S)):
        for j in range(i + 1, i + 1 + K):
            d.add(S[i:j])

    return sorted(d)[K - 1]


def main():
    S = read_str()
    K = read_int()
    # K = 3
    # S = ''.join([random.choice('abcdefghijklmnopqrstu') for _ in range(5000)])
    print(slv(S, K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61932
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define int long long int
#define vi vector<int>
#define vvi vector < vi >
#define pii pair<int,int>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define tr(k,st,en) for(int k = st; k <= en ; k++)

using namespace std;

int32_t main()
{
    std::ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    int m = n/k;
    int a = n - (m*k);
    m++;
    int b = (m*k) - n;
    cout<<min(a,b)<<endl;
    return 0;
}



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

using namespace std;

int main(int argc, char *argv[]) {
  string s;
  cin >> s;
  vector<pair<int, int>> v1;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != 'x') {
      v1.push_back({s[i], i});
    }
  }
  auto v2 = v1;
  reverse(v2.begin(), v2.end());
  for (int i = 0; i < v1.size(); ++i) {
    if (v1[i].first != v2[i].first) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (v1.empty()) {
    cout << 0 << endl;
    return 0;
  }
  int n = s.size();
  int ans = max(v1[0].second, n - v2[0].second - 1) * 2 + 1;
  for (int i = 1; i < v1.size(); i++) {
    ans += max(v1[i].second - v1[i - 1].second, -v2[i].second + v2[i - 1].second);
  }
  cout << ans - n << endl;
  return 0;
}


Measured memory_bytes: 2164
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;
void solve(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	bool flag = 0;
	if(a[0] == a[1] && a[2] != a[1])
		flag = 1;
	else if(a[0] != a[1] && a[1] == a[2]) 
		flag = 1;
	
	if(flag)
		cout << "Yes\n";
	else
		cout <<"No\n";
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> t;
		while(t--){
			solve();
		}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int md = 998244353;
inline int mul(int &a, int b) {
  a = (int)((long long)a * b % md);
}
int gcd (int a, int b) {
  if (a < 0) a = -a;
  if (b < 0) b = -b;
  if (a < b) swap(a, b);
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ret = 1;
  for (int i = 0; i < n; i++) {
    mul(ret, gcd(a[i], i));
  }
  cout << ret << '\n';
  return 0;
}

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

string s;
int csum[200007];
int n, t;

int main()
{
    cin >> n >> t;
    cin >> s;

    for (int i = 1; i < n; i++) {
        if (s[i] == 'C' && s[i-1] == 'A') csum[i] = 1;
    }

    for (int i = 1; i < n; i++) csum[i] = csum[i-1] + csum[i];

    while (t--) {
        int lo, hi;
        scanf("%d %d", &lo, &hi);

        printf("%d\n", csum[hi-1] - csum[lo-1]);
    }
}


Measured memory_bytes: 1408
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd
from functools import reduce

N,K,*A = map(int,read().split())
g = reduce(gcd,A)
x = max(A)

bl = (K<=x) and (K%g==0)
ans = 'POSSIBLE' if bl else 'IMPOSSIBLE'
print(ans)

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

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

	for (double i = 1; i <= 50000; ++i) {
		if (x == int(i * 1.08)) {
			cout << i << endl;
			system("pause");
			return 0;
		}
	}
	cout << ":(" << endl;

	return 0;
}

Measured memory_bytes: 504
from collections import deque
N=int(input())
if N==1:
    print("a")
    exit()
X=[chr(i+97) for i in range(N)]
#print(X)
Y=[]
q=deque(["a"])
while(len(q)>0):
    r=q.pop()
    k=len(set(r))
    for i in range(k+1):
        p=r+X[i]
        if len(p)==N:
            Y.append(p)
        else:
            q.append(p)
Y.sort()
for line in Y:
    print(line)


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

int main() {
    char c;
    cin >> c;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        cout << "vowel";
    } else {
        cout << "consonant";
    }
}

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

int main()
{
 int Time;
 int h,m,s;

 cin >> Time;

 h = Time/3600;
 m = (Time % 3600)/60;
 s = (Time % 3600) % 60;

 cout <<h<<":"<<m<<":"<<s<<endl;
 return 0;
}

Measured memory_bytes: 1168
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def string_to_number(a):
    return 1 << (ord(a) - 97)

class SegmentTree:
    """
    セグ木は 1-indexed
    """
    def __init__(self, n, initial=0):
        self.offset = 2**(n-1).bit_length()
        self.initial = initial
        self.seg = [self.initial] * (2 * self.offset)


    def build(self, A):
        """
        A: 処理したい配列
        """
        for i, a in enumerate(A, start=self.offset):
            self.seg[i] = string_to_number(a)
        for i in range(self.offset-1,0,-1):
            self.seg[i] = self.seg[i<<1] | self.seg[(i<<1)+1]

            
    def update(self, k, a):
        k += self.offset
        self.seg[k] = string_to_number(a)
        while k:
            k >>= 1
            self.seg[k] = self.seg[k<<1] | self.seg[(k<<1)+1]

            
    def query(self, a, b):
        a += self.offset
        b += self.offset
        res = self.initial
        while a < b:
            if a & 1:
                res |= self.seg[a]
                a += 1
            if b & 1:
                res |= self.seg[b-1]
            a >>= 1
            b >>= 1
        
        return bin(res).count("1")


def main():
    N,s,Q,*q = read().split()
    seg = SegmentTree(int(N))
    seg.build(s)
    #print(seg.seg)

    for t, a, b in zip(*[iter(q)]*3):
        if t == "1":
            seg.update(int(a)-1, b)
        else:
            print(seg.query(int(a)-1, int(b)))


if __name__ == "__main__":
    main()


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

using namespace std;
const int MAX_N = 305; 

double dp[MAX_N][MAX_N][MAX_N]; 
double pro[MAX_N][MAX_N][MAX_N];
int n; 
int cnt[4]; 

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int x;
		scanf("%d", &x);
		cnt[x]++;
	}
	for (int c1 = 0; c1 < MAX_N; c1++) {
		for (int c2 = 0; c2 < MAX_N; c2++) {
			for (int c3 = 0; c3 < MAX_N; c3++) {
				pro[c1][c2][c3] = 0.0;
			}
		}
	}
	pro[cnt[1]][cnt[2]][cnt[3]] = 1.0;  
	for (int c3 = MAX_N - 1; c3 >= 0; c3--) {
		for (int c2 = MAX_N - 1; c2 >= 0; c2--) {
			for (int c1 = MAX_N - 1; c1 >= 0; c1--) {
				if (pro[c1][c2][c3] > 0.0) {
					double E = dp[c1][c2][c3];
					double p = pro[c1][c2][c3];
					double S = c1 + c2 + c3; 
					p *= n;
					p *= 1.0 / (S * S); 
					if (c1 > 0) {
						pro[c1 - 1][c2][c3] += pro[c1][c2][c3] * c1 / S;
						dp[c1 - 1][c2][c3] += E * c1 * 1.0 / S + 1.0 * c1 * p;
					}
					if (c2 > 0) {
						pro[c1 + 1][c2 - 1][c3] += pro[c1][c2][c3] * c2 / S;
						dp[c1 + 1][c2 - 1][c3] += E * c2 * 1.0 / S + 1.0 * c2 * p; 
					}
					if (c3 > 0) {
						pro[c1][c2 + 1][c3 - 1] += pro[c1][c2][c3] * c3 / S;
						dp[c1][c2 + 1][c3 - 1] += E * c3 * 1.0 / S + 1.0 * c3 * p; 
					}
				}
			}
		}
	}
	cout << fixed << setprecision(10) << dp[0][0][0];
	return 0; 
}

Measured memory_bytes: 440576
#include <cstdio>
#include <algorithm>
#include <stdint.h>

int N,W;

int ws[101];
int vs[101];
int64_t light[100001];

int main(){
  scanf("%d %d",&N,&W);
  for(int i=0;i<N;i++){
    scanf("%d %d",&ws[i],&vs[i]);
  }
  for(int i=1;i<=100000;i++){
    light[i]=1e15;
  }
  for(int i=0;i<N;i++){
    for(int j=100000;j>=vs[i];j--){
      light[j]=std::min(light[j],light[j-vs[i]]+ws[i]);
    }
  }
  for(int i=100000;i>=0;i--){
    if(light[i]<=W){
      printf("%d\n",i);
      return 0;
    }
  }
  return 0;
}


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

int sum(int n)
{
	if(n==0) return 1;
	else return n+sum(n-1);
}

int main(void)
{
	int n;
	cin>>n;
	cout<<((1+n)*(n)/2)<<endl;
	return 0;
}

Measured memory_bytes: 256
n,l = gets.split(" ").map(&:to_i)
pies = []
aji = 0
(1..n).each do |ap|
    aji = l.to_i + ap.to_i - 1
    pies.push(aji)
end

result = pies.sort_by do |i|
    i.abs
end

result[0] = 0
sum = 0
result.each{|i| sum = sum + i }
puts sum

Measured memory_bytes: 1788
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, x, m; cin >> n >> x >> m;
    if (n <= 10000000) {
        ll ans = x;
        for (ll i = 1; i < n; i++) {
            x = x * x % m;
            ans += x;
        }
        cout << ans << '\n';
    } else {
        ll start, sx;
        V<int> used(m + 1, -1);
        used[x] = 0;
        ll origx = x;
        for (int i = 1; ;i++) {
            x = x * x % m;
            if (used[x] > -1) {
                start = used[x];
                sx = x;
                break;
            } else used[x] = i;
        }
        n -= start;

        ll ans = (start == 0 ? 0 : origx);
        x = origx;
        for (int i = 1; i < start; i++) {
            x = x * x % m;
            ans += x;
        }

        vll loop;
        ll loopsum = 0;
        x = sx;
        do {
            loopsum += x;
            loop.emplace_back(x);
            x = x * x % m;
        } while (x != sx);

        ans += n / ll(loop.size()) * loopsum;
        n -= n / ll(loop.size()) * ll(loop.size());
        for (ll i = 0; i < n; i++) {
            ans += sx;
            sx = sx * sx % m;
        }
        cout << ans << '\n';
    }
    return 0;
}


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

using namespace std;


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int b=0,w=0,sum=0;
	
	string s;
	cin >> s;
	for(int i=0; i<s.length(); i++){
		switch(s[i]){
			case '0' :
				b++;
				w=0;
				if(b>=2){ sum++; b=0; w=1;} 
				break;
			case '1':
				w++;
				b=0;
				if(w>=2){ sum++; w=0; b=1;} 
				break;
		}
	}
	
	cout << sum << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int m=1e7+1;
int main()
{
    int n,i,j;
    cin>>n;
    int prime[m];
    long long sum=1,p;
    memset(prime,0,sizeof(prime));
    prime[0]=0;
    prime[1]=0;
    for(i=2;i<m;i++)
    {
        if(prime[i]==0)
        {
            for(j=i;j<m;j+=i)
                prime[j]=i;
        }
    }
    map<int,long long> count;
    map<int,long long> :: iterator itr;
    for(i=2;i<=n;i++)
    {
        j=i;
        while(j>1)
        {
            count[prime[j]]++;
            j=j/prime[j];
        }
        p=1;
        for(itr=count.begin();itr!=count.end();itr++)
        {
            p*=(itr->second + 1);
        }
        sum+=(i*p);
        count.clear();
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 42684
// ~/BAU/ACM-ICPC/Teams/Rampage/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 10;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int d, g, p[N], c[N];

int main() {
	scanf("%d%d", &d, &g);
	for (int i = 0; i < d; i++)
		scanf("%d%d", p + i, c + i);

	int ans = 1e9;
	for (int msk = 0; msk < (1 << d); msk++) { //try every mask of d bits 
		int req = g, mx = -1, prob = 0; //req is required score and mx is maximum index doesn't appear in msk
		for (int i = 0; i < d; i++) { 
			if (msk & (1 << i)) { //if i-th bit is one we solve all pi problems and take bounus ci
				req -= p[i] * 100*(i+1) + c[i]; //i+1 since the score multiplied by 1-based index 
				prob += p[i];
			}
			else { //i-th bit is zero we want not to solve all pi problems
				mx = i;
			}
		}
		//mx = maximum bit i is zero
		if (req > 0) {
			int rem = (req + 100*(mx+1)-1) / (100 * (mx + 1)); //remaining number of problems required of score 100mx
			prob += rem;
			if (rem >= p[mx]) { //number of problems pmx is less than or equal rem so we must take all pmx problems and take some problems from another index but we will try it in different mask
				continue;
			}
		}
		ans = min(ans, prob);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
s=list(input())
left=s[:(len(s)-1)//2]
right=s[(len(s)+1)//2:]

def check(lis):
  for i in range(len(lis)//2):
    if lis[i] != lis[len(lis)-i-1]:
      return False
  return True

if not check(left):
  print('No')
elif not check(right):
  print('No')
elif not check(s):
  print('No')
else:
  print('Yes')

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

int cnt(vector<int> arr, int b) {
	int cnt = 0;
	for (int i = 0; i < arr.size(); ++i) {
		if (arr[i] <= b + i) cnt++;
	}
	return cnt;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; ++i) cin >> arr[i];
	
	int low = -200000, high = 1001000000;
	while (true) {
		if (high - low == 1) break;
		int mid = (low + high) / 2;
		int r = cnt(arr, mid);
		if (r >= (n / 2 + 1)) high = mid;
		else low = mid;
	}
	long long ans = 0;
	for (int i = 0; i < arr.size(); ++i) {
		ans += abs(arr[i] - (high + i));
	}
	cout << ans;
}

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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int main() {
    string S,T;
    cin >>S>>T;
    int ans=0;
    rep(i,S.length()){
        if(S[i]!=T[i])ans++;
    }
    if(T.length()!=(S.length()+1))ans++;

    if(ans!=0)cout <<"No";
    else cout <<"Yes";

    return 0;
}

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

#define int long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (long long)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 500005


int32_t main(){
sp;
    int n;
    cin>>n;
    int a[n+1],b[n+1];
    for(int i=1; i<=n; ++i){
        cin>>a[i];
        b[i]=0;
    }
    for(int i=n; i>0; --i){
        int sum=0;
        int j=i+i;
        while(j<=n){
            sum+=b[j];
            j+=i;
        }
        sum%=2;
        if(a[i]==sum)
            b[i]=0;
        else
            b[i]=1;
    }
    vector<int> ans;
    for(int i=1; i<=n; ++i)
        if(b[i]==1)
            ans.push_back(i);
    cout<<ans.size()<<"\n";
    for(auto &it:ans)
        cout<<it<<" ";
    return 0;
}


Measured memory_bytes: 5108