akhauriyash/Code-Regression huggingface dataset:
// AOJ 2300 "Calender Colors" (JAG夏合宿 2011 day 3 Problem A)
import java.util.Scanner;

public class Main {
    static double[] l;
    static double[] a;
    static double[] b;
    static double ans;
    static int n;
    static int m;
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        n = sc.nextInt();
        m = sc.nextInt();
        
        l = new double[n];
        a = new double[n];
        b = new double[n];
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextDouble();
            a[i] = sc.nextDouble();
            b[i] = sc.nextDouble();
        }
        
        ans = 0.0;
        dfs(0, 0, new double[m], new double[m], new double[m]);
        System.out.println(ans);
    }
    
    public static void dfs(int pos, int c, double[] tmpl, double[] tmpa, double[] tmpb) {
        if (c == m) {
            double tmp = 0.0;
            for (int i = 0; i < tmpl.length; i++) {
                for (int j = i + 1; j < tmpl.length; j++) {
                    tmp += Math.pow(tmpl[i] - tmpl[j], 2) + Math.pow(tmpa[i] - tmpa[j], 2)
                           + Math.pow(tmpb[i] - tmpb[j], 2);
                    ans = Math.max(ans, tmp);
                }
            }
        } else if (m - c > n - pos) {
            return;
        } else {
            dfs(pos + 1, c, tmpl, tmpa, tmpb);
            tmpl[c] += l[pos];
            tmpa[c] += a[pos];
            tmpb[c] += b[pos];
            dfs(pos + 1, c + 1, tmpl, tmpa, tmpb);
            tmpl[c] = tmpa[c] = tmpb[c] = 0.0;
        }
    }
}

Measured memory_bytes: 26264
from math import ceil
N=int(input())
trains=[list(map(int,input().split())) for _ in range(N-1)]
t=0
cnt=0
for i in range(N):
    t=0
    for j in range(i,N-1,1):
        t=max(ceil(t/trains[j][2]),ceil(trains[j][1]/trains[j][2]))*trains[j][2]
        t=t+trains[j][0]
        #print(t)
        #input()
    print(t)


Measured memory_bytes: 42716
n,m = map(int,input().split())
s = [list(map(int,input().split())) for i in range(m)]
l = s[0][0]
r = s[0][1]
for item in s:
  if item[0] > l:
    l = item[0]
  if item[1] < r:
    r = item[1]
if r-l+1 > 0:
  print(r-l+1)
else:
  print(0)

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

int main(){
	int n;cin >> n;
	for(int i = 0;i < n;i++){
		int t;cin >> t;
		if(!(t & 1) && t % 3 != 0 && t % 5 != 0)return cout << "DENIED", 0;
	}
	cout << "APPROVED";
}
// make pair, tuple
// make pair, tuple
// 
// __gcd(int, int);
// lcm = a * b / __gcd(a, b);
// 
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }
// 
// #Count leading & trailing zero of an integer bits
// __builtin_clz(n);
// __builtin_clzll(n);
//
// #Count 1s bits of an integer
// __builtin_popcount(n);
// __builtin_popcountll(n);
//
// #Error checking
// assert(n == 3);
// 
// #Error Printing
// cerr << "Some thing";

// #binary exponentiation
// long long binpow(long long a, long long b) {
//     long long res = 1;
//     while (b > 0) {
//         if (b & 1)
//             res = res * a;
//         a = a * a;
//         b >>= 1;
//     }
//     return res;
// }


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll cnt = 0;
    for (ll i = 1; i <= n; i++)
    {
        ll a;
        cin >> a;
        if (i % 2 && a % 2)
            cnt++;
    }
    cout << cnt << endl;
}


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

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

    int h,w,k;
    cin >> h >> w >> k;
    int sur[h][w] = {};
    for(int i = 0; i < k; i++){
        int v,u,w;
        cin >> v >> u >> w;
        v--;u--;
        sur[v][u] = w;
    }
    
    vector<vector<vector<ll>>> dp(h,vector<vector<ll>>(w,vector<ll>(4,0)));

    dp[0][0][0] = 0;
    if(sur[0][0] > 0) dp[0][0][1] = sur[0][0];

    for(int i = 0; i < h-1; i++){//w = 0の準初期化
        for(int k = 0; k < 4; k++){
            ll d = sur[i+1][0];
            if(d > 0){
                dp[i+1][0][1] = max(dp[i+1][0][1],dp[i][0][k]+d);
            } else dp[i+1][0][0]= max(dp[i][0][k],dp[i+1][0][0]);
        }
    }

    for(int j = 0; j < w-1; j++){//h = 0の準初期化
        for(int k = 0; k < 4-1; k++){
            if(sur[0][j+1] > 0){
                dp[0][j+1][k+1] = max(dp[0][j][k]+sur[0][j+1],dp[0][j+1][k+1]);
            }
        }
        for(int k = 0; k < 4; k++) dp[0][j+1][k] = max(dp[0][j+1][k],dp[0][j][k]);
    }

    for(int i = 0; i < h-1; i++){
        for(int j = 0; j < w-1; j++){
            ll d = sur[i+1][j+1];
            for(int k = 0; k < 4; k++){
                if(d > 0) dp[i+1][j+1][1] = max(dp[i+1][j+1][1],dp[i][j+1][k]+d);
                dp[i+1][j+1][0] = max(dp[i+1][j+1][0],dp[i][j+1][k]);
                dp[i+1][j+1][k] = max(dp[i+1][j+1][k],dp[i+1][j][k]);
            }
            for(int k = 0; k < 4-1; k++){
                dp[i+1][j+1][k+1] = max(dp[i+1][j+1][k+1],dp[i+1][j][k]+d); 
            }
        }
    }

    ll ans = -1;

    for(int i = 0; i < 4; i++){
        ans = max(ans,dp[h-1][w-1][i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 671004
#include <iostream>

using namespace std;

int main(void){
	int a,b;
	cin >> a;
	cin >> b;
	
	int x,y,z;
	cout << (a+b > a-b ? (a+b > a*b ? a+b : a*b) : (a-b > a*b ? a-b : a*b));
	return 0;
}

Measured memory_bytes: 256
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
count = 0
for i in range(n):
    x = 0
    for j in range(m):
        x += a[i][j]*b[j]
    
    if (x+c > 0):
        count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
 
int main(){
    ll s, c;
    cin >> s >> c;
    if(2*s >= c){
        cout << c/2 << endl;
    }else{
        ll rem = c - 2*s;
        cout << s + (ll)(rem / 4) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if((a+b)%3 == 0 || a*b % 3 == 0) {
			System.out.println("Possible");
		}else {
			System.out.println("Impossible");
		}

	}

}


Measured memory_bytes: 23380
from collections import defaultdict
from collections import OrderedDict

N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k] += 1
    else:
        ans.update({k: 1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)


Measured memory_bytes: 45268
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
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; }
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}
void solve(long long N){
    int v = 1000-N%1000;
    if(v==1000)cout<<0<<endl;
    else cout<<v<<endl;
}
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3768
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    static int dx[]={1,-1,0,0};
    static int dy[]={0,0,1,-1};

    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        int d[] = new int[n];
        int e[] = new int[n];

        for (int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}
        sort(d);
        int l=d[0],r=d[n-1];
        long ans=abs(l-r);
        for (int i = 2,x=1,y=n-2; i < n; i++) {
        	db(l,r);
        	int ll=0,a=0,rr=0,b=0;
        	if(abs(l-d[x])<abs(r-d[x])) {ll=abs(r-d[x]);a=1;}
        	else {ll=abs(l-d[x]);}
        	if(abs(l-d[y])<abs(r-d[y])) {rr=abs(r-d[y]);b=1;}
        	else {rr=abs(l-d[y]);}
        	
        	if(ll<rr) {ans+=rr; if(b==0)l=d[y]; else r=d[y]; y--;}
        	else {ans+=ll; if(a==0)l=d[x]; else r=d[x]; x++;}
 	
        }
     
        out.println(ans);
        out.flush();
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 56540
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;

const LL inf = 1000000000000000;
const LL mod = 1000000007;

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

	LL x = -1;
	for (LL i = 0; i <= n; ++i) {
		if ((LL)(1.08*i) == n) {
			x = i;
			break;
		}
	}

	if (x == -1) {
		cout << ":(" << endl;
	}
	else {
		cout << x << endl;
	}

}

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

int main(){
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i, n) cin >> L[i];
  sort(L.begin(), L.end());
  int sum = 0;
  rep(i, n-1){
    sum += L[i];
  }
  if(L[n-1]<sum) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    int x ;
    cin >> x ;

    int ans = x / 500 ;
    ans *= 1000 ;

    x %= 500 ;

    ans += ( x / 5 ) * 5 ;
    cout << ans ;

    line ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string s,t;
    cin >> s >> t;
    
    // 文字列を回転させていけばよいのでは？
    string res = "No";
    for(int i=0; i<s.size(); i++){
        if(t==s){
            res ="Yes";
            break;
        }else{
            t.push_back(t.at(0));
            t.erase(t.begin());
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    double n; cin >> n;
    vector <ll> taxed;
    REP(i, 50001){
        if (i==0){
            continue;
        }
        if (n == floor(i * 1.08)){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>

int main(int argc, char const* argv[])
{
	unsigned h{}, w{};
	while (std::cin >> h >> w, h != 0) {
		std::vector<char> tiles{};
		std::vector<bool> walked{};
		auto mapsize = h * w;
		tiles.reserve(mapsize);
		walked.assign(mapsize, false);
		for (int i = 0; i < mapsize; i++) {
			char c;
			std::cin >> c;
			tiles.push_back(c);
		}
		//walk
		unsigned current{};
		bool end{false}, loop{false};
		while ( !(end || loop) ) {
			switch (tiles.at(current)) {
				case '>':
					current += 1;
					break;
				case '<':
					current -= 1;
					break;
				case 'v':
					current += w;
					break;
				case '^':
					current -= w;
					break;
				case '.':
					end = true;
					break;
				default:
					break;
			}
			if (walked.at(current) && !end) {
				loop = true;
				break;
			}
			walked.at(current) = true;
		}
		if (loop) {
			std::cout << "LOOP" << std::endl;
		} else {
			auto x = current % w;
			auto y = current / w;
			std::cout << x << ' ' << y << std::endl;
		}
	}


	return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

int cal(int x) {
  return (x + 9) / 10 * 10;
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  vector<int> a(5);
  for (auto &i : a) cin >> i;
  sort(all(a), [](int &a, int &b) -> bool {
    return (a - 1) % 10 > (b - 1) % 10;
  });
  int x = 0;
  for (int i = 0; i < 4; i++) {
    x = cal(x + a[i]);
  }
  cout << x + a[4] << '\n';
}


Measured memory_bytes: 3656
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
   
using namespace std;
typedef long long int ll;
  
int main()
{
	int n, k;
  int x, y;
  scanf("%d", &n);
  scanf("%d", &k);
  scanf("%d", &x);
  scanf("%d", &y);
  if(n<=k){
    printf("%d\n", n*x);
  }else{
    printf("%d\n", k*x+(n-k)*y);
  }
    return 0;
}

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



int main(){
    
       int n;
       cin>>n;
       int a[n];
       for(int i=0;i<n;i++){
        cin>>a[i];
       }
       int max=a[0];
       int min=a[0];
       int count=0;
       for(int i=1;i<n;i++){
         if(a[i]<=max && a[i]<=min ){
            count++;
            min=a[i];
         }else{
            max=a[i];
         }
       }
       cout<<count+1<<endl;
    return 0;
}




Measured memory_bytes: 1024
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

#define POS(x) cout<<((x)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define Pos(x) cout<<((x)?"Possible":"Impossible")<<endl;
#define YES(x) cout<<((x)?"YES":"NO")<<endl;
#define Yes(x) cout<<((x)?"Yes":"No")<<endl;
#define yes(x) cout<<((x)?"yes":"no")<<endl;


int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  string s;
  string t = "keyence";
  cin >> s;
  for(int i = 0; i <= 7; i++) {
    int j = 7 - i;
    if(s.substr(0, i) + s.substr(s.size() - j, j) == t) {
      YES(1);
      return 0;
    }
  }
  YES(0);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main();
    }

    public Main() {
        Scanner sc = new Scanner(System.in);
        int H = Integer.parseInt(sc.next());
        int N = Integer.parseInt(sc.next());
        for (int i = 0; i < N; i++) {
            int A = Integer.parseInt(sc.next());
            H -= A;
            if (H <= 0) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int D=365,A=26,K=5;

int d;
int c[A],s[D][A],last[A];

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

    cin>>d;
    for(int j=0;j<A;j++)
        cin>>c[j],
        last[j]=-1;
    for(int i=0;i<d;i++)
        for(int j=0;j<A;j++)
            cin>>s[i][j];
    for(int i=0;i<d;i++)
    {
        int best=0;
        for(int j=0;j<A;j++)
            if(s[i][j]+c[j]*(i-last[j])*min(K,d-i)>
               s[i][best]+c[best]*(i-last[best])*min(K,d-i))
                best=j;
        last[best]=i;
        cout<<best+1<<"\n";
    }
}


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

using namespace std;
typedef long long ll;
int main(){
 ll N,T; cin >> N >> T;

  vector<ll> t(N);
  for(int i = 0; i < N; i++){ cin >> t[i];}
  if( N == 1){ cout << t[0] + T << endl; return 0;}
 
  int head = 0; int tail = 0;
  ll sum = 0;
  while( head < N){
    
    while( tail < N - 1 && t[tail] + T >= t[tail + 1]){
      tail++;}
    
    sum += t[tail] + T - t[head];
    
    if( tail == N - 1){ break;}
    
    tail++; head = tail;}
  
  cout << sum << endl; return 0;}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map
#include<cstring>
#include<cmath>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define MOD 1000000007

typedef  long long ll;

using namespace std;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}
/*
ll Integer_factorization(ll n){
    ll num = 0;
    ll ndash = n;
    if(n == 1) return 1;
    ll a = 2;
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    return num;
}
*/

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

ll factrial(ll n){
    if(n == 0) return 1;
    ll p = factrial(n-1)*n%MOD;
    return p;
}

//MOD逆元
ll farmat(ll n,ll p){    
    if(p == 0) return 1;
    else if(p == 1) return n%MOD;
    ll d = farmat(n,p/2);
    if(p%2 == 0){
        return (d*d)%MOD;
    }else{
        return ((n*d)%MOD*d)%MOD;
    }
}

ll conbination(ll n,ll k){
    ll a = factrial(n);
    ll b = factrial(k);
    ll c = factrial(n-k);
    return (a*farmat(b,MOD-2)%MOD*farmat(c,MOD-2))%MOD;
}

int memo[10000000];

int fib(int i){
    if(i <= 1) return i;
    if(memo[i] != 0) return memo[i];
    return memo[i] = fib(i-1)+fib(i-2);
}

ll dig(ll n){
    ll d = 0;
    while(n != 0){
        n/=10;
        d++;
    }
    return d;
}

ll prime(ll n){
    ll i = 2;
    ll sum = 0;
    ll m = 10000000000000;
    bool flag = true;
    while(i*i < n+1){
        if(n%i == 0){
            sum = n/i+i;
            m = min(sum,m);
            flag = false;
        }
        i++;
    }
    if(flag) m = n+1;
    return m;
}

void solve() {
    double a,b,x;
    cin >> a >> b >> x;
    if(a*a*b == 2*x){
        cout << fixed << atan2(b,a)*180/M_PI << endl;
    }else if(a*a*b < 2*x){
        cout << fixed << atan2(2*(a*a*b-x)/(a*a),a)* 180/M_PI << endl;
    }else{
        cout <<fixed <<  atan2(b,(2*x/(a*b)))* 180/M_PI << endl;
    }
    
}




int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {
	int hs, i;
	bool check = false;
	string s;
	cin >> s;

	hs = s.size() / 2 - 1;
	
	while (1) {
		for (i = 0; i < hs; i++) {
			if (s[i] != s[i + hs]) {
				break;
			}
			if (i == hs - 1) {
				check = true;
			}
		}
		if (check) { break; }
		hs -= 1;
	}

	cout << i + hs << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n, x, t;
  cin>>n>>x>>t;
  int count=1, r;
  if(n%x!=0)
  {
    r=n/x;
    count=count+r;
    cout<<count*t<<endl;
  }
  else
  {
    r=n/x-1;
    count=count+r;
    cout<<count*t<<endl;
  }
}


Measured memory_bytes: 3516
#pragma GCC optimize("unroll-loops,Ofast")
#pragma GCC target("avx,sse,sse2,ssse3,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1<<18;
typedef int str __attribute(( vector_size(4*sizeof(int)) ));
int tr[1660][1010], sz = 1, cnt[1660], t[1660];
str m[4] = {{0, 1, 2, 3}, {1, 2, 3, 0}, {2, 3, 0, 1}, {3, 0, 1, 2}};
#define INLINE inline __attribute(( always_inline ))
INLINE void nw(str a) {
	int p = 0;
	for(int i = 0; i < 4; i++) {
		if(!tr[p][a[i]]) tr[p][a[i]] = sz++;
		p = tr[p][a[i]];
	}
	t[p] = 1;
}

INLINE int count(str a, int s = 0) {
	a = __builtin_shuffle(a, m[s]);
	int p = 0;
	p = tr[p][a[0]];
	p = tr[p][a[1]];
	p = tr[p][a[2]];
	p = tr[p][a[3]];
	return cnt[p];
}

INLINE void add(str a, int x, int s = 0) {
	a = __builtin_shuffle(a, m[s]);
	int p = 0;
	p = tr[p][a[0]];
	p = tr[p][a[1]];
	p = tr[p][a[2]];
	p = tr[p][a[3]];
	if(t[p]) cnt[p] += x;
}
int n;
str x[maxn];
ll ans = 0;
#define shi(x, y) (((x)>>(2*(y)))&3)
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 4; j++) cin >> x[i][j];
		
		for(int j = 0; j < i; j++) {
			add(x[j], -1);
			for(int sD = 0; sD < 4; sD++) {
				str l = {x[j][(sD+1)&3], x[i][0], x[i][3], x[j][(sD+2)&3]};
				str r = {x[i][1], x[j][sD&3], x[j][(sD+3)&3], x[i][2]};
				str f = {x[j][(sD+1)&3], x[j][sD&3], x[i][1], x[i][0]};
				str b = {x[i][3], x[i][2], x[j][(sD+3)&3], x[j][(sD+2)&3]};
				for(int s = 0; s < 256; s++) {
					ll cur = 1;
					
					cur *= count(l, shi(s, 0)), add(l, -1, shi(s, 0));
					cur *= count(r, shi(s, 1)), add(r, -1, shi(s, 1));
					cur *= count(f, shi(s, 2)), add(f, -1, shi(s, 2));
					cur *= count(b, shi(s, 3)), add(b, -1, shi(s, 3));
					
					ans += cur;
					
					add(l, 1, shi(s, 0));
					add(r, 1, shi(s, 1));
					add(f, 1, shi(s, 2));
					add(b, 1, shi(s, 3));
				}
			}
			add(x[j], 1);
		}
		nw(x[i]);
		add(x[i], 1);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 6400
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

vector<int> DecimalToBinary(int decimal)
{
    vector<int> bit(0);
    while (true)
    {
        bit.push_back(decimal % 2);
        decimal /= 2;
        if (decimal == 0)
        {
            break;
        }
    }
    //reverse(bit.begin(), bit.end());
    return bit;
}

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> c(H, vector<char>(W, '.'));
    vector<int> row(H, 0);
    int black_count_sum = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> c[i][j];
            if (c[i][j] == '#')
            {
                black_count_sum++;
                row[i]++;
            }
        }
    }
    cout << endl;
    vector<int> column(W, 0);
    for (int j = 0; j < W; j++)
    {
        for (int i = 0; i < H; i++)
        {
            cin >> c[i][j];
            if (c[i][j] == '#')
            {
                column[j]++;
            }
        }
    }

    int count = 0;
    for (int i = 0; i < pow(2, H); i++)
    {
        for (int j = 0; j < pow(2, W); j++)
        {
            int black_count = 0;
            vector<int> bit_i = DecimalToBinary(i);
            vector<int> bit_j = DecimalToBinary(j);
            for (int r = 0; r < bit_i.size(); r++)
            {
                if (bit_i[r] == 1)
                {
                    black_count += row[r];
                    for (int col = 0; col < bit_j.size(); col++)
                    {
                        if (bit_j[col] == 1)
                        {
                            if (c[r][col] == '#')
                            {
                                black_count--;
                            }
                        }
                    }
                }
            }
            for (int c = 0; c < bit_j.size(); c++)
            {
                if (bit_j[c] == 1)
                {
                    black_count += column[c];
                }
            }

            if (black_count_sum - black_count == K)
            {
                count++;
            }
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int x, lol;
vector<int> vec;

int main(){
	lol = 0;
	while(cin >> x){
		if(x == 0){
			cout << vec[lol-1] << "\n";
			vec.erase(vec.begin()+(lol-1));
			lol--;
		}
		else{
			vec.push_back(x);
			lol++;
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 3124
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a != b && b != c && c != a)
        cout << "3";
    else if (a != b && b == c && c != a)
        cout << "2";
    else if (a == b && a != c && b != c )
        cout << "2";
    else if ( a == c && a != b && c != b )
        cout << "2";
    if (a == b && a == c && b == c )
        cout << "1";
    return 0;
}


Measured memory_bytes: 256
# ABC084D - 2017-like Number
import sys
input = sys.stdin.readline

from bisect import bisect_left, bisect_right


def get_primes(n):
    # return a list of primes <= n
    n += 1  # include n itself
    sieve = [1] * n
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i]:
            sieve[i * i :: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1)
    return [2] + [i for i in range(3, n, 2) if sieve[i]]


def main():
    Q = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in range(Q))
    P = get_primes(10 ** 5)
    S = set(P)
    selected_P = [p for p in P if (p + 1) // 2 in S]
    ans = []
    for l, r in A:
        x = bisect_right(selected_P, r) - bisect_left(selected_P, l)
        ans += [x]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int answer = 0;
	if (k <= a) {
		answer += k;
		k = 0;
	} else {
		answer += a;
		k -= a;
	}
	if (k <= b) {
		k = 0;
	} else {
		k -= b;
	}
	//cout << k << '\n';
	if (k <= c) {
		answer -= k; 
	} else {
		answer -= c;
	}
	cout << answer;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define Abra_Ka_Dabra ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

const long long mod = 1e9 + 7;
const double PI = acos(-1);
const double EPS = 1e-9;


int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	Abra_Ka_Dabra

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll res1 = a * c, res2 = a * d, res3 = b * c, res4 = b * d;
	cout << max(max(max(res1, res2), res3), res4) << "\n";

	return 0;
}


Measured memory_bytes: 3648
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las
    

main = do
    (a, b) <- readTuple2
    print $ max 0 (a - b * 2)


Measured memory_bytes: 380
object Main extends App {
  val s = scala.io.StdIn.readLine()
  val sReverse = s.reverse
  var result = 0
  s.zipWithIndex.foreach(c =>
    if(sReverse(c._2) != c._1) {
      result += 1
    }
  )
  println(result / 2)
}

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

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e18;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
// int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;


vector<double>  w, p;
vector<double>  q;

int N; 
vector<int> X;

int main() {

  cin >> N;
  X.resize(N);
  int _max = 0;
  ll _min = INFTY;
  ll sum = 0;
  
  REP(i, N){
    cin >> X[i];
    _max = max(_max, X[i]);
  }


  REP(i, 1000){
    sum = 0;
    REP(j, N){
      sum += (X[j] - i) *  (X[j] - i);
    }
    _min = min( _min, sum);
    // cout << sum << endl;
  }

  cout << _min << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

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

using namespace std;

int main(){
	while(1){
		int h, w; cin >> h >> w;
		if (h + w == 0) break;
		int taikaku = h * h + w * w;
		int larger_min = 10000000;
		int ansh = h,answ = w;
		bool f = true;
		for (int i = 1; i <= 150; i++){	
			for (int j = i + 1; j <= 150; j++){
				int T = i * i + j * j;
				if (T > taikaku and larger_min > T){
						larger_min = T;
						ansh = i;
						answ = j;
				}else if (T == taikaku and h < i and f){
						larger_min = T;
						ansh = i;
						answ = j;
						f = false;
				}
			}	
		}
		cout << ansh << " " << answ << endl; 
	}
return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
#define REP(i,x,n) for(int i=x; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()

int main(){
  int a;
  string s;
  cin >> a >> s;

  if(3200<=a){
    cout << s << endl;
  }
  else  cout << "red" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};


int main(void) {
  ll a,b;
  cin >> a >> b;
  cout << a/__gcd(a,b)*b << endl;
  
  
         
         
  
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[3200][3200], a[200000], b[200000];
string str, ss;
bool f, F;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<Pll>vec;
vector<edge>ed;
vector<LL>v;
map<Pll, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> str;
	rep(i, str.size()) {
		if (str[i] == 'W') {
			ans += i-cnt;
			cnt++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
X, Y, Z, K = map(int, input().split())
A_array = list(map(int, input().split()))
B_array = list(map(int, input().split()))
C_array = list(map(int, input().split()))

A_array.sort()
B_array.sort()
C_array.sort()

use_array = []
sum_array = []
candidate_array = []

max_sum = A_array[-1] + B_array[-1] + C_array[-1]

candidate_array = [[X - 1, Y - 1, Z - 1, max_sum]]

use_array.append((X - 1, Y - 1, Z - 1))

for i in range(K):
    candidate_array = sorted(candidate_array, key=lambda x: -x[3])

    x, y, z, s = candidate_array.pop(0)

    sum_array.append(s)
    if x != 0 and (x - 1, y, z) not in use_array:
        use_array.append((x - 1, y, z))
        diff = A_array[x] - A_array[x - 1]
        candidate_array.append([x - 1, y, z, s - diff])

    if y != 0 and (x, y - 1, z) not in use_array:
        use_array.append((x, y - 1, z))
        diff = B_array[y] - B_array[y - 1]
        candidate_array.append([x, y - 1, z, s - diff])

    if z != 0 and (x, y, z - 1) not in use_array:
        use_array.append((x, y, z - 1))
        diff = C_array[z] - C_array[z - 1]
        candidate_array.append([x, y, z - 1, s - diff])

for ans in sum_array:
    print(ans)

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

int main(){
    int N,M,C;
    cin >> N >> M >> C;
    vector<int> B(M);
    rep(i,M) cin >> B.at(i);
    vector<vector<int>> A(N,vector<int>(M));
    rep(i,N) rep(jj,M) cin >> A.at(i).at(jj);

    int cnt = 0;

    rep(i,N){
        int value = C;
        rep(jj,M) value += A.at(i).at(jj)*B.at(jj);
        if(value >0) cnt++;
    }

    cout << cnt << endl;
}   

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int n,m,q,ans = 0;
vector<int> a(51),b(51),c(51),d(51),g(11);
void generate(int cnt,int now){
    if (cnt == n){
        int count = 0;
        rep(i,q){
            if (g[b[i]]-g[a[i]] == c[i]){
                count += d[i];
            }
        }
        chmax(ans,count);
        return;
    }
    else{
        rep(i,now,m+1){
            g[cnt] = i;
            generate(cnt+1,i);
        }
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> q;
    int aa,bb,cc,dd;
    rep(i,q){
        cin >> aa >> bb >> cc >> dd;
        aa--;
        bb--;
        a[i] = aa;b[i] = bb;c[i] = cc;d[i] = dd;
    }
    generate(0,1);
    PRINT(ans);
}


Measured memory_bytes: 3620
#include <stdio.h>

int main(void){
	int x,y,w;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0) break;
		if(x>y){
			w=x;
			x=y;
			y=w;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, k;
    cin >> n >> k;
    if (k == 1) cout << 0 << endl;
    else cout << n - k << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
using namespace std;
int main(){
	int n,i,a[7]={1,2,4,8,16,32,64};
	cin>>n;
	for(i=0;i<7;i++){
		if(a[i]>n)break;
	}
	cout<<a[i-1]<<endl;
	
	

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;
import static java.lang.System.*;
public class Main
{
public static void main (String args[]) throws Exception
{
	Scanner sc=new Scanner(in);
    int n=sc.nextInt();
    long arr[]=new long[n];
    long sum=0;
    for(int i=0;i<n;i++)
    {
		arr[i]=sc.nextLong();
		sum+=arr[i];
	}
    int pos=-1;
    long a=0;
    long b=0;
    long min=0;
    int flag=0;
    for(int i=0;i<n-1;i++)
    {
		a+=arr[i];
		b=(sum-a);
		long diff=b-a;
		if(diff<0)
		diff=diff*-1;
		//out.println(diff);
		//out.println(a);

		//out.println(b);
		if(flag==0)
		{
			//out.println("ss");
			flag=1;
			min=diff;
			pos=i;
			//	out.println(Math.abs(b-a));

		}
		else if(diff<min)
		{min=diff;pos=i;	//out.println(Math.abs(b-a));
}
	}
    if(n==2)
	out.println(Math.abs(arr[1]-arr[0]));
	else
	out.println(min);



}
}


class Berland
{
char ch;
int pos;
public Berland(int a,char b)
{
ch=b;
pos=a;
}
}
class ChComparator implements Comparator<Berland>
{
public int compare(Berland f1,Berland f2)
{
if(f1.ch==f2.ch)
return 0;
if(f1.ch<f2.ch)
return -1;
return 1;
}
}


Measured memory_bytes: 83920
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAX=109999;
const ll INF=0x3f3f3f3f3f3f3f;
vector<int> conn[MAX];
queue<pii> bfs;
int n,m,chk[MAX],c[2];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        conn[t1].push_back(t2);
        conn[t2].push_back(t1);
    }
    bfs.push(make_pair(1,0)); bfs.push(make_pair(n,1));
    while(!bfs.empty()){
        pii tmp=bfs.front();
        bfs.pop();
        if(chk[tmp.x]==0) {
            chk[tmp.x]=1; c[tmp.y]++;
            for(int i=0;i<conn[tmp.x].size();i++) if(chk[conn[tmp.x][i]]==0) bfs.push(make_pair(conn[tmp.x][i],tmp.y));
        }
    }
    if(c[0]>c[1]) printf("Fennec\n");
    else printf("Snuke\n");
}


Measured memory_bytes: 6528
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, X = get_ints
L = get_ints

sum = 0
ans = -1
L.each.with_index do |l, i|
  sum += l
  if sum > X
    ans = i + 1
    break
  end
end

puts ans == -1 ? L.length + 1 : ans



Measured memory_bytes: 14288