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

// B - Palindrome-philia
// https://atcoder.jp/contests/abc147/tasks/abc147_b
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] S = scanner.next().toCharArray();
        scanner.close();

        int diffCount = 0;
        for (int i = 0; i < S.length / 2; i++) {
            char left = S[i];
            char right = S[S.length - 1 - i];
            if (left != right) {
                diffCount++;
            }
        }
        System.out.println(diffCount);
    }
}


Measured memory_bytes: 22868
from _collections import deque
N,X,Y=map(int,input().split())
X-=1
Y-=1
inf=pow(10,9)
answers=[0]*N
def bfs(n):
    visited_point=[inf for _ in range(N)]
    visited_point[n]=0
    stack=deque([n])
    while len(stack)>0:
        x=stack.pop()
        if x==X and visited_point[Y]==inf:
            visited_point[Y]=visited_point[x]+1
            stack.appendleft(Y)
        if x==Y and visited_point[X]==inf:
            visited_point[X]=visited_point[x]+1
            stack.appendleft(X)
        for nx in (1,-1):
            new_n=x+nx
            if new_n<0 or new_n>=N:
                continue
            if visited_point[new_n]==inf:
                visited_point[new_n]=visited_point[x]+1
                stack.appendleft(new_n)
    for i in visited_point:
        answers[i]+=1
for a in range(N):
    bfs(a)
for b in range(1,N):
    print(answers[b]//2)
    

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

int main() {
  int s, ans;
  cin >> s;
  ans = 0;
  for (int i = 2; i >= 0; i--) {
    ans += s / int(pow(10, i));
    s = s % int(pow(10, i));
  }
  cout << ans << endl;
}


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

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

    int A, B;

    cin >> A >> B;

    cout << max(A+B, max(A-B, A * B));

    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/arc090/tasks/arc090_a

#include "algorithm"
#include "cmath"
#include "functional"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  VL ts(N);
  VL bs(N);

  rep(i, N) cin >> ts[i];
  rep(i, N) cin >> bs[i];

  VL t_sums(N + 1);
  VL b_sums(N + 1);
  rep(i, N) t_sums[i + 1] = t_sums[i] + ts[i];
  rep(i, N) b_sums[i + 1] = b_sums[i] + bs[i];

  ll res = 0;

  rep(i, N) {
    ll t = t_sums[i + 1];
    ll b = b_sums[N] - b_sums[i];

    chmax(res, t + b);
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<20)
typedef pair<int,int> P;

vector<P> edge[10];

int dijkstre(int pos){
  int min_cost[10];
  fill_n(min_cost,10,INF);
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,pos));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int cost = p.first;
    int now = p.second;
    if(min_cost[now] < cost) continue;
    min_cost[now] = cost;
    for(int i=0;i<edge[now].size();i++){
      int nc = edge[now][i].second;
      int next = edge[now][i].first;
      if(cost+nc < min_cost[next]){
	que.push(P(cost+nc,next));
      }
    }
  }
  int sum = 0;
  for(int i=0;i<10;i++){
    if(min_cost[i] != INF){
      sum += min_cost[i];
    }
  }
  return sum;
}

int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0) break;
    int l=100,r=0;
    for(int i=0;i<10;i++){
      edge[i].clear();
    }
    for(int i=0;i<n;i++){
      int a,b,c;
      cin >> a >> b >> c;
      edge[a].push_back(P(b,c));
      edge[b].push_back(P(a,c));
      l = min(min(l,a),b);
      r = max(max(r,a),b);
    }
    int ans = INF;
    int pos = l;
    for(int i=l;i<=r;i++){
      int tmp = dijkstre(i);
      if(ans > tmp){
	pos = i;
	ans = tmp;
      }
    }
    cout << pos << " " << ans << endl;
  }
}

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

#define  ll long long
#define  il inline
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)

const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const int maxm = 2e5 + 10;
const double PI = acos(-1.0);

int n,l;
int a[205],sum[250];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> n >> l;
    rep(i,1,n) sum[i] = sum[i - 1] + l + i - 1;
    int ans = 1e9;
    //cout << sum[n] << endl;
    rep(i,1,n){
        int cur = l + i - 1;
        cur = sum[n] - cur;
        if(abs(sum[n] - cur) < abs(ans - sum[n])) ans = cur;
    }
    cout << ans  << endl;
    return 0;

}


Measured memory_bytes: 256
fn main() {
    let ab = read_vec::<usize>();
    let a = ab[0];
    let b = ab[1];

    let mut ret = 0;
    let mut outret = 1;
    while outret < b {
        outret -= 1;
        outret += a;
        ret += 1;
    }

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void){
    int suuti1,suuti2;
    
    scanf("%d",&suuti1);
    scanf("%d",&suuti2);
    
    if (suuti1 != 1 && suuti2 != 1) {
        printf("1\n");
    } else if (suuti1 != 2 && suuti2 != 2) {
        printf("2\n");
    } else if (suuti1 != 3 && suuti2 != 3) {
        printf("3\n");
    }
    
    return 0;
}


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

//関数
const long INF=1000000000000;
//main関数
int main() {
    
    
    //入力
    long N,W;
    cin>>N>>W;
    
    vector<long> w(N),v(N);
    for(int i=0;i<N;i++){
        cin>>w.at(i)>>v.at(i);
    }
    
    //計算
    long MAXV=1000*N;
    vector<vector<long>> dp(N, vector<long>(MAXV+1,0));
    dp.at(0).at(0)=0;
    for(int i=1;i<=MAXV;i++){
        if(i<=v.at(0)){
            dp.at(0).at(i)=w.at(0);
        }else{
            dp.at(0).at(i)=INF;
        }
    }
    
    
    for(int n=1;n<N;n++){
        for(int i=0;i<=MAXV;i++){
            if(i<v.at(n)){
                dp.at(n).at(i)=dp.at(n-1).at(i);
            }else{
                dp.at(n).at(i)=min(dp.at(n-1).at(i),dp.at(n-1).at(i-v.at(n))+w.at(n));
            }
        }
    }
    
    long ans=0;
    for(int i=0;i<=MAXV;i++){
        if(dp.at(N-1).at(i)<=W){
            ans=i;
        }
    }
    
   // cout<<"dpテーブル始め"<<endl;
    for(int i=0;i<N;i++){
      //  cout<<i+1<<"個目始め ";
        for(int j=0;j<=29;j++){
           // cout<<dp.at(i).at(j)<<" ";
        }
      //  cout<<endl;
    }
  //  cout<<"dpテーブル終わり"<<endl;
    
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 79488
#include<bits/stdc++.h>
using namespace std;
bool a[205];
int main(){
	int x,n,y;scanf("%d%d",&x,&n);
	for(int i=0;i<n;i++)scanf("%d",&y),a[y]=1;
	for(int i=0;;i++){
		if(!a[x-i])return printf("%d",x-i),0;
		if(!a[x+i])return printf("%d",x+i),0;
	}
	return 0;
}

Measured memory_bytes: 3788
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
	char s[3];
	int i=0;
	scanf("%s", s);

	if (s[0] == '1') {
		i++;
	}
	if (s[1] == '1') {
		i++;
	}
	if (s[2] == '1') {
		i++;
	}
	printf("%d", i);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N;
	cin >> N;

	int A[100];
	rep(i, N) cin >> A[i];

	co(*max_element(A, A + N) - *min_element(A, A + N));

	Would you please return 0;
}

Measured memory_bytes: 256
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        x: u64,
    }

    let mut ans = x / 500 * 1000;
    let mut x = x % 500;
    ans += x / 5 * 5;

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


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

using str = string;
using ss = stringstream;

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

    str s;
    cin>>s;

    int cnta=0;
    int cntb=0;

    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='0')cnta++;
        else cntb++;
    }

    cout<<min(cnta,cntb)*2<<"\n";

    return 0;
}


Measured memory_bytes: 3772
'use strict'

function main(s) {

  s = s.split('\n');
  const n = Number(s[0]);
  const a = Number(s[1]);

  const ans = (a >= (n % 500)) ? 'Yes' : 'No';
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 22964
#include<bits/stdc++.h>
using namespace std;
using Int = signed;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T>
vector<vector<T> > make_v(size_t a,size_t b){
  return vector<vector<T> >(a,make_v<T>(b));
}
template<typename T>
vector<vector<vector<T> > > make_v(size_t a,size_t b,size_t c){
  return vector<vector<vector<T> > > (a,make_v<T>(b,c));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


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

//INSERT ABOVE HERE
signed main(){
  string s;
  Int k;
  cin>>s>>k;
  Int n=s.size();

  const Int INF = 1e5;
  auto dp=make_v<Int>(k+2,n,n);
  fill_v(dp,-INF);

  for(Int i=0;i<n;i++){
    dp[0][i][i]=1;
    for(Int j=i+1;j<n;j++)
      dp[s[i]!=s[j]][i][j]=2;
  }

  for(Int l=1;l<=n;l++){
    for(Int i=0;i<=k;i++){
      for(Int p=0;p+l<=n;p++){
	Int q=p+l-1;
	//cout<<i<<" "<<p<<" "<<q<<":"<<dp[i][p][q]<<endl;
	if(p  >0) chmax(dp[i][p-1][q],dp[i][p][q]);
	if(q+1<n) chmax(dp[i][p][q+1],dp[i][p][q]);
	if(p>0&&q+1<n) chmax(dp[i+(s[p-1]!=s[q+1])][p-1][q+1],dp[i][p][q]+2);
      }
    }
  }
  
  Int ans=0;
  for(Int i=0;i<=k;i++) chmax(ans,dp[i][0][n-1]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 110336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


ll f(ll i,ll j){
	ll x = 2;
	ll p = 1;
	while(1){
		if( (i%x) != (j%x))return p;
		x*=2;
		p++;
	}	
}


int main(){
	ll N;
	cin >> N;
	FOR(i,1,N){
		cout << f(i,i+1);
		FOR(j,i+2,N+1){
			cout << " " << f(i,j);
		}
		cout << "\n";
	}
}


Measured memory_bytes: 512
import java.io.*;

/**
 * ??´??°?????\??? "x" ????????????x???3????????????????????????
 * (1 ??? x ??? 100)
 * 
 * (ex)
 * 1 -> 1
 * 3 -> 27
 * 100 -> 1000000
 * 
 * @author dawkins_j
 */
class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String line;
            while((line = br.readLine()) != null) {
            	String[] list = line.split(" ", 0);
            int 	x = Integer.parseInt(list[0]);
            	int y = Integer.parseInt(list[1]);
            	while(x < y){
                    int r = x;
                    x = y;
                    y = r;
                }
            	System.out.println(getCubicOf(x, y));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param line
     *            ??´??°x?????\???
     * @return x???3???
     */
    private static long getCubicOf(int x, int y) {
    	if(y == 0) {
            return x;
        }else{
            return getCubicOf(y, x % y);
        }
    }
}

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

signed main() {
  int n, k;
  cin >> n >> k;
  if(n < k){
    cout << "NO" << endl;
    return 0;
  }

  bool isRight = false;
  if(n % 2 == 1){
    isRight = (n + 1) / 2 >= k;
  }else{
    isRight = n / 2 >= k;
  }
  cout << ((isRight) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            if (a == b) {
                out.println(c);
            } else if (a == c) {
                out.println(b);
            } else {
                out.println(a);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n + 1], x[n + 1][n + 1], y[n + 1][n + 1];
  for (auto i = 0; i < n; ++i) {
    cin >> a[i];
    for (auto j = 0; j < a[i]; ++j) {
      cin >> x[i][j] >> y[i][j];
    }
  }
  int ans = 0;
  for (auto bit = 0; bit < 1 << n; ++bit) {
    bool good = true;
    for (auto i = 0; i < n; ++i) {
      if (!((bit >> i) & 1)) continue;
      for (auto j = 0; j < a[i]; ++j) {
        if (((bit >> (x[i][j] - 1)) & 1) ^ y[i][j]) good = false;
      }
    }
    if (good) {
      int b = bit;
      int cnt = 0;
      while (b) {
        cnt += b & 1;
        b >>= 1;
      }
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
function Main(input) {
    const lines = input.split("\n");
    let h = +lines[0];
    let attackCount = 0;
    let enemyCount = 1;

    while (h > 0) {
        attackCount += enemyCount;
        enemyCount *= 2;
        h = Math.floor(h / 2);
    }
    
    console.log(attackCount);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n, k = map(int, input().split())
s = input()

cnt = 0
for i in range(n):
    if s[i] == s[i + 1]:
        cnt += 1

ans = min([k * 2 + cnt, n - 1])
print(ans)


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

using namespace std;

int main ()
{
	int a , b;
	while( cin >> a >> b )
	{
		vector<int>data ( 104 );
		data[1]++; data[2]++;
		data[a]++; data[b]++;
		while( cin >> a >> b , a || b )
		{
			data[a]++; data[b]++;
		}
		bool f = true;
		for( size_t i = 0; i < 104; i++ )
		{
			if( data[i] % 2 == 1 )
			{
				f = false;
				break;
			}
		}
		if( f )
		{
			cout << "OK" << endl;
		} else
		{
			cout << "NG" << endl;
		}

	}
}

Measured memory_bytes: 1188
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {

	Scanner sc = new Scanner(System.in);
	int a = Integer.parseInt(sc.next());
	int b = Integer.parseInt(sc.next());
	int c = Integer.parseInt(sc.next());
	
	System.out.println( c +" " + a + " " + b);
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>

using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// 4-direction
int dy4[] = {0,  1, -1,  0};
int dx4[] = {1,  0,  0, -1};

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

int main() {
  int k, s;
  cin >> k >> s;

  int cnt = 0;
  rep(x, k+1) rep(y, k+1) {
    if(x+y <= s && x+y+k >= s) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 200000
#define INFTY 2000000000
double cnt=0;
void bubble(int *,int,int,int);
void bubbleSort(int *,int,int);

void bubble(int *A,int left,int mid,int right){
  int i,j,k;
  int x1,x2;
  int L[MAX],R[MAX];

  x1=mid-left;
  x2=right-mid;
  
  for(i=0;i<x1;i++){
    L[i]=A[left+i];
  }

  for(i=0;i<x2;i++){
    R[i]=A[mid+i];
  }

  L[x1]=INFTY;
  R[x2]=INFTY;

  i=0;
  j=0;
  
  for(k=left;k<right;k++){
    if(L[i]<R[j]){
      A[k]=L[i];
      i++;
    }else{
      A[k]=R[j];
      cnt=cnt+(x1-i);
      j++;
    }
  }
  
}

void bubbleSort(int *A,int left,int right){
  int middle;

  if(left+1<right){
    middle=(left+right+1)/2;
    bubbleSort(A,left,middle);
    bubbleSort(A,middle,right);
    bubble(A,left,middle,right);
  }
}

int main()
{
  int i,n,A[MAX];

  scanf("%d",&n);

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

  bubbleSort(A,0,n);

  printf("%.0f\n",cnt);

  return 0;
}

Measured memory_bytes: 4256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=4000+10,mod=1e9+7;
int fac[maxn],ifac[maxn];
inline int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=(ll)res*x%mod;
		x=(ll)x*x%mod;
		y>>=1;
	}
	return res;
}
inline void init(int n){
	fac[0]=1;
	REP(i,1,n) fac[i]=(ll)i*fac[i-1]%mod;
	ifac[n]=ksm(fac[n],mod-2);
	DREP(i,n,1) ifac[i-1]=(ll)i*ifac[i]%mod;
}
inline int C(int n,int m){
	if(n<0 || m<0 || n<m) return 0;
	return (ll)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main(){
	init(maxn-10);
	int n=read(),m=read(),ans=n+1;
	REP(i,1,m-1) REP(j,1,m-i){
		int u=n-(m-i)-(m-i-j);
		if(u<0) continue;
		if(j!=0) ans=(ans+(ll)(2+u)*(u+1)/2%mod*C(m-1,i-1)%mod*C(m-i-1,j-1))%mod;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pii;
const int N=1e5+10,M=4e5+10,p=1e9+7;
int n,m,s,t,fs[N],gs[N],ft[N],gt[N],vis[N],ans,al;
int tot,fi[N],ne[M],a[M],c[M];
inline void A(int &x,int y){x+=y;if (x>=p) x-=p;}
inline void add(int x,int y,int z){
	a[++tot]=y;c[tot]=z;ne[tot]=fi[x];fi[x]=tot;
}
inline int dp(int x,int *f,int *g){
	if (vis[x]) return g[x];vis[x]=1;
	for (int i=fi[x];i;i=ne[i]) if (f[x]-c[i]==f[a[i]]) A(g[x],dp(a[i],f,g));
	return g[x];
}	
inline void dij(int *f,int *g,int s,int t){
	priority_queue<pii,vector<pii>,greater<pii> > q;
	for (int i=1;i<=n;++i) f[i]=1e15;
	f[s]=0;q.push(make_pair(0,s));
	while (!q.empty()){
		pii tmp=q.top();q.pop();
		int u=tmp.second;
		if (tmp.first>f[u]) continue;
		for (int i=fi[u];i;i=ne[i]) if (f[u]+c[i]<f[a[i]]) f[a[i]]=f[u]+c[i],q.push(make_pair(f[a[i]],a[i]));
	}
	memset(vis,0,sizeof vis);
	g[s]=1;vis[s]=1;
	dp(t,f,g);
}
inline void solve(int x){
	if (vis[x]) return;vis[x]=1;
	if (fs[x]*2==al) {A(ans,p-1ll*gs[x]*gt[x]%p);return;}
	for (int i=fi[x];i;i=ne[i]) if (fs[x]+c[i]==fs[a[i]]){
		if (fs[a[i]]*2>al) A(ans,p-1ll*gs[x]*gt[a[i]]%p);
			else solve(a[i]);
	}
}
signed main(){
	scanf("%lld%lld%lld%lld",&n,&m,&s,&t);
	for (int i=1,x,y,z;i<=m;++i) scanf("%lld%lld%lld",&x,&y,&z),add(x,y,z),add(y,x,z);
	dij(fs,gs,s,t);dij(ft,gt,t,s);
	for (int i=1;i<=n;++i) (gs[i]*=gs[i])%=p,(gt[i]*=gt[i])%=p;
	al=fs[t];ans=gs[t]%p;
	memset(vis,0,sizeof vis);
	solve(s);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 17872
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <bitset>

using namespace std;
typedef long long LL;
const int maxn = 1005;
const int maxm = 5005;

int n,x[maxn],f[maxn],p[maxn];
bool dp[maxn][maxm];int sum[maxn];

int main()
{
	#ifdef Amberframe
		freopen("arc083e.in","r",stdin);
		freopen("arc083e.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int i=2;i<=n;i++) scanf("%d",&p[i]);
	for (int i=1;i<=n;i++) scanf("%d",&x[i]);
	for (int i=1;i<=n;i++) dp[i][0]=true;
	for (int i=n;i>=1;i--)
	{
		int j=x[i];while (j>=0&&!dp[i][j]) --j;
		if (j<0) {puts("IMPOSSIBLE");return 0;}
		f[i]=sum[i]-j;int a=p[i];sum[a]+=f[i]+x[i];
		for (int j=x[a];j>=0;j--)
		{
			bool tag=false;
			tag|=j>=f[i]&&dp[a][j-f[i]];
			tag|=j>=x[i]&&dp[a][j-x[i]];
			dp[a][j]=tag;
		}
	}
	puts("POSSIBLE");
	return 0;
}

Measured memory_bytes: 4864
from collections import deque
H, W, M = map(int, input().split())
bomb = []
counth = [0 for k in range(H)]
countw = [0 for k in range(W)]
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  bomb.append(h+ w*H)
  counth[h] += 1 
  countw[w] += 1

maxh = max(counth)
maxw = max(countw)
  
counth = deque(counth)
countw = deque(countw)

def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            #return mid
            return True
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    #return None
    return False


index_h = deque([])
index_w = []
for k in range(H):
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)

for k in range(W):
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)

ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)


if lenh*lenw > M:
  ans += 1
else:
  bomb.sort()
  kouho = []
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      kouho.append(h+ H*w)
  for K in kouho:
    if binary_search(bomb, K):
      continue
    else:
      ans += 1
      break
    
print(ans)




Measured memory_bytes: 59048
#include<bits/stdc++.h>
using namespace std;
#define INF 2000000000
#define N 2000
#define pb push_back
typedef long long LL;
int n;
vector<LL> a, b, h;

void printlog() {
    while (h.size() > 1) {
        if (h[0] == 0) b.pb(0), h.erase(h.begin());
        if (h[h.size() - 1] == 0) b.pb(h.size() - 1), h.erase(h.begin() + h.size() - 1);
        for(int i = 1; i < h.size() - 1; i++) {
            if (h[i]) continue;
            if ((h[i - 1] == 1 && h[i + 1] == 1) || (h[i - 1] == 0 && h[i + 1] == 0)) {
                b.pb(i);
                h.erase(h.begin() + i, h.begin() + i + 2);
                break;
            }
        }
    }
    cout << b.size() << endl;
    for(int i = 0; i < b.size(); i++) cout << b[i] + 1 << endl;
}

int main() {
    //freopen("sample.in", "r", stdin);
    cin >> n;
    for(int i = 0; i < n; i++) {
        LL tmp; cin >> tmp; 
        a.pb(tmp), h.pb(0);
    }
    bool all_neg = 1;
    for(int i = 0; i < n; i++) all_neg &= (a[i] < 0);
    if (all_neg) {
        int pos = 0; LL ans = a[0];
        for(int i = 1; i < n; i++) 
            if (a[i] > ans) ans = a[i], pos = i;
        cout << ans << endl, h[pos] = 1;
    } else {
        LL x = 0, y = 0;
        for(int i = 1; i < n; i += 2) if (a[i] >= 0) x += a[i];
        for(int i = 0; i < n; i += 2) if (a[i] >= 0) y += a[i];
        cout << max(x, y) << endl;
        if (x > y) { for(int i = 1; i < n; i += 2) if (a[i] >= 0) h[i] = 1; }
        else { for(int i = 0; i < n; i += 2) if (a[i] >= 0) h[i] = 1; }
    }
    printlog();
}

Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n; cin >> n;
    set<string> se;
    vector<string> s(n);
    rep(i, n) {
        cin >> s[i];
        se.insert(s[i]);
    }
    cout << (int)se.size() << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

void solve()
{
    int N;
    ll K;
    cin >> N >> K;
    ll visited[N+1];
    ll a[N+1];
    rep(i,N+1){
        visited[i]=-1;
    }
    for(int i=1;i<=N;++i)cin >> a[i];
    ll count=0;
    ll visit=1;
    while(visited[visit]==-1){
        visited[visit]=count;
        visit=a[visit];
        count++;
    }
    ll key=visit;
    ll key_dist=visited[visit];
    ll loop_dist=count-visited[visit];
    if(K>=key_dist){
        K=K-key_dist;
        K=K%loop_dist;
    }else{
        key=1;
    }

    rep(i,K){
        key=a[key];
    }
    cout << key << endl;
}

int main()
{
    ll t,p;
    t=1;
    for(p=1;p<=t;++p){
        solve();
    }
}

Measured memory_bytes: 6760
#include <iostream>
#include <string>

using namespace std;

void print(int N, int k, const string &substr) {
    const int len = substr.length();

    if (len == N) {
        cout << substr << endl;
    } else {
        for (int i = 0; i < k; ++i) {
            print(N, k, substr + (char)('a' + i));
        }

        print(N, k + 1, substr + (char)('a' + k));
    }
}

int main() {
    int N;
    cin >> N;
    print(N, 0, "");
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  string s;
  Int k;
  Int zyou = 5000000000000000;
  cin >> s >> k;
  for(Int i=0;i<s.size();i++){
    if(s[i]==1) {
      k--;
      if(k<=0) {cout << s[i] << endl;return 0;}
      continue;
    }
    else{
      if(pow(s[i]-'0',zyou)>=k){
        cout << s[i] << endl;
        return 0;
      }else{
        k-=pow(s[i]-'0',zyou);
      }
    }
    if(k<=0){
      cout << s[i] << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#define MN 200005
using namespace std;
int n,a[MN],b[MN],ans,num,head[MN],tt,sum[MN];
struct edge{int to,next;}g[MN];
map<int,int>mp;bool vis[MN];
void ins(int u,int v){g[++num].next=head[u];head[u]=num;g[num].to=v;}
void dfs(int u){vis[u]=1;for(int i=head[u];i;i=g[i].next)if(!vis[g[i].to])dfs(g[i].to);}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),a[n+1]^=a[i];
	for(int i=1;i<=n;i++)scanf("%d",&b[i]),b[n+1]^=b[i];
	for(int i=1;i<=n+1;i++)mp[a[i]]++,mp[b[i]]--;
	for(int i=1;i<=n+1;i++)if(mp[a[i]]){puts("-1");return 0;}
	for(int i=1;i<=n+1;i++)if(!mp[a[i]])mp[a[i]]=++tt;
	for(int i=1;i<=n+1;i++)if(a[i]!=b[i])ins(mp[a[i]],mp[b[i]]),ans++,++sum[mp[a[i]]];
	for(int i=1;i<=tt;i++)if(!vis[i]&&sum[i])dfs(i),ans++;
	ans-=(sum[mp[a[n+1]]]!=0)+(a[n+1]!=b[n+1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10112
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yesOrNo(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

void solve(ll N, ll M, std::vector<std::string> A, std::vector<std::string> B) {
  bool result = false;

  rep(i, N - M + 1) {
    rep(j, N - M + 1) {
      rep(l, M) {
        rep(m, M) {
          if (B.at(l).at(m) != A.at(i + l).at(j + m))
            goto L;
        }
      }
      result = true;
    L:
      continue;
    }
  }
E:
  yesOrNo(result);
}

int main() {
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  std::vector<std::string> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  std::vector<std::string> B(M);
  for (int i = 0; i < M; i++) {
    std::cin >> B[i];
  }
  solve(N, M, std::move(A), std::move(B));
  return 0;
}


Measured memory_bytes: 256
X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

ans = []
for i in range(X):
    for j in range(Y):
        ij = (i+1)*(j+1)
        if ij > K:
            break
        for k in range(Z):
            if ij*(k+1) > K:
                break
            ans.append(A[i]+B[j]+C[k])
ans = sorted(ans, reverse=True)
for i in range(K):
    print(ans[i])

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

typedef long long ll;

int main() {
    ll R[400009];
    string s;
    cin >> s;
    ll n = s.size();
    map<char, int>mp;
    for (int i = 0; i < n; i++) {
        mp[s[i]]++;
    }
    ll ans = n*(n-1)/2;
    for (auto& p : mp) {
        ll v = p.second;
        ans -= v*(v-1)/2;
    }
    cout << ans + 1 << endl;
}


Measured memory_bytes: 3756
import sys,collections as cl,bisect as bs,random
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

d = onem()

c = l()

s = []
sel = [0 for i in range(365)]

day = [[0 for i in range(26)] for j in range(365)]
ans = 0
for i in range(d):
	s.append(l())
	ss = [[s[-1][i],i+1] for i in range(26)]

	ak = 0

	for j in range(26):
		if i != 0:
			ak -= c[j] * (i-day[i-1][j]+1)
		else:
			ak -= c[j]

	ma = [-1,-1]
	for j in range(26):
		if i != 0:
			if ma[0] <= c[j] * (i-day[i-1][j]+1) + s[-1][j]:
				ma[0] = c[j] + (i-day[i-1][j]+1) + s[-1][j]
				ma[1] = j
		else:
			if ma[0] <= c[j] + s[-1][j]:
				ma[0] = c[j] + s[-1][j]
				ma[1] = j
	ans += ma[0] + ak
	sel[i] = ma[1]+1

	for j in range(26):
		if j == ma[1]:
			day[i][j] = i
		else:
			day[i][j] = day[i-1][j] if i - 1 >= 0 else 0



for _ in range(140000):
	ima = random.randrange(365)
	po = [[s[ima][i]-c[i],i+1] for i in range(26)]
	po.sort(reverse = True)
	while True:
		data = po[random.randrange(10)][1]
		if sel[ima] != data:
			break
	data = data-1
	ppp = 0
	now = sel[ima]-1
	for i in range(ima+1,365):
		if day[i][data] == i:
			ppp += (i - ima) * c[data]
			break
	else:
		ppp += (364-ima) * c[data]
	ppp += s[ima][data]

	for i in range(ima+1,365):
		if day[i][now] == i:
			ppp -= (i - ima) * c[now]
			break
	else:
		ppp -= (364-ima) * c[now]
	ppp -= s[ima][now]
	if ppp > 0:
		for i in range(ima,365):
			if day[i][data] != i:
				day[i][data] = ima
			else:
				break
		po = ima - 1 if ima != 0 else 0
		for i in range(ima,365):
			if i == ima:
				day[i][now] = po
			elif day[i][now] != i:
				day[i][now] = po
			else:
				break
		sel[ima] = data+1
		ans += ppp

for i in sel:
	print(i)


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

#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<int, int> pint;
typedef pair<long, long> plong;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> void print(T &x) {
    cout << x << '\n';
    return;
}

template <class T> ll sized_subset(T &comb) {
    T x = comb & -comb, y = x + comb;
    return ((comb & ~y) / x) >> 1 | y;
}

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

int main() {
    string s;
    cin>>s;
    if(s[5]=='1' || s[6]>='5' || (s[6]=='4' && s[8]=='3' && s[9]=='1')){
        cout<<"TBD"<<endl;
    }
    else cout<<"Heisei"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb  					push_back
#define mp 						make_pair
#define all(v) 					((v).begin()) ,((v).end())
#define let(o,v)				memset(o,v,sizeof (o))
typedef long long 				ll;
typedef vector<int>				vi;
typedef vector<vi>				vvi;
typedef vector<string>			vs;
const int N = (int)1e5 + 9;
const int MOD = 1e9+7;
const int oo = (int)1e9;
const ll OO = (ll)1e18;
const double PI = acos(-1.0);


bool isprime(ll n) {
	if (n <= 1)
		return 0;
	for (ll i = 2; i*i <= n; i++)
		if (n%i == 0)
			return false;
	return 1;
}
ll intlog(ll base, ll x) {
	return (log(x) / log(base));
}
bool prime[N];
void primee()
{

	for (int p = 2; p*p <= N; p++)
	{

		if (prime[p] == true)
		{
			for (int i = p * 2; i < N; i += p)
				prime[i] = false;
		}
	}

}
string decToBinary(ll n)
{
	string z = "";
	int i = 0;
	while (n > 0) {

		z += (n % 2) + 48;
		n = n / 2;
		i++;
	}
	reverse(all(z));
	return z;
}
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
ll power(ll x, int y)
{
	ll temp;
	if (y == 0)
		return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp * temp;
	else
		return x * temp*temp;
}

int n, m, dp[N];
vector<int> ar[N];
bool vis[N];
int calc(int u) {
	if (ar[u].empty()) return 0;
	int &ret = dp[u];
	if (ret != -1) return ret + 1;
	ret = 0;
	int z = ar[u].size();
	for (int i = 0; i < z; i++)
	{
		ret = max(ret, calc(ar[u][i]));
	}
	return ret + 1;
}
int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		ar[a].pb(b);
	}
	let(dp, -1);
	int ans = -1;
	for (int i = 1; i <= n; i++)
	{
		if (dp[i] == -1) ans = max(ans, calc(i));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8192
n = int(input())
a = [int(i) for i in input().split()]
fr = min(a)
to = max(a)
ans = []

for i in range(fr, to+1):
  tmp = 0
  for j in range(n):
    tmp += (i - a[j]) ** 2
  ans.append(tmp)
  
print(min(ans))

Measured memory_bytes: 3064
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
finalAns = 0
for i in range(n):
    ans = 0
    for j in range(n):
        if j < i:
            ans += a1[j]
        elif j == i:
            ans += a1[j] + a2[j]
        else:
            ans += a2[j]
    if ans > finalAns:
        finalAns = ans
print(finalAns)


Measured memory_bytes: 3064
ss = input()
ans = []

def bfs(exp, x):
    # 探索終了
    if x == len(ss):
        return exp
    nxt = None
    # まだ使っていない数字を求める
    if exp[-1] == '+':
        nxt = ss[x]
        ret = bfs(exp+nxt, x+1)
        if ret:
            s_ = sum([int(i) for i in ret.split("+")])
            ans.append(s_)
    else:
        nxt = ss[x]
        ret = bfs(exp+nxt, x+1)
        if ret:
            s_ = sum([int(i) for i in ret.split("+")])
            ans.append(s_)
        ret = bfs(exp+'+', x)
        if ret:
            s_ = sum([int(i) for i in ret.split("+")])
            ans.append(s_)
if len(ss) == 1:
    print(int(ss))
else:
    bfs(ss[0],1)
    print(sum(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;


ll n,m,x;
ll a[13][13];
ll c[13];



int main(){FIN
 
    cin>>n>>m>>x;
    REP(i,n){
        cin>>c[i];
        REP(j,m) cin>>a[i][j];
    }
    ll ans = inf;
    for(ll i=0; i<=(1<<n)-1; i++){
        ll e[13]={0};
        ll res = 0;
        REP(j,n){
            if(i>>j & 1){
                REP(k,m){
                    e[k] += a[j][k];
                }
                res += c[j];
            }
        }
        bool ok = true;
        REP(i,m) if(e[i]<x) ok = false;
        if (ok) ans = min(ans, res);
    }
    if (ans==inf) ans = -1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3656
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, x = MAP()
xx = LIST()
xx = [xx[i] - x for i in range(n)]
d = abs(xx[0])
for i in range(1, n):
    d = gcd(d, abs(xx[i]))
print(d)


Measured memory_bytes: 83820
#include<iostream>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (c >= a) {
		if (c <= b) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int r,c;
	int i,s;
	int h[101][101] = {0};
	
	scanf("%d %d",&r,&c);
	
	for(i = 0;i < r;i++)
	{
		for(s = 0;s < c;s++){
		
		scanf("%d ",&h[i][s]);
		h[i][c]+=h[i][s];
		h[r][s]+=h[i][s];
		h[r][c]+=h[i][s];
		}
	}
	
	for(i = 0;i <= r;i++){
	for(s = 0;s < c;s++)
	printf("%d ",h[i][s]);
	printf("%d\n",h[i][s]);
	}
	
	
	return 0;
}


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

using namespace std;
#define deb(x) cout << #x << ": " << x << endl
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fkn(i, k, n) for (i = k; i < n; i++)
#define ll long long
#define F first;
#define S second;
#define PB(x) push_back(x);
#define MP(x,y) make_pair(x,y);
typedef vector<ll> vll;

bool powerOfTwo(ll x)
{
    return !(x & (x - 1));
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    set<string> s;
    ll n;
    cin>>n;
    string p;
    fo(i,n)
    {
     cin>>p;
     s.insert(p);
    }

    cout<<s.size();
    

}



Measured memory_bytes: 19184
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

int modPow(long long a, long long n, long long p) {//0でバグる
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

ll comb(ll n, ll p) {
	if (p * 2 > n) p = n - p;
	if (p > n - p) p = n - p;
	ll a = 1, b = 1;
	rrep(i, p + 1) {
		a = (a * (n - i + 1)) % mod;
		b = (b * i) % mod;
	}
	return a * (modPow(b, mod - 2, mod)) % mod;
}

ll fact(int a) {
	ll ret = 1;
	for (int i = 1; i <= a; ++i) (ret *= i) %= mod;
	return ret;
}

ll f(int a, int b) {
	if (a < 0 || a < b) return 0;
	return comb(a, b) * fact(b) % mod;
}

int n, k;
vector<int> g[100005];
ll ans;

void dfs(int s, int p = -1) {
	for (auto& c : g[s]) {
		if (c == p) continue;
		dfs(c, s);
	}
	int nk = (p == -1) ? k : k - 2;
	int c = (p == -1) ? g[s].size() + 1 : g[s].size() - 1;
	(ans *= f(nk, c)) %= mod;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	ans = 1;
	dfs(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define MOD 100000007

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;


int main() {
  int n, k;
  cin >> n >> k;
  int ar[n];
  for (int ctr1 = 0; ctr1 < n; ctr1++)
    cin >> ar[ctr1];
  sort(ar, ar + n);
  reverse(ar, ar + n);
  cout << accumulate(ar, ar + k, 0);
  return 0;
}

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

int main() {

  char b; cin >> b;
  if (b == 'A') {
    cout << 'T' << endl;
  } else if (b == 'T') {
    cout << 'A' << endl;
  } else if (b == 'G') {
    cout << 'C' << endl;
  } else {
    cout << 'G' << endl;
  }

}



Measured memory_bytes: 256