akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        boolean[][] cards = new boolean[4][13];
        for (int i=0; i<n; i++) {
            String s = stdIn.next();
            switch (s.charAt(0)) {
                case 'S':cards[0][stdIn.nextInt()-1] = true; break;
                case 'H':cards[1][stdIn.nextInt()-1] = true; break;
                case 'C':cards[2][stdIn.nextInt()-1] = true; break;
                case 'D':cards[3][stdIn.nextInt()-1] = true; break;
            }
        }
        char[] c = {'S','H','C','D'};
        for (int i=0; i<4; i++) {
            for (int j=0; j<13; j++) {
                if (!cards[i][j]) {
                    System.out.println(c[i]+" "+(j+1));
                }
            }
        }
    }
}


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

int main() {

  long long a,b,c,d,e;
  cin >> a >> b >> c;
  d=4*a*b;
  e=(c-a-b);

 if(e>0&&d<e*e)
      cout << "Yes" << endl;
 else
      cout << "No" << endl;
 }



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

using namespace std;

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> first(n+1), last(n+1);
	rep(i,m) {
		int x,y;
		cin>>x>>y;
		if(x==1)first[y]=1;
		if(x==n)last[y]=1;
		if(y==1)first[x]=1;
		if(y==n)last[x]=1;
	}
	rep(i,n-2){
		if(first[i+2]&&last[i+2]){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 4792
from operator import itemgetter

N, M = map(int, input().split())
lists = [list(map(int, input().split())) for _ in range(N)]

lists.sort(key=itemgetter(0))
mon = 0
for shop in lists:
    if shop[1] < M:
        mon += shop[0]*shop[1]
        M -= shop[1]
    else:
        mon += shop[0]*M
        break
print(mon)


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

int main() {
  int n,l,sum = 0;
  cin >> n >> l;
  for(int i = 0; i < n; ++i){
    sum += i + l;
  }
  if(l >= 0){
    cout << sum - l << endl;
  }
  else if(n > l * -1){
    cout << sum << endl;
  }
  else{
    cout << sum - (l + n - 1) << endl;
  }
}


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

int main() {
	u64 N, M;
	cin >> N >> M;
	
	vector<u64> H(N);
	for(u64 t=0; t<N; t++) cin >> H[t];
	
	vector<bool> lights(N, true);
	for(u64 t=0; t<M; t++) {
		u64 A, B;
		cin >> A >> B;
		A--;
		B--;
		
		bool AisGood = (H[A] > H[B]);
		bool BisGood = (H[B] > H[A]);
	
		lights[A] = lights[A] & AisGood;
		lights[B] = lights[B] & BisGood;
	}
	
	u64 ans = 0;
	for(u64 t=0; t<N; t++) ans += lights[t];
	
	cout << ans;
	
	return 0;
}

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

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

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

char s[100010];
int k, n;
int main() {
  scanf("%s%d", s, &k);
  n = strlen(s);
  const int a = 'z' + 1;
  for (int i = 0; i < n; ++i) if (s[i] != 'a') {
    if (k >= a - s[i]) {
      k -= a - s[i];
      s[i] = 'a';
    }
  }
  if (k) {
    s[n - 1] = ((int)s[n - 1] - 'a' + k) % 26 + 'a';
  }
  puts(s);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
using namespace std;

int main() {
	int max;
	cin >> max;
	vector<int> questions;
	for (int i = 0; i < max; i++) {
		int tmp;
		cin >> tmp;
		questions.push_back(tmp);
	}
	sort(questions.begin(), questions.end());
	
	int sum = 0;
	sum = accumulate(questions.begin(), questions.end(), 0);
	if (sum % 10 != 0) {
		cout << sum;
		return 0;
	}

	for (int i = 0; i < max; i++) {
		vector<int> tmps;
		copy(questions.begin(), questions.end(), back_inserter(tmps));
		tmps.erase(tmps.begin() + i);
		int sum = 0;
		sum = accumulate(tmps.begin(), tmps.end(), 0);
		if (sum % 10 != 0) {
			cout << sum;
			return 0;
		}
	}

	cout << 0;
	return 0;
}

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)

signed main () {
  string s;
  cin >> s;
  cout << s.substr(0, 4) << " " << s.substr(4, 8) << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> a(H);
  for (int i = 0; i < H; i++) {
    cin >> a.at(i);
  }

  vector<bool> row(H);
  vector<bool> col(W);

  for (int i = 0; i < H; i++) {
    row.at(i) = false;
    for (int j = 0; j < W; j++) {
      if (a.at(i).at(j) == '#') row.at(i) = true;
    }
  }

  for (int j = 0; j < W; j++) {
    col.at(j) = false;
    for (int i = 0; i < H; i++) {
      if (a.at(i).at(j) == '#') col.at(j) = true;
    }
  }

  for (int i = 0; i < H; i++) {
    bool output = false;
    for (int j = 0; j < W; j++) {
      if (row.at(i) && col.at(j)) {
        cout << a.at(i).at(j);
        output = true;
      }
    }
    if (output) cout << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	bool A[100][100];
	bool B[100];
	for (int N; cin >> N&&N;) {
		memset(A, 0, sizeof(A));
		memset(B, 1, sizeof(B));
		for (int i = 0; i < N; i++) {
			int M; cin >> M;
			for (int j = 0; j < M; j++) {
				int p; cin >> p;
				A[i][p] = true;
			}
		}
		int K; cin >> K;
		int cnt = N;
		for (int i = 0; i < K; i++) {
			int l; cin >> l;
			for (int j = 0; j < N; j++) {
				if (B[j] && !A[j][l]) {
					B[j] = false;
					cnt--;
				}
			}
		}
		
		//cout << " " << cnt << endl;
		if (cnt == 1) {
			for (int i = 0; i < N; i++) {
				if (B[i]) {
					cout << i + 1 << endl;
				}
			}
		}
		else {
			cout << -1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1176
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {
	string a[3];
	int n;
	int count = 0;

	cin >> n;
	FOR(i, 0, 2) {
		cin >> a[i];
	}

	FOR(i, 0, n - 1) {
		if (a[0][i] != a[1][i]) {
			if (a[1][i] != a[2][i]) {
				if (a[2][i] != a[0][i]) {
					count += 2;
				}
				else {
					count++;
				}
				
			}
			else {
				count++;
			}
		}
		else if (a[1][i] != a[2][i]) {
			count++;
		}
		else if (a[2][i] != a[0][i]) {
			count++;
		}
		//cout << count << endl;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
    }
    if c >= a && c <= b {
        println!("Yes");
    } else if c >= b && c <= a {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int gcd(int a, int b, int c)
{
    while (a != b)
    {
        if (a > b)
            a -= b;
        else
            b -= a;
    }
    
    while (a != c)
    {
        if (a > c)
            a -= c;
        else
            c -= a;
    }
    return a;
}
int main()
{
  long long n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
        for (int k = 1; k <= n; k++)
            sum += gcd(i, j, k);
    cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> LR(N);
    rep(i, N) {
        int l, r;
        cin >> l >> r;
        r++;
        LR[i] = { l, r };
    }
    vector<int> lsort(N), rsort;
    iota(all(lsort), 0);
    rsort = lsort;
    sort(all(lsort), [&](auto&& l, auto&& r) { return LR[l].first < LR[r].first; });
    sort(all(rsort), [&](auto&& l, auto&& r) { return LR[l].second < LR[r].second; });

    int ml = rsort[0], mr = lsort[N - 1];
    int ans = 0;
    if (ml == mr) {
        rep(i, N) {
            if (i == ml) continue;
            ans = max(ans, LR[ml].second - LR[ml].first + LR[i].second - LR[i].first);
        }
    }
    else {
        // mlmr同じグループ
        rep(i, N) {
            if (i == ml || i == mr) continue;
            ans = max(ans, max(0, LR[ml].second - LR[mr].first) + LR[i].second - LR[i].first);
        }

        // mlmr別グループ
        vector<int> minr(N + 1);
        minr[N] = LR[mr].second;
        for (int i = N - 1; i >= 0; --i) {
            if (rsort[i] == ml || lsort[i] == mr) minr[i] = minr[i + 1];
            else minr[i] = min(minr[i + 1], LR[lsort[i]].second);
        }

        int maxl = LR[ml].first;
        ans = max(ans, LR[ml].second - maxl + max(0, minr[0] - LR[mr].first));
        rep(i, N) {
            if (rsort[i] == ml || lsort[i] == mr) continue;
            maxl = max(maxl, LR[lsort[i]].first);
            ans = max(ans, max(0, LR[ml].second - maxl) + max(0, minr[i + 1] - LR[mr].first));
        }
    }

    write(ans);
}

Measured memory_bytes: 2176
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

using namespace std;

int n;
int A[1010];

void insertsort(int n,int *A)
{
    for(int k=0;k<n;k++)
        {
            if(k!=n-1)
            printf("%d ",A[k]);
            else
                printf("%d\n",A[k]);
        }
    for(int i=1;i<n;i++)
    {
        int j=i-1;
        int v=A[i];
        while(j>=0&&A[j]>v)
        {
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;
        for(int k=0;k<n;k++)
        {
            if(k!=n-1)
            printf("%d ",A[k]);
            else
                printf("%d\n",A[k]);
        }

    }
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    insertsort(n,A);
    return 0;
}



Measured memory_bytes: 3220
//vinay
#include<bits/stdc++.h>
using namespace std;
//#define mod 10e9+7;
#define ll long long int
#define flash ios_base::sync_with_stdio(false);cin.tie(0);
// C++ program to print all 
// permutations with duplicates allowed 
//vector<int > a;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    float d, t, s;
    scanf("%f %f %f",&d,&t,&s);
    float p = d/s;
    if(p <= t){
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    
}

Measured memory_bytes: 3860
#include<stdio.h>


int main()
{
	int r, c, n, flag, cnt;
	int arr[16][16] = { 0 };

	while (1)
	{
		scanf("%d", &n);
		if (n == 0)
		{
			break;
		}
		flag = 1;
		r = (n + 1) / 2 + 1;
		c = (n + 1) / 2;
		arr[r][c] = cnt = 1;

		while (cnt != n*n + 1)
		{
			++cnt;
			if (flag)
			{
				++r;
				++c;
				if (c > n)
				{
					c = 1;
				}

				if (r > n)
				{
					r = 1;
				}

				if (arr[r][c])
				{
					flag = 0;
					--cnt;
				}
				else
				{
					arr[r][c] = cnt;
				}
			}
			else
			{
				++r;
				--c;
				if (c < 1)
				{
					c = n;
				}

				if (r > n)
				{
					r = 1;
				}

				if (arr[r][c])
				{
					flag = 0;
				}
				else
				{
					arr[r][c] = cnt;
					flag = 1;
				}

			}

			//printf("r=%d  c=%d   cnt=%d\n", r, c, cnt);
		}

		for (r = 1; r < n + 1; r++)
		{
			for (c = 1; c < n + 1; c++)
			{
				printf("%4d", arr[r][c]);
				arr[r][c] = 0;
				if (c == n)
				{
					printf("\n");
				}
			}
		}
	}

	return 0;
}


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

int main() {
    int a=1;
    int b=1;
    while(a+b>0){
        cin>>a>>b;
        if(a+b==0){
            return 0;
        }
        if(a>=b){
            cout<<b<<" "<<a<<endl;
        }else{
            cout<<a<<" "<<b<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(),a.end());
	cout << a[0] << ' ' << a[1] << ' ' << a[2] << endl;
}

Measured memory_bytes: 1208
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	const long INFL = 4011686018427387913L;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int Y = I[0], X = I[1];
		var dp = new long[X, Y];
		dp[X - 1, Y - 1] = 1;
		var map = new bool[X, Y];
		for (var y = 0; y < Y; y++)
		{
			var S = Str;
			for (var x = 0; x < X; x++) map[x, y] = S[x] == '.';
		}
		for (var y = Y - 2; y >= 0; y--) if (map[X - 1, y]) dp[X - 1, y] = dp[X - 1, y + 1];
		for (var x = X - 2; x >= 0; x--) if (map[x, Y - 1]) dp[x, Y - 1] = dp[x + 1, Y - 1];
		for (var x = X - 2; x >= 0; x--) for (var y = Y - 2; y >= 0; y--) if (map[x, y]) dp[x, y] = (dp[x + 1, y] + dp[x, y + 1]) % MOD;
		WriteLine(dp[0, 0]);
	}
}


Measured memory_bytes: 23900
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    if(a > 8 || b > 8){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
}


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

int main() {
    string S;cin>>S;
    for (int i = 0; i < S.size(); i++){
        if(i%2==0 && S[i]=='L'){
            cout<<"No"<<endl;
            return 0;
        }else if(i%2==1 && S[i]=='R'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String[] list={sc.next(), sc.next(), sc.next()};
        int five_count=0;
        int seven_count=0;
        for(String l:list){
            if(l.equals("5"))
                five_count++;
            else if(l.equals("7"))
                seven_count++;
        }
        if(five_count==2 && seven_count==1)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

Measured memory_bytes: 21716
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

int main() {
    ll N;
    cin >> N;
    vector<ll> vis;
    for (ll i = 0; i < N; i++) {
        ll vi;
        cin >> vi;
        vis.push_back(vi);
    }
    sort(vis.begin(), vis.end());
    double ans = (vis[0] + vis[1]) / 2.0;
    for (ll i = 2; i < vis.size(); i++) {
        ans = (ans + vis[i]) / 2.0;
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
	int A;
	int count_5=0, count_7=0;
	for(int i = 0; i < 3; i++){
		cin >> A;
		switch(A){
			case 5:
				count_5++;
				break;
			case 7:
				count_7++;
				break;
			default:
				break;
		}
	}
	if(count_7 == 1 && count_5 == 2) printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 256
while(True):
    H, W = map(int, input().split())
    if(H == 0 and W == 0):
        break
    else:
        fir = "#"
        sec = "."
        for i in range(H):
            for k in range(W):
                if k%2:
                    print(sec, end = "")
                else:
                    print(fir, end = "")
            tmp = fir
            fir = sec
            sec = tmp
            print("")
        print("")


Measured memory_bytes: 7012
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


int main(){
	int N;
	int a[105], b[105]={}, d=0, mx=0;

	cin >> N;
	rep(i,N){
		cin >> a[i];
		chmax(d, a[i]);
		b[ a[i] ]++;
	}
	
	bool ans = true;
	int r = (d+1)/2;
	rep(i,N+1){
		if( i < r && b[i] > 0 ){
			ans = false;
			break;
		}
		if( i == r ){
			if( d%2 == 0 && b[i] != 1 ) ans = false;
			if( d%2 == 1 && b[i] != 2 ) ans = false;
		}
		if( i > r && i <= d ){
			if( b[i] < 2 ) ans = false;
		}
	}
	if( b[1] > 2 ) ans = false;
	if( b[1] == 2 && N != 2 ) ans = false;

	cout << (ans?"Possible":"Impossible") << endl;

	return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 1e9;
const int MB = 30;
const int MOD = 1e9 + 7;
const int maxN = 2e5 + 1;

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }

    sort(rall(a));

    vector<vector<int>> dp(n + 1, vector<int>(n + 1));

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n && i + j <= n; j++) {
            if (!i && !j) continue;
            int id = i + j - 1;
            int one = (i ? dp[i - 1][j] + abs(a[id].second - i + 1) * a[id].first : 0);
            int two = (j ? dp[i][j - 1] + abs(a[id].second - (n - j)) * a[id].first : 0);
            dp[i][j] = max(one, two);
        }
    }
    
    int ans = 0;
    for (int i = 0; i <= n; i++) ans = max(ans, dp[i][n - i]);
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //int t;
    //cin >> t;
    int t = 1;
    //srand(time(0));
    cout.precision(12);
    cout << fixed;
    while (t--) solve();
}

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

using namespace std;

int main(){
    // Your code here!
    int dp[101][10001];
    int N,W;
    cin>>N>>W;
    vector<int> val(N),wei(N);
    
    for(int i=0; i<N; i++){
        cin>>val[i];
        cin>>wei[i];
    }
    
    //dp初期化
    for(int i=0; i<10001; i++){
        dp[0][i]=0;
    }
    
    for(int i=0; i<N; i++){
        for(int j=0; j<=W; j++){
            if(j-wei[i]<0){
                dp[i+1][j]=dp[i][j];
            }
            else{
                dp[i+1][j]=max(dp[i][j],max( dp[i][j-wei[i]]+val[i], dp[i+1][j-wei[i]]+val[i] ));
            }
        }
    }
    
    cout<<dp[N][W]<<endl;
    return 0;
}



Measured memory_bytes: 7044
n = int(input())
h = list(map(int, input().split()))

for i in range(n-1, 0, -1):
  if h[i] == h[i-1]-1:
    h[i-1] -= 1
  elif h[i] <= h[i-1]-2:
    print('No')
    exit(0)
print('Yes')

Measured memory_bytes: 14252
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

int main(void) {
    ll n, m; cin >> n >> m;
    vector<ll> xs; vector<ll> ys;
    
    for (ll i = 0; i < n; i++) {
        ll t; cin >> t; xs.push_back(t);
    }
    
    for (ll i = 0; i < m; i++) {
        ll t; cin >> t; ys.push_back(t);
    }

    ll sumx = 0;
    for (ll i = 1; i <= n; i++) {
        sumx += (2 * i - 1 - n) * xs[i - 1];
        sumx %= 1000000007;
    }

    ll sumy = 0;
    for (ll i = 1; i <= m; i++) {
        sumy += (2 * i - 1 - m) * ys[i - 1];
        sumy %= 1000000007;
    }

    //cout << sumx << ", " << sumy << endl;
    
    cout << (sumx * sumy) % 1000000007 << endl;

    return 0;
}

Measured memory_bytes: 2548
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    gcd_L = [0]*(N+1)
    gcd_R = [0]*(N+1)

    def gcd(x, y):
        if y == 0:
            return x
        while y != 0:
            x, y = y, x % y
        return x

    for i, a in enumerate(A):
        gcd_L[i+1] = gcd(gcd_L[i], a)
    for i, a in enumerate(A[::-1], start=1):
        gcd_R[-(i+1)] = gcd(gcd_R[-i], a)
    ans = 0
    for i in range(N):
        cur = gcd(gcd_L[i], gcd_R[i+1])
        ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63984
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits>
class cDie
{
  private:
    std::array<int64_t, 6> aEye;

  public:
    cDie(std::array<int64_t, 6> aEye)
    {
        cDie::aEye = aEye;
    }
    void fE()
    {
        int64_t t = aEye[0];
        aEye[0] = aEye[3];
        aEye[3] = aEye[5];
        aEye[5] = aEye[2];
        aEye[2] = t;
    }
    void fW()
    {
        fE();
        fE();
        fE();
    }
    void fN()
    {
        int64_t t = aEye[0];
        aEye[0] = aEye[1];
        aEye[1] = aEye[5];
        aEye[5] = aEye[4];
        aEye[4] = t;
    }
    void fS()
    {
        fN();
        fN();
        fN();
    }
    size_t top()
    {
        return aEye[0];
    }
};
int main()
{
    std::cout << std::setprecision(16);
    int64_t i1, i2, i3, i4, i5, i6;
    std::cin >> i1 >> i2 >> i3 >> i4 >> i5 >> i6;
    cDie die({i1, i2, i3, i4, i5, i6});

    std::string cmd;
    std::cin >> cmd;

    for (auto it : cmd)
    {
        if (it == 'S')
        {
            die.fS();
        }
        else if (it == 'E')
        {
            die.fE();
        }
        else if (it == 'N')
        {
            die.fN();
        }
        else if (it == 'W')
        {
            die.fW();
        }
    }
    std::cout << die.top() << "\n";

    return 0;
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
    ll n; cin >> n;
    string ans;
    while(n){
        n--;
        ans += 'a'+n%26;
        n /= 26;
    }
    reverse(All(ans));
    cout << ans << endl;
    system("pause");
}

//https://www.geisya.or.jp/~mwm48961/kou3/base2.htm
//https://math.nakaken88.com/textbook/basic-base-conversion-of-integers/


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

int main(){
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;

  if( (x-r)<0 || (y-r)<0 || (x+r)>w || (y+r)>h ){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}



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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  map<int,int> cnt;
  REP(i,N){
	int x;
	cin >> x;
	cnt[x]++;
	cnt[x-1]++;
	cnt[x+1]++;
  }
  int ans = 0;
  for(auto& p: cnt)
	maxi(ans, p.SS);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4736
#include<cstdio>

int main(void){
    int N;
    scanf("%d",&N);
    int d[N];
    for(int i=0;i<N;i++){
        scanf("%d",&d[i]);
    }
    int sum = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            sum += d[i]*d[j];
        }
    }
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 128
N, M, Q = gets.split.map(&:to_i)
Qu = Q.times.map{ gets.split.map(&:to_i) }


def dfs(data, i, &block)
  if i < data.size
    s = data[i - 1]
    (s .. M).each do |j|
      data[i] = j
      dfs(data, i + 1, &block)
    end
  else
    block.call(data)
  end
end
def max(a,b); a > b ? a : b; end

ans = 0
dfs(Array.new(N + 1, 1), 1) do |g|
  score = Qu.inject(0){|s, (a,b,c,d)| g[b] - g[a] == c ? s + d : s }
  ans = max(ans, score)
end
puts ans


Measured memory_bytes: 14380
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

//char arr[57][57];
int main(){
	Lancer();
	string s1, s2;
	cin >> s1 >> s2;
	sort(s1.begin(), s1.end());
	sort(s2.begin(), s2.end());
	if (s2[s2.length() - 1] > s1[0])
		cout << "Yes";
	else if (s1.length() < s2.length()){
		for (int i = 0; i < s1.length(); i++){
			if (s1[i] != s2[i]){
				cout << "No";
				return 0;
			}
		}
		cout << "Yes";
	}
	else cout << "No";
	cout << endl;
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 20160116
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}
const int Maxn=200005;
int a[Maxn];
LL sum[Maxn];
map<LL,int> to;
LL from[Maxn];
int BIT[Maxn];
int nn;
void add(int pos,int val){
	while (pos<=nn){
		BIT[pos]+=val;
		pos+=pos&-pos;
	}
}
int query(int pos){
	int res=0;
	while (pos>0){
		res+=BIT[pos];
		pos-=pos&-pos;
	}
	return res;
}
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	for (int i=0;i<n;i++){
		scanf("%d",&a[i]);
		a[i]-=k;
	}
	for (int i=1;i<=n;i++){
		sum[i]=sum[i-1]+(LL)a[i-1];
		to[sum[i]]=0;
	}
	to[0]=0;
	int cnt=0;
	for (map<LL,int>::iterator it=to.begin();it!=to.end();it++){
		it->second=++cnt;
		from[cnt]=it->first;
	}
	nn=cnt;
	LL ans=0;
	for (int i=0;i<=n;i++){
		
		ans+=(LL)query(to[sum[i]]);
	//	cout<<ans<<endl;
		add(to[sum[i]],1);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  float T, X;
  cin >> T >> X;
  cout << T / X << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<set>
#include<map>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
int main()
{
	int A,B,K;
	while( scanf(" %d %d %d",&A,&B,&K) != EOF ){
		if( B-A + 1 < 2 *K )
			for( int i = A; i <= B ; i++ ){
				printf("%d\n",i);
			}
		else{
			for( int i = A ; i <= A + K - 1 ; i++ ){
				printf("%d\n",i);
			}
			for( int i = B-K+1 ; i <= B ; i++ ){
				printf("%d\n",i);
			}
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};

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

int next(int n,int L){
  stringstream ss;
  ss << n;
  string s=ss.str();
  while(SZ(s)<L) s+='0';
  sort(ALL(s));
  ll a=0,b=0;
  FOR(it,s) a=a*10+*it-'0';
  reverse(ALL(s));
  FOR(it,s) b=b*10+*it-'0';
  
  return b-a;
}

int n,l;

void solve(){
  map<int,int> a;
  int cnt=0;
  a[n]=cnt++;
  while(true){
    n=next(n,l);
    if(a.count(n)){
      cout << a[n] << ' ' << n << ' ' << cnt-a[n] << endl;
      return;
    }
    a[n]=cnt++;
  }
}

int main(int argc, char *argv[])
{
  while(cin >> n >> l && n|l) solve();
  return 0;
}

Measured memory_bytes: 1236
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    A = list(map(int, input().split()))

    """考え方
    ruiseki[i] := i番目までの累積和

    ・ruiseki[0]を+にするパターン
    ・ruiseki[0]を-にするパターン

    の2通りを求め、小さい方を答えにする
    """

    # ruiseki[0]を+にするパターン
    ans1 = 0
    ruiseki = [0] * N
    ruiseki[0] = A[0]
    if ruiseki[0] <= 0:
        diff = abs(ruiseki[0] - 1)
        ans1 += diff
        ruiseki[0] = 1

    for i in range(1, N):
        ruiseki[i] = ruiseki[i-1] + A[i]

        if i%2 != 0:
            # iが奇数
            if ruiseki[i] >= 0:
                diff = abs(ruiseki[i] - (-1))
                ans1 += diff
                ruiseki[i] = -1
        else:
            # iが偶数
            if ruiseki[i] <= 0:
                diff = abs(ruiseki[i] - 1)
                ans1 += diff
                ruiseki[i] = 1
    
    # ruiseki[0]を-にするパターン
    ans2 = 0
    ruiseki = [0] * N
    ruiseki[0] = A[0]
    if ruiseki[0] >= 0:
        diff = abs(ruiseki[0] - (-1))
        ans2 += diff
        ruiseki[0] = -1

    for i in range(1, N):
        ruiseki[i] = ruiseki[i-1] + A[i]

        if i%2 != 0:
            # iが奇数
            if ruiseki[i] <= 0:
                diff = abs(ruiseki[i] - 1)
                ans2 += diff
                ruiseki[i] = 1
        else:
            # iが偶数
            if ruiseki[i] >= 0:
                diff = abs(ruiseki[i] - (-1))
                ans2 += diff
                ruiseki[i] = -1
    
    print(min(ans1, ans2))


if __name__ == "__main__":
    solve()


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;
ll a[3001], X=0, Y=0, sum = 0;
ll dp[3001][3001];
ll recur(ll flag, ll start, ll end){
	if(start > end)return 0;
	if(dp[start][end] != 0){
		return dp[start][end];
	}else if(flag){
		dp[start][end] = max(a[start] + recur(!flag, start+1, end), a[end] + recur(!flag, start, end-1));		
		return dp[start][end];
	}
	else{ 
		dp[start][end] = min(recur(!flag, start+1, end) - a[start], recur(!flag, start, end-1) - a[end]);
		return dp[start][end];
	}		
}

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,n,t,q,temp,sum=0,count=0,f=1;
    cin>>n;
    // memset(dp, inf, sizeof(dp));
    for(i=0;i<n;i++){
    	cin>>a[i];
    	sum += a[i];
    }
    x = recur(1, 0, n-1);    
    cout<<x;    
}    
    

Measured memory_bytes: 70144
N = int(input())
str_list = {}
for i in range(N):
  str_dict = {}
  for j in input():
    if j in str_dict:
      str_dict[j] += 1
    else:
      str_dict[j] = 1
  key = "".join([str(k)+str(v) for k, v in sorted(str_dict.items(), key=lambda x:x[0])])
  if key in str_list:
    str_list[key] += 1
  else:
    str_list[key] = 1
  
result = sum([i*(i-1)//2 for i in str_list.values()])
print(result)

Measured memory_bytes: 73688
#include <algorithm>
#include <iostream>
#include <iomanip>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
ll N, M, kaizyo[100005]; 

void init() {
  kaizyo[0] = 1ll;
  rep(i, 100005) {
    if (i==0) continue;
    kaizyo[i] = kaizyo[i-1]*i % MOD;
  }
}

int main() {
  INCANT;
  cin >> N >> M;
  init();
  if (abs(N-M)>=2) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = kaizyo[N]*kaizyo[M]%MOD;
  if (N!=M) {
    cout << ans << endl;
    return 0;
  }

  ans *=2ll;
  ans %= MOD;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4432
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

vector<int>ss(5);
void  fall(vector<vector<int>>&field) {
	for (int t = 0; t < 5; ++t) {
		for (int y = 4; y > 0; --y) {
			for (int x = 0; x < 5; ++x) {
				if (field[y][x] == 0 && field[y - 1][x]) {
					swap(field[y][x], field[y - 1][x]);
				}
			}
		}
	}
}
int getscore(vector<vector<int>>field) {
	int bonus = 1;
	int ans = 0;
	int num = 10;
	while (num--) {

		vector<vector<int>>del(5, vector<int>(5));
		{
			for (int x = 0; x < 5; ++x) {
				for (int u = 0; u < 3; ++u) {
					int c = field[u][x];
					if (!c)continue;
					int num = 0;
					for (int y = u; y < 5; ++y) {
						if (field[y][x] == c) {
							num++;
						}
						else {
							break;
						}
					}
					if (num >= 3) {
						for (int y = u; y < u + num; ++y) {
							del[y][x] = true;
						}
					}
				}
			}
			for (int y = 0; y < 5; ++y) {
				for (int l = 0; l < 3; ++l) {
					int c = field[y][l];
					if (!c)continue;
					int num = 0;
					for (int x = l; x < 5; ++x) {
						if (field[y][x] == c) {
							num++;
						}
						else {
							break;
						}
					}
					if (num >= 3) {
						for (int x = l; x < l + num; ++x) {
							del[y][x] = true;
						}
					}
				}
			}
		}
		for (int y = 0; y < 5; ++y) {
			for (int x = 0; x < 5; ++x) {
				if (del[y][x]) {
					ans += ss[field[y][x]-1] * bonus;
					field[y][x] = 0;
				}
			}
		}
		fall(field);

		bonus++;
	}
	return ans;
}
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
int solve(vector<vector<int>>field, int rest,int x,int y) {
	int ans = getscore(field);
	if (rest) {
		for (int way = 0; way < 4; ++way) {
			int nx = x + dx[way];
			int ny = y + dy[way];
			if (nx >= 0 && nx < 5 && ny >= 0 && ny < 5) {
				swap(field[y][x], field[ny][nx]);
				ans = max(ans, solve(field, rest - 1, nx, ny));
				swap(field[y][x], field[ny][nx]);
			}
		}
	}
	return ans;
}

int main() {
	while (1) {
		int N; cin >> N;
		if (N == -1)break;
		vector<vector<int>>field(5, vector<int>(5));
		for (int i = 0; i < 5; ++i) {
			for (int j = 0; j < 5; ++j) {
				int a; cin >> a; field[i][j] = a;
			}
		}
		for (int i = 0; i < 5; ++i) {
			cin >> ss[i];
		}
		int ans = 0;
		for (int i = 0; i < 5; ++i) {
			for (int j = 0; j < 5; ++j) {
				ans = max(ans, solve(field, N, i, j));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3184
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

ll sum_dig(ll x) {
    ll ans = 0;
    while (x > 0) {
        ans += x % 2;
        x /= 2;
    }
    return ans;
}

ll N;

int main() {
    cin >> N;

    ll ans = sum_dig(N);

    for (ll d = 2; d <= N; d *= 2) {
        ans = max(ans, sum_dig(N / d * d - 1));
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3100
#!/usr/bin/env python3
import numpy as np
n = int(input())
abc = [input() for _ in range(n)]
dp = [[0 for _ in range(3)] for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(3):
        dp[i][j] = max([dp[i-1][k] for k in range(3)if k != j ]) +int(abc[i-1].split()[j])

print(max( [dp[n][i] for i in range(3)] ) )

Measured memory_bytes: 41196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<int> A(N),cnt(1000005),ok(1000005,1);
    for(int i=0;i<N;i++){
        cin>>A[i];
        cnt[A[i]]++;
    }
    
    for(int i=1;i<=1000000;i++){
        if(cnt[i]==0) continue;
        for(int j=2;i*j<=1000000;j++){
            ok[i*j]=false;
        }
        if(cnt[i]>=2) ok[i]=false;
    }
    int ans=0;
    
    for(int i=0;i<N;i++){
        if(ok[A[i]]) ans++;
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 11912
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
ll fact[200002];
ll inverse[200002];
ll mod_pow(ll x, ll n, ll mod){
  if(n==0)return 1;
  ll res=mod_pow(x*x%mod,n/2,mod);
  if(n&1) res=res*x%mod;
  return res;
}

ll comb(ll n, ll r){
  ll res=1;
  res*=fact[n]%mod;
  res=res*inverse[r]%mod;
  res=res*inverse[n-r]%mod;
  return res;
}
int H,W,A,B;
int main(){
  scanf("%d %d %d %d",&H,&W,&A,&B);
  fact[0]=1;fact[1]=1;
  for(int i=2;i<=H+W-2;i++){
    fact[i]=(fact[i-1])*i%mod;
  }
  for(int i=0;i<=H+W-2;i++){
   inverse[i]= mod_pow(fact[i],mod-2,mod);
  }
  ll ans=0,res,res2;
  for(int i=B;i<W;i++){
    res=comb(H-A-1+i,i)%mod;
    res=res*comb(A-1+(W-1)-i,A-1)%mod;
    ans=(ans+res)%mod;
    
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 3328
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int M = 998244353;

int mul(int a, int b) {
  return (a * (ll) b) % M;
}

int sum(int a, int b) {
  int c = a + b;
  if (c >= M) c -= M;
  if (c < 0) c += M;
  return c;
}

const int N = 3001;

int dp[N][N];

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  for (int i = 1; i <= c; i++) {
    for (int j = 1; j <= d; j++) {
      if (i <= a && j <= b) {
        dp[i][j] = 1;
      } else {
        if (i > a && j <= b) {
          dp[i][j] = sum(dp[i][j], mul(dp[i - 1][j], j));
        } else if (j > b && i <= a) {
          dp[i][j] = sum(dp[i][j], mul(dp[i][j - 1], i));
        } else {
          dp[i][j] = sum(dp[i][j], mul(j, dp[i - 1][j]));
          dp[i][j] = sum(dp[i][j], mul(i, dp[i][j - 1]));
          dp[i][j] = sum(dp[i][j], -mul(i - 1, mul(j - 1, dp[i - 1][j - 1])));
        }
      }
    }
  }
  cout << dp[c][d] << endl;
}


Measured memory_bytes: 38740
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;
    if (D2 < D1)
    {
        cout << 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int s1=Math.abs(a-b)+Math.abs(b-c);
		int s2=Math.abs(a-c)+Math.abs(b-c);
		int s3=Math.abs(a-b)+Math.abs(a-c);
		System.out.println(Math.min(s1, Math.min(s2,s3)));
	}
}

Measured memory_bytes: 23252
using System;
using System.Linq;
using System.Text;

namespace ALDS1_2_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int.Parse(Console.ReadLine());
            var line = Console.ReadLine();
            var array = line.Split(' ').Select(int.Parse).Cast<int>().ToArray();

            int swapCnt = selectionSort(array);
            // Console.WriteLine(string.Join(" ", array));
            Console.WriteLine(string.Join(" ", array.Select(e => e.ToString()).Cast<string>().ToArray()));
            Console.WriteLine(swapCnt);
        }
        static int selectionSort(int[] array)
        {
            var swapCnt = 0;
            for (var i = 0; i < array.Length - 1; i++)
            {
                int min = array[i];
                var minIndex = i;
                for (var j = i + 1; j < array.Length; j++)
                {
                    if (array[j] < min)
                    {
                        min = array[j];
                        minIndex = j;
                    }
                }
                if (min != array[i])
                {
                    int tmp = array[i];
                    array[i] = array[minIndex];
                    array[minIndex] = tmp;
                    swapCnt++;
                }
            }
            return swapCnt;
        }
    }
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int p;
  cin >> p;
  cout << p-p%500 << endl;
  return 0;
}



Measured memory_bytes: 3132
n, m = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]
ans = 0
A.sort(key=lambda x:x[0])

#print(A)
i = 0
while m>0 :
    ans += min(m,A[i][1])*A[i][0]
    m -= A[i][1]
    i += 1
    #print(ans)

print(ans)


Measured memory_bytes: 29024