akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int kou[17][17],dp[17][17],a,b,i,j,x,y,n;
	while(1)	{
		scanf("%d %d",&a,&b);
		if(a==0 && b==0)	break;
		scanf("%d",&n);
		for(i=1;i<=b;i++)	{
			for(j=1;j<=a;j++)	{
				kou[i][j]=0;
				dp[i][j]=0;
			}
		}
		for(i=0;i<n;i++)	{
			scanf("%d %d",&x,&y);
			kou[y][x]=1;
		}
		dp[1][1]=1;
		for(i=1;i<=b;i++)	{
			for(j=1;j<=a;j++)	{
				if(j+1<=a && kou[i][j+1]!=1)	dp[i][j+1]+=dp[i][j];
				if(i+1<=b && kou[i+1][j]!=1)	dp[i+1][j]+=dp[i][j];
			}
		}
		printf("%d\n",dp[b][a]);
	}
	return 0;
}


Measured memory_bytes: 2584
N, M = gets.chomp.split.map(&:to_i)
 
arr = Array.new(N)
 
M.times {
  s, c = gets.chomp.split.map(&:to_i)
  if arr[s - 1] && arr[s - 1] != c then
    puts "-1"
    exit
  end
  arr[s - 1] = c
}
  
if arr.count > 1 && arr[0] == 0 then
    puts "-1"
    exit
end
  
if !arr[0] && arr.count > 1 then
  arr[0] = 1
end
 
ret = arr.reduce(""){|sum, i|
  if (i) then
    sum = sum << i.to_s
  else
    sum = sum << "0"
  end
}
 
puts ret

Measured memory_bytes: 1788
#include<stdio.h>

int main(){
    int n;
    int i = 1;
    scanf("%d",&n);
    while(i <= n){
        int x = i;
        if(x % 3 == 0 || x % 10 == 3) printf(" %d",i);
        else{
            while(x){
            x /= 10;
            if(x % 10 == 3 && x){
                printf(" %d",i);
                break;
            }
            }
        }
        ++i;
    }
    printf("\n");
}


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

int main()
{
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  for (int i = 0; i < d; i++) cin >> p.at(i) >> c.at(i);
  int min_problems = 1 << 30;
  for (int i = 0; i < 1 << d; i++) {
    int highest = 0;
    for (int j = d - 1; j >= 0; j--) {
      if ((i >> j) % 2 == 0) {
        highest = (j + 1) * 100;
        break;
      }
    }
    int score = 0, problems = 0;
    for (int j = 0; j < d; j++) {
      if ((i >> j) % 2 == 1) {
        score += p.at(j) * (j + 1) * 100 + c.at(j);
        problems += p.at(j);
      }
    }
    if (g - score > 0 && g - score <= highest * p.at(highest / 100 - 1)) {
      problems += (g - score + highest - 1) / highest;
      score = g;
    }
    if (g - score <= 0 && problems < min_problems) {
      min_problems = problems;
    }
  }
  cout << min_problems << endl;
}


Measured memory_bytes: 256
#include <cstdio>
int N,count=0;
void dfs(long long,int);
int main(void)
{
    scanf("%d",&N);
    dfs(0,0);
    printf("%d\n",count);
    return 0;
}
void dfs(long long nextNum,int flag357)
{
    if(nextNum<=N)
    {
        if(flag357==7)    // 07 is BIN 111
            count++;
        dfs(nextNum*10+3,flag357|1); // BIN 001
        dfs(nextNum*10+5,flag357|2); // BIN 010
        dfs(nextNum*10+7,flag357|4); // BIN 100
    }
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
int n,k;
char a[2000],b[2000];

scanf("%d",&n);

for(k=0;k<n;k++){
scanf("%s",a);
scanf("%s",b);
printf("%d\n",LCS(a,b));
}

}

int LCS(char *a,char *b){
int i,j,c[2000][2000];

for(i=0;i<strlen(a);i++){
for(j=0;j<strlen(b);j++){
if(a[i]==b[j]) c[i+1][j+1]=c[i][j]+1;
else if(c[i][j+1]>=c[i+1][j]) c[i+1][j+1]=c[i][j+1];
else c[i+1][j+1]=c[i+1][j];
}
}
return c[i][j];
}



Measured memory_bytes: 9608
n = int(input())
f = 100000
if n == 0:
    print(int(f))
else:
    for i in range(n):
        f *= 1.05
        #print(f)
        #F = f - f%1000 + 1000
        if f%1000 != 0:
            f = (f//1000)*1000 + 1000
            #print(i,f)
print(int(f))


Measured memory_bytes: 5608
#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
		int map[10][10];
		int m = 0;
		for(int i = 0 ;i < 10; i++){
			for(int j = 0; j < 10; j++){
				if(i == j) map[i][j] = 0;
				else map[i][j] = 10000000;
			}
		}
		for(int i = 0 ; i< n; i++){
			int a,b,c;
			cin >> a >> b >> c;
			m = max(max(a,b),m);
			map[a][b] = map[b][a] = c;
		}
		for(int k = 0; k <= m; k++){
			for(int i = 0; i <= m; i++){
				for(int j = 0; j <= m; j++){
					map[i][j] = min(map[i][j],map[i][k]+map[k][j]);
				}
			}
		}
		int ans[10] = {};
		for(int i = 0 ; i<=m; i++)for(int j = 0 ; j <= m; j++)ans[i] += map[i][j];
		int a = 0;
		for(int i = 0; i <= m; i++){
			if(ans[i] < ans[a]) a = i;
		}
		cout << a << " " << ans[a] << endl;
	}
}

Measured memory_bytes: 1160
var table={};
    table[11] = "a";
    table[12] = "b";
    table[13] = "c";
    table[14] = "d";
    table[15] = "e";
 
    table[21] = "f";
    table[22] = "g";
    table[23] = "h";
    table[24] = "i";
    table[25] = "j";
 
    table[31] = "k";
    table[32] = "l";
    table[33] = "m";
    table[34] = "n";
    table[35] = "o";
 
    table[41] = "p";
    table[42] = "q";
    table[43] = "r";
    table[44] = "s";
    table[45] = "t";
 
    table[51] = "u";
    table[52] = "v";
    table[53] = "w";
    table[54] = "x";
    table[55] = "y";
 
    table[61] = "z";
    table[62] = ".";
    table[63] = "?";
    table[64] = "!";
    table[65] = " ";
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.replace(/\n$/,"")).split("\n");
Arr.forEach(function(str){
   str=str.replace(/\d\d/g,function(s){
      if(table.hasOwnProperty(s))s=table[s];
      return s;
   });
   if(str.match(/\d/))str="NA";
   console.log(str);
});

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long
#define mod 1000000007

using namespace std;

int main()
{
  string w;
  map<char, int> cnt;

  cin >> w;

  rep(i, w.size()) {
    ++cnt[w[i]];
  }

  for(auto it = cnt.begin(); it != cnt.end(); ++it) {
    if (it->second % 2) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


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

int main(){
   int n,y;

   while(1){
	int con=0;

	cin >> n;
	if(n == 0) break;
	y = n;

	while(1){
		if(y == 1) break;

		if(y%2 == 0){
			y = y/2;
		}else{
			y = y*3 + 1;
		}

		con++;

	}

	cout << con << endl;

   }

   return 0;

}


   


	

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

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

    //1010101...
    auto r0 = 0;
    for(auto i = 0; i != s.length(); ++i) {
        auto c = s[i];
        if(c != (i % 2 == 0 ? '1' : '0'))
            ++r0;
    }

    //0101010...
    auto r1 = 0;
    for(auto i = 0; i != s.length(); ++i) {
        auto c = s[i];
        if(c != (i % 2 == 0 ? '0' : '1'))
            ++r1;
    }

    cout << min(r0, r1) << endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
	int k,s,c=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)c++;
		}
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<int> reversed, stand;
    int count = 0;
    if (S[0] == '0') reversed.push_back(0);
    for (int i = 0; i < N; i++) {
        if (i != 0) {
            if (S[i - 1] != S[i]) {
                if (S[i] == '0') reversed.push_back(count);
                else stand.push_back(count);
                count = 0;
            }
        }
        count++;
    }
    if (S[N - 1] == '0') {
        stand.push_back(count);
        reversed.push_back(0);
    } else reversed.push_back(count);

    int i = 0;
    int now_count = reversed[0];
    int maximum = now_count;
    while (stand.size() >= ++i) {
        now_count += (stand[i - 1] + reversed[i]);
        if (i > K) now_count -= (stand[i - K - 1] + reversed[i - K - 1]);
        maximum = max(maximum, now_count);
    }

    cout << maximum << endl;

    return 0;
}

Measured memory_bytes: 1020
#![allow(non_snake_case)]

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

fn main() {
    let N: usize = read();
    let mut vec: Vec<usize> = vec![];
    use std::collections::HashMap;
    let mut map: HashMap<usize, usize> = HashMap::new();
    for _ in 0..N {
        let val = read();
        let entry = map.entry(val).or_insert(0);
        *entry += 1;
        if *entry % 2 == 0 {
            vec.push(val);
        }
    }
    if vec.len() < 2 {
        println!("0");
    } else {
        vec.sort();
        println!("{}", vec[vec.len() - 1] * vec[vec.len() - 2]);
    }
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

int N, color[9], ovr;

int main() {
	scanf("%d", &N);
	set<int> st;
	rep(i, N) {
		int a;
		scanf("%d", &a);
		if(a >= 3200) ++ovr;
		else st.insert(a / 400);
	}
	cout << max(int(st.size()), 1) << " " << int(st.size()) + ovr << endl;
	return 0;
}

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define ll long long
#define M 998244353
#define all(v) (v).begin(),(v).end()
#define fr first
#define sc second
#define sz(x) (ll)((x).size())
#define endl "\n"
#define vc vector
#define pb push_back
#define pii pair<ll,ll>
#define psi pair<string,ll>
#define msi map<string,ll>
#define mii map<ll,ll>
#define mp  make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265
#define mem(x,val) memset(x,val,sizeof(x))
#define r0 return 
const long long INF=1e18;
template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
#define dbgv(container) {cerr << #container << " : \n"; int cnt = 0; for (auto& x: container) cerr << #container << "[" << cnt++ << "] = " << x << '\n';} 
#define dbgvv(container) {cerr << #container << " : \n"; int c1=0,c2=0; for (auto& x : container){c2 = 0; for (auto& y : x) {cerr << #container << "[" << c1 << "][" << c2++ << "] = " << y << '\n';}c1++;}}
#define dbg(...)__f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

//code begins here
ll dp[105][100005],n,w1,w[105],v[105];
ll calc(ll i,ll wl)
{
	if(wl<0) return -INF;
	if(i==n+1&&wl>=0) return 0;
	if(dp[i][wl]!=-1) return dp[i][wl];
	dp[i][wl]=max(calc(i+1,wl-w[i])+v[i],calc(i+1,wl));
	//dbg(dp[i][wl],i,wl);
	return dp[i][wl];
}
void solve()
{
 	cin>>n>>w1;
 	mem(dp,-1);
 	rep(i,1,n+1) cin>>w[i]>>v[i];
 	cout<<calc(1,w1);
}
signed main()
{
	fast
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 82304
if __name__ == '__main__':
    N = int(input())
    matrix = [['0'] * N for _ in range(N)]
    for i in matrix:
        node_info = [int(i) for i in input().split()]
        node_i = node_info[0] - 1
        if not node_info[1] == 0:
            for i in node_info[2:]:
                matrix[node_i][i - 1] = '1'
    [print(' '.join(line)) for line in matrix]

Measured memory_bytes: 7744
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<int, int>p;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
const ull INF3 = 18000000000000000000LL;
bool flag = true;
bool fl = false;
bool used[210];
bool graph[100][100];
bool visited[8];
int abc[26] = { 0 };

int main() {
	int n, ans = 1, a, f = -1;
	std::cin >> n >> a;
	for (int i = 1;i < n;i++) {
		int b;
		std::cin >> b;
		if (f == -1) {
			if (a > b) f = 0;
			else if (a < b)f = 1;
		}
		else if (f == 0) {
			if (a < b) f = -1, ans++;
		}
		else  {
			if (a > b) f = -1, ans++;
		}
		a = b;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(int i=a;i<b;i++)
#define rFor(i,a,b) for(int i=a;i>b;i--)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<b>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a,b,c;
  ci(a>>b>>c);
  vec d(c);
  For(i,0,c)
    ci(d[i]);
  vec e(a);
  For(i,0,c)
    e[d[i]-1]++;
  For(i,0,a){
    if(b-c+e[i]>0)
      co("Yes");
    else
      co("No");
  }
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int dp[100050],a[100050];
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    dp[0]=0;
    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i-a[j]<0)continue;
            if(!dp[i-a[j]])dp[i]=1;
        }
    }
    
    
    if(dp[k])cout<<"First";
    else cout<<"Second";
    
    
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n;
ll a[100];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	a[0]=2;
	a[1]=1;
	for (int i = 2; i <= n; i++) {
		a[i]=a[i-1]+a[i-2];
	}
	cout << a[n] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using T = tuple<int, int, int>;
using T2 = tuple<ll, int, int>;
constexpr ll INF = 1e18+7;
int n, m, s, u, v, a, b;
vector<T> tp[55];
ll dp[55][2505], c[55], d[55], ans = INF;
priority_queue<T2, vector<T2>, greater<T2>> qu;
int main(){
	scanf("%d%d%d", &n, &m, &s);
	s = min(2499, s);
	fill(dp[0], dp[50], INF);
	rep(i,m){
		scanf("%d%d%d%d", &u, &v, &a, &b);
		u--; v--;
		tp[u].emplace_back(v, a, b);
		tp[v].emplace_back(u, a, b);
	}
	rep(i,n) scanf("%lld%lld", c+i, d+i);
	qu.push({dp[0][s] = 0, 0, s});
	while(!qu.empty()){
		auto[cost, town, coin] = qu.top(); qu.pop();
		if(dp[town][coin] < cost) continue;
		for(auto [nxtown, coin2, cost2]: tp[town]){
			if(coin2 > coin) continue;
			if(dp[nxtown][coin - coin2] > cost + cost2){
				qu.push({dp[nxtown][coin - coin2] = cost + cost2, nxtown, coin - coin2});
			}
		}
		if(coin + c[town] < 2500){
			if(dp[town][coin + c[town]] > cost + d[town]){
				qu.push({dp[town][coin + c[town]] = cost + d[town], town, coin + c[town]});
			}
		}
	}
	for(int i=1; i<n; i++){
		ans = INF;
		rep(j,2500) ans = min(ans, dp[i][j]);
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 6380
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());
		  int count=0;
		  for(int i=a;i<=b;i++){
		  if(c%i==0){
			  count++;
		  }
		  }
		  System.out.println(count);
    
  }
}

Measured memory_bytes: 17320
#include<bits/stdc++.h>
using namespace std;
int64_t calc(int64_t X){
    int64_t ret=0;
    int64_t st=X/4*4;
    for(int64_t x=st;x<=X;x++)ret^=x;
    return ret;
}

int main(){
    int64_t A,B;
    cin>>A>>B;
    int64_t ans=calc(A-1)^calc(B);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define PI 3.14159265358979323846
int main(void) {
    double A, B , H , M;
    double ans;
    cin >> A >> B >> H >> M;

    double ang_A,ang_B;

    ang_A = 30.0*H + 0.5*M;
    ang_B = 6.0*M;

    if(H==0 && M==0) {
      cout << abs(A-B) << endl;
      return 0;
    }

    double rad;
    rad = (ang_A-ang_B)*PI/180.0;
    ans = A*A + B*B - 2.0*A*B*cos(rad);
    //ans = sqrt(A*A + B*B - 2.0*A*B*cos((ang_A-ang_B)*  PI/180.0));

    printf("%.10lf\n",sqrt(ans) );

    return 0;
}


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

using ll = long long int;

int n;

unordered_map<char, int> cnt;
unordered_map<int, char> mpi2c;
int k = 3;

ll ans;

int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub & ~y) / x) >> 1) | y;
}

int main(void){
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H') cnt[s[0]] += 1;
  }

  mpi2c[0] = 'M';
  mpi2c[1] = 'A';
  mpi2c[2] = 'R';
  mpi2c[3] = 'C';
  mpi2c[4] = 'H';

  for (int bit = (1 << k) - 1; bit < (1 << cnt.size()); bit = next_combination(bit)) {
    vector<int> s;
    for (int i = 0; i < cnt.size(); ++i) {
      if (bit & (1 << i)) {
        s.push_back(i);
      }
    }

    ll tmp = (ll)(1);
    for (int i = 0; i < s.size(); ++i) {
      tmp *= (ll)(cnt[mpi2c[s[i]]]);
    }
    ans += (ll)(tmp);
  }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric> 
#include <math.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define INF 999999999
using namespace std;

bool graph[8][8];

int dfs(int v, int n, bool visited[8]) {
    bool all_visited = true;

    REP(i, n) {
        if(visited[i] == false) {
            all_visited = false;
        }
    }

    if(all_visited) return 1;

    int ret = 0;
    REP(i, n) {
        if(graph[v][i] == false) continue; //no edge
        if(visited[i]) continue; // already

        visited[i] = true;
        ret += dfs(i, n, visited);
        visited[i] = false;
    }

    return ret;
}

int main()
{
    int n, m;
    cin >> n >> m;

    REP(i, m) {
        int a, b;
        cin >> a >> b;
        graph[a-1][b-1] = graph[b-1][a-1] = true;
    }

    bool visited[8];
    REP(i, n) {
        visited[i] = false;
    }

    visited[0] = true;
    cout << dfs(0, n, visited) << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
lst=list(map(int,input().split()))
idou=[abs(lst[0])]
for i in range(1,n):
    idou.append(abs(lst[i]-lst[i-1]))
idou.append(abs(lst[-1]))
kyori=sum(idou)


kyo=kyori-(idou[0]+idou[1])
kyo+=abs(lst[1])
print(kyo)

for i in range(1,n-1):
    kyo=kyori-(idou[i]+idou[i+1])
    kyo+=(abs(lst[i+1]-lst[i-1]))
    print(kyo)

kyo=kyori-(idou[-1]+idou[-2])
kyo+=abs(lst[-2])
print(kyo)

Measured memory_bytes: 90772
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
llint tento(vector<int>a){
	int i,j,n=a.size(),ans=0;
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(a[i]>a[j]){ans++;}
		}
	}
	return ans;
}

int main(void){
	llint n,i,K,ans=0;cin>>n>>K;
	vector<int>a(n);
	for(i=0;i<n;i++){cin>>a[i];}
	llint x=tento(a);
	a.res(n+n);
	for(i=0;i<n;i++){a[i+n]=a[i];}
	llint y=tento(a)-x-x;
	ans=x*K+y*((K*(K-1)/2)%mod);
	ans%=mod;
	cout<<ans<<endl;
	return 0;
}

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

int n;
string s;

vector< vector<int> > dp;

bool equal(int i, int l)
{
    for (int j = 0; j < l; ++j)
        if (s[i + j] != s[i - l + j])
            return false;
    return true;
}

int max_split(int i, int b = 0)
{
    if (i == n)
        return 0;

    if (dp[i][b] != INT_MIN)
        return dp[i][b];

    int k = -1;

    for (int l = 1; l <= 3; ++l) {
        if (l + i <= n) {
            if (b != l || !equal(i, l)) {
                int ms = max_split(i + l, l);
                if (ms != -1)
                    k = max(k, ms + 1);
            }
        }
    }

    dp[i][b] = k;
    return k;
}

int main()
{
    cin >> s;
    n = s.length();

    dp.resize(n);
    for (int i = 0; i < n; ++i) {
        dp[i].resize(4);
        for (int j = 0; j < 4; ++j)
            dp[i][j] = INT_MIN;
    }

    cout << max_split(0) << '\n';

    return 0;
}


Measured memory_bytes: 26372
a = list(map(int,input().split()))
N = a[0]
M = a[1]
X = a[2]
cost = 0
line = list(map(int,input().split()))
for i in range(M):
    if X <= line[i]:
        cost = i
        break
print(str(min(cost, len(line) - cost)))

Measured memory_bytes: 3188
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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long a = in.nextInt();
            long b = in.nextInt();
            long c = in.nextInt();
            long d = in.nextInt();
            --n;
            for (int pluses = 0; pluses <= n; ++pluses) {
                int minuses = n - pluses;
                long max = pluses * d - minuses * c;
                long min = pluses * c - minuses * d;
                if (min <= b - a && max >= b - a) {
                    out.println("YES");
                    return;
                }
            }
            out.println("NO");
        }

    }

    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: 23124
#include <bits/stdc++.h>
 
#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
 
using namespace std;
#define prime 1000000007
 
#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

ll n, k;
ll v[100100];
ll b[100100][60];

int main(){
    scanf("%lld %lld", &n, &k);
    ll ma = 0;
    ll y = k;
    vi r1, r2;
    while(y){ 
        r1.pb(y%2);
        y/=2, ma++;
    }
    reverse(r1.begin(), r1.end());
    for (ll i = 0; i < n; ++i){
        scanf("%lld", v+i);
        ll j = 0, aux = v[i];
        while(aux){
            b[i][j] = aux%2;
            aux/=2;
            j++;
        }
    }
    ll x = 0;
    for (ll j = ma-1; j >= 0; --j){
        x*=2;
        ll c = 0;
        for (ll i = 0; i < n; ++i){
            if(b[i][j]) c++;
        }
        if(c < (n+1)/2)
            x++;
    }
    y = x;
    while(y){ 
        r2.pb(y%2);
        y/=2;
    }
    reverse(r2.begin(), r2.end());
    if(k < x){
        for (int i = 0; i < (int)r2.size(); ++i){
            if(r2[i] == 0 && r1[i] == 1) break;
            if(r2[i] == 1 && r1[i] == 0) r2[i] = 0;
        }
        x = 0;
        for (int i = 0; i < (int)r2.size(); ++i){
            x*=2;
            x+=r2[i];
        }
    }
    ll ans = 0;
    for (ll i = 0; i < n; ++i){
        ans+=v[i]^x;
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 48000
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
  int i,j,k,cnt;
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  if(a+b<2*c){
    cout<<a*x+b*y;
    return 0;
  }
  if(x<=y){
    cout<<2*c*x+min(b,2*c)*(y-x);
  }else{
    cout<<2*c*y+min(a,2*c)*(x-y);
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1);
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
inline double ABS(double a){return max(a,-a);}
struct Pt {
	double x, y;
	Pt() {}
	Pt(double x, double y) : x(x), y(y) {}
	Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
	Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
	Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
	Pt operator-() const { return Pt(-x, -y); }
	Pt operator*(const double &k) const { return Pt(x * k, y * k); }
	Pt operator/(const double &k) const { return Pt(x / k, y / k); }
	double ABS() const { return sqrt(x * x + y * y); }
	double abs2() const { return x * x + y * y; }
	double arg() const { return atan2(y, x); }
	double dot(const Pt &a) const { return x * a.x + y * a.y; }
	double det(const Pt &a) const { return x * a.y - y * a.x; }
};
double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }
Pt L[100];
Pt R[100];
int iSP(Pt a, Pt b, Pt c) {
	int s = sig((b - a).det(c - a));
	if (s) return s;
	if (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b
	if (sig((a - b).dot(c - b)) < 0) return +2; // a-b-c
	return 0;
}
bool iSS(Pt a, Pt b, Pt c, Pt d) {
	return (iSP(a, b, c) * iSP(a, b, d) <= 0 && iSP(c, d, a) * iSP(c, d, b) <= 0);
}
double dSP(Pt a, Pt b, Pt c) {
	if (sig((b - a).dot(c - a)) <= 0) return (c - a).ABS();
	if (sig((a - b).dot(c - b)) <= 0) return (c - b).ABS();
	return ABS(tri(a, b, c)) / (b - a).ABS();
}
double dSS(Pt a, Pt b, Pt c, Pt d) {
	return iSS(a, b, c, d) ? 0 : min(min(dSP(a, b, c), dSP(a, b, d)), min(dSP(c, d, a), dSP(c, d, b)));
}

int main(){
	int a;scanf("%d",&a);
	L[0]=Pt(0,0);
	for(int i=0;i<a;i++){
		double X,Y;
		scanf("%lf%lf",&X,&Y);
		L[i+1]=Pt(X,Y);
	}
	L[a+1]=Pt(1000,0);
	int b;scanf("%d",&b);
	R[0]=Pt(0,1000);
	for(int i=0;i<b;i++){
		double X,Y;
		scanf("%lf%lf",&X,&Y);
		R[i+1]=Pt(X,Y);
	}
	R[b+1]=Pt(1000,1000);
	a+=2;
	b+=2;
	double left=0;
	double right=10000;
	for(int i=0;i<100;i++){
		double M=(left+right)/2;
		bool ok=true;
		for(int j=0;j<a-1;j++){
			for(int k=0;k<b-1;k++){
				if(dSS(L[j],L[j+1],R[k],R[k+1])<M*2)ok=false;
			}
		}
		if(ok)left=M;
		else right=M;
	}
	printf("%.12f\n",left*2);
}

Measured memory_bytes: 1084
#include<iostream>
using namespace std;
int main(){
	int N,M;
	while(cin>>N>>M){//N个城市  M条道路 
		int num[100]={0};
		int ai,bi;
		for(int i=1;i<=M;i++){
			cin>>ai>>bi;
			num[ai]++;
			num[bi]++;
		}
		for(int i=1;i<=N;i++){
			cout<<num[i]<<endl;
		} 
	}
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int Anum, Znum;
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) == 'A'){
      Anum = i;
      break;
    }
  }
  for(int i = S.size() - 1; i >= 0; i--){
    if(S.at(i) == 'Z'){
      Znum = i;
      break;
    }
  }
  cout << Znum - Anum + 1 << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int max=0, min=1000000000;
  for(int i=0; i<N; i++){
    cin >> A.at(i);
    if(max<A.at(i)) max = A.at(i);
    if(min>A.at(i)) min = A.at(i);
  }
  cout << max-min << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())

s = str(n)
l = str(m)

s = s*m
l = l*n

if len(l)>len(s):
    print(l)
elif len(s)>len(l):
    print(s)
else:
    if l>s:
        print(l)
    else: print(s)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#define ll long long
#define INF 1e+18
#define MOD 998244353
using namespace std;



int main(){
    ll N,K;
    cin >> N >> K;
    ll ans=0;
    
    
    if(K==1){
        cout<<N*N*N<<endl;
        return 0;
    }
    
    for(ll a=1; a<=N; a++){

        ll temp;
        if(a%K == 0){
            temp=N/K;
        }else if((a%K)*2 == K ){
            temp=(N-a%K)/K+1;
        }else{
            continue;
        }

        ans+=temp*temp;
        

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


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
int nmax=200000; // 2*(10^5)
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    double n,m;
    cin>>n>>m;
    vector<double> a(n);
    REP(i,n) cin >> a[i];
    double sum=0;
    rep(i,n) sum+=a[i];
    int cnt=0;
    rep(i,n){
        if(a[i]>=sum/(4*m)){
            cnt++;
        }
    }
    if(cnt>=m){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>

using namespace std;

#define ll long long
#define MAX 200000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    ll n, rem;
    string s = "";
    cin >> n;
    while (n > 0) {
        rem = n % 26;
        if (rem == 0) {
            rem = 26;
        }
        s.push_back(rem - 1 + 'a');
        n -= rem;
        n /= 26;
    }
    reverse(s.begin(), s.end());
    cout << s;

    return 0;
}

Measured memory_bytes: 3156
#include <iostream>

using namespace std;

int int1; 
int int2;
string impossible = "IMPOSSIBLE";

int main() {

    cin >> int1 >> int2;
    int add = int1 + int2;

    if (add % 2 == 0){
        int result = add / 2;
        cout << result;
    } else{
        cout << impossible;
    }

    return 0;
}

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

const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,r,n) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

using ll = long long int;
using ull = unsigned long long int;
using vi = vector<ll>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main() {
    cin >> n;
  	if (n < 10) {
      cout << "Yes" << endl;
      return 0;
    }
	if (n > 81) {
      cout << "No" << endl;
      return 0;   
    }
	for (int i = 2; i <= 9; ++i) {
      if (n % i == 0 && n / i < 10) {
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
import itertools
import math

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
seq = []
for i in range(n):
    seq.append(i)
b = itertools.permutations(seq)
total = 0

for a in b:
    for i in range(1, n):
        total += math.sqrt((xy[a[i]][0] - xy[a[i-1]][0]) ** 2 +
                           (xy[a[i]][1] - xy[a[i-1]][1]) ** 2)
print(total/math.factorial(n))


Measured memory_bytes: 3064
using System;

namespace C___Traveling_Salesman_around_Lake
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var k = int.Parse (input[0]);
            var n = int.Parse (input[1]);
            input = Console.ReadLine ().Split (' ');
            var a = new int[n];
            var b = 0;
            for (var i = 0; i < n; i++)
            {
                a[i] = int.Parse (input[i]);
            }
            b += a[0] + k - a[n - 1];
            var max = b;
            for (var i = 1; i < n; i++)
            {
                b += a[i] - a[i - 1];
                max = Math.Max (max, a[i] - a[i - 1]);
            }
            Console.WriteLine (b - max);
        }
    }
}

Measured memory_bytes: 34652
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

vector<string> s(1000);
int dist[1010][1010];
int h, w, ch, cw, dh, dw;
vector<P> moves = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

bool is_range(int y, int x) {
  return 0 <= y && 0 <= x && y < h && x < w;
}
bool is_wall(int y, int x) {
  return s[y][x] == '#';
}
bool already_visited(int y, int x, int d) {
  return dist[y][x] <= d;
}
bool is_goal(int y, int x) {
  return y == dh && x == dw;
}

// 0-1 BFS
void bfs() {
  deque<P> d;
  d.push_back({ ch, cw });

  while(!d.empty()) {
    auto v = d.front(); d.pop_front();
    int y = v.first, x = v.second;
    int nd = dist[y][x];
    int ndd = nd+1;
    for(auto move:  moves) {
      int ny = y + move.first;
      int nx = x + move.second;

      if (!is_range(ny, nx)) continue;
      if (already_visited(ny,nx,nd)) continue;

      if (!is_wall(ny,nx)) {
        dist[ny][nx] = nd;
        d.push_front({ ny, nx });
      } else {
        for (int i = -2; i <= 2; i++) {
          for (int j = -2; j <= 2; j++) {
            if (i==0 && j==0) continue;
            int ni = i+y;
            int nj = j+x;

            if (!is_range(ni,nj)) continue;
            if (is_wall(ni,nj)) continue;
            if (already_visited(ni,nj,ndd)) continue;

            dist[ni][nj] = ndd;
            d.push_back({ ni, nj });
          }
        }
      }
    }
  }
}

int main() {
  IOS;
  cin >> h >> w;
  cin >> ch >> cw;
  cin >> dh >> dw;
  s.resize(h); REP(i,h) cin >> s[i];
  ch--; cw--; dh--; dw--;
  REP(i,1010) REP(j,1010) dist[i][j] = INF;
  dist[ch][cw] = 0;

  bfs();

  if (dist[dh][dw] != INF) {
    COUT(dist[dh][dw]);
    return 0;
  }

  COUT(-1);
  return 0;
}

Measured memory_bytes: 8784
def evaluate_score(data):
    a_score = 0
    b_score = 0
    for a, b in data:
        if a > b:
            a_score += (a + b)
        elif b > a:
            b_score += (a + b)
        else:
            a_score += a
            b_score += b
    return a_score, b_score


if __name__ == '__main__':
    # ??????????????\???
    while True:
        data_num = int(input())
        if data_num == 0:
            break
        data = []
        for i in range(data_num):
            data.append([int(x) for x in input().split(' ')])

        # ???????????????
        a_scores, b_scores = evaluate_score(data)

        # ???????????¨???
        print('{0} {1}'.format(a_scores, b_scores))

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

const long long MOD = 1000000007;
const long long inverse2 = 500000004;
int main(){
    int n; cin >> n;
    vector<long long> A(n); long long sum = 0, square = 0;
    for (int i = 0; i < n; i++){
        cin >> A[i];
        sum += A[i]; sum %= MOD;
        square += A[i] * A[i]; square %= MOD;
    }
    sum *= sum; sum %= MOD;
    sum = (sum - square + MOD) % MOD; sum *= inverse2; sum %= MOD;
    cout << sum << '\n';
    return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n",(a+b)%24);
    return 0;
}

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

using namespace std;

int main(){
    int n;cin>>n;
    string s;
    cin>>s;
    int left=0,right=0;
    for(int i=0;i<n;++i){
        char c;
        c=s[i];
        if(c=='(')left++;
        else if(left==0)right++;
        else left--;
    }
    for(int i=0;i<right;++i){
        cout<<"(";
    }
    cout<<s;
    for(int i=0;i<left;++i){
        cout<<")";
    }
    cout<<endl;
}


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


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):                                          # 根を見つける関数を定義（同時にxを直接根にくっつける操作も行う）
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])        # 右辺で再帰的に根を探索。根に到達すると一つ目のif判定に引っかかるので、
                                                                # 最終的にself.parents[根]が返ってくる。
                                                                # これを左辺に代入することで、根が親になるように変更する。（根までの距離が長いとO(N)になってしまうので）
            return self.parents[x]

    def union(self, x, y):                                      # 二つの木をくっつける（子を多く持つ方を根とした親子関係）。これは破壊的操作を行う。
        x = self.find(x)                                        # xをxの根に置き換える
        y = self.find(y)                                        # yをyの根に置き換える

        if x == y:                                              # 根が同じなら置き換える必要なし
            return

        if self.parents[x] > self.parents[y]:                   # 子がたくさんある方を x とする（出来るだけ浅い木にするため）
            x, y = y, x

        self.parents[x] += self.parents[y]                      # xの子の数を更新
        self.parents[y] = x                                     # yの親を更新

    def same(self, x, y):                                       # xとyが同じ根の子かを判定
        return self.find(x) == self.find(y)

    def size(self, x):                                          # xの根のparent（= 要素数）を返す
        return -self.parents[self.find(x)]

    def members(self, x):                                       # xが属するグループの要素をリストとして返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):                                            # 全ての根の要素をリストとして返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):                                      # グループの数を返す
        return len(self.roots())

    def all_group_members(self):                                # {根:[根の子のリスト],...}を辞書で返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):                                          # print(self) での返し方を定義
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


##############################################################################################################
##### UnionFind を用いた連結判定
##############################################################################################################
V, E = map(int, input().split())                            # V: 頂点数　E: 辺の数
edges = [map(int, input().split()) for _ in range(E)]       # 辺で結ばれたペア
edges.reverse()
tree = UnionFind(V)
S = V*(V-1)//2
res = [S]
for a, b in edges:
    a -= 1
    b -= 1
    if tree.find(a) != tree.find(b):
        S -= tree.size(a)*tree.size(b)
    res.append(S)
    tree.union(a, b)                                        # 辺の増設クエリ
print(*list(reversed(res))[1:], sep="\n")

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T INF = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 2;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T>
istream& operator>>(istream& in, vector<T>& a) { for (T& x : a) cin >> x; }

void LOG(const int& x) { cerr << x << "\n"; }
void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }

int ceil(int a, int b) { return (a - 1) / b + 1; }

class UnionFind {
private:
  vector<int> par;
  vector<int> rnk;
  int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
public:
  UnionFind(int size) { par.resize(size); rnk.resize(size); REP(i, size) par[i] = i, rnk[i] = 0; }
  void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } }
  bool same(int x, int y) { return find(x) == find(y); }
};

struct InitCpp { InitCpp() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
} } initCpp;

signed main() {
  int n;
  cin >> n;
  set<int> s;
  vector<int> u;
  REP(_, n) {
    int a;
    cin >> a;
    if(s.count(a)) {
      s.erase(a);
      u.push_back(a);
    } else {
      s.insert(a);
    }
  }
  sort(ALL(u), greater<int>());
  cout << (u.size() >= 2 ? i64(u[0]) * i64(u[1]) : 0LL) << endl;
}

Measured memory_bytes: 4992
import sys

N,K,Q = map(int,input().split())

status = [0]*N

input = sys.stdin.readline

need_win = Q-K+1


for i in range(Q):
    s = int(input())
    status[s-1]+=1


if need_win<=0:
    for _ in range(N):
        print('Yes')
    exit(0)

for i in range(N):
    print('Yes' if status[i]>=need_win else 'No')



Measured memory_bytes: 4680
n,k = map(int, input().split())
A = [int(x) for x in input().split()]
d = {}
for a in A:
  if a in d:
    d[a] +=1
  else:
    d[a] =1
    
d =sorted(d.values())
if len(d) > k:
  ans = 0
  for i in range(len(d)-k):
    ans += d[i]
  print(ans)
else:
  print(0)


Measured memory_bytes: 32264