akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if(a==b+c || b==a+c || c==a+b) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21204
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

struct edge{
    int cost, to;

    edge(int in_cost, int in_to){
        cost=in_cost;
        to=in_to;
    }
    bool operator<(const edge &a) const
    {
        return cost > a.cost;
    }
};

int main() {
    ll N,K;
    cin >> N >> K;

    ll ans=0LL;
    for(int b=1; b<=N; b++){
        ans+=(N/b)*max(0LL, b-K)+max(0LL, (N%b)-K+1);
    }

    if(K==0){
        ans-=N;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
using namespace std;
int n;
bool p[5001][5001];
bool c(int a){
    return 0<=a&&a<=5000;
}
int main(){
    while(cin>>n&&n){
        int x[5001],y[5001],an = 0;
        for(int i=0; i<n; i++) cin >> x[i] >> y[i],p[x[i]][y[i]] = 1;
        for(int i=0; i<n; i++)
            for(int j=i; j<n; j++){
                int dx = x[i]-x[j];
                int dy = y[i]-y[j];
                int x1 = x[i]-dy; int x2 = x[j]-dy;
                int y1 = y[i]+dx; int y2 = y[j]+dx;
                int x3 = x[i]-dy,y3 = y[i]+dx,x4=x[j]+dy,y4=y[j]-dx;
                if(c(x1)&&c(y1)&&p[x1][y1]&&c(x2)&&c(y2)&&p[x2][y2])
                    an = max(an, dx*dx+dy*dy);
                if(c(x3)&&c(y3)&&p[x3][y3]&&c(x4)&&c(y4)&&p[x4][y4])
                    an = max(an, dx*dx+dy*dy);
            }
        cout<<an<<endl;
    }
    return 0;
}

Measured memory_bytes: 22632
use std::io;
use std::cmp;
use std::collections::BinaryHeap;

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

fn main() {
    let nk: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nk[0];
    let k = nk[1];

    let mut h: Vec<usize> = Vec::with_capacity(n);

    for _ in 0..n {
        let val:usize = read_line().trim().parse().unwrap();
        h.push(val);
    }

    h.sort();

    let mut ans = h[n-1] - h[0];

    for i in 0..n-k+1 {
        ans = cmp::min(ans, h[i+k-1] - h[i]);
    }

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


Measured memory_bytes: 4352
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main() {

	int a;

	string s;

	cin >> a >> s;

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

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
	static PrintWriter out=new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		if(n==0)out.println(1);
		else out.print(0);
        out.close();
    }
	
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
		public int[] nextArr(int n) throws IOException{
			int arr[]=new int[n];
			for(int i=0;i<n;i++)arr[i]=nextInt();
			return arr;
		}
		public BigInteger BigInteger(String s) throws IOException{
			BigInteger a=new BigInteger(s);
			return a;
		}
	}
}

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

#define int long long
#define fi first
#define se second
#define pb push_back

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

int n, m, vis[100005], ans[100005];
bool ok = 1;
vector<ii> vc[100005];

void dfs(int u, int p, int val){
	//cout << u << "\n";
	if(vis[u]){
		ok &= (val == ans[u]);
		return;
	}
	vis[u] = 1;
	ans[u] = val;
	for(int i = 0; i < vc[u].size(); i++){
		int v = vc[u][i].fi;
		if(v == p) continue;
		dfs(v, u, val + vc[u][i].se);
	}
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		int x, y, w;
		cin >> x >> y >> w;
		vc[y].pb({x, w});
		vc[x].pb({y, -w});
	}
	for(int i = 1; i <= n; i++) if(!vis[i]) dfs(i, i, 0);
	if(ok) cout << "Yes";
	else cout << "No";
}


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

using namespace std;

int main() {
    long long n, m, l, a[100][100], b[100][100], c;
    cin >> n >> m >> l;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < l; ++j) {
            cin >> b[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < l; ++j) {
            c = 0;
            for (int k = 0; k < m; ++k) {
                c += a[i][k] * b[k][j];
            }
            cout << c;
            if (j == l - 1) {
                cout << endl;
            } else {
                cout << ' ';
            }
        }
    }
    return 0;
}


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


const long long mod = 1e9 + 7;


int main() {
	int N, M;

	cin >> N >> M;
	vector<int> arr(N+1, true);
	rep(i, M) {
		int a;
		cin >> a;
		arr[a] = false;
	}

	vector<long long int> dp(N+1);
	dp[0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j <= min(N, i+2); j++) {
			if (arr[j]) {
				dp[j] += dp[i];
				dp[j] %= mod;
			}
		}
	}
	cout << dp[N] << endl;
	return 0;
}

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

signed main() {
  string S;
  cin >> S;
  int l = (int)S.size();
  int ans=0;
  for(int i=0; i<l/2; i++) {
    if(S[i] != S[l-1-i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
// Ryo Kamoi
#define DEBUG

#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

int INF = 1000000000;

int n;
int dist[110];
int degree[110];
vector<int> graph[110];
int cur_room;
int max_idx;

int main(){
  cin >> n;
  REP(iter, n) {
    REP(i, 100) {
      dist[i] = INF;
      degree[i] = 0;
      graph[i] = vector<int>();
    }

    cur_room = -1;
    int max_idx = -1;
    while(1) {
      int m;
      cin >> m;
      if (m == 0) break;

      if (m > 0) {
        int prev_room = cur_room;
        max_idx++;
        cur_room = max_idx;
        
        if (prev_room >= 0) {
          degree[prev_room]--;
          degree[cur_room] = m-1;
          dist[cur_room] = dist[prev_room] + 1;
        
          graph[prev_room].push_back(cur_room);
          graph[cur_room].push_back(prev_room);
        } else {
          degree[cur_room] = m;
          dist[cur_room] = 0;
        }
        while(degree[cur_room] == 0) {
          cur_room = graph[cur_room][0];
          if (cur_room == 0) break;
        }
      } else {
        for(int i=cur_room-1; i>=0; i--) {
          if (degree[i] > 0 && dist[i] - dist[cur_room] == m) {
            degree[cur_room]--;
            degree[i]--;

            graph[i].push_back(cur_room);
            graph[cur_room].push_back(i);
            break;
          }
        }

        while(degree[cur_room] == 0) {
          cur_room = graph[cur_room][0];
          if (cur_room == 0) break;
        }
      }
    }

    REP(i, max_idx+1) {
      sort(graph[i].begin(), graph[i].end());
      cout << i+1 << " ";
      REP(j, graph[i].size()) {
        cout << graph[i][j] + 1;
        if (j < graph[i].size()-1) {
          cout << " ";
        } else {
          cout << endl;
        }
      }
    }
  }
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define mx 10001
typedef long long L;
L stor[mx+5],xa[mx+5],ya[mx+5],za[mx+5],x,y,z,k,id=0,sum=0,flg;
priority_queue<L, vector<L>, greater<L> > pq,pq2;
void init(){
	sum=xa[0]+ya[0];
	for(L i=0;i<z;i++){
		stor[i]=(sum+za[i]);
		pq.push(stor[i]);
		if((i+1)==k)break;
	}
	id=pq.size();
}
void setData(){
	pq2=pq;id=pq2.size();
	for(L i=id-1;i>=0;i--){
		stor[i]=pq2.top();pq2.pop();
	}
}
void solve(){
	sort(xa,xa+x,greater<L>());
	sort(ya,ya+y,greater<L>());
	sort(za,za+z,greater<L>());
	init();
/*
printf("\n");
	for(L i=0;i<x;i++)printf("%lld ",xa[i]);printf("\n");
	for(L i=0;i<y;i++)printf("%lld ",ya[i]);printf("\n");
	for(L i=0;i<z;i++)printf("%lld ",za[i]);printf("\n");
	for(L i=0;i<id;i++)printf("%lld ",stor[i]);printf("\n");
printf("\n");
*/
	setData();
	L pv=ya[0],cv,dv;
	for(L i=1;i<y;i++){
		cv=ya[i];
		dv=pv-cv;flg=1;
		for(L j=0;j<id;j++){
			sum=stor[j];
			if(pq.size()<k){
				pq.push((sum-dv));flg=0;
			}
			else if((sum-dv) > pq.top()){
				pq.pop();pq.push((sum-dv));flg=0;
			}
			else break;
		}
		if(flg)break;
	}
	setData();
	pv=xa[0];
	for(L i=1;i<x;i++){
		cv=xa[i];
		dv=pv-cv;flg=1;
		for(L j=0;j<id;j++){
			sum=stor[j];
			if(pq.size()<k){
				pq.push((sum-dv));flg=0;
			}
			else if((sum-dv) > pq.top()){
				pq.pop();pq.push((sum-dv));flg=0;
			}
			else break;
		}
		if(flg)break;
	}
	setData();
	//printf("id omg %lld\n",id);
	for(L i=0;i<id;i++)printf("%lld\n",stor[i]);
}

int main()
{
	scanf("%lld%lld%lld%lld",&x,&y,&z,&k);
	for(L i=0;i<x;i++)scanf("%lld",&xa[i]);
	for(L i=0;i<y;i++)scanf("%lld",&ya[i]);
	for(L i=0;i<z;i++)scanf("%lld",&za[i]);
	//k=min(k,x*y*z);
	solve();
	return 0;
}
/*
4 4 4 3000
2 10 4 8
5 4 10 15
2 15 20 1

3 2 1 3000
5 3 2
4 1
5

*/

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

using namespace std;

int main(){
    
    int n,t;
    cin >> n >> t;
    
    int prev;
    int current;
    
    long long total = 0;
    for(int i = 0; i < n; i++){
        cin >> current;
        
        total += t;
        if(i > 0 && prev + t > current){
            total -= (prev + t - current);
        }
        prev = current;
    }
    
    cout << total << endl;;
    
    
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    string s;
    cin >> s;
    string ans = "";
    rep(i, s.size()) {
        if (i%2==0) ans += s[i];
    }
    
    cout << ans << endl;
    return 0;
}


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

int main(){
    string S, T;
    cin >> S >> T;

    int length = S.length();
    int differ = 0;
    for (int i = 0; i < length; i++){
        if(S[i] != T[i]) differ++;
    }
    cout << differ << endl;
}

Measured memory_bytes: 3864
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N, X, T; cin >> N >> X >> T;
    cout << (N + X - 1) / X * T << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3560
#include <stdio.h>

int main()
{
	int day, n, a;
	int sum = 0;

	scanf("%d %d", &day,&n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		sum += a;
	}

	if (sum > day)
		sum = -1;
	else
		sum = day-sum;

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

	return 0;
}

Measured memory_bytes: 1732
use text_io::*;
use std::collections::*;
use std::process::exit;

fn main() {
    let mut n:String = read!();
    if n=="Sunny" {
        println!("Cloudy");
    }
    if n=="Cloudy" {
        println!("Rainy");
    }
    if n=="Rainy" {
        println!("Sunny");
    }
}

Measured memory_bytes: 2080
import java.util.Scanner;

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

		sc.close();

		if((a.equals("H") && b.equals("H"))||(a.equals("D") && b.equals("D"))){
			System.out.print("H");
		}else if((a.equals("H") && b.equals("D"))||(a.equals("D") && b.equals("H"))){
			System.out.print("D");
		}
	}
}

Measured memory_bytes: 21716
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    X=int(input())
    A=[399.99+200*i for i in range(8)]
    A.append(X)
    A.sort()
    print(9-A.index(X)) 




if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;

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

  unordered_set<int> st1 = {1, 3, 5, 7, 8, 10, 12};
  unordered_set<int> st2 = {4, 6, 9, 11};

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

  if ((st1.count(a) && st1.count(b)) ||
      (st2.count(a) && st2.count(b)) || (a == 1 && b == 1)) {
    cout << "Yes" << "\n";
  }
  else cout << "No" << "\n";
}


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

long long choose2(long long n){
return n*(n-1)/2;
}

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  rep(i,n)a[i]--;
  vector<int> cnt(n);
  rep(i,n) cnt[a[i]]++;
  long long tot=0;
  rep(i,n){
  tot+=choose2(cnt[i]);
  }
  rep(i,n){
  long long ans=tot;
    ans-=choose2(cnt[a[i]]);
    ans+=choose2(cnt[a[i]]-1);
    cout<<ans<<endl;
  }
  
}

Measured memory_bytes: 4096
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}


int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll ans[3][3], memo[3][3];
  rep(i,3){
    rep(j,3){
      cin>>ans[i][j];
      memo[i][j] = 0;
    }
  }
  ll n;cin>>n;
  rep(i,n){
    ll b;cin>>b;
    rep(y,3){
      rep(x,3){
        if(ans[y][x] == b){
          memo[y][x] = 1;
        }
      }
    }
  }

  rep(i,3){
    if(memo[i][0] && memo[i][1] && memo[i][2]){
      cout<<"Yes"<<endl;
      return 0;
    }
    if(memo[0][i] && memo[1][i] && memo[2][i]){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  if(memo[0][0] && memo[1][1] && memo[2][2]){
    cout<<"Yes"<<endl;
    return 0;
  }
  if(memo[0][2] && memo[1][1] && memo[2][0]){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
	int n,ans;
	double x;
	while(~scanf("%d",&n)){
		int w=0;
	x=n/1.08;
	if(n==floor((int)x*1.08)){ans=x;w=1;}
	x+=1;
	if(n==floor((int)x*1.08)){ans=x;w=1;}
	if(w)printf("%d\n",ans);
	else printf(":(\n");
		
	}
}

Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N = INT()
	A = [LIST() for _ in range(N)]

	graph_out = defaultdict(list)
	graph_in = defaultdict(list)
	match_id = [[0]*N for _ in range(N)]

	def toid(i, j):  # 選手から試合IDに変換
		if i > j: i, j = j, i
		return match_id[i][j]

	cnt = 0
	for i in range(N):
		for j in range(N):
			if i < j:
				match_id[i][j] = cnt
				cnt += 1

	V = N*(N-1)//2
	gout = [[] for _ in range(V)]
	gin = [[] for _ in range(V)]
	deg = [0]*(V)
	for i in range(N):
		for j in range(N-2):
			gout[toid(i, A[i][j]-1)].append(toid(i, A[i][j+1]-1))
			deg[toid(i, A[i][j+1]-1)] += 1
			gin[toid(i, A[i][j+1]-1)].append(toid(i, A[i][j]-1))
	# トポロジカルソート
	ans = [v for v in range(V) if deg[v]==0]
	deq = deque(ans)
	used = [0]*V
	while deq:
	    v = deq.popleft()
	    for t in gout[v]:
	        deg[t] -= 1
	        if deg[t]==0:
	            deq.append(t)
	            ans.append(t)
	if any(deg):
		print(-1)
		exit()

	cnt = [0]*V  # cntが入り次数に達したら発火
	day = [0]*V
	q = deque(ans)
	ans = 0

	while q:
		n = q.popleft()
		for node in gout[n]:
			cnt[node] += 1
			if cnt[node] == len(gin[node]):
				q.append(node)
				day[node] = day[n] + 1
				ans = day[node]
	print(ans+1) 

if __name__ == '__main__':
	main()


Measured memory_bytes: 207024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var xy = Sarray();
            var sx = xy[0];
            var sy = xy[1];
            var tx = xy[2];
            var ty = xy[3];
            var u1 = new string('U', (int)(ty - sy));
            var r1 = new string('R', (int)(tx - sx));
            var d1 = new string('D', (int)(ty - sy));
            var l1 = new string('L', (int)(tx - sx));
            var ll = "L";
            var u2 = u1 + "U";
            var r2 = r1 + "R";
            var dd = "D";
            var rr = "R";
            var d2 = d1 + "D";
            var l2 = l1 + "L";
            var uu = "U";
            WriteLine(u1 + r1 + d1 + l1 + ll + u2 + r2 + dd + rr + d2 + l2 + uu);
        }
    }
}

Measured memory_bytes: 28248
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;
const long long inf = 1e12;

int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int n;
	cin >> n;
	vi a(n + 1);
	vi res(n + 1);

	for (int i = 0; i < n; i++)
		cin >> a[i + 1];
	for (int i = n; i >= 1; i--)
	{
		int cur = 0;
		for (int j = 2; i * j <= n; j++)
			cur += res[i * j];
		if (cur % 2 != a[i])
			res[i] = 1;
	}
	vi final_res;
	for (int i = 0; i < sz(res); i++)
		if (res[i] == 1)
			final_res.push_back(i);
	cout << sz(final_res) << "\n";
	for (int i = 0; i < sz(final_res); i++)
		cout << final_res[i] << " ";
	return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>
int main(void)
{
	int S;
	int h, m, s;

	scanf("%d", &S);

	h = S / 3600;
	m = S % 3600 / 60;
	s = S % 3600 % 60;

	printf("%d:%d:%d\n",h,m,s);

	return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;
 
int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    std::vector<int> L(N);
    for (int i = 0; i < N; i++) {
        std::cin >> L[i];
    }

    int max = 0;
    for (int i = 0; i < N; i++) {
        if (max < L[i]) {
            max = L[i];
        }
    }

    int sum = 0;
    for (int i = 0; i < N; i++) {
        sum += L[i];
    }

    sum -= max;

    if (sum > max) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No"  << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iterator>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100007;

string s = "000000000000";
vector<int> f[maxn];
int a[maxn], x[maxn], y[maxn];
int main(){
    memset(a, 0, sizeof(a));
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; ++i){
        cin >> x[i] >> y[i];
        f[x[i]].push_back(y[i]);
    }
    for(int i = 1; i <= n; ++i){
        sort(f[i].begin(), f[i].end());
    }
    for(int i = 1; i <= m; ++i){
        int delta = distance(f[x[i]].begin(), lower_bound(f[x[i]].begin(), f[x[i]].end(), y[i])) + 1;
        string s1 = s;
        int d = 5;
        while(x[i] > 0){
            s1[d] = x[i] % 10 + '0';
            x[i] /= 10;
            --d;
        }
        d = 11;
        while(delta > 0){
            s1[d] = delta % 10 + '0';
            delta /= 10;
            --d;
        }
        cout << s1 << endl;
    }
    return 0;
}


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

int main() {
    string N;
    cin >> N;
    if (N[0] == N[1] && N[1] == N[2] || N[1] == N[2] && N[2] == N[3]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" <<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(s: str):
    
    s = s.replace('BC', 'X')

    ans = 0
    cur = 0
    for i in range(len(s)):
        if(s[i] == 'A'):
            cur += 1
        elif(s[i] == 'X'):
            ans += cur
        else:
            cur = 0    

    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int N;
    cin >> N;
    int ans = 0;
    reps(i, N) {
        if (i % 3 != 0 && i % 5 != 0) { ans += i; }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	sum := 0
	if a > b {
		sum += b
	} else {
		sum += a
	}
	if c > d {
		sum += d
	} else {
		sum += c
	}

	fmt.Println(sum)
}


Measured memory_bytes: 512
/*       _________
        /|______/ \
        ||  _|_|\  |
        || |_|   | /
        ||    _ / |
        ||  _| \\  \    
        ||_|_|\ || |
        |/_|/ | /|_/
              /__/      Written by: Rishabh Roshan
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int            	long long
#define integer        	int32_t
#define mod         	1000000007
#define vint        	vector<int>
#define pint        	pair<int, int>
#define umint        	unordered_map<int, int>
#define mint        	map<integer, integer>
#define in(x)        	int x; cin>>x
#define setbits(x)    	__builtin_popcountll(x)
#define zerobits(x)    	__builtin_ctzll(x)
#define w(x)        	int x; cin>>x; while(x--)
#define sp(x, y)    	fixed<<setprecision(y)<<x
#define poll(x)        	x.front(); x.pop()
#define f(x)        	for(int i=0; i<x; i++)
#define fj(x)			for(int j=0; j<x; j++)
#define fn(n, x)			for(int i=n; i<x; i++)
#define endl         	'\n'
#define inf         	1e9 
#define order_set     	tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

// #include "functions.h"

void om_shree_ganeshaya_namah(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void print(vint arr){
	f(arr.size()) cout<<arr[i]<<" ";
	cout<<endl;
}

int32_t main() {

    om_shree_ganeshaya_namah();

    in(n); in(W);
    vector<pint> arr;
    int sum=0;
    f(n){
    	in(w); in(v);
    	sum+=v;
    	arr.push_back(make_pair(v, w));
    }
    sort(arr.begin(), arr.end());

    vint dp(sum+1, INT_MAX);

    dp[0] = 0;


    f(n){
    	for(int j=sum-arr[i].first; j>=0; j--)
    		dp[j+arr[i].first] = min(dp[j+arr[i].first], dp[j]+arr[i].second);
    }

    // print(dp);

    int ans=0;
    for(int i=1; i<sum+1; i++){
    	if(dp[i]<=W)
    		ans = max(ans, i);
    }
    cout<<ans;
}

Measured memory_bytes: 3984
class Manipulation:
    def __init__(self, x_prev, y_prev, x_after, y_after):
        self.x_prev = x_prev
        self.y_prev = y_prev
        self.x_after = x_after
        self.y_after = y_after

    def print(self):
        print(self.x_prev, self.y_prev, self.x_after, self.y_after)


H, W = map(int, input().split())
# A[y][x]: y行目、x文字目
A = [list(map(int, input().split())) for _ in range(H)]

N = 0
manipulations = []

for i in range(H):
    for j in range(W):
        x = j+1
        y = i+1
        if A[i][j] % 2 == 1:
            if j == W-1:
                if i != H-1:
                    A[i+1][j] += 1
                    N += 1
                    manip = Manipulation(y, x, y+1, x)
                    manipulations.append(manip)
            else:
                A[i][j+1] += 1
                N += 1
                manip = Manipulation(y, x, y, x+1)
                manipulations.append(manip)
print(N)
for manip in manipulations:
    manip.print()


Measured memory_bytes: 47096
#!/usr/bin/env python3
# %%
stdin = open(0)
import numpy as np
 
# %%
data = np.fromstring(stdin.read(), np.int64, sep=' ')
 
# %%
X = data[1:]
costs = []
for p in range(101):
    costs.append(np.sum((X-p)**2))
 
# %%
answer = min(costs)
print(answer)

Measured memory_bytes: 13352
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) {
	if(a == 0){
		return b;
	} else if (b == 0){
		return a;
	} else {
	  if(a < b) return gcd(b, a);
	  ll r;
	  while ((r=a%b)) {
	    a = b;
	    b = r;
	  }
	  return b;
	}
}
ll ketasum(ll n) {
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}

int main(){
	ll N, M;
	cin >> N >> M;
	vl A(N);
	vl B(N);
	REP(i, N){
		cin >> A[i] >> B[i];
	}
	sort2vectors(A, B);
	ll tmp = 0;
	ll ans = 0;
	REP(i, N){
		if(B[i] + tmp >= M){
			cout << ans + A[i] * (M-tmp) << endl;
			break;
		} else {
			ans += A[i]*B[i];
			tmp += B[i];
		}
	}
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(n+1);re(i, n) std::cin >> a[i+1];
  vll use(n+1, 0);
  use[1] = 1;
  ll now = 1;
  for(int i=0;i<n;i++){
    if(use[a[now]]==1){
      std::cout << -1 << '\n';
      return 0;
    }else{
      now = a[now];
      use[now] = 1;
      if(now==2){
        std::cout << i+1 << '\n';
        return 0;
      }
    }
  }
}


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

int main() { /* ここに書く */

  int N;
  long long a,A,b,B,Ans;
  a = 0;
  A = 0;
  b = 0;
  B = 0;
  Ans = 0;
  cin >> N;
  
  vector<int>vecA(N);
  vector<int>vecB(N+1);
  
  for(int i = 0; i<N ; i++){
    cin >> vecA.at(i);}
  
  for(int i = 0; i<N ; i++){
    vecB.at(vecA.at(i))++;}
  
  for(int i = 0; i<N+1 ; i++){
    a = vecB.at(i);
    a = a*(a-1)/2;
    A = A + a;}
  
  for(int i = 0; i<N ; i++){
    b = vecB.at(vecA.at(i));
    B = b-1;
    Ans = A - B;
    
    cout << Ans << endl;}
  
  
}

Measured memory_bytes: 4096
#pragma GCC optimize ("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cmath>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<utility>
#include<valarray>
#include<vector>
#include<array>
#include<forward_list>
#include<random>
#include<ratio>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<cstring>

using namespace std;
using Int = long long; using uint = unsigned int; using uInt = unsigned long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 1e9+7;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rer(i,l,r) for(int i=(l); i<=(r); ++i)
#define gnr(i,l,r) for(int i=(r); i>=(l); --i)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
#define priend(a) {cout<<(a)<<'\n'; return 0;}
#define fil(a,v) memset((a),v,sizeof(a))
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char ch;

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

  cin>>n; pri1(n*n);
}

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

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

int main() {
  int n,k;
  while(cin >> n >> k, n+k) {
    vector<bool> v(n);
    int zero = 0;
    int mi = INF;
    REP(i,k) {
      int a;
      cin >> a;
      if (a == 0) ++zero;
      else {
        v[a-1] = 1;
        mi = min(a-1,mi);
      }
    }
    // REP(i,n)
    //   cout << v[i] << " ";
    // cout<< endl;
    // cout << mi << endl;
    int res = 0;
    for (int i=mi,j=mi; ;) {
      for (; j<n; ++j)
        if (!v[j]) 
          if (zero) --zero;
          else break;
//      cout << j << endl;
      res = max(res, j-i);
      if (j == n) break;
      while (i<n && v[i++]) ;
      zero++;
      //    cout << "i: " << i << endl;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 0
import math

def makelist(n, m):
    return [[[] for _ in range(m)] for _ in range(n)]

# n
# a, b = list(map(int, input().split()))
# s = input()


N = int(input())
A = [0]*(N+1)
x = [[] for _ in range(N+1)]
for i in range(1, N+1):
    A[i] = int(input())
    for _ in range(A[i]):
        a, b = list(map(int, input().split()))
        x[i].append((a, b))

ans = 0
for i in range(1<<N):
    dp = [False]*(N+1)
    flag = True

    ind = 1
    hoge = i
    while i > 0:
        if i % 2 == 1:
            dp[ind] = True
            
        ind += 1
        i //= 2

    
    for i in range(1, N+1):
        if dp[i]:
            for (a, b) in x[i]:
                if b == 1:
                    if not dp[a]:
                        flag = False
                        break
                elif b == 0:
                    if dp[a]:
                        flag = False
                        break
        if not flag:
            break
        

    if flag:
        ans = max(ans, dp.count(True))
print(ans)


Measured memory_bytes: 46188
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;

int min(int a, int b){
	if(a<b)return a;
	else return b;
}

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


int main(void){
	ll n,a[5], min;
	cin>>n;
	rep(i,5)cin>>a[i];
	min=a[0];
	rep(i,4)if(min>a[i+1])min=a[i+1];
	if(n<=min)cout<<5<<endl;
	else if(n%min == 0)cout<<4+n/min<<endl;
	else cout<<5+n/min<<endl;
	return 0;

}


Measured memory_bytes: 256
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;

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


Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		StringBuilder output = new StringBuilder();

		while (true) {

			int a = Integer.parseInt(input());
			String op = input();
			int b = Integer.parseInt(input());

			if (op.equals("+")) {

				output.append(a + b);

			} else if (op.equals("-")) {

				output.append(a - b);

			} else if (op.equals("*")) {

				output.append(a * b);

			}else if (op.equals("/")) {

				output.append(a / b);

			} else if (op.equals("?")) {

				output.delete(output.length() - 1, output.length());
				break;

			}

			output.append("\n");

		}

		System.out.println(output);
		close();

	}

	public static String input() {

		return scanner.next();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 26156
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N,K;
    cin >> N >> K;
    vector<int> vec(N);
    for(int i = 0; i < N;i++)cin >> vec[i];
    sort(vec.begin(),vec.end());
    int ans = 0;
    for(int i = 0; i < K;i++)ans += vec[i];
    cout <<ans << endl;
}

Measured memory_bytes: 3640
N, x = map(int, input().split())
A = list(map(int, input().split()))

# print(x)
A.sort()

# print(A)
ans = 0
i = 0
while(i < len(A) - 1):
    a = A[i]
    # print(x)
    x -= a
    if(x >= 0):
        ans += 1
    else:
        break

    i += 1

if(i == len(A) - 1 and x == A[N - 1]):
    ans += 1

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>

#define	rep(i,n)	for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

int n,c[100];
int dp1[1000000],dp2[1000000];

int main(){
	for(int T=1;scanf("%d",&n),n;T++){
		rep(i,n)	scanf("%d",c+i);

		if(c[0]!=1){
			printf("Case #%d: Cannot pay some amount\n",T);
			continue;
		}

		const int L=10*c[n-1];
		dp1[0]=0;
		fill(dp1+1,dp1+L,INF);
		rep(k,n)for(int p=c[k];p<L;p++)	dp1[p]=min(dp1[p],dp1[p-c[k]]+1);

		dp2[0]=0;
		fill(dp2+1,dp2+L,INF);
		rep(p,L)for(int k=n-1;k>=0;k--){
			if(p-c[k]>=0){
				dp2[p]=dp2[p-c[k]]+1;
				break;
			}
		}

		bool ok=true;
		rep(i,L)if(dp1[i]<dp2[i]){ ok=false; break; }
		printf("Case #%d: %s\n",T,ok?"OK":"Cannot use greedy algorithm");
	}

	return 0;
}

Measured memory_bytes: 844
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;




int main()
{
    int a,b;scanf("%d%d",&a,&b);
    int ans=0;
    if (a-2*b >ans) ans= a-2*b;
    printf("%d\n",ans);


}


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

using namespace std;

int main(){
  int H,W; cin>>H>>W;
  char field[2000][2000];
  int L[2000][2000],R[2000][2000],U[2000][2000],D[2000][2000];
  int ans=0;

  string tmp;
  for(int i=0;i<H;i++){
    cin>>tmp;
    for(int j=0;j<W;j++){
      field[i][j]=tmp[j];
    }
  }

  //左にいくつあるか
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(field[i][j]=='#') L[i][j]=0;
      else if(j==0) L[i][j]=1;
      else L[i][j]=L[i][j-1]+1;
    }
  }

  //右にいくつあるか
  for(int i=0;i<H;i++){
    for(int j=W-1;j>=0;j--){
      if(field[i][j]=='#') R[i][j]=0;
      else if(j==W-1) R[i][j]=1;
      else R[i][j]=R[i][j+1]+1;
    }
  }

  //上にいくつあるか
  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
      if(field[i][j]=='#') U[i][j]=0;
      else if(i==0) U[i][j]=1;
      else U[i][j]=U[i-1][j]+1;
    }
  }

  //下にいくつあるか
  for(int j=0;j<W;j++){
    for(int i=H-1;i>=0;i--){
      if(field[i][j]=='#') D[i][j]=0;
      else if(i==H-1) D[i][j]=1;
      else D[i][j]=D[i+1][j]+1;
    }
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
    }
  }

  printf("%d",ans);
}

Measured memory_bytes: 66688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
    int n;
    ll t;
    cin >> n >> t;
    ll tm[n];
    for (int i = 0; i < n; i++) {
        cin >> tm[i];
    }

    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ans += min(tm[i] - tm[i - 1], t);
    }
    ans += t;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#import sys
#input = sys.stdin.readline
from itertools import accumulate
def main():
    N = int( input())
    A = list( map( int, input().split()))
    S = sum(A)//2
    ANS = [0]*N
    Odd = [0]*((N+1)//2)
    Even = [0]*(N//2)
    for i in range((N+1)//2):
        Odd[i] = A[i*2]
    for j in range(N//2):
        Even[j] = A[j*2+1]
    accOdd = [0] + list( accumulate(Odd))
    accEven = [0] + list( accumulate(Even))
    ANS = [0]*N

    for i in range((N+1)//2):
        ANS[i*2] = (S - (accEven[-1] - accEven[i] + accOdd[i]))*2
    for i in range(N//2):
        ANS[i*2+1] = (S - (accOdd[-1]-accOdd[i+1] + accEven[i]))*2
    print( " ".join( map( str, ANS)))
if __name__ == '__main__':
    main()


Measured memory_bytes: 25512
#include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int main() {
  for (int i=0; i<3; i++) {
    int h, m, s;
    cin >> h >> m >> s;

    int o = h*60*60 + m*60 + s;
    cin >> h >> m >> s;
    int n = h*60*60 + m*60 + s;
    
    int t = n - o;
    cout << t/3600 << " " << (t % 3600)/60 << " " << t%60 << '\n';
  }
  return 0;
}

Measured memory_bytes: 1192
import itertools

N,M,Q = map(int,input().split())
ABCD = []
for _ in range(Q):
    a,b,c,d = map(int,input().split())
    ABCD.append(tuple([a-1,b-1,c,d]))


A = list(range(1,M+1))
MAX = 0
for L in itertools.combinations_with_replacement(A,N):
    SUM = 0
    for a,b,c,d in ABCD:
        if L[b] - L[a] == c:
            SUM += d

    MAX = max(SUM,MAX)
print(MAX)

Measured memory_bytes: 9216