akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif


typedef long long lint;

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

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



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

	lint n, in; vector<lint> a; cin >> n; rep(i, n) { cin >> in; a.push_back(in); }
	vsort(a);
	lint now = -1, sum = 0;
	rep(i, n) {
		if (a[i] == now) {
			sum++;
			continue;
		}
		now = a[i];
	}
	if (sum % 2)co(n - sum - 1);
	else co(n - sum);
	gc();
}

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

int main()
{
	long n;
	long i;
	long a[10000];
	long min;
	long max;
	long sum;
	
	// n???????????\???
	cin >> n ;
	
	// n???????????´??°?????\???
	for(i=0 ; i < n ; i++){
		cin >> a[i] ;
	}
	
	// min,max,sum???????????????a[0]
	min=a[0];
	max=a[0];
	sum=a[0];
	
	// 1???n-1?????§???????????°????????????????°????min????±???????
	for(i=1 ; i < n ; i++){
		if(min > a[i]){
		min=a[i];
		}
	
	// 1???n-1?????§???????????°?????????????????§???max????±???????
		if(max < a[i]){
		max=a[i];	
		}
		
	// 1???n-1?????§????????????sum????±???????
		sum=sum+a[i];
	}
		cout << min << " " << max << " " << sum <<endl;
}

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

#define swap(type,a,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(i=0;i<n;i++)
#define forR(i,start,n) for(i=start;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}
#define DOUBLE fixed << setprecision(10)

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int main(){
    int n,m,i,j,cnt;

    double tmp,res=0;
    cin >> n;
    vpii p;
    vi ary;
    forN(i,n){
        int x,y;
        cin >> x >> y;
        p.push_back({x,y});
        ary.push_back(i);
    };
    cnt = 0;
    do{
        cnt++;
        forR(i,1,n){
            res += tmp = sqrt(pow(p[ary[i]].first - p[ary[i-1]].first,2) + pow(p[ary[i]].second - p[ary[i-1]].second,2));
        }
    }while(next_permutation(ary.begin(), ary.end()));
    cout << DOUBLE << res/(double)cnt << endl;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int n;
  cin >> n;
  vector<int> b(n);
  rep(i, n){
    cin >> b[i];
    b[i]--;
  }

  vector<int> a;

  for(int i = n-1; i >= 0; i--){

    bool ok = false;
    for(int j = i; j >= 0; j--){

      if(b[j]==j){
        a.push_back(j);
        b.erase(b.begin() + j);
        ok = true;
        break;
      }
    }
    if(!ok){
      cout << -1 << endl;
      return 0;
    }
  }

  rep(i, a.size()){
    cout << a[n-1-i] + 1 << endl;
  }

  return 0;
}


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

using namespace std;

int main() {
  int N;
  int d[100];

  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> d[i];
  }

  sort(d, d + N, greater<int>());

  int X = 1;
  for (int i = 1; i < N; ++i) {
    if (d[i - 1] == d[i]) {
      continue;
    }
    ++X;
  }
  cout << X << endl;

  return 0;
}

Measured memory_bytes: 256
//Help : https://www.geeksforgeeks.org/probability-of-getting-more-heads-than-tails-when-n-biased-coins-are-tossed/
//struct cmp {bool operator()(const pair<int, char> &a, const pair<int, char> &b) {if (a.first == b.first) {return a.second > b.second;} else {return a.first > b.first;}}};
#include<bits/stdc++.h>
#define endl "\n"
#define _  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define min_heap priority_queue <int, vector<int>, greater<int> >
#define max_heap priority_queue <int>
#define ll long long
//#define int long long
#define MOD 1000000007
#define DEBUG cout<<"Hello1\n";
#define deb(x) cout << #x << " " << x << endl;
#define deb2(x,y) cout << #x << "=" << x << "\t\t"<<#y<<"="<<y<<endl;
#define deb3(x,y,z) cout << #x << "=" << x << "\t"<<#y<<"="<<y<< "\t"<<#z<<"="<<z<<endl;
#define all(v) (v).begin(),(v).end()
#define clear(x) memset(x,0,sizeof(x))
const int N = 1e5 + 5;
using namespace std;
template<class T>
void print_container(T &container) {for (auto &t : container) {cout << t << " ";} cout << endl;}


void solve() {
	int n;
	cin >> n;
	double a[n];
	for (int i = 0; i < n; i++)cin >> a[i];

	double dp[n + 1][n + 1];
	clear(dp);
	dp[0][0] = 1.0;

	for (int i = 1; i <= n; i++) {
		dp[i][0] = dp[i - 1][0] * (1 - a[i - 1]);
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
//dp[i - 1][j - 1] * a[i - 1]  --->We did not have j heads yet i.e. we had (j-1) yet ... So we get a head now
// dp[i - 1][j] * (1 - a[i - 1])  ---> We aldready had j heads ... So we get a tail now!
			dp[i][j] = dp[i - 1][j - 1] * a[i - 1] + dp[i - 1][j] * (1 - a[i - 1]);
		}
	}


	// for (int i = 0; i <= n; i++) {
	// 	for (int j = 0; j <= n; j++) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }


	double ans = 0;
	for (int i = 0; i <= n; i++) {
		int heads = i;
		int tails = n - i;
		if (heads > tails) {
			ans += dp[n][i];
		}
	}

	cout << setprecision(12) << ans << endl;

}

int32_t main() {
	_
	solve();
}



Measured memory_bytes: 70656
#include<cstdio>
int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)==2)
    {
        if((a%3==0)||(b%3==0)||(a+b)%3==0)printf("Possible\n");
        else printf("Impossible\n");
    }
    return 0;
}


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

int main() {
	int n, a, b; cin >> n >> a >> b;
	
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		string tmp = to_string(i);
		int sum_tmp = 0;
		for (int j = 0; j < tmp.size(); j++) {
			sum_tmp += tmp[j] - '0';
		}
		if (a <= sum_tmp && sum_tmp <= b)ans += i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#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;
    long long k;
    cin >> n >> k;

    map<int, long long> mp;
    REP(i, n){
        int a, b;
        cin >> a >> b;
        mp[a] += b;
    }

    long long cnt = 0;
    for(auto x : mp){
        cnt += x.second;
        if(cnt >= k){
            cout << x.first << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 4224
/**
 */

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(Debug, Copy, Clone)]
struct Coord{
    time:u32,
    x:u32,
    y:u32
}

// impl Coord
// {
//     fn copy(&self) -> Coord
// }

fn main() {
    let n: u32 = read();

    // if (n < 1) || (100000 < n)
    // {
    //     eprintln!("ERROR!(1)¥n");
    //     return;
    // }

    let mut coord_org = Coord {
        time: 0,
        x: 0,
        y: 0
    };

    let mut can_move: bool = true;

    for _i in 0u32..n
    {
        eprintln!("Now pos:({},{})", coord_org.x, coord_org.y);

        let coord_new = Coord {
            time: read(),
            x: read(),
            y: read()
        };

        if can_move
        {
            // let mut coord_calc = Coord{
            //     time: coord_org.time,
            //     x: coord_org.x,
            //     y: coord_org.y
            // };
            let mut coord_calc = coord_org;

            for _j in coord_org.time+1..coord_new.time+1
            {
                if coord_calc.x < coord_new.x
                {
                    coord_calc.x += 1;
                }
                else if coord_calc.x > coord_new.x
                {
                    coord_calc.x -= 1;
                }
                else
                {
                    // xが同じ
                    if coord_calc.y < coord_new.y
                    {
                        coord_calc.y += 1;
                    }
                    else if coord_calc.y > coord_new.y
                    {
                        coord_calc.y -= 1;
                    }
                    else
                    {
                        // xもyも同じ
                        coord_calc.x -= 1;
                    }
                }

                eprintln!("Calc pos({}):({},{})", _j, coord_calc.x, coord_calc.y);
            }

            if (coord_calc.x == coord_new.x) && (coord_calc.y == coord_new.y)
            {
                // coord_org.time = coord_new.time;
                // coord_org.x = coord_new.x;
                // coord_org.y = coord_org.y;
                coord_org = coord_new;
            }
            else
            {
                can_move = false;
            }
        }
    }

    if can_move
    {
        println!("Yes");
    }
    else
    {
        println!("No");
    }
}


Measured memory_bytes: 4668
#include <iostream>
using namespace std;
int main(void){
    for(int i = 0;i < 4; i++){
        int t,n;
        cin>>t>>n;
        
        if(t == 1)cout<<6000*n<<endl;
        if(t == 2)cout<<4000*n<<endl;
        if(t == 3)cout<<3000*n<<endl;
        if(t == 4)cout<<2000*n<<endl;
    }
}



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

static const int MAX = 100000;
static const int INFTY = (1<<29);

class Edge{
public:
  int t,w;
  Edge(){}
  Edge(int t,int w): t(t),w(w){}
};

vector<Edge> G[MAX];
int n,d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s){
  for(int i=0;i<n;i++) d[i] = INFTY;

  queue<int> Q;
  Q.push(s);
  d[s] = 0;

  int u;
  while(!Q.empty()){
    u = Q.front();
    Q.pop();
    for(int i=0;i<G[u].size();i++){
      Edge e = G[u][i];
      if(d[e.t] == INFTY){
        d[e.t] = d[u] + e.w;
        Q.push(e.t);
      }
    }
  }
}

void solve(){
  bfs(0);

  int maxv = 0;
  int tgt = 0;

  for(int i=0;i<n;i++){
    if(d[i] == INFTY) continue;
    if(maxv < d[i]){
      maxv = d[i];
      tgt = i;
    }
  }

  bfs(tgt);
  maxv = 0;
  for(int i=0;i<n;i++){
    if(d[i] == INFTY) continue;
    maxv = max(maxv,d[i]);
  }

  cout << maxv << endl;
}

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

  for(int i=0;i<n-1;i++){
    cin >> s >> t >> w;
    G[s].push_back(Edge(t,w));
    G[t].push_back(Edge(s,w));
  }
  solve();

  return 0;
}



Measured memory_bytes: 9936
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <utility>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
using ll = long long;
using VI = vector<int>;

int main() {
    int n;
    cin >> n;
    VI b;
    int ans = 0;
    for (int i = 0; i < n-1; i++) {
        int in; cin >> in;
        b.push_back(in);
        if (i == 0) {
            ans += in;
        }
        else {
            ans += min(b[i], b[i - 1]);
        }
    }
    ans += b[n - 2];
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    int a,b;
    cin >> a >> b;
    P(a * b);
    return  0;
}


Measured memory_bytes: 3644
#include <stdio.h>

int main(void){
  int H,W,i,j;
  while(1){
    scanf("%d%d",&H,&W);
    if(H == 0 && W == 0){
      break;
    }
    else if(H % 2 == 0 && W % 2 == 0){
      for(i = 1; i <= H / 2; i++){
        for(j = 1; j <= W / 2; j++){
          printf("#.");
        }
        printf("\n");
        for(j = 1; j <= W / 2; j++){
          printf(".#");
        }
        printf("\n");
      }
      printf("\n");
    }
    else if(H % 2 == 0 && W % 2 == 1){
      for(i = 1; i <= H / 2; i++){
        for(j = 1; j <= W / 2; j++){
          printf("#.");
        }
        printf("#\n");
        for(j = 1; j <= W / 2; j++){
          printf(".#");
        }
        printf(".\n");
      }
      printf("\n");
    }
    else if(H % 2 == 1 && W % 2 == 0){
      for(i = 1; i <= H / 2; i++){
        for(j = 1; j <= W / 2; j++){
          printf("#.");
        }
        printf("\n");
        for(j = 1; j <= W / 2; j++){
          printf(".#");
        }
        printf("\n");
      }
      for(j = 1; j <= W / 2; j++){
        printf("#.");
      }
      printf("\n");
      printf("\n");
    }
    else{
      for(i = 1; i <= H / 2; i++){
        for(j = 1; j <= W / 2; j++){
          printf("#.");
        }
        printf("#\n");
        for(j = 1; j <= W / 2; j++){
          printf(".#");
        }
        printf(".\n");
      }
      for(j = 1; j <= W / 2; j++){
        printf("#.");
      }
      printf("#\n");
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 2032
#include <stdio.h>

const char *grade(int m, int f, int r)
{
    if (m == -1 || f == -1 || m + f < 30)
    {
        return "F";
    }
    if (m + f >= 80)
    {
        return "A";
    }
    if (m + f >= 65)
    {
        return "B";
    }
    if (m + f >= 50 || r >= 50)
    {
        return "C";
    }
    return "D";
}
int main()
{
    for (;;)
    {
        int m, f, r;
        scanf("%d %d %d", &m, &f, &r);
        if (m == -1 && f == -1 && r == -1)
        {
            break;
        }
        printf("%s\n", grade(m, f, r));
    }
    return 0;
}


Measured memory_bytes: 2608
import sys
from string import ascii_lowercase as alp
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S = input().rstrip()

	# 使われていない文字が残っている場合
	for i, letter in enumerate(alp):
		if not S.count(letter):
			print(S+letter)
			sys.exit()

	# 26文字全て使われている場合
	# 後ろから見ていって、昇順に並んでいる箇所の2文字目を
	# より後ろの文字に入れ替える
	# ABCDE(01234) -> ABCED(01243) にするイメージ
	tmp = []
	for i in range(len(S)-1, 0, -1):
		if S[i] < S[i-1]:
			tmp.append(S[i])
		elif S[i] > S[i-1]:
			tmp.append(S[i])
			tmp.sort()
			# print(tmp, S[i-1])
			for t in tmp:
				if S[i-1] < t:
					print(S[:i-1]+t)
					sys.exit()
	
	# 全て降順に並んでいる場合(EDCBA)はこれ以上変えようがないので-1
	print(-1)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3832
#include <bits/stdc++.h>
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
 
using namespace std;
 
auto main() -> int
{
   string S, T, U;  cin >> S >> T;
   int a, b; cin >> a >> b;
   cin >> U;
   
   if(U == S) a--;
   if(U == T && b > 0) b--;
   
   cout << a << " " << b << endl;
}

Measured memory_bytes: 256
//#if 0
//????????????????§£?????????????????????????????????????????????????????????C++??§string??????????????§???
//?????????????????§???????????§???AOJ?????????????????????Runtime Error??????????????????????????????
//??£????????¨??????????????????????????????????????????????????????Runtime Error???????????¨???????????????
//??§???????????????????????????????????§???
//#endif
#include<iostream>
#include<string>
#define lth 1010

using namespace std;

int main()
{
	int n, L[1010][1010], Lmax = 0, *save;
	string *Xi, *Yi;
	cin >> n;
	save = new int[n];

		Xi = new string[lth];
		Yi = new string[lth];
	

	for (int k = 0; k < n; k++)
	{
		Lmax = 0;
		string X, Y;
		cin >> X >> Y;
		for (int i = 0; i <= X.length(); i++)
		{
			if (i != 0)
				Xi[i] = X.substr(0, i );
		}
		for (int i = 0; i <= Y.length(); i++)
		{
			if (i != 0)
				Yi[i] = Y.substr(0, i );
		}
		for (int i = 0; i <= X.length(); i++)
			for (int j = 0; j <= Y.length(); j++)
			{
				if (i == 0 || j == 0)
					L[i][j] = 0;
				else if (Xi[i][i - 1] == Yi[j][j - 1])
				{
					L[i][j] = L[i - 1][j - 1] + 1;
				}
				else
				{
					L[i][j] = (L[i][j - 1] > L[i - 1][j]?L[i][j - 1] : L[i - 1][j]);
				}
				if (Lmax < L[i][j]) Lmax = L[i][j];
			}
		save[k] = Lmax;
	}

	for (int i = 0; i < n; i++)
		cout << save[i] << endl;
}

Measured memory_bytes: 8116
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

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

bool pr[1000000];

template <size_t N>
void psieve(bool (&p)[N]) {
  for (int i = 0; i < N; i++)
    p[i] = true;
  p[0] = p[1] = false;
  for (int i = 2; i * i < N; i++) {
    if (!p[i])
      continue;
    for (int j = i * i; j < N; j += i)
      p[j] = false;
  }
}

int solve(int n) {
  int r = 0;
  REP (i, n+1) r += pr[i];
  return r;
}

int main() {
  ios::sync_with_stdio(false);
  psieve(pr);
  int n;
  while (cin >> n) {
    cout << solve(n) << endl;
  }
  return 0;
}

Measured memory_bytes: 4116
#include <iostream>

using namespace std;

int main()
{
	int maxv;
	int minv;
	int i;
	int n;
	int r[200000];
	
	cin >> n;
	
	for (i = 0; i < n; i++){
		cin >> r[i];
	}
	
	maxv = r[1] - r[0];
	minv = r[0];
	
	for (i = 1; i < n; i++){
		if (maxv < r[i] - minv){
			maxv = r[i] - minv;
		}
		if (minv > r[i]){
			minv = r[i];
		}
	}
	
	cout << maxv << "\n";
	
	return (0);
}



Measured memory_bytes: 3876
#include<stdio.h>

int main(void)
{
	int i = 0;
	int N;
	char S[10001];
	scanf("%d", &N);
	scanf("%s", &S);
	while (S[i] != NULL) {
		S[i] += N;
		if (S[i] > 'Z')
		{
			S[i] -= 26;
		}
		i++;
	}
	printf("%s", S);



	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
#include <stdbool.h>
//#include <limits.h>
#include <math.h>

int main() {
  int n;
  scanf("%d", &n);
  int a[n], i=0, j=2;
  while (i<n && j<=55555) {
    bool boo = true;
    for (int k=2; k<=sqrt((double)j); k++) {
      if (j%k == 0) {
        boo = false;
        break;
      }
    }
    if (boo) {
      a[i] = j;
      i++;
    }
    j+=5;
  }
  for (int i=0; i<n; i++) printf("%d ", a[i]);
  printf("\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stack>

using namespace std;
typedef unsigned long long ull;

int N;
ull h[100002];

ull solve() {
  ull ans = 0;
  int last_j;
  stack<pair<int, ull>> s;
  pair<int, ull> tmp;
  for (int j = 1; j <= N+1; ++j) {
    if (s.empty() || (s.top().second < h[j])) {
      s.push(make_pair(j, h[j]));
    }
    else {
      while (!s.empty() && s.top().second >= h[j]) {
        last_j = s.top().first;
        ans = max(ans, (j-last_j)*(s.top().second));
        s.pop();
      }
      s.push(make_pair(last_j, h[j]));
    }
  }
  return ans;
}

int main () {
  cin>>N;
  for (int i = 0; i < N; ++i) {
    cin>>h[i+1];
  }
  cout<<solve()<<endl;
}



Measured memory_bytes: 5452
N,K,*H=`dd`.split.map &:to_i
d=Array.new(N,0)
(1...N).each{ |i|
  v = d[i-1] + (H[i]-H[i-1]).abs
  ([i-K, 0].max ... i-1).each{ |j| vv = d[j] + (H[i]-H[j]).abs; v = vv if vv < v; }
  d[i] = v
}
p d[-1]


Measured memory_bytes: 12288
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e3+10;
int n,cnt[N],s,m,ans[N];

int b[N];
poly res;
bool vis[N];
inline bool check(int len){
	int las=n-len;
	if (m-las+1<=0||m+len>s) return 0;
	For(i,1,n) vis[i]=0;
	For(i,m-las+1,m) vis[ans[i]]=1;
	int mn=1e9,mx=0;
	For(i,1,n) b[i]=cnt[i]-(vis[i]^1),mn=min(mn,b[i]),mx=max(mx,b[i]);
	if (mn<0) return 0;
	res={};
	if (mn*2>=mx){
		For(i,1,n) if (!vis[i]) res.pb(i);
		return 1;
	} else if (mn*2+1==mx){
		int cnt=0;
		For(i,1,n) if (!vis[i]) cnt+=b[i]==mx;
		poly tmp;
		For(i,1,n) if (!vis[i]){
			if (b[i]!=mx&&b[i]!=mn) res.pb(i),vis[i]=1;
			else if (b[i]==mx){
				res.pb(i),vis[i]=1,--cnt;
				if (cnt==0)	for (auto j:tmp) res.pb(j);
			} else if (b[i]==mn){
				if (cnt==0) res.pb(i),vis[i]=1;
					else tmp.pb(i);
			}
		}
		int r=0,l=0;
		For(i,1,las){
			if (b[ans[m-i+1]]==mx) r=i;
			if (b[ans[m-i+1]]==mn&&!l) l=i;
		}
		FOR(i,0,siz(res)){
			if (b[res[i]]==mx) r=las+i+1;
			if (b[res[i]]==mn&&!l) l=las+i+1; 
		}
		if (r<l) return 1;
			else return 0;
	} else return 0;
}
inline bool check(poly a,poly b){
	int n=max(siz(a),siz(b));
	a.resize(n),b.resize(n);
	FOR(i,0,n) if (a[i]!=b[i]) return a[i]<b[i];
	return 0;
}
inline void insert(){
	poly ret;
	For(i,1,n)
		if (check(i))
			if (ret.empty()||check(res,ret)) ret=res;
	for (auto i:ret) ans[++m]=i,cnt[i]--;
}

int main(){
	n=read();
	int mx=0,mn=1e9;
	For(i,1,n){
		cnt[i]=read(),s+=cnt[i];
		mx=max(mx,cnt[i]),mn=min(mn,cnt[i]);
	}
	if (mn*2<mx) return puts("-1"),0;
	while (m<s) insert();
	For(i,1,m) printf("%d ",ans[i]);
}

Measured memory_bytes: 3744
#include <iostream>

using namespace std;

int main()
{
  int a, b;
  int res;

  cin >> a >> b;

  for (int i = a; i <= b; i++) {
    int target = i;
    int x5 = target % 10;

    target /= 10;

    int x4 = target % 10;

    target /= 100;

    int x1 = target % 10;

    int x0 = target / 10;

    if (x0 == x5 && x1 == x4) res++;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
/// 11:57 AM 02/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

template<typename T>
void ContainerError(T &v);

ll powmod(ll base, ll exp, ll MOD);

ll mpow(ll base, ll exp);

ll gcd(ll a, ll b);

void dfs(ll i, vector<ll> &v, vector<vector<ll> > &G, vector<bool> &vis, multiset<ll> &s, vector<ll> &ans) {
    if(vis[i]) {
        return;
    }
    vis[i] = true;
    s.insert(v[i]);
    auto it = s.find(v[i]);
    it++;
    ll val = -1;
    if(it!=s.end()) {
        val = *it;
        s.erase(it);
    }
    ans[i] = s.size();
    for(auto &x:G[i]) {
        dfs(x, v, G, vis, s, ans);
    }
    if(val != -1) {
        s.insert(val);
    }
    it = s.find(v[i]);
    if(it!=s.end()) {
        s.erase(it);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> v(n);
    for(auto &x:v) {
        cin >> x;
    }
    vector<vector<ll> > G(n);
    for(ll i=1;i<n;i++) {
        ll a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    priority_queue<ll> q;
    q.push(0);
    multiset<ll> s;
    s.insert(v[0]);
    vector<ll> ans(n);
    vector<bool> visited(n,0);
    dfs(0, v, G, visited, s, ans);
//    while(!q.empty()) {
//        ll ver = q.top();
//        q.pop();
//        for(auto &x:G[ver]) {
//            if(!visited[x]) {
//                q.push(x);
//                lis[x] = lis[ver];
//                lis[x].insert(v[x]);
//                auto it = lis[x].find(v[x]);
//                it++;
//                if(it!=lis[x].end()) {
//                    lis[x].erase(it);
//                }
//                ans[x] = lis[x].size();
//                visited[x] = 1;
//            }
//        }
//        lis[ver].clear();
//    }
    for(auto x:ans) {
        cout<<x<<endl;
    }
    return 0;
}

template<typename T>
void ContainerError(T &v) {
    cout << "{";
    for (auto &x:v) { cout << x << ','; }
    cout << "}" << endl;
    return;
}

ll powmod(ll base, ll exp, ll MOD) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return (res % MOD);
}

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base);
        base = (base * base);
        exp /= 2;
    }
    return (res);
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }



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

using namespace std;


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

    cin >> n;
    vector<long long > a(n);

    for(long long  i=0;i<n;++i) {
        cin >> a[i];
    }

    sort(a.begin(),a.end());
    if (a[0] == 0){
        cout << 0;
        return 0;

    }


    long long  res = 1;
    for(long long  i = 0; i < n; i++){
    if (res > (long long)1e18 / a[i]){
        cout << -1;
        return 0;
    }else {
        res *=a[i];
    }
    }
        cout << res;


}


Measured memory_bytes: 3980
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

const int mod=1e9+7;

int modexp(int x,int y){
	x%=mod;
	int res=1;
	while(y>0){ 
        if(y & 1)res=(res*x)%mod; 
        y=y>>1;
        x=(x*x)%mod;   
    } 
    return res; 
}

int invmod(int x){
	return modexp(x,mod-2);
}

int nCk(int n, int k) {  
    int num = 1;  
    if ( k > n - k )  
        k = n - k;  
   
    for (int i = 0; i < k; ++i){  
        num *= (n - i);  
        num%=mod; 
    }  


    int den=1;

    for(int i=0;i<k;i++){
    	den*=(i + 1); 
    	den%=mod;
    }

    int res=(num*invmod(den))%mod;
  
    return res;  
}  

int32_t main(){
	boost;
	int n,a,b;
	cin>>n>>a>>b;
	int ans=(modexp(2,n)-1+mod)%mod;
	ans-=nCk(n,a);
	ans+=mod;
	ans%=mod;
	ans-=nCk(n,b);
	ans+=mod;
	ans%=mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<stack>
using namespace std;

stack<char>s;
char a[2010000];
int main()
{
	cin>>a+1;
	int n=strlen(a+1);
	for(int i=1;i<=n;i++)
	{
		s.push(a[i]);
		while(s.size()>1)
		{
			int u=s.top();s.pop();
			int v=s.top();s.pop();
			if(u!='T'||v!='S')
			{
				s.push(v);
				s.push(u);
				break;
			}
		}
	}
	cout<<s.size();
	return 0;
}

Measured memory_bytes: 640
#include<iostream> 
#include<bits/stdc++.h> 
using namespace std;
const int MOD=1000000007;
vector<vector<int>> dp;
vector<vector<int>> adj;
vector<vector<int>> dg;
vector<bool> visited; 
typedef long long ll;
ll modmul(ll a,ll b){ 
	return (a%MOD)*(b%MOD)%MOD;
}
void dfs(int u){ 
	visited[u]=true;
	for(int v:adj[u]){ 
		if(not visited[v]){
			dg[u].push_back(v);
			dfs(v);
		}
	} 
}
ll compute(int u,bool black){ 
	int val=black?1:0;
	if(dp[u][val]!=-1){ 
		return dp[u][val]; 
	}
	ll am=1;
	for(int v:dg[u]){ 
		if(black){ 
			am=modmul(am,compute(v,false));
		}else{
			am=modmul(am,compute(v,true)+compute(v,false)); 
		}
		
	}	       
	return dp[u][val]=am;
}


int main(){ 
	ios::sync_with_stdio(false); 
	cin.tie(0); 
	int N;
	cin>>N;
	dp.resize(N);
	visited.assign(N,false);
        for(int i=0;i<N;i++){
		dp[i]={-1,-1};
	}

	adj.resize(N);
	dg.resize(N);
	int x,y;
	for(int i=0;i<N-1;i++){ 
		cin>>x>>y;
		x--;
		y--;
		adj[x].push_back(y); 
		adj[y].push_back(x);
	}
	dfs(0);
	ll out=compute(0,false)+compute(0,true); 
	if(out>=MOD){ 
		out-=MOD;
	}
	if(out<0){
		out+=MOD;
	}

	cout<<out;


	
	return 0;
} 



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


int main() {
  char a,b; cin >> a >> b;
  if(a=='H'&&b=='D'||a=='D'&&b=='H') cout << 'D' << endl;
  else cout << 'H' << endl;
}

Measured memory_bytes: 256
//
// Created by 遠藤護 on 7/16/18.
//
#include <iostream>
#include <string>
using namespace std;

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

    int ans = 0;

    for (int i = 0; i < 4; ++i) {
        if (S[i] == '+') ans ++;
        else ans --;
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N+1);
    rep(i,N) cin >> A[i+1];

    vector<ll> dp(N+1,-1e18);
    dp[0] = dp[1] = 0;
    vector<ll> O(N+5),E(N+5);
    for (int i = 1; i <= N; i++) {
        if (i&1) O[i+2] = O[i] + A[i];
        else E[i+2] += E[i] + A[i];
    }
    for (int i = 2; i <= N; i++) {
        if (i&1) {
            //cout << O[i+2] << ln;
            chmax(dp[i],O[i]);
            chmax(dp[i],dp[i-3]+A[i-1]);
            chmax(dp[i],dp[i-2]+A[i]);
        } else {
            chmax(dp[i],O[i+1]);
            chmax(dp[i],dp[i-2]+A[i]);
        }
        //cout << dp[i] << " ";
    }
    //cout << ln;

    cout << dp[N] << ln;
}




Measured memory_bytes: 9536
S = input()
Ls = [i for i in range(len(S)) if S[i]=='L' and S[i-1]=='R']
Rs = [i for i in range(len(S)) if S[i]=='R' and S[i+1]=='L']
humans = [0]*len(S)
l_i = 0
l = Ls[l_i]
r_i = 0
r = Rs[r_i]
for i in range(len(S)):
    state = 0
    # Lのとき
    if S[i]=='L':
        if r_i-l_i<0:
            r_i += 1
            r = Rs[r_i]
        state += i-r+1
        if state%2==0:
            humans[r+1]+=1
        else:
            humans[r]+=1
    # Rのとき
    else:
        if i > l:
            l_i += 1
            l = Ls[l_i]
        state += l-i-1
        if state%2==0:
            humans[l-1]+=1
        else:
            humans[l]+=1
print(' '.join([str(num) for num in humans]))

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

using namespace std;

long long ans;
int n;

int main() {
	cin >> n;
	for(register int i=1;i<=n;++i)
		if ((i % 3) != 0 && (i % 5) != 0)
			ans += i;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    n = sc.intarr()[0]
    for i in range(1, 10):
        if n % i == 0:
            for j in range(1, 10):
                if i*j == n:
                    print('Yes')
                    quit()
    print('No')


class Scan():

    def intarr(self):
        self.line = input()
        array = self.line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        self.line = input()
        array = self.line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


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

using namespace std;

#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)

template <typename T>
inline auto operator << (ostream & stream, const vector <T> & x) -> ostream &
{
  stream << "[";
  copy (x.begin (), x.end (), ostream_iterator <T> (stream, " "));
  return stream << "]";
}

using light_t = pair <vector <size_t>, int>;
using switch_t = int;

vector <light_t> lights;
vector <switch_t> switches;

inline auto is_on (const light_t & light)
{
  vector <size_t> ss;
  int p;
  tie (ss, p) = light;

  auto sum = 0;

  for (auto && s : ss)
  {
    sum ^= switches [s];
  }
  return sum == p;
}

inline auto solve (size_t switch_index = 1)
{
  if (switch_index == switches.size ())
  {
    return all_of (lights.begin (), lights.end (), [&] (auto && light) {
      return is_on (light);
    }) ? 1 : 0;
  }
  else
  {
    auto ans = 0;
    switches [switch_index] = 0;
    ans += solve (switch_index + 1);
    switches [switch_index] = 1;
    ans += solve (switch_index + 1);
    return ans;
  }
}

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t n, m;
  cin >> n >> m;

  switches = vector <switch_t> (n + 1, 0);

  rep (i, m)
  {
    int k;
    cin >> k;

    vector <size_t> ss;
    rep (j, k)
    {
      size_t s;
      cin >> s;
      ss.emplace_back (s);
    }
    lights.emplace_back (move (ss), -1);
  }

  rep (i, m)
  {
    int p;
    cin >> p;

    lights [i].second = p;
  }

  auto ans = solve ();

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
/*
for(int bit = 0 ; bit < (1<<10) ; bit++){
	for(int j = 0 ; j < 10 ; j++){
		if( i & (1<<j) ){
			//なにか
		}
	}
}
*/
	/*
	箱2つあって
	/*
		00
		10
		01
		11
	
	for(int i = 0 ; i < 4  ; i++)
		int a = (i >> 0) & 1;
		int b = (i >> 1) & 1;
	}
	/*
	0000000000~
	1111111111
	 (10000000000)
	 cout << (1<<3) << endl;
	*/
int main(){
	int n,s,i;
	while(1){
	cin>>n;
	cin>>s;
		if(n==0 && s==0)
		break;
	int ans=0;
	for(int bit = 0 ; bit < (1<<10) ; bit++){
		int p[10]={},a=0,x=0;
	for(int j = 0 ; j < 10 ; j++){
		if( bit & (1<<j) ){
			p[j]=1;;
			a++;
		}
	}
		//cout<<a<<" ";
		
		if(a==n){
			for(i=0;i<10;i++){
				if(p[i]==1)
				x+=i;
				//cout<<i;
			}
			//cout<<endl;
			if(x==s)
			ans++;
		}
	}
		cout<<ans<<endl;
	}
return 0;
}

Measured memory_bytes: 1160
import re

N = int(input())
s = [input() for _ in range(N)]

tmp = 0

B_A = 0
B_any = 0
any_A = 0

for i in range(N):
    tmp = tmp + s[i].count("AB")
    if s[i][0:1] == "B":
        if s[i][-1:] == "A":
            B_A = B_A + 1
        else:
            B_any = B_any + 1
    elif s[i][-1:] == "A":
        any_A = any_A + 1

add = 0

add1 = min(B_any,any_A)

add = max(B_A - 1,0)


if B_any + any_A > 0:
    if B_A >= 1:
        add1 = add1 + 1

print(tmp+add+add1)

Measured memory_bytes: 3956
#include "bits/stdc++.h"
using namespace std;
 
int dp[100005];
 
int main(){
	int n,k;
	cin>>n>>k;
	 int arr[101];
	      for(int i=0;i<n;i++)
	      {
	      	cin>>arr[i];
		  }
	
	dp[0] = 0;
	for(int i = 1; i <= k; i++){
		dp[i] = 0;
		for(int j=0;j<n;j++)
	      	{   
	      	     
	      	   if(i>=arr[j]&&dp[i-arr[j]]==0)
				 {
				      dp[i]=1; 
					  break;	
				 }	
			}
	}
	
	if(dp[k] == 1)
		cout<<"First";
	else
		cout<<"Second";
	
}

Measured memory_bytes: 3988
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = sc.nextInt()
  val b = sc.nextInt()
  val s = sc.next()

  println(b(n, a, b, s))
}

private fun b(n: Int, a: Int, b: Int, s: String): String {
  val ab = a + b
  var count = 0
  var countB = 1

  val ans = Array(s.length) { "Yes" }

  var index = 0;
  for (c in s) {
    if (c == 'a') {
      if (count < ab) {
        count++
      } else {
        ans[index] = "No"
      }
    } else if (c == 'b') {
      if (count < ab && countB <= b) {
        count++
      } else {
        ans[index] = "No"
      }
      countB++
    } else {
      ans[index] = "No"
    }
    index++
  }

  return ans.joinToString("\n")
}


Measured memory_bytes: 40652
#include <bits/stdc++.h>
#define lli long long 
using namespace std;

typedef vector<lli> vi;



int main() {
    
    const int INF= 1e9 +5;
	lli n;
	cin>>n;
	vi h(n);
	
	for(int i=0;i<n;i++)
	{
	    cin>>h[i];
	}
	

	vi cost(n,INF);
	
	
	cost[0] = 0;
	for(int i=0;i<n;++i)
	{
	    for(int j:{i+1,i+2})
	    {
	        if(j<n)
	        {
	            cost[j]=min(cost[j], cost[i]+abs(h[i]-h[j]));
	        }
	    }
	}
	
	cout<<cost[n-1];
	
	
	return 0;
}

Measured memory_bytes: 1792
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

const int N = (int) 1e5 + 5, mod = (int) 0;
int win[N], a[N];
pair<int, int> sr[N];
vector<int> adj[N];
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    for (int j = 0; j < N; ++j) win[j] = 1;
    int n;
    cin >> n;
    for (int j = 0; j < n; ++j) {
        cin >> a[j];
        sr[j] = make_pair(a[j], j);
    }
    for (int j = 1; j < n; ++j) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    sort(sr, sr + n);
    for (int _ = 0; _ < n; ++_) {
        int j = sr[_].second;
        win[j] = 0;
        for (int u : adj[j]) {
            if (a[j] <= a[u]) continue;
            if (!win[u])
                win[j] = 1;
        }
    }
    for (int j = 0; j < n; ++j)
        if (win[j])
            cout << j + 1 << ' ';
}




Measured memory_bytes: 3200
def I_S(a,n):
	print(' '.join(map(str,a)))
	for i in range(1,n):
		v=a[i]
		j=i-1
		while j>=0 and a[j]>v:
			a[j+1]=a[j]
			j-=1
		a[j+1]=v
		print(' '.join(map(str,a)))
		
n=int(input())
a=[int(x) for x in input().split()]

I_S(a,n)


Measured memory_bytes: 5608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, m;
    cin >> n >> m;

    vector<int> b(n + 1);
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;

        b[i] = (b[i - 1] + a) % m;
    }

    sort(b.begin(), b.end());

    map<int, int> mp;
    for (int i = 0; i <= n; i++) {
        mp[b[i]]++;
    }

    ll r = 0;
    for (const auto& p : mp) {
        ll t = p.second;
        r += t * (t - 1) / 2;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3584
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
ans = sum(b_list)
for i in range(n-1):
    if a_list[i+1]-a_list[i] == 1:
        ans += c_list[a_list[i]-1]
print(ans)

Measured memory_bytes: 38384
N, A, B = map(int, raw_input().split())
S = raw_input()
pass_conf = []
abroad = []
for s in S:
    if s == 'c':
        print 'No'
        continue
    if len(pass_conf) < A+B:
        if s == 'a':
            pass_conf.append(s)
            print 'Yes'
        elif s == 'b':
            if len(abroad) < B:
                pass_conf.append(s)
                abroad.append(s)
                print 'Yes'
            else:
                print 'No'
        else:
            print 'No'
    else:
        print 'No'



Measured memory_bytes: 4392
#include<bits/stdc++.h>
#define forn(i,n) for(int i = 0; i<n; i++)
#define fi first
#define se second
using namespace std;
string s;
int a, b;
int main(){
	cin >> s;
	forn(i,3){
		s[i] == 'A'? a++: b++;
	}
	if(a&&b) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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")
    };
}

use std::cmp;

fn main() {
    input!(n: usize, a: [usize; n]);

    let mut a = a;
    a.sort();

    if n % 2 == 1 {
        let min_num = (n - 1) / 2;
        let mut minus = 0;
        for i in 0..min_num {
            minus += a[i] * 2;
        }
        let mut plus = a[min_num] + a[min_num + 1];
        for i in (min_num + 2)..n {
            plus += a[i] * 2;
        }
        assert!(plus >= minus);
        let ans1 = plus - minus;

        a.reverse();
        let mut plus = 0;
        for i in 0..min_num {
            plus += a[i] * 2;
        }
        let mut minus = a[min_num] + a[min_num + 1];
        for i in (min_num + 2)..n {
            minus += a[i] * 2;
        }
        assert!(plus >= minus);
        let ans2 = plus - minus;
        println!("{}", cmp::max(ans1, ans2));
    } else {
        let mut plus = 0;
        let mut minus = 0;
        for i in 0..(n / 2) {
            minus += a[i] * 2;
        }
        minus -= a[(n / 2) - 1];

        for i in (n / 2)..n {
            plus += a[i] * 2;
        }
        plus -= a[n / 2];
        println!("{}", plus - minus);
    }
}


Measured memory_bytes: 6396
#include <iostream>
#include <cmath>
#define ll long long

using namespace std;

int main() {
    ll n;
    cin >> n;
    for (ll i = sqrtl(n) + 1; i > 0; i--) {
        if (n % i == 0) {
            cout << ((n / i) + i - 2);
            break;
        }
    }
}

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

int main() {
  int N,K,i,sum=0;
  cin>>N>>K;

  for(i=0;i<N;i++){
    int x;
    cin>>x;
  	if(x<K-x) sum+=x;
    else sum+=K-x;
  }
  
  cout<<sum*2<<endl;
}


Measured memory_bytes: 256