akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
std::vector<std::vector<int> > res;

void solve(int l, int r, int depth) {
	if (r - l == 2) {
		res[l + 1][l] = depth;
		return;
	} else if (r - l == 1) return;
	int m = l + (r - l) / 2;
	for (int i = l; i < m; i++)
		for (int j = m; j < r; j++) res[j][i] = depth;
	solve(l, m, depth + 1);
	solve(m, r, depth + 1);
}

int main () {
	int n = ri();
	res.resize(n);
	for (int i = 0; i < n; i++) res[i].resize(i);
	solve(0, n, 1);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) std::cout << res[j][i] << " ";
		std::cout << std::endl;
	}
	return 0;
}


Measured memory_bytes: 1024
export class Main {
  static main(input): string {
    const tmp: string[] = input.split("\n");
    const n: number = parseInt(tmp[0]);
    const t: number[][] = tmp.slice(1, n + 1).map(l => l.split(" ").map(a => parseInt(a)));
    t.sort(([a1, b1], [a2, b2]) => b1 - b2);
    let time = 0;
    for (let i = 0; i < n; ++i) {
      time += t[i][0];
      if (time > t[i][1]) {
        return "No";
      }
    }
    return "Yes";
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 66316
from collections import defaultdict

n = int(input())
S = [input() for i in range(n)]
m = int(input())
T = [input() for i in range(m)]

dictS = defaultdict(int)
dictT = defaultdict(int)

for s in S:
    dictS[s] += 1
for t in T:
    dictT[t] += 1

res = 0
for key in dictS:
    res = max(res, dictS[key] - dictT[key])
print(res)


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

int main() {
  vector<string> s(3); for (auto& e: s) cin >> e;
  char pastcard = s.at(0).at(0);
  vector<int> idx = {1, 0, 0};
  char ans;
  while (true) {
    int nowplayer = pastcard - 'a';
    if (!(s.at(nowplayer).size() > idx.at(nowplayer))) {
      ans = nowplayer + 'A';
      break;
    }
    pastcard = s.at(nowplayer).at(idx.at(nowplayer));
    idx.at(nowplayer)++;
  }
  cout << ans << endl;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9+5;

int n, m, l, a, b, c, d[305][305];
void wf(){rep(k,n) rep(i,n) rep(j,n) d[i][j] = min(d[i][j],d[i][k] + d[k][j]);}

int main()
{
  scanf("%d%d%d",&n,&m,&l);
  fill(d[0], d[n], INF);
  
  rep(i,m){
    scanf("%d%d%d",&a,&b,&c);
    d[a-1][b-1] = d[b-1][a-1] = c;
  }
  wf();
  rep(i,n) rep(j,n) d[i][j] = (d[i][j] <= l ? 1 : INF);
  wf();
  scanf("%d",&c);
  rep(i,c){
    scanf("%d%d",&a,&b);
    printf("%d\n",d[a-1][b-1]==INF ? -1: d[a-1][b-1] - 1);
  }
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>

typedef long long ll;


using namespace std;

int main() {
    ll n, x, y;
    cin >> n >> x >> y;

    ll length[2001] = { 0 };


    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= n; j++) {
            ll lix = abs(x - i);
            ll ljx = abs(x - j);
            ll liy = abs(y - i);
            ll ljy = abs(y - j);

            ll min = abs(j - i);

            if (lix + ljy + 1 < min) {
                min = lix + ljy + 1;
            }
            if (ljx + liy + 1 < min) {
                min = ljx + liy + 1;
            }
            
            length[min]++;
        }
    }

    for (int i = 1; i < n; i++) {
        cout << length[i] / 2 << "\n";
    }


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int x,y,r,c,rc[102][102];
int main(void){
    for(scanf("%d%d",&r,&c),x=0;x<r;x++){
        for(y=0;y<c;y++){
            scanf("%d",&rc[x][y]);
            rc[x][c]+=rc[x][y];
            rc[r][y]+=rc[x][y];
            rc[r][c]+=rc[x][y];
        }
    }
    for(x=0;x<r+1;x++){
        for(y=0;y<c+1;y++){
            printf("%d%s",rc[x][y],c-y==0?"\n":" ");
        }
    }
}

Measured memory_bytes: 1800
#include<bits/stdc++.h>
using namespace std;
const int N = 2e6+5;
typedef long long ll;
int a[N], n, inv[N];
int prime[N], phi[N], pcnt;ll cnt[N];
bool v[N];

const int mod = 998244353;
inline void sieve(int n = 2e6){
	inv[1]=1;
	for(int i=2;i<=n;i++)inv[i] = 1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1;i<=n;i++)for(int j=i*2;j<=n;j+=i){cnt[i]+=cnt[j];cnt[i]%=mod;}
}
ll ans=0;
int main()
{
	cin >> n;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),cnt[a[i]]+=a[i];
	sieve();
	for(int i=1000000;i;i--){
		// if(i<=6)cout << cnt[i] << endl;
		cnt[i] = cnt[i]*cnt[i]%mod;
		for(int j=i*2;j<=1000000;j+=i){
			cnt[i] -= cnt[j];
			cnt[i] += mod;
			cnt[i] %= mod;
		}
		// if(i<=6)cout << i << ":" << cnt[i] << endl;
		ans += cnt[i] *inv[i] % mod;
		ans += mod;
		ans %=mod;
	}
	for(int i=1;i<=n;i++)ans -= a[i], (ans+=mod)%=mod;
	ans = ans * ((mod+1)/2) % mod;
	cout << ans << endl;
}

Measured memory_bytes: 18816
#[allow(unused_macros)]
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 ) * } };
}
#[allow(unused_macros)]
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 ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

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

    let mut dp = vec![false;k+1];
    for i in 0..k {
        for j in 0..n {
            if i + a[j] <= k {
                dp[i + a[j]] |= !dp[i];
            }
        }
    }

    println!("{}", if dp[k] {"First"} else {"Second"});
}

Measured memory_bytes: 4352
def sol(x):
    mod=x&3
    if mod==0:
        return x
    if mod==1:
        return 1
    if mod==2:
        return x+1
    if mod==3:
        return 0


a,b=input().split()
aa=sol(int(a)-1)
bb=sol(int(b))
ans =aa^bb
print(ans)

Measured memory_bytes: 61868
# 標準入力
k = gets.chomp.to_i

# 集計
sum = 0
(1..k).each do |a|
  (1..k).each do |b|
    (1..k).each do |c|
      sum += a.gcd(b).gcd(c)
    end
  end
end

# 解答
puts sum

Measured memory_bytes: 14264
#include <iostream>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)

int main() {
  int N;
  cin >> N;
  
  long int ans = 0;
  rep(i, N) {
    if(i % 3 != 0 && i % 5 != 0) {
      ans += i;
    }
  }
  cout << ans << endl;
}

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

public class Main {
	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		String s = fs.next();
		if(n%2!=0) {
			System.out.println("No");
			return;
		}
		int m = n/2;
		String a = s.substring(0,m);
		String b = s.substring(m);
		if(a.equals(b)) System.out.println("Yes");
		else System.out.println("No");
	}
}
//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

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

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 21204
n, q = gets.chomp.split.map(&:to_i)
s = gets.chomp
count = [0]

(1...n).each do |i|
  count[i] = count[i-1]
  count[i] += 1 if s[i-1] == 'A' && s[i] == 'C'
end

q.times do
  l, r = gets.chomp.split.map(&:to_i)
  puts(count[r-1] - count[l-1])
end

Measured memory_bytes: 3452
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>/
// #include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007
#define maxn 100005
#define IN freopen("nocross.in","r",stdin)
#define OUT freopen("nocross.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

// using namespace __gnu_pbds;
using namespace std ;

// typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

i64 a[100005] ;

int main()
{
    i64 i , j , k , l , m , n ;

    scanf("%lld",&n) ;

    for(i=1 ; i<=n ; i++) scanf("%lld",&a[i]) ;
    a[0] = a[n+1] = 0LL ;

    i64 tot = 0LL ;

    for(i=1 ; i<=n+1 ; i++) tot += abs( a[i]-a[i-1] ) ;

    for(i=1 ; i<=n ; i++)
    {
        printf("%lld\n", tot-abs(  a[i-1]-a[i] )-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]) ) ;
    }

    return 0 ;
}


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

int main(){
	// sengen
	string s;
	map<vector<int>,long long> mp;
	// nyuryoku
	int n;
	cin >> n;
	vector<int> vec(26);
	for(int i=0;i<n;i++){
		vector<int> vec(26,0);
		cin >> s;
		for(int i=0;i<10;i++){
			vec[s[i]-'a']++;
		}
		mp[vec]++;
	}
	// keisan
	LL sum = 0;
	for(auto x:mp){
		sum += x.second*(x.second - 1)/2;
	}
	cout << sum;
	// syutsuryoku
}

Measured memory_bytes: 22240
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define MAX 100000
#define INFTY (1<<30)

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

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

bool vis[MAX];
int cnt;

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

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

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

}

void solve(){
	//???????????????s????????????????????????tgt????±???????
	bfs(0);
	int maxv=0;
	int tgt=0;
	for(int i=0; i<n; ++i){
		if(d[i]==INFTY) continue;
		if(maxv<d[i]){
			maxv=d[i];
			tgt=i;
		}
	}

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

	cout << maxv << endl;
}

int main(){
	cin >> n;

	for(int i=0; i<n-1; ++i){
		int s, t, w;
		cin >> s >> t >> w;

		G[s].push_back(Edge(t,w));
		G[t].push_back(Edge(s,w));
	}
	solve();
}

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

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

	vector <int> v(n);
	for(int &i: v)
		cin >> i;

	sort(v.begin(), v.end());
	int sum = 0;
	for(int i = 0;i < k; ++i){
		sum += v[i];
	}
	cout << sum << "\n";
}

Measured memory_bytes: 3584
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

//つねに10億7などの剰余をとる構造体
//参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858
//参考: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
int mod  = MODA;
struct modint {
	ll x;
	modint (ll x):x(x%mod){}
	modint& operator+=(const modint a){
		(x += a.x ) %= mod;
		return *this;
	}
	modint& operator-=(const modint a){
		(x -= a.x ) %= mod;
		if (x < 0) x += mod;
		return *this;
	}
	modint& operator*=(const modint a){
		(x *= a.x ) %= mod;
		return *this;
	}
	modint& operator/=(modint a){ //除算のみO(log mod)なので注意。割る数が小さいならnCrのinvを使うこと
		ll exp = mod - 2;
		while(exp > 0){ 
			if(exp & 1) *this *= a.x;
			a *= a.x;
			exp >>= 1;
		}
		return *this;
	}
	modint operator+(const modint a) const{
		modint res(*this);
		return res+=a;
	}
	modint operator-(const modint a) const{
		modint res(*this);
		return res-=a;
	}
	modint operator*(const modint a) const{
		modint res(*this);
		return res*=a;
	}
	modint operator/(const modint a) const{
		modint res(*this);
		return res/=a;
	}
};
modint modpow(modint x, ll n){
	modint res=1;
	while(n > 0){
		if(n & 1) res = res * x.x;
		x = x * x;
		n >>= 1;
	}
	return res;
}

int main() {
	modint ans = 1;
	ll tmp;
	int n, k; cin >> n >> k;
	vector<ll> p, m, z;
	REP(i, n){
		cin >> tmp;
		if(tmp>=0) p.push_back(tmp);
		else m.push_back(tmp);
	}
	sort(p.begin(), p.end());
	sort(m.rbegin(), m.rend());
	if(n == k){
		REP(i, p.size()) ans *= p[i];
		REP(i, m.size()) ans *= m[i];
		if(ans.x<0) ans += MODA;
	}
	else if(p.size() == 0){
		if(k % 2 == 1)REP(i, k) ans *= m[i];
		else REP(i, k) ans *= m[m.size() - 1 - i];
	}
	else{
		int nowp = p.size() - 1;
		int nowm = m.size() - 1;
		if(k % 2 == 1){
			ans *= p[nowp];
			nowp --;
			k--;
		}
		while(k>0){
			if(nowp > 0 && nowm <= 0){
				REP(two, 2){
					ans *= p[nowp];
					nowp --;
					k--;
				}
			}
			else if(nowm > 0 && nowp <= 0){
				REP(two, 2){
					ans *= m[nowm];
					nowm--;
					k--;
				}
			}
			else{
				if(p[nowp] * p[nowp-1] > m[nowm-1] * m[nowm]){
					REP(two, 2){
						ans *= p[nowp];
						nowp --;
						k--;
					}
				}
				else{
					REP(two, 2){
						ans *= m[nowm];
						nowm--;
						k--;
					}
				}
			}
		}
	}
	if(ans.x<0) ans.x += MODA;
	cout << ans.x << endl;
}

Measured memory_bytes: 5456
#include <iostream>
using namespace std;
int main(void){
   string s,p;
   cin>>s>>p;
    
   string ans="No";
   for(int i=0;i<(int)s.length();i++){
       bool flag=true;
       for(int j=0; j<(int)p.length();j++){
           if(s[(i+j)%(int)s.length()]!=p[j]){
               flag=false;
               break;
           }
       }
       if(flag){
           ans="Yes";
           break;
       }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 3224
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    long X = scanner.nextLong();
    int[] x = new int[N];
    for (int i = 0; i < N; i++) {
      x[i] = scanner.nextInt();
    }
    reverse(x);

    long sum = 0;
    long[] xcum = new long[N + 1];
    for (int i = 0; i < N; i++) {
      sum += x[i];
      xcum[i + 1] = sum;
    }

    long min = Long.MAX_VALUE;
    for (int k = 1; k <= N; k++) {
      long e = compute(xcum, k, N);
      if (e < 0) continue;
      e += k * X;
      e += N * X;
      if (min > e) min = e;
    }
    System.out.println(min);
  }

  private static long compute(long[] xcum, int k, int N) {
    long e = 0;
    long co = 5;
    for (int i = 0; i < (N - 1) / k + 1; i++) {
      if (i > 1) co += 2;
      e += co * (xcum[Math.min(k * (i + 1), xcum.length - 1)] - xcum[k * i]);
      if (e < 0) return -1;
    }
    return e;
  }

  private static void reverse(int[] x) {
    int left = 0;
    int right = x.length - 1;
    while (left < right) {
      int tmp = x[left];
      x[left] = x[right];
      x[right] = tmp;
      left++;
      right--;
    }
  }
}


Measured memory_bytes: 64500
import java.util.Scanner;

/**
 * 172 Beginner
 * B:Minor Change
 */
public class Main {
	public static void main(String[] args){
		// input
		java.util.Scanner inData = new Scanner(System.in);

		String s = inData.nextLine();
		String t = inData.nextLine();

		int cnt = 0;
		for (int i = 0; i < s.length(); i++) {
			if (!s.substring(i,i+1).equals(t.substring(i, i+1)))  cnt++;
		}

		System.out.println(cnt);

		inData.close();

	}
}


Measured memory_bytes: 46588
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	string s; cin >> s;
	rep(i, 0, 7)
	{
		int ans = s[0] - '0';
		rep(j, 0, 2)
		{
			if (i >> j & 1)ans += s[j + 1] - '0';
			else ans -= s[j + 1] - '0';
		}
		if (ans == 7)
		{
			cout << s[0];
			rep(j, 0, 2)
			{
				if (i >> j & 1)cout << "+";
				else cout << "-";
				
				cout << s[j + 1];
			}
			cout << "=7" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
    long long int h,w;
    cin>>h>>w;

    if(h%3==0 || w%3==0){
        cout<<0<<endl;
        return 0;
    }

    long long int Max,Min;
    long long int maxS,minS;
    long long int S=h*w;

    Min=min(h,w);
    Max=max(h,w);

    long long int ans;
    long long int re=pow(10,17);
    long long int S1,S2,S3;

    for(long long int i=1;i<Max;i++){
        S1 = Min*i;
        if((S-S1)%2==0){
            S2 = (S-S1)/2;
            S3 = (S-S1)/2;
            maxS = max(max(S1,S2),S3);
            minS = min(min(S1,S2),S3);

            ans = abs(maxS - minS);
            if(ans<re)re = ans;
        }else{
            S2 = (Max-i)*(Min/2);
            S3 = S2 + (Max-i);
            maxS = max(max(S1,S2),S3);
            minS = min(min(S1,S2),S3);

            ans=abs(maxS-minS);
            if(ans<re)re = ans;
        }
    }


    for(long long int i=1;i<Min;i++){
        S1 = Max*i;
        if((S-S1)%2==0){
            S2 = (S-S1)/2;
            S3 = (S-S1)/2;
            maxS = max(max(S1,S2),S3);
            minS = min(min(S1,S2),S3);

            ans = abs(maxS - minS);
            if(ans<re)re = ans;
        }else{
            S2 = (Min-i)*(Max/2);
            S3 = S2 + (Min-i);
            maxS = max(max(S1,S2),S3);
            minS = min(min(S1,S2),S3);

            ans=abs(maxS-minS);
            if(ans<re)re = ans;
        }
    }

    cout<<re<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

S = input()
T = input()
N = len(S)

SD = defaultdict(set)
TD = defaultdict(set)

for i in range(N):
  SD[S[i]].add(T[i])
  TD[T[i]].add(S[i])

cnt = 0

for i in SD.values():
  cnt = max(cnt, len(i))

for i in TD.values():
  cnt = max(cnt, len(i))

if cnt >= 2:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 9648
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    A.sort(reverse = True)
    ans = 0
    for i in range(N):
        ans += A[2*i+1]
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 41916
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;




int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long long ans = 0;
    int a, b, c, n;
    cin >> a >> b >> c >> n;
    for (int i = 0; i <= n; i += a)
        for (int j = i; j <= n; j += b)
            if ((n - j) % c == 0) ++ans;
    cout << ans << '\n';
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    uint64_t a, b, x;
    cin >> a >> b >> x;

    uint64_t fb = b / x + 1;
    uint64_t fa = (a == 0 ? 0 : (a - 1) / x + 1);
    cout << fb - fa << endl;

    return 0;
}

Measured memory_bytes: 888
n,x,y = map(int,input().split())
d = [0]*(n)
for i in range(1,n):
    for j in range(i+1,n+1):
        c = min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
        d[c] += 1
for i in range(1,n):
    print(d[i])

Measured memory_bytes: 9192
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextStr()

	if N[0] == '9' || N[1] == '9' {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
	wtr.Flush()
}


Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cassert>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
//typedef pair<int, int> pii;
using pll = pair<ll, ll>;
using pii = pair<short, short>;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using ti3 = tuple<int, int, int>;
using vti3 = vector<ti3>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<(a);i++)
#define rep1(i,a) for(int i=1;i<=(a);i++)
#pragma warning(disable:4996)
//#define INF 1000000000000000.0
int main() {
    int n;
    while (cin >> n, n) {
        vector<char> op{ '+' };
        vector<int> num{ 0 };
        int nest = 0;
        rep(i, n) {
            string buf;
            cin >> buf;
            int next=count(ALL(buf), '.');
            while (nest > next) {
                if(op[nest-1]=='+')num[nest-1] += num[nest];
                else num[nest - 1] *= num[nest];
                nest--;
                num.pop_back();
                op.pop_back();
            }
            if (buf[next] == '+') {
                op.push_back('+');
                num.push_back(0);
            }
            else if (buf[next] == '*') {
                op.push_back('*');
                num.push_back(1);
            }
            else if (op[next] == '+')num[next] += buf[next] - '0';
            else num[next] *= buf[next] - '0';
            nest = next;
        }
        while (nest > 0) {
            if (op[nest - 1] == '+')num[nest - 1] += num[nest];
            else num[nest - 1] *= num[nest];
            nest--;
            num.pop_back();
        }
        cout << num[0] << endl;
    }
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i<n; i++)
#define per(i,a,n) for (int i = n-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define all(now) (now).begin(),(now).end()
#define fi first
#define se second
#define SZ(now) ((int)(now).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod = 1000000007;
inline int read(int &n){char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}return n = x*f;}
ll powmod(ll a,ll b,ll mod) {ll res = 1; a%=mod; assert(b>=0); for(;b; b>>=1){if(b&1)res = res*a%mod; a = a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N = 1e2+7;
int T,n,m;
VI X,Y,H;
int main()
{
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    rep(i,0,n){
        int x, y, h;
        cin >> x >> y >> h;
        X.pb(x);
        Y.pb(y);
        H.pb(h);
    }
    rep(x,0,101){
        rep(y,0,101){
            // int height = -1;

            // bool flag = 0;
            // rep(k,0,n){
            //     if(H[k]==0)
            //         continue;
            //     if(height==-1)
            //         height = H[k] + abs(X[k] - x) + abs(Y[k] - y);
            //     else if(height != H[k] + abs(X[k] - x) + abs(Y[k] - y))
            //         flag = 1;
            // }
            // rep(k,0,n){
            //     if(H[k]==0 && height-abs(X[k]-x)-(Y[k]-y) > 0)
            //         flag = 1;
            // }

            int height=-1;
			bool flag=0;
			for(int i=0;i<n;i++){
				if(H[i]==0)
					continue;
				if(height==-1)
					height=H[i]+abs(X[i]-x)+abs(Y[i]-y);
				else{
					if(height!=H[i]+abs(X[i]-x)+abs(Y[i]-y))
						flag=1;
				}
			}
			for(int i=0;i<n;i++){
				if(H[i]==0){
					if(height-abs(X[i]-x)-abs(Y[i]-y)>0)
						flag=1;
				}
			}

            if(!flag){
                // printf("%d %d %lld\n", i, j, height);
				cout<<x<<" "<<y<<" "<<height<<endl;
                return 0;
            }
        }
    }
    return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll A, B, C; cin >> A >> B >> C;

	if ((A&1) && (B&1) && (C&1)) {
		vll arr = {A, B, C};
		sort(arr.begin(), arr.end());
		ll X = arr[0] * arr[1];
		print((arr[2] - arr[2]/2) * X - arr[2]/2 * X);
	} else {
		print(0);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define boost  ios_base::sync_with_stdio(0);
#define N 1000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define fo(i,a,b) for(i = a; i < b; i++)
#define foe(i, a,b) for(i = a; i <= b; i++)
#define tc long long int t; cin >> t; while(t--)
#define vect vector <ll>
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll>>

ll lcs(string s, string s2, ll n, ll n2){
	if(n == 0 || n2 == 0){
		return 0;
	}
	if(s[n] == s2[n2])
		return 1+lcs(s,s2,n-1,n2-1);
	else
		return max(lcs(s,s2,n-1,n2),lcs(s,s2,n,n2-1));
}
string lcsdp(string s, string s2, ll n, ll n2){
	ll dp[n+1][n2+1];
	ll i,j;
	foe(i,0,n){
		foe(j,0,n2){
			if(i == 0 || j == 0)
				dp[i][j] = 0;
			else if(s[i-1] == s2[j-1]){
				dp[i][j] = 1+dp[i-1][j-1];
			}
			else
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);

		}
	}
	string res="";
   	i=n,j=n2;
	while (i > 0 && j > 0)
	{
	    if (s[i-1] == s2[j-1]){
		    res+=s[i-1]; // Put current character in result
		    i--; j--;
		}
		      // If not same, then find the larger of two and
		      // go in the direction of larger value
		else if (dp[i-1][j] > dp[i][j-1]){
		    i--;
		}
		else{
		    j--;
		}
	}
	reverse(res.begin(),res.end());
	return res;
}
int main(){
	boost;
	string str1,str2;
	ll n,n2;
	cin >> str1>> str2;
	n = str1.length();
	n2 = str2.length();
	cout << lcsdp(str1,str2,n,n2) <<endl;

	
	return 0;
}


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

#define int long long
#define endl '\n'

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n, k; cin >> n >> k;
    priority_queue<int> q;
    for (int i = 0, x; i < n; i++) {
        cin >> x;
        q.push(x);
    }
    while (k--) {
        q.push(q.top() / 2);
        q.pop();
    }
    int ans = 0;
    while (q.size())
        ans += q.top(), q.pop();
    cout << ans;
}

Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
  long long  n,power=1;
  cin>>n;
  long long A=pow(10,9)+7;
  for(int i=1;i<n+1;i++){
    power=power*i%A;
  }
 
  cout<<power<<endl;
  return 0;
}

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
l = inputILL(N-1)

dic = dict([(i,[]) for i in range(1,N+1)])

for i in l:
  dic[i[0]].append(i[1])
  dic[i[1]].append(i[0])


d = [[INF,i] for i in range(N+1)]
d[1][0] = 0
q = deque([1])

while q:
  x = q.popleft()
  nd = d[x][0]+1
  for nx in dic[x]:
    if nd < d[nx][0]:
      d[nx][0] = nd
      q.append(nx)


d_ = sorted(d[1:],reverse=True)
n = [1 for _ in range(N+1)]

for item in d_:
  depth = item[0]
  i = item[1]
  for j in dic[i]:
    if d[j][0] == depth+1:
      n[i] += n[j]

ans = (pow(2,N,MOD)-N*pow(2,N-1,MOD)-1)%MOD
for i in range(2,N+1):
  ans = (ans + (pow(2,n[i],MOD)-1) * (pow(2,N-n[i],MOD)-1)) % MOD

print((ans*inv(pow(2,N,MOD)))%MOD)

Measured memory_bytes: 132820
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e+9+7;
const ll MAX_V=2900;
ll N,K;
ll fanc[MAX_V],inv[MAX_V],finv[MAX_V];
void COMinit(){
  fanc[0]=fanc[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll i=2;i<MAX_V;i++){
    fanc[i]=fanc[i-1]*i%MOD;
    inv[i]=MOD-(MOD/i)*inv[MOD%i]%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
ll COM(ll a,ll b){
  if(a<b)return 0;
  if(a<0||b<0)return 0;
  return (fanc[a]*finv[a-b]%MOD)*finv[b]%MOD;
}
int main(){
  ll N,K;
  cin>>N>>K;
  COMinit();
  N-=K;
  for(ll i=1;i<=K;i++){
		ll ans = 0;
		ans = COM(N+1,i);
		// b1 + b2 + ... + bi = k;
		ans *= COM(K-1,i-1);
		ans %= MOD;
		cout << ans << endl;
  }
}

Measured memory_bytes: 3704
from collections import deque

H, W = map(int, input().split())
grid = [input() for _ in range(H)]

f_inf = float('inf')
ans = []
for h in range(H):
    for w in range(W):
        if grid[h][w] == "#":
            continue
        else:
            maze = [[f_inf] * W for _ in range(H)]
            sh, sw = h, w
            maze[sh][sw] = 0
            que = deque([[sh, sw]])
            while que:
                h, w = que.popleft()
                for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    next_h, next_w = h + dh, w + dw
                    if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                        continue
                    elif grid[next_h][next_w] == "#":
                        continue
                    elif grid[next_h][next_w] == ".":
                        if maze[next_h][next_w] > maze[h][w] + 1:
                            maze[next_h][next_w] = maze[h][w] + 1
                            que.append([next_h, next_w])
                            ans.append(maze[next_h][next_w])

print(max(ans))


Measured memory_bytes: 52572
// ref. https://www.youtube.com/watch?v=bHzohtVsG0Q&feature=youtu.be

#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 fr first
#define sc second
#define mp make_pair
#define pb push_back

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

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

ll n;
// s .. created string, mx .. max character in s
void dfs(string s, char mx) {
  if (s.size() == n) {
    cout << s << endl;
  } else {
    for (char c = 'a'; c <= mx+1; ++c) {
      string t = s;
      t += c;
      dfs(t, max(c, mx));
    }
  }
}

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

  cin >> n;
  dfs("a", 'a');
}


Measured memory_bytes: 1536
H,W,K = map(int,input().split())
maze = [list(input()) for i in range(H)]

pattern = []
for i in range(2 ** (H+W)):
    tmp = [False] * (H+W)
    for j in range(H+W):
        if i >> j & 1:
            tmp[j] = True
    pattern.append(tmp)

import copy

ans = 0
for i in range(len(pattern)):
    copm = copy.deepcopy(maze)
    loop = 1
    for j in range(H+W):
        if loop <= H:
            loop += 1
            if pattern[i][j]:
                copm[j] = ['*' for i in range(W)]
        else:
            if pattern[i][j]:
                for k in range(len(maze)):
                    copm[k][j-H] = '*'
    k = 0
    for i in range(H):
        k += copm[i].count('#')
    if k == K:
        ans += 1

print(ans)

Measured memory_bytes: 9784
# 最大値はひとつだけ、自分自身が最大値の場合を除く

n = int(input())
max_a, max_ai = 0, 0
arr = []
for i in range(n):
    a = int(input())
    arr.append(a)
    if a > max_a:
        max_a = a
        max_ai = i + 1
arr = sorted(arr)

for i in range(n):
    if max_ai == i + 1:
        print(arr[-2])
    else:
        print(max_a)



Measured memory_bytes: 13404
import heapq
N,M = map(int,input().split())
ls = []
h = []
ans = 0
for n in range(N):
    ls.append(list(map(int,input().split())))
ls = sorted(ls,key=lambda ls:ls[0],reverse=False)
n = 0
for m in range(1,M+1):
    #print (m)
    while(n<N and ls[n][0]<=m ):
        heapq.heappush(h, -ls[n][1])
        n+=1
    if len(h)>0:
        ans -= heapq.heappop(h)
        # print (m,ans)
print (ans)

Measured memory_bytes: 31916
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

a, b = ZIP(M)

a_cnt, b_cnt = Counter(a), Counter(b)

for i in range(1, N+1):
	if (a_cnt[i]+b_cnt[i])%2 != 0:
		print("NO")
		break
else:
	print("YES")

Measured memory_bytes: 62696
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vint a,b,p;
	const int CON=30000;
	for(int i=0;i<N;i++){
		int c;
		cin>>c;
		p.pb(c);
	}
	for(int i=0;i<N;i++){
		a.pb((i+1)*CON);
		b.pb((N-i)*CON);
	}
	for(int i=0;i<N;i++){
		a[p[i]-1]+=i;
	}
	for(int i=0;i<N-1;i++)
		cout<<a[i]<<" ";
	cout<<a.back()<<endl;
	for(int i=0;i<N-1;i++)
		cout<<b[i]<<" ";
	cout<<b.back()<<endl;
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
manzoku = 0

for i in range(N):
    manzoku += B[A[i]-1]
    if i < N-1 and A[i+1] == A[i]+1:
        manzoku += C[A[i]-1]
print(manzoku)

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m, n) {
    vector<int> t(m), s(m), d(m);
    for (int i = 0; i < m; ++i) {
      cin >> t[i] >> s[i] >> d[i];
      --s[i], --d[i];
    }
    vector<int> idx(m);
    iota(begin(idx), end(idx), 0);
    sort(begin(idx), end(idx), [&](int i, int j) {
      return t[i] < t[j];
    });
    vector<int> infected(n);
    infected[0] = 1;
    for (int i : idx) {
      if (infected[s[i]]) {
        infected[d[i]] = 1;
      }
    }
    int res = accumulate(begin(infected), end(infected), 0);
    cout << res << '\n';
  }
}



Measured memory_bytes: 3400
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1000000000
typedef long long  ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a /g* b ;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
int  GetDigit(T num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};


int main()
{
    int N,K;
    cin >> N>>K;
    int a[N];
    REP(i,0,N){
        cin >> a[i];
    }
    bool dp[K + 1];
    REP(i, 0, K + 1)
    dp[i] = false;

    for(int i = 1; i <= K; i++){
		for(int j = 0; j < N; j++){
			if(i >= a[j]){
				dp[i] |= !dp[i-a[j]];
			}
		}
	}
    cout << (dp[K] ? "First" : "Second") << endl;
}

Measured memory_bytes: 512
x = int(input())

maxi = int(1e5) + 100
prime = [True for _ in range(maxi + 1)]

for num in range(3, maxi + 1):
    i = 2 * num
    while i <= maxi:
        prime[i] = False
        i += num

while True:
    if prime[x] is True:
        print(x)
        exit(0)
    else:
        x += 1



Measured memory_bytes: 44988
n = int(input())
mi = []
pl = []

l = list(map(int,input().split()))
for i in l:
    if i >= 0:
        pl.append(i)
    else:
        mi.append(i)
pl.sort()
mi.sort()
if n == 2:
    print(max(l)-min(l))
    print(max(l),min(l))
    exit()

if pl and mi:
    ans = []
    np = pl[-1]
    for i in range(1,len(mi)):
        ans.append([np,mi[i]])
        np -= mi[i]
    nm = mi[0]
    for i in range(len(pl)-1):
        ans.append([nm,pl[i]])
        nm -= pl[i]
    ans.append([np,nm])
    print(np-nm)
    for i in ans:
        print(*i)
elif pl:
    ans = []
    ans.append([pl[0],pl[1]])
    nm = pl[0]-pl[1]
    for i in range(2,len(pl)-1):
        ans.append([nm,pl[i]])
        nm -= pl[i]
    ans.append([pl[-1],nm])
    print(pl[-1]-nm)
    for i in ans:
        print(*i)
else:
    ans = []
    ans.append([mi[-1],mi[-2]])
    np = mi[-1]-mi[-2]
    for i in range(1,len(mi)-2):
        ans.append([np,mi[i]])
        np -= mi[i]
    ans.append([np,mi[0]])
    print(np-mi[0])
    for i in ans:
        print(*i)


Measured memory_bytes: 25932