akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{

    map<ll, ll> ans;
    ll n;
    cin >> n;
    rept(i,1,100){
        rept(j,1,100){
            rept(k,1,100){
                ll tmp=i*i+j*j+k*k+i*j+i*k+j*k;
                ans[tmp]++;
            }
        }
    }
    for(int i=1; i<=n; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 5988
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
    int n;
    string str;
    cin >> n >> str;
    if(n >= str.length()){
        cout << str << endl;
    }else{
        string res = "";
        rep(i, n){
            res += str[i];
        }
        res += "...";
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
      
      //入力
      int N = sc.nextInt();
      String S = sc.next();
      
      int count = 1;//1つは絶対スライムが存在する
      
      char[] slime = S.toCharArray();
      
      //初めにスライムの2番目と1番目を比べる
      for(int i =1; i<N; i++){
      		if(slime[i]!=slime[i-1]){
              	count +=1;//被っていなかったら
            }
      }
       System.out.println(count);
    }
}  

Measured memory_bytes: 39920
n,m = map(int, input().split())
A = list(map(int, input().split()))

s = 0
for i in range(n):
  if A[i] >= sum(A)/(4*m):
    s += 1
  else:
    pass
  
if s >= m:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9096
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] arr = in.next().toCharArray();
        int x = 0;
        for (char c : arr) {
            if (c == '+') ++x;
            else --x;
        }

        System.out.println(x);
    }
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
namespace csx_std {
	using namespace std;
	typedef long long ll;
	#define FOR(i,a,b) for (register int i=(a);i<=(b);i++)
	#define For(i,a,b) for (register int i=(a);i>=(b);i--)
	#define mem(i,j) memset(i,j,sizeof(i))
	#define pii pair<int,int>
	#define MP make_pair
	#define fi first
	#define se second
	#define GO(u) for (register int j=f[u];j!=-1;j=nxt[j])
	const int N=1e5+5;
	const int mod=1e9+7;
	inline int qpow(int x,int y) {int ret=1;for (;y;y>>=1,x=1LL*x*x%mod) if (y&1) ret=1LL*ret*x%mod;return ret;}
	inline int Inv(int x) {return qpow(x,mod-2);}
	inline void upd(int &x,int y) {x=(1LL*x+y)%mod;return;}
	inline int chkmax(int &x,int y) {return (x<y)?(x=y,1):0;}
	inline int chkmin(int &x,int y) {return (x>y)?(x=y,1):0;}
	inline ll read()
	{
		ll x=0,f=1;
		char c=getchar();
		while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
		while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
		return f*x;
	}
	inline void write(ll x)
	{
		if (x<0) x=-x,putchar('-');
		if (x>9) write(x/10);
		putchar(x%10+'0');
		return;
	}
}
using namespace csx_std;
ll n,ans=1e18;
int main()
{
	n=read();
	FOR(i,1,min(1LL*1000000,n)) if (n%i==0) ans=min(ans,i+(n/i));
	ans-=2;
	write(ans);
	return 0;
}


Measured memory_bytes: 384
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

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)*}};}
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:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        l: usize,
        r: usize,
        d: usize
    }

    let mut ans = 0;
    for i in l..r + 1 {
        if i % d == 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2224
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long ll;
const ll INF=0x7fffffff;
const int MAXN=1e5+5;

ll n,m;
vector <pair<ll,ll> > E[MAXN];
ll a[MAXN],c0[MAXN];
ll last=-1ll;

void noway(){
    printf("0\n");
    exit(0);
}

void dfs(ll u,ll &l,ll &r,ll flag){
    c0[u]=flag;
    if(flag==1ll) l=max(l,-a[u]);
    else r=min(r,a[u]);
    //printf("#%lld %lld %lld\n",u,a[u],c0[u]);
    for(ll i=0;i<(ll)E[u].size();i++){
        ll v=E[u][i].first,s=E[u][i].second;
        if(c0[v]==0ll){
            a[v]=s-a[u];
            dfs(v,l,r,-flag);
        }
        else{
            if(c0[v]+flag==0ll){
                if(a[u]+a[v]!=s)
                    noway();
            }
            else if(c0[v]+flag==2ll){
                ll d=s-(a[u]+a[v]);
                //printf("    %lld-%lld\n",v,d);
                if(d<=0||d&1ll) noway();
                d/=2ll;
                //printf("    - %lld,%lld\n",d,last);
                if(last==-1ll||last==d) last=d;
                else noway();
            }
            else if(c0[v]+flag==-2ll){
                ll d=a[u]+a[v]-s;
                if(d<=0||d&1ll) noway();
                d/=2ll;
                if(last==-1ll||last==d) last=d;
                else noway();
            }
        }
    }
}

int main(){
    scanf("%lld%lld",&n,&m);
    for(ll i=1;i<=m;i++){
        ll u,v,va;
        scanf("%lld%lld%lld",&u,&v,&va);
        E[u].push_back(make_pair(v,va));
        E[v].push_back(make_pair(u,va));
    }
    ll r=INF,l=0ll;
    dfs(1,l,r,1);
    if(last!=-1){
        if(last>l&&last<r) printf("1\n");
        else printf("0\n");
    }
    else printf("%lld\n",max(r-l-1,0ll));
}


Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> VI;
typedef vector<ll> VLL;

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

    int y = stoi(s.substr(0,4)),month = stoi(s.substr(5,2));
    if(y <= 2018 || (y == 2019 && month <= 4)){cout << "Heisei" << endl; return 0;}
    if(y ==2019 && month > 4){cout << "TBD" << endl; return 0;}
    if(y > 2019 ){cout << "TBD" << endl; return 0;}
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int a,b,q;
           cin>>a>>b>>q;
           vll s(a);vll t(b);vll x(q);
           rep(i,0,a)cin>>s[i];
           rep(i,0,b)cin>>t[i];
           rep(i,0,q)cin>>x[i];
           map<ll,ll> dists,distt;
           /////////////
           rep(i,0,a){//sからtへの最短距離
             ll n=s[i];
             int l=-1,r=b;
             while(r-l>1){
              int mid=(l+r)/2;
               if(t[mid]<=n)l=mid;
               else r=mid;
             }
             if(l==-1)l++;
             if(r==b)r--;
             dists[n]=min(abs(n-t[l]),abs(n-t[r]));
             
           }
           rep(i,0,b){//t->s
             ll n=t[i];
             int l=-1,r=a;
             while(r-l>1){
              int mid=(l+r)/2;
               if(s[mid]<=n)l=mid;
               else r=mid;
             }
             if(l==-1)l++;
             if(r==a)r--;
             distt[n]=min(abs(n-s[l]),abs(n-s[r]));
             //cout<<i<<" "<<distt[n]<<endl;
           }
           //////////
           rep(i,0,q){
             ll ans=INF;
             ll cnt=0;
             ll n=x[i];
             //
             int l=-1,r=a;
             while(r-l>1){
              int mid=(l+r)/2;
               if(s[mid]<=n)l=mid;
               else r=mid;
             }
             if(l==-1)l++;
             if(r==a)r--;
             cnt+=dists[s[l]];
             cnt+=abs(n-s[l]);
             chmin(ans,cnt);
             cnt=0;
             cnt+=dists[s[r]];
             cnt+=abs(n-s[r]);
             chmin(ans,cnt);
             cnt=0;
             l=-1,r=b;
             while(r-l>1){
              int mid=(l+r)/2;
               if(t[mid]<=n)l=mid;
               else r=mid;
             }
             if(l==-1)l++;
             if(r==b)r--;
             cnt+=distt[t[l]];
             cnt+=abs(n-t[l]);
             chmin(ans,cnt);
             cnt=0;
             cnt+=distt[t[r]];
             cnt+=abs(n-t[r]);
             chmin(ans,cnt);
             cout<<ans<<endl;
           }
}

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

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> dice(n);

    for (int i = 0; i < n; i++) {
        cin >> dice.at(i).first >> dice.at(i).second;
    }

    int count = 0;
    bool flag = false;
    for (int i = 0; i < n; i++) {
        if (dice.at(i).first == dice.at(i).second) {
            count++;
        }
        else {
            count = 0;
        }

        if (count == 3) {
            flag = true;
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

signed main(){
  
  int N, D;
  cin>>N>>D;
  
  int X[10][10];
  
  for(int i=0;i<N;i++)
    for(int j=0;j<D;j++) cin>>X[i][j];
  
  int ans = 0;
  
  for(int i=0;i<N;i++){
    
    for(int j=i+1;j<N;j++){
      
      int sum = 0;
      
      for(int k=0;k<D;k++){
	sum += ( X[i][k] - X[j][k] ) * ( X[i][k] - X[j][k] );
      }
      
      int flg = 0;
      
      for(int k=1;k<=sum;k++){
	if( k * k == sum ) flg = 1;
      }

      ans += flg;
      
    }
    
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
   int a;
   set<int>s;
   cin>>a;
   s.insert(a);cin>>a;
   s.insert(a);cin>>a;
   s.insert(a);
   cout<<s.size()<<endl;

    return 0;
}


Measured memory_bytes: 3616
local h,w=io.read("n","n")
local a={}
for i=1,h do
    a[i]={}
    for j=1,w do
        a[i][j]=io.read("n")
    end
end

local operation={}
for i=1,h do
    for j=1,w do
        if a[i][j]&1>0 then
            if j<w then
                a[i][j+1]=a[i][j+1]+1
                a[i][j]=a[i][j]-1
                table.insert(operation,{i,j,i,j+1})
            elseif i<h then
                a[i+1][j]=a[i+1][j]+1
                a[i][j]=a[i][j]-1
                table.insert(operation,{i,j,i+1,j})
            end
        end
    end
end

local n=#operation
print(n)
for i=1,n do
    print(table.concat(operation[i]," "))
end

Measured memory_bytes: 30580
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
using namespace std::string_literals;

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

    const string table[] = {"Sunny"s, "Cloudy"s, "Rainy"s};
    int i;
    for (i = 0; i < 3; i++)
        if (table[i] == s)
            break;
    i = (i + 1) % 3;

    cout << table[i];
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef vector<ll>vi;
typedef pair<ll,ll>pi;
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
ll max(ll a,ll b){return (a>b?a:b);}
ll min(ll a,ll b){return (a<b?a:b);}
ll gcd(ll a,ll b)
{return (b?gcd(b,a%b):a);
}
void algo()
{
    ll n;
    cin>>n;
    string s[]={"pon","pon","hon","bon","hon","hon","pon","hon","pon","hon"};
    cout<<s[n%10];
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout<<setprecision(20);
    ll t=1;//cin>>t;
    while(t--)
    {
        algo();
	cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
import java.io.IOException;
import java.util.Scanner;

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

		char Alpa = sc.next().charAt(0);
		
		if(Character.isUpperCase(Alpa))
			System.out.println('A');
		else
			System.out.println('a');

	}

}

Measured memory_bytes: 35788
program redistribution
  implicit none
  integer(8), parameter :: modu = 1000000007_8
  integer :: s
  integer(8) :: m(3, 3) = 0
  read(*,*) s
  if (s < 6) then
    write(*,'(i0)') s / 3
    stop
  end if
  m(1, 1) = 1
  m(2, 1) = 1
  m(3, 2) = 1
  m(1, 3) = 1
  m = modmatpow(m, s - 6)
  write(*,'(i0)') mod(m(1, 1) + m(1, 1) + m(1, 2) + m(1, 3), modu)
contains
  function modmatmul(x, y) result(res)
    integer(8), intent(in) :: x(3, 3), y(3, 3)
    integer(8) :: tmp, res(3, 3)
    integer :: j, k
    do j = 1, 3
      res(1, j) = 0
      res(2, j) = 0
      res(3, j) = 0
      do k = 1, 3
        tmp = y(k, j)
        res(1, j) = res(1, j) + x(1, k) * tmp
        res(2, j) = res(2, j) + x(2, k) * tmp
        res(3, j) = res(3, j) + x(3, k) * tmp
      end do
    end do
    res = mod(res, modu)
  end
  function modmatpow(x, n) result(res)
    integer(8), intent(in) :: x(3, 3)
    integer, intent(in) :: n
    integer(8) :: res(3, 3), tmp(3, 3)
    integer :: m
    res(1, 1) = 1
    res(2, 1) = 0
    res(3, 1) = 0
    res(1, 2) = 0
    res(2, 2) = 1
    res(3, 2) = 0
    res(1, 3) = 0
    res(2, 3) = 0
    res(3, 3) = 1
    tmp = x
    m = n
    do while (m > 0)
      if (btest(m, 0)) res = modmatmul(res, tmp)
      tmp = modmatmul(tmp, tmp)
      m = rshift(m, 1)
    end do
  end
end program redistribution

Measured memory_bytes: 2904
n = int(input())
a = [int(input()) for _ in range(n)]

b = 1
cnt = 0
while cnt <= 100000:
  b = a[b-1]
  cnt += 1
  if b == 2:
    break
  
if cnt > 100000:
  print(-1)
else:
  print(cnt)


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

int main()
{
    priority_queue<int> mheap;
    int N, K;
    cin >> N >> K;
    int i;
    for (i=0;i<K;++i) {
        int x;
        cin >> x;
        mheap.push(-1*x);
    }
    for (;i<N;++i) {
        int x;
        cin >> x;
        if (-1*x < mheap.top()) {
            mheap.pop();
            mheap.push(-1*x);
        }
    }
    int sum = 0;
    while (!mheap.empty()) {
        int l = mheap.top();
        sum += l;
        mheap.pop();
    }
    cout << -1*sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
    int n,m,c,a[20],b[20],ans=0;
    long long int sum;
    cin>>n>>m>>c;
    for(int i=0;i<m;i++)cin>>b[i];
    for(int i=0;i<n;i++){
      sum=0;
      for(int j=0;j<m;j++)
      {
        cin>>a[j];
        sum+=a[j]*b[j];
      }
      if(sum+c>0)ans++;
    }
      cout<<ans<<endl;
      return 0;
    }

Measured memory_bytes: 256
// ref. https://www.hamayanhamayan.com/entry/2019/01/12/151211

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<vector<ll>> a(n, vector<ll>(n));
  rep(i,n)rep(j,n) {
    cin >> a[i][j];
  }
  vector<ll> s(1ll<<n);
  rep(msk,1ll<<n) {
    rep(i,n)rep(j,i) {
      if ((msk&(1ll<<i)) && (msk&(1ll<<j))) {
        s[msk] += a[i][j];
      }
    }
  }
  vector<ll> dp(1ll<<n);
  // Here, do DP in O(3^n). cf. https://codeforces.com/blog/entry/45223
  rep(msk,1ll<<n) {
    for (ll msk2 = msk; msk2 > 0; msk2 = (msk2-1)&msk) {
      chmax(dp[msk], dp[msk^msk2] + s[msk2]);
    }
  }
  cout << dp[(1ll<<n)-1] << endl;
}


Measured memory_bytes: 1280
n = int(input())

def get_divisors(num):
    divs = []
    for i in range(1, int(num**0.5)+1):
        if not num % i:
            divs.append((i, num // i))
    return divs

ans = float("inf")
d = get_divisors(n)
for a, b in d:
    ans = min(ans, a+b-2)
print(ans)


Measured memory_bytes: 3432
A = int(input())
B = int(input())
C = int(input())
X = int(input())
counter = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500 * a + 100 * b + 50 * c == X:
                counter += 1
print(counter)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N; cin >> N;
    map<string, int> ms;
    rep(i, N) {
        string s; cin >> s;
        sort(all(s));
        ms[s]++;
    }

    ll ans = 0;
    for (auto i : ms) {
        ll tmp = i.second;
        ans += tmp * (tmp - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  long long h;
  cin >> h;

  int cnt2div=0;
  while (h>0)
  {
    cnt2div++;
    h = h/2;
  }

  long long ans=0;
  for (int i=0; i<cnt2div; i++)
  {
    ans += pow(2, i);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
N,K = list(map(int,input().split()))
B = []
ans = 0
for i in range(K):
    d = input()
    A = list(map(int,input().split()))
    for l in range(len(A)):
      B.append(A[l])
for j in range(1,N+1):
    if j not in B:
        ans += 1
print(ans)


Measured memory_bytes: 67844
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	// 入力
	string S, T;
	cin >> S >> T;
	
	bool isAnswer = true;
	// aからzは26種類
	vector<int> vecS(26, -1);
	vector<int> vecT(26, -1);
	for (int i = 0; i < S.size(); i++)
	{
		// S[i]とT[i]のindexの計算
		int s = S[i] - 'a';
		int t = T[i] - 'a';
		
		// 文字の値が入っている場合
		if (vecS[s] != -1 || vecT[t] != -1)
		{
          	// (1対1)以外の文字が入っている場合、SをTにすることができない
			if (vecS[s] != t || vecT[t] != s)
			{
				isAnswer = false;
				break;
			}
		}
		
		// 文字の値を交換します。(文字交換は1対1)
		vecS[s] = t;
		vecT[t] = s;
	}
	
	if (isAnswer)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

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

void min_self(long long &x,long long y)
{
    x=min(x,y);
}
long long inf=1e18+1;
int main()
{
    int  n;
    int w;
    scanf("%d %d",&n,&w);
    vector<int>weight(n+1),value(n+1);
    for( int i=0;i<n;i++)
    {
        scanf("%d%d",&weight[i],&value[i]);
    }
    int sum_value=0;
    for(int x:value)
    {   
        sum_value+=x;
    }
    vector<long long>dp(sum_value+1,inf);
    dp[0]=0;
    for(int item=0;item<n;item++)
    {
        for(int value_already=sum_value-value[item];value_already>=0;value_already--)
        {
            min_self(dp[value_already+value[item]],dp[value_already]+weight[item]);
        }
    }
    long long answer=0;
    for(int long long i=0;i<=sum_value;i++)
    {
        if(dp[i]<=w)
        {
            answer=max(answer, i);
        }
    }
    printf("%ld",answer);
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))

zero = l[0]
count = 1

for i in range(n):
    #print("c:",count)
    if zero != 2:
        count += 1
        zero = l[zero-1]
    else:
        print(count)
        exit()
else:
    print(-1)


Measured memory_bytes: 7084
class BIT: #0-indexed
    __slots__ = ["size", "tree","depth","n0"]
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length()
        self.n0 = 1<<self.depth

    def get_sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def range_sum(self,l,r): #a_l + ... + a_r 閉区間
        return self.get_sum(r) - self.get_sum(l-1) 

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def bisect_left(self,w):
        #和が w 以上になる最小の index
        #w が存在しない場合 self.size を返す
        if w <= 0: return 0
        x,k = 0,self.n0
        for _ in range(self.depth):
            k >>= 1
            if x+k <= self.size and self.tree[x+k] < w:
                w -= self.tree[x+k]
                x += k
        return x


# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,k = map(int,readline().split())
*p, = map(int,readline().split())

b = BIT(n)
num = BIT(n)
MOD = 998244353
inv = (MOD+1)//2
for i in range(k):
    b.add(p[i]-1,1)
    num.add(p[i]-1,1)

ans = k*(k-1)//2%MOD*inv%MOD

tot = k
rate = (k-1)*pow(k,MOD-2,MOD)%MOD
rateinv = pow(rate,MOD-2,MOD)
bunbo = rate
hosei = rateinv
for i in range(k,n):
    pi = p[i]-1
    v = b.get_sum(pi)
    #print(v*inv%MOD*bunbo%MOD,v*inv%MOD*bunbo%MOD*4%MOD,"v")
    ans += v*inv%MOD*bunbo%MOD
    ans %= MOD
    

    x = i - num.get_sum(pi)
    w = x - (tot-v)*inv%MOD*bunbo%MOD
    #print(x,tot,v)
    #print(w,w*4%MOD,"w")
    ans += w
    ans %= MOD
    
    b.add(pi,hosei)
    num.add(pi,1)
    tot += hosei
    hosei = hosei*rateinv%MOD
    bunbo = bunbo*rate%MOD



print(ans%MOD)
#print(ans*8%MOD)



Measured memory_bytes: 96404
#include <stdio.h>

void sw_char(char ch){

}

int main(){
char ch;
while(1){
scanf("%c", &ch);

if(ch>=97&&ch<=122){
ch = ch - 32;
}else if(ch >= 65&&ch<=90){
ch = ch + 32;
}

printf("%c", ch);

if(ch == '\n') break;
}
return 0;
}


Measured memory_bytes: 2124
#include <iostream>
#include <cstdlib>

const int MAX_SIZE = 36;

struct Cell {
  char card;
  int order;
  int value;
};

void bubbleSort(struct Cell *list[MAX_SIZE], int n) {
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j >= i + 1; j--) {
      if (list[j]->value < list[j - 1]->value) {
	struct Cell *tmp = list[j];
	list[j] = list[j - 1];
	list[j - 1] = tmp;
      }
    }
  }
}

void selectionSort(struct Cell *list[MAX_SIZE], int n) {
  for (int i = 0; i < n; i++) {
    int minj = i;
    
    for (int j = i; j < n; j++) {
      if (list[j]->value < list[minj]->value) {
	minj = j;
      }
    }

    struct Cell *tmp = list[i];
    list[i] = list[minj];
    list[minj] = tmp;
  }
}

bool isStable(struct Cell *list[MAX_SIZE], int n) {
  for (int i = 1; i < n; i++) {
    if ((list[i - 1]->value == list[i]->value) && (list[i - 1]->order > list[i]->order)) {
      return false;
    }
  }
 
  return true;
}

void print(struct Cell *list[MAX_SIZE], int n) {
  for (int i = 0; i < n; i++) {
    std::cout << list[i]->card << list[i]->value;
    
    if (i < (n - 1)) {
      std::cout << " ";
    } else {
      std::cout << std::endl;
    }
  }

  if (isStable(list, n)) {
    std::cout << "Stable" << std::endl;
  } else {
    std::cout << "Not stable" << std::endl;
  }
}

int main() {
  int n = 0;

  std::cin >> n;

  struct Cell *B[MAX_SIZE];
  struct Cell *S[MAX_SIZE];

  int order = 0;

  for (int i = 0; i < n; i++) {
    B[i] = (struct Cell *) std::malloc(sizeof(struct Cell));
    S[i] = (struct Cell *) std::malloc(sizeof(struct Cell));    
    
    std::string card;

    std::cin >> card;
    
    B[i]->order = order;
    B[i]->card = card[0];
    B[i]->value = card[1] - '0';
    
    S[i]->order = B[i]->order;
    S[i]->card = B[i]->card;
    S[i]->value = B[i]->value;

    order++;
  }


  bubbleSort(B, n);
  selectionSort(S, n);

  print(B, n);
  print(S, n);
  
  return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> h(N);
	int ans = 0;
	int active = 0;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	for (int i = 0; i < N; i++) {
		if (active >= h[i]) {
			active = h[i];
		}
		else {
			ans += h[i] - active;
			active = h[i];
		}

	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int a;
scanf("%d",&a);
int b;
scanf("%d",&b);
int s;
s=0;
int c;
int d;
for(int i=0;i<a;i++){
     scanf("%d",&c);
     d=min(c,b-c);
     s=s+d;
}
s=2*s;
printf("%d\n",s);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

int main()
{
    long long n;
    scanf("%lld", &n);
    std::vector<long long> a(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
    }

    if (n % 2 == 0)
    {
        for (int i = (n - 1); 0 <= i; i -= 2)
        {
            cout << a[i] << " ";
        }
        for (int i = 0; i < n; i += 2)
        {
            if (i != n - 2)
            {
                cout << a[i] << " ";
            }
            else
            {
                cout << a[i] << endl;
            }
        }
    }
    else
    {
        if (n != 1)
        {
            for (int i = (n - 1); 0 <= i; i -= 2)
            {
                cout << a[i] << " ";
            }
            for (int i = 1; i < n; i += 2)
            {
                if (i != n - 2)
                {
                    cout << a[i] << " ";
                }
                else
                {
                    cout << a[i] << endl;
                }
            }
        }else{
            cout << a[0] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 10000000000000000
typedef long long ll;

int main() {
    int N;
    cin>>N;
    
    ll nums[N+1];
    rep(i,N) cin>>nums[i];
    
    ll sum=0, cost1=0;
    rep(i,N){
        sum += nums[i];
        if(i%2==0){
            if(sum>=0){
                cost1 += abs(sum)+1;
                sum = -1;
            }
        }else{
            if(sum<=0){
                cost1 += abs(sum)+1;
                sum = 1;
            }
        }
    }
    sum=0;
    ll cost2=0;
    rep(i,N){
        sum += nums[i];
        if(i%2==1){
            if(sum>=0){
                cost2 += abs(sum)+1;
                sum = -1;
            }
        }else{
            if(sum<=0){
                cost2 += abs(sum)+1;
                sum = 1;
            }
        }
    }
    cout1(min(cost1,cost2));
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val cin = Scanner(System.`in`)
    val N = cin.nextInt()
    val A = cin.nextInt()
    val B = cin.nextInt()

    val ans = (1..N).map {
        var sum = 0
        var tmp = it
        while (tmp > 0) {
            sum += (tmp % 10)
            tmp /= 10
        }
        if (A <= sum && sum <= B) it else 0
    }.sum()
    println(ans)
}

Measured memory_bytes: 31524
#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(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;
 
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(m),b(m);
    
    rep(i,m) cin>>a[i]>>b[i];
    int num[100]={0};
    rep(i,m) {
        num[a[i]]++;
        num[b[i]]++;
    }
    for(int i=1;i<=n;i++){
        cout<<num[i]<<endl;
    }
    return 0;
}

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

int main() {
	int K, S, count = 0;
	cin >> K >> S;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			if (0 <= S - i - j && S - i - j <= K) count++;
		}
	}
	cout << count << endl;
}

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

using namespace std;

using ll = long long;
using p  = pair<ll, ll>;
constexpr ll INF = 1LL << 62;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll H, W, N;
    cin >> H >> W >> N;
    
    unordered_map<ll, ll> m;
    
    for (ll i = 0; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        
        for (ll dh = -1; dh <= 1; dh++) {
            for (ll dw = -1; dw <= 1; dw++) {
                if (a + dh < 0 || a + dh > H - 1 || b + dw < 0 || b + dw > W - 1) {
                    continue;
                }
                m[(a + dh) * W + (b + dw)] += 1;
            }
        }
    }
    
    vector<ll> ans(10, 0);
    ll non_zero = 0;
    
    for (auto&& a : m) {
        ll h = a.first / W;
        ll w = a.first % W;
        if (h <= 0 || h >= H - 1 || w <= 0 || w >= W - 1) {
            continue;
        }
        ans[a.second] += 1;
        non_zero += 1;
    }
    
    ans[0] = (H - 2) * (W - 2) - non_zero;
    for (auto a : ans) {
        cout << a << endl;
    }
    
    return 0;
}


Measured memory_bytes: 36624
#include<bits/stdc++.h>
using namespace std;
bool all_9(const string& s)
{
    for(int i=0;i<s.size();++i)
        if(s[i]!='9')
            return false;
    return true;
}
int main()
{
    string s;
    cin>>s;
    if(all_9(s))
        cout<<s.size()*9<<endl;
    else if(all_9(s.substr(1)))
        cout<< 9*(s.size()-1)+(s[0]-'0')<<endl;
    else
        cout<< 9*(s.size()-1)+(s[0]-'0'-1)<<endl;
}

Measured memory_bytes: 256
import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n-2):
    a = l[i]
    for j in range(i+1,n-1):
        b = l[j]
        c = bisect.bisect_left(l,a+b)
        ans += max(c-j-1,0)
print(ans)

Measured memory_bytes: 45608
#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<int, int>;
int main(void){
  int n;
  cin >> n;

  if (n == 1) cout << "Hello World" << endl;
  else{
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
}


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

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

  vector< vector<char> > Graph(H);
  for (int i = 0; i < H; i++) {
    string str;
    cin >> str;
    for (int j = 0; j < W; j++) {
      Graph[i].push_back(str[j]);
    }
  }

  vector< pair<int, int> > eightside = { {-1, 0}, {-1, -1}, {0, -1}, {1, -1}, 
                                         {1, 0}, {1, 1}, {0, 1}, {-1, 1} };
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j ++) {
      if (Graph[i][j] == '.') {
        int cnt = 0;
        for (int k = 0; k < eightside.size(); k++) {
          int a = i + eightside[k].first;
          int b = j + eightside[k].second;
          if (0 <= a && a < H && 0 <= b && b < W && Graph[a][b] == '#') cnt++;
        }
        Graph[i][j] = '0' + cnt;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << Graph[i][j];
    }
    cout << '\n';
  }

  return 0;
}


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

int main(){
  int i,a,b,c,array[101],array1[101],array2[101],d=0,e,f=0,g,h;
  cin>>a>>b>>c;
  e=a;
  g=b;
  for(i=0;i<c;i++){
    cin>>array[i]>>array1[i]>>array2[i];
  switch(array2[i]){
    case 1:
      if(array[i]>d){
        d=array[i];
      }
      break;
    case 2:
      if(array[i]<e){
        e=array[i];
      }
      break;
    case 3:
      if(array1[i]>f){
        f=array1[i];
      }
      break;
    case 4:
      if(array1[i]<g){
        g=array1[i];
      }
      break;
  }
  }
    h=(e-d)*(g-f);
  if(h<0||e-d<0&&g-f<0){
    cout<<0;
  }else{
    cout<<h;
  }
  cout<<endl;
}

Measured memory_bytes: 256
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln endl
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inp freopen("input.txt", "r", stdin)
#define outp freopen("output.txt", "w", stdout)
#define dbgm(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
typedef long long int  ll;
typedef long double  ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 2e5+5, MOD = 1e9+7, EPS = 1e-9;
int t,n,m,k,x,y;
 
 
const int MAX_N = 50; // Fibonacci matrix, increase/decrease this value as needed
 
struct Matrix { ll mat[MAX_N][MAX_N]; }; // we will return a 2D array
 
Matrix matMul(Matrix a, Matrix b) {
	Matrix ans; int i, j, k;
	for (i = 0; i < MAX_N; i++)
	for (j = 0; j < MAX_N; j++)
	for (ans.mat[i][j] = k = 0; k < MAX_N; k++){
		ans.mat[i][j] += a.mat[i][k] * b.mat[k][j];
		ans.mat[i][j]%=MOD;
	}
	return ans; 
}
 
// if necessary, use modulo arithmetic
 
Matrix matPow(Matrix base, ll p) {
	// O(n^3 log p)
	Matrix ans; int i, j;
	for (i = 0; i < MAX_N; i++) for (j = 0; j < MAX_N; j++) 
	ans.mat[i][j] = (i == j); // prepare identity matrix
	while (p) {
		// iterative version of Divide & Conquer exponentiation
		if (p & 1) ans = matMul(ans, base);	// if p is odd (last bit is on)
		base = matMul(base, base);	// square the base
		p >>= 1;
		// divide p by 2
	}
	return ans; 
}
 
 
 
int main(){
	fastio;
	ll n,k;
	cin>>n>>k;
	Matrix m;
	forn(i,n){
		forn(j,n){
			cin>>m.mat[i][j];
		}
	}
	Matrix p = matPow(m,k);
	ll ans=0;
	forn(i,n){
		forn(j,n){
			ans+=p.mat[i][j];
		}
	}
	ans%=MOD;
	cout<<ans<<ln;
	return 0;
}

Measured memory_bytes: 384
import sys
n = int(input())
P = [0] * n
for i in range(n):
    P[i] = list(map(int, input().split()))
P = sorted(P, key=lambda x: x[2], reverse=True)

max_h = P[0][2]

for hh in range(max_h+200, max_h-1, -1):
    for cx in range(101):
        for cy in range(101):
            for x, y, h in P:
                th = max(hh-abs(cx-x)-abs(cy-y),0)
                if h == th:
                    continue
                else:
                    break
            else:
                print('%d %d %d' % (cx, cy, hh))
                sys.exit(0)


Measured memory_bytes: 51420
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-01 14:19:54
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n; cin >> n;

  int c[20][20];

  fill(c[0], c[20], -1);

  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    for (int j = 0; j < a; ++j) {
      int x, y; cin >> x >> y; --x;
      c[i][x] = y;
    }
  }

  int ans = 0;

  for (int i = 0; i < (1 << n); ++i) {
    bool flag = true;
    for (int j = 0; j < n; ++j) {
      if (!(i & (1 << j))) continue;
      for (int k = 0; k < n; ++k) {
        if (c[j][k] == -1) continue;
        if ((c[j][k] == 1 && (!(i & (1 << k)))) || (c[j][k] == 0 && (i & (1 << k)))) flag = false;
      }
    }
    if (flag) ans = max(ans, __builtin_popcount(i));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


k = int(input())
s = input()
n = len(s)
M = 10**9+7

N = n+k # 必要なテーブルサイズ

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

ans = 0
for i in range(n-1, n+k):
    ans += pow(25,i-n+1,M)*pow(26,n+k-i-1,M)*cmb(i,n-1,M)
    ans %= M
print(ans)

Measured memory_bytes: 248236
n,m = map(int,input().split())
ps = [list(input().split()) for _ in range(m)]
d = {}
cl_cnt = 0
pl_cnt = 0
for i in ps:
  if int(i[0]) in d:
    if (d[int(i[0])] >= 0) and (i[1] == 'WA'):
      d[int(i[0])] += 1
    elif (d[int(i[0])] >= 0) and (i[1] == 'AC'):
      cl_cnt += 1
      d[int(i[0])] += 1
      pl_cnt += d[int(i[0])]
      d[int(i[0])] = -1
  else:
    if i[1] == 'WA':
      d[int(i[0])] = 0
    else:
      d[int(i[0])] = -1
      cl_cnt += 1
print(cl_cnt,pl_cnt)

Measured memory_bytes: 37960
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s=sc.next();
    int count=0;
    for(int i=0;i<3;i++){
      for(int j=i+1;j<4;j++){
        if(s.charAt(i)==s.charAt(j)){
          count++;
        }
      }
    }
    if(count==2){
        System.out.println("Yes");
    }else{
        System.out.println("No");
    }
  }
}


Measured memory_bytes: 21716
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl '\n'
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
   int a,b;
   cin>>a>>b;
   if(a>=13)cout<<b<<endl;
   else if(6<=a and a<=12)cout<<(b>>1)<<endl;
   else if(a<=5)cout<<"0"<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


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

const int N = 5e6 + 5;

int n, k, p[N], q[N], du[N];
set <int> L, R;
vector <int> G[N];

typedef set <int> :: iterator it;

int main(void) {
	L.clear(); R.clear();
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &p[i]);
		q[p[i]] = i;
	}
	
	for (int i = 1; i < k; ++ i) {
		R.insert(p[i]);
	}
	for (int i = 1; i <= n; ++ i) {
		if (i + k - 1 <= n) R.insert(p[i + k - 1]);
		if (i) R.erase(p[i - 1]);
		
		L.insert(p[i]);
		if (i > k) L.erase(p[i - k]);
		
		it cur = R.upper_bound(p[i]);
		if (cur != R.end()) G[q[* cur]].push_back(i), ++ du[i];
		cur = L.upper_bound(p[i]);
		if (cur != L.end()) G[q[* cur]].push_back(i), ++ du[i];
	}
	
	L.clear(); R.clear();
	
	for (int i = 1; i <= n; ++ i) if (du[i] == 0) {
		L.insert(- i);
	}
	
	int tp = 0;
	while (L.size()) {
		int pos = - (* L.begin());
		p[ ++ tp] = pos;
		L.erase(L.begin());
		
		for (int i = 0; i < G[pos].size(); ++ i) {
			int v = G[pos][i]; -- du[v];
			if (du[v] != 0) continue;
			L.insert(- v);
		}
	}
	
	for (int i = 1; i <= n; ++ i) {
		q[p[i]] = n - i + 1;
	}
	
	for (int i = 1; i <= n; ++ i) {
		printf("%d\n", q[i]);
	}
	
	return 0;
}

Measured memory_bytes: 172160