akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const int N = 1e4 + 5;
typedef long long ll;

int n, m, x;

int main() {
	cin>>n>>m;
	for(int i = 1; i <= m; i++) {
		cin>>x;
		n -= x;
	}
	if(n >= 0) cout<<n<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>

#define INFTY 150

int G[110][110] = { 0 };
int color[110] = { 0 };

int Distance[110];

int BFSQ[110];
int sp = 0, ep = 1;

void InQ(int p) {
	BFSQ[ep] = p;
	ep = (ep + 1) % 110;
}

int DeQ(void) {
	if (ep - sp == 1)return -1;
	sp = (sp + 1) % 110;
	return BFSQ[sp];

}


int main() {
	int N;
	int k, v;
	int u;
	scanf("%d", &N);
	for (int u = 1; u <= N; u++) {
		scanf("%d", &k);
		scanf("%d", &k);
		for (int i = 0; i < k; i++) {
			scanf("%d", &v);
			G[u][v] = 1;
		}
	}
	for (int i = 1; i <= N; i++) {
		Distance[i] = INFTY;
	}
	Distance[1] = 0;
	InQ(1);
	while (1) {
		u = DeQ();
		if (u == -1)break;
		for (int v = 1; v <= N; v++) {
			if (G[u][v] == 1&&color[v]==0) {
				Distance[v] = Distance[u] + 1;
				InQ(v);
				color[v] = 1;
			}
		}
		color[u] = 2;
	}

	for (int i = 1; i <= N; i++) {
		if(Distance[i]!=INFTY)
		printf("%d %d\n", i, Distance[i]);
		else printf("%d -1\n", i);

	}

	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int lcs(string a, string b)
{
	vector<vector<int> > dp(1001, vector<int>(1001));
	for (int i = 0; i < a.size(); ++i)
	{
		for (int j = 0; j < b.size(); ++j)
		{
			if (a[i] == b[j])
			{
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			else
			{
				dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
			}
		}
	}
	return(dp[a.size()][b.size()]);
}

void solve()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i)
	{
		string a, b;
		cin >> a >> b;
		cout << lcs(a, b) << endl;
	}
}

int main()
{
	solve();
	return(0);
}



Measured memory_bytes: 6896
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

string s;
int k;

void input(){
    cin >> s;
    cin >> k;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int n = s.size();
    vector<string> ans;
    for(int i=1; i<=min(n,k); i++){
        for(int j=0;j<n-i+1;j++){
            ans.push_back(s.substr(j,i));
        }
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    cout << ans[k-1] << endl;
    return 0;
}

Measured memory_bytes: 1660
n = int(input())
station = [tuple(map(int, input().split())) for _ in range(n-1)]

for i in range(n):
    res = 0
    for j in range(i, n-1):
        c, s, f = station[j]
        res += max(s - res, (res+f-1)//f*f - res) + c
    print(res)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define pll  pair<ll,ll>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1000000000+7;
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
ll factor(ll n){
    vll ans;
	if(n==2)ans.pb(2);
	else
    {for(ll i=2;i*i<=n;i++){if(n%i==0 && n%i!=i){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}ans.pb(n);}
    return ans.sz+1;
}
ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i; 
    return res; } 
  
ll nCr(ll n, ll r){ return fact(n) / (fact(r) * fact(n - r)); } 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 

ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

void solve()
{
	ll h,w;
	cin>>h>>w;
	if(h%3==0 || w%3==0)
	{
		cout<<0;
		return;
	}
	
	else
	{
		ll ans=min(h,w);
		if(h>=2)
		{
        	ll p=h/2,q=h-p;
        	for(ll i=0;i<w;i++)
        	{
            	ll a=p*i,b=q*i,c=(w-i)*h;
            	ans=min(ans,(max({a,b,c})-min({a,b,c})));
        }
    }
    	if(w>=2)
    	{
        	ll p=w/2,q=w-p;
        	for(ll i=0;i<h;i++)
        	{
            	ll a=p*i,b=q*i,c=(h-i)*w;
            	ans=min(ans,(max({a,b,c})-min({a,b,c})));
        	}
    	}
    cout<<ans<<endl;
	}
    return;
}            
int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}


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

const int MAXN = 100055;

int A[MAXN][3], B[MAXN][3];

int N;

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i <= N; i++) {
		for(int j = 0; j < 3; j++)
			cin >> A[i][j];
		for(int j = 0; j < 3; j++) {
			int &ret = B[i][j];
			for(int k = 0, t; k < 3; k++) if(j != k) {
				t = B[i-1][k] + A[i][j];
				if(ret < t) ret = t;
			}
		}
	}

	cout << *max_element(B[N], B[N]+3) << endl;
	return 0;
}

Measured memory_bytes: 2560
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
ans=0

for i in range(n-1):
	if a*(x[i+1] - x[i]) <= b:
		ans += a*(x[i+1] - x[i])
	else:
		ans += b
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
    ll n,m;cin>>n>>m;
    vl h(n);rep(i,n)cin>>h[i];
    vl a(m),b(m);rep(i,m){cin>>a[i]>>b[i];a[i]--;b[i]--;}
    ll sum=0;

    vl ans(n);rep(i,n)ans[i]=1;

    rep(i,m){
        if(h[a[i]]<h[b[i]])ans[a[i]]=0;
        if(h[a[i]]>h[b[i]])ans[b[i]]=0;
        if(h[a[i]]==h[b[i]]){ans[a[i]]=0;ans[b[i]]=0;}
        
       }



        rep(i,n)if(ans[i])sum++;

        cout<<sum<<endl;

}

Measured memory_bytes: 6376
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
int main(){
	/*
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	#endif
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int l=0;
	for(int i=1;i<n-1;i++){
		vector<int> v;
		for(int j=i-1;j<=i+1;j++) v.push_back(a[j]);
		sort(v.begin(),v.end());
		if(v[1]==a[i]) l++;
	}
	cout<<l;
}

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



int main() {
    ios::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
    cout<<setprecision(32);

  	long long n;
  	cin>>n;
  	long long ans = n-1;
  	for(long long i = 1; i * i <= n; i++) {
  		if(n % i == 0) ans = min(ans, i + n/i - 2); 
  		
  	}


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



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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    
    ll n;
    cin>>n;
    cout<<3*(n*n);
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    if (s.length() % 2 == 0 ^ s[0] == s[s.length() - 1]) {
        printf("Second\n");
    } else {
        printf("First\n");
    }
    return 0;
}



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

int main() {
    ll N, K, d, read, count = 0;
    cin >> N >> K;
    vec A(N);

    REP(i, K) {
        cin >> d;
        REP(i, d) {
            cin >> read;
            A[read - 1] = 1;
        }
    }

    REP(i, N){
        if(A[i] != 1)
            count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
	int A, B;
	int a, b, c, i;
	scanf("%d", &a);
	for (i = 1; i <= 9; i++)
		for (b = 1; b <= 9; b++)
			if (a == i * b)
			{printf("Yes\n"); return 0;
              }
				printf("No");
  return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int k = scanner.nextInt();
		List<Pair>[] list = new List[n];
		for (int i = 0; i < n; i++)
			list[i] = new ArrayList<Pair>();
		while (m-- > 0) {
			int a = scanner.nextInt() - 1;
			int b = scanner.nextInt() - 1;
			int l = scanner.nextInt();
			list[a].add(new Pair(b, l));
			list[b].add(new Pair(a, l));
		}
		int[] dp = new int[n];
		Arrays.fill(dp, 1 << 25);
		PriorityQueue<Pair> pq = new PriorityQueue<Main.Pair>();
		for (int i = 0; i < k; i++) {
			int s = scanner.nextInt() - 1;
			dp[s] = 0;
			pq.offer(new Pair(0, s));
		}
		while (!pq.isEmpty()) {
			Pair pair = pq.poll();
			int f = pair.f;
			int s = pair.s;
			for (Pair p : list[s]) {
				if (dp[p.f] <= f + p.s)
					continue;
				dp[p.f] = f + p.s;
				pq.offer(new Pair(f + p.s, p.f));
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++)
			for (Pair p : list[i])
				ans = Math.max(
						ans,
						Math.max(dp[i], dp[p.f])
								+ (p.s - Math.abs(dp[i] - dp[p.f]) + 1) / 2);
		System.out.println(ans);
	}

	class Pair implements Comparable<Pair> {
		int f, s;

		public Pair(int f, int s) {
			super();
			this.f = f;
			this.s = s;
		}

		@Override
		public String toString() {
			return "Pair [f=" + f + ", s=" + s + "]";
		}

		@Override
		public int compareTo(Pair o) {
			return f - o.f;
		}

	}
}

Measured memory_bytes: 109076
#include <iostream>
#include <string>
using namespace std;
int main(){
    int a = 0;
    string s;
    cin >> a >> s;

    if (a >= 3200)
    {
        cout << s << endl;
    }else
    {
        cout << "red" <<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, M, H[111111], A[111111], B[111111];

  std::cin >> N >> M;

  for (int i = 0; i < N; i ++)
    std::cin >> H[i];

  std::vector<std::vector<int>> G(N);

  for (int i = 0; i < M; i ++) {
    std::cin >> A[i] >> B[i];

    A[i] --;
    B[i] --;

    G[A[i]].push_back(B[i]);
    G[B[i]].push_back(A[i]);
  }

  int C = 0;

  for (int i = 0; i < N; i ++) {
    if (G[i].empty()) {
      C ++;
    }
    else {
      int c = 0;

      for (const auto& x : G[i])
        if (H[i] > H[x]) {
          c ++;
        }
      
      if (c == G[i].size())
        C ++;
    }
  }

  std::cout << C << std::endl;

  return 0;
}


Measured memory_bytes: 9532
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
        long[] a = new long[n];
        long sum=0;
        int cnt=0;
        int zero=0;
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
            if(a[i]<0) cnt++;
            if(a[i]==0) zero++;
            sum+=Math.abs(a[i]);
        }
        long ans=0;
        for(int i=0;i<n;i++){
            // out.println(ans);
            ans=Math.max(ans,sum-2*Math.abs(a[i]));
        }
        if(cnt%2==0) ans=sum;
        if(cnt%2==1&&zero>0) ans=sum;
        out.println(ans);
	}
}

// int n = sc.nextInt();
// int[] array = new int[n];
// String s = sc.next();
// s.charAt(i)
// out.println();
// Math.min()


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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 0; i < s.length() - 2; i++)
  {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int x,d,rem,y;
    cin>>x>>d>>rem;
    ll ans=0;
    for (int i=0;i<x;i++){
        cin>>y;
        ans+=d/y+(d%y!=0);
    }
    cout<<ans+rem<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

vector<int> g[5010];
int dp[5010];

void solve(ll N, vector<ll> A, vector<ll> a, vector<ll> b) {
  REP(i,N-1) {
    int s = a[i] - 1, t = b[i] - 1;
    g[s].push_back(t);
    g[t].push_back(s);
  }
  vector<pair<ll,int>> vec;
  REP(i,N) vec.emplace_back(A[i], i);
  sort(ALL(vec));
  vector<vector<int>> ord;
  vector<int> tmp;
  REP(i,N) {
    tmp.push_back(vec[i].second);
    if (i == N - 1 || vec[i].first != vec[i+1].first) {
      ord.push_back(tmp);
      tmp.clear();
    }
  }
  for (auto v: ord) {
    vector<int> upd;
    for (int i: v) {
      bool win = false;
      for (int j: g[i]) {
        if (dp[j]) win = true;
      }
      if (!win) upd.push_back(i);
    }
    for (int i: upd) dp[i] = 1;
  }
  vector<int> res;
  REP(i,N) if (!dp[i]) res.push_back(i);
  REP(i,res.size()) cout << res[i] + 1 << " \n"[i == len(res) - 1];
  if (res.empty()) cout << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	vector<ll> A(N-1+1);
	vector<ll> a((N-1)-1+1);
	vector<ll> b((N-1)-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &A[i]);
	}
	for (int i = 0 ; i <= (N-1)-1 ; i++) {
	  scanf("%lld", &a[i]);
	  scanf("%lld", &b[i]);
	}
	solve(N, A, a, b);
	return 0;
}


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

int main() {
  
 string s;
 string t;
 int A;
 int B;
 string u;
 
 cin >> s >> t ;
 cin >> A >> B ;
 cin >> u;
 
 if ( s == u){
     
 cout <<A-1 <<" " <<B <<endl;
 }
 if ( t == u ){
     
 cout <<A<<" "<< B-1 << endl;
 }
 
    
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    int n;
    cin >> n;
    cout << pow(n, 3) << endl;
    return 0;
}

Measured memory_bytes: 4140
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   string S;
   cin >> S;
   bool flag1 = true, flag2 = false;
   if(S[0] == 'A'){
      flag1 = false;
   }
   int cnt_topper_c = 0;
   for(int i=2; i < S.size()-1; i++){
      if(S[i] == 'C'){
         cnt_topper_c++;
      }
   }
   for(int i=1; i < S.size(); i++){
      if(not(S[i] == 'C')){
         if(isupper(S[i])){
            flag2 = true;
            break;
         }
      }
   }
   if(cnt_topper_c != 1 or flag1 or flag2){
      cout << "WA" << endl;
   }
   else{
      cout << "AC" << endl;
   }

return 0;
}

Measured memory_bytes: 504
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int n, m; cin >> n >> m;
	int d[31][31], c[501][31] = {};
	rep(i, m) {
		rep(j, m) {
			cin >> d[i][j];
		}
	}
	rep(i, n) {
		rep(j, n) {
			int p; cin >> p; p--;
			c[(i + j) % 3][p]++;
		}
	}
	ll ans = INF;
	rep(i, m) {
		rep(j, m) {
			rep(k, m) {
				if (i == j) continue;
				if (k == j) continue;
				if (i == k) continue;
				ll sub = 0;
				rep(l, m) sub += d[l][i] * c[0][l];
				rep(l, m) sub += d[l][j] * c[1][l];
				rep(l, m) sub += d[l][k] * c[2][l];
				ans = min(ans, sub);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n, k;
vector<pair<int, int>> lr;
ll M = 998244353;
int main() {
    cin >> n >> k;
    lr.resize(k);
    rep(i, k) { cin >> lr[i].first >> lr[i].second; }
    vector<ll> v(n + 2, 0);
    v[1] = 1;
    v[2] = -1;
    reps(i, n - 1) {
        ll cur = v[i];
        rep(j, k) {
            if (i + lr[j].first <= n) {
                v[i + lr[j].first] += cur;
                v[i + lr[j].first] %= M;
                v[min(i + lr[j].second + 1, n + 1)] -= cur;
                v[min(i + lr[j].second + 1, n + 1)] += M;
                v[min(i + lr[j].second + 1, n + 1)] %= M;
            }
        }
        v[i + 1] += v[i];
        v[i + 1] %= M;
    }
    cout << v[n] << endl;
    return 0;
}

Measured memory_bytes: 4748
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int a[1 << 17];
//100000
const int MAX_N = (1 << 17);
int nn, dat[2 * MAX_N - 1];
void init(int n_) {
	nn = 1;
	while (nn < n_)nn *= 2;
}
void update(int k, int a) {
	k += nn - 1;
	dat[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = dat[k * 2 + 1]+ dat[k * 2 + 2];
	}
}
int query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l)return 0;
	if (a <= l && r <= b)return dat[k];
	else {
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return vl+vr;
	}
}
vector<int> v[1 << 17];
int main() {
	int n; cin >> n; init(n);
	rep(i, n) {
		cin >> a[i];
		update(i, 1);
		v[a[i]].push_back(i);
	}
	ll out = 0;
	rep1(i, 100000) {
		rep(j, v[i].size()) {
			update(v[i][j], 0);
		}
		rep(j, v[i].size()) {
			out += min(query(0, v[i][j], 0, 0, nn), query(v[i][j], n, 0, 0, nn));
		}
	}
	cout << out << endl;
	return 0;
}


Measured memory_bytes: 10464
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
d=Counter(A)
t_s=sum(A)
Q=int(input())
for __ in range(Q):
    a,b=list(map(int,input().split()))
    if d[a]!=0:
        curr_c=d[a]
        t_s-=a*(curr_c)
        t_s+=b*(curr_c)
        d[b]=d.get(b,0)+curr_c
        d[a]=0
    print(t_s)


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

using namespace std;

#define fi first
#define se second

const int N = 105;
int n, a[N], sum;
pair<double, int> ans = { 1e9, n };

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }

    for (int i = 0; i < n; ++i) ans = min(ans, { abs(a[i] - 1.0 * sum / n), i } );

    cout << ans.se;

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val k = readLine()!!.toInt()
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }

    for (n in a..b) {
        if(n % k == 0) {
            println("OK")
            return
        }
    }

    println("NG")
}

Measured memory_bytes: 36344
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
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(a>b){a=b;return 1;}return 0;}
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,m;
	cin >> n;
	int sum = 0;
	int a[n], b[n];
	rep(i, n){
		cin>>a[i];
	}
	rep(i, n){
		int c;
		cin >> c;
		if(a[i] - c > 0){
			sum += a[i] - c;
		}
	}
	cout << sum << endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll T;
    cin >> T;
    rep(t, T) {
        ll N;
        cin >> N;
        vector<ll> K(N), L(N), R(N);
        ll ans = 0;
        vector<vector<ll>> F(N), S(N);
        rep(i, N) {
            cin >> K[i] >> L[i] >> R[i];
            if (L[i] > R[i]) {
                ans += R[i];
                F[K[i] - 1].push_back(L[i] - R[i]);
            } else {
                ans += L[i];
                if (K[i] == N) continue;
                S[N - K[i] - 1].push_back(R[i] - L[i]);
            }
        }
        priority_queue<ll> que1, que2;
        for (ll i = N - 1; i >= 0; i--) {
            for (ll f : F[i]) {
                que1.push(f);
            }
            if (!que1.empty()) {
                ll v = que1.top();
                que1.pop();
                ans += v;
            }
        }
        for (ll i = N - 1; i >= 0; i--) {
            for (ll s : S[i]) {
                que2.push(s);
            }
            if (!que2.empty()) {
                ll v = que2.top();
                que2.pop();
                ans += v;
            }
        }
        cout << ans << '\n';
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

using namespace std;

typedef pair<int,int> PII;
map<int,PII> a;
int s[100100];
int b[100100];

int main()
{
    int h,w,d,i,m,j,l,r,q;
    cin >> h >> w >> d;
    for(i = 0; i < h; i ++)
    {
        for(j = 0; j < w; j ++)
        {
            cin >> m;
            a[m] = {i,j};
        }
    }
    for(i = d; i <= h*w; i ++)
    {
        s[i] = s[i-d] + abs(a[i-d].first - a[i].first);
        s[i] += abs(a[i-d].second - a[i].second);
    }
    cin >> q;
    for(i = 0; i < q; i ++)
    {
        cin >> l >> r;
        b[i] += s[r] -s[l];
    }
    for(i = 0; i < q; i ++)
    {
        cout << b[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 7552
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
    }

    println!("{}", n/3);

}


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

int N;
int M[205][205];
long long ans;

int main() {
  for(int i = 1; i <= 200; i++) {
    for(int j = 1; j <= 200; j++) {
      M[i][j] = __gcd(i, j);
    }
  }
  cin >> N;
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= N; j++) {
      for(int k = 1; k <= N; k++) {
        ans += M[k][M[i][j]];
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
int main(){
    int n,A[200001],ans=1;
    cin>>n;
    rep(i,n) cin>>A[i];
    rep(i,n-1) if(A[i]>=A[i+1]) ans++;
    cout<<ans<<"\n"<<n<<"\n";
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if(A == 1) A = 14;
  if(B == 1) B = 14;
  if(A < B) cout << "Bob" << endl;
  else if(B < A) cout << "Alice" << endl;
  else cout << "Draw" << endl;
}

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

int32_t main() {
	// your code goes here
	int n;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	int mx = v[0];
	int ans = 0 ;
	for(int i=1;i<n;i++){
		if(v[i]<mx){
			ans+=mx-v[i];
		}
		else{
			mx = v[i];
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4852
#include<iostream>
#include<algorithm>
using namespace std;
int dp[1001][1001];
string s,t;
int n,m,a,ans;
int main(){
  cin>>a;
  for(int b=0;b<a;b++){
    cin>>s>>t;
    for(int i=0;i<=1000;i++)
      for(int j=0;j<=1000;j++)
	dp[i][j]=0;
    m=s.size();
    n=t.size();
    ans=0;
    for(int i=1;i<=m;i++){
      for(int j=1;j<=n;j++){
	if(s[i-1]==t[j-1]){
	  dp[i][j]=dp[i-1][j-1]+1;
	}else{
	  dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}
      }
    }  
    cout<<dp[m][n]<<endl;
  }
  return 0;
}


Measured memory_bytes: 7104
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    //int k,i,j,tep,x,a[170],m;
    char a[22];
    gets(a);
     int l=strlen(a);
     while(l--)
        cout<<a[l];
    cout<<endl;
return 0;
}

Measured memory_bytes: 1116
#include <stdio.h>

struct queue{
  int first;
  int last;
  int arr[100];
};

void enq(int input, struct queue *que){
  que->arr[(que->last)++] = input;
  return;
}

int deq(struct queue *que){
  return que->arr[(que->first)++];
}

int empty_q(struct queue *que){
  if(que->first == que->last) return 1;
  else return 0;
}

void init_q(struct queue *que){
  que->first = 0;
  que->last = 0;
  for(int i = 0; i < 100; i++) que->arr[i] = 0;
}

int
main(int argc, char *argv[])
{
  int n, m, a[51], b[51], g[51][51], ans = 0;
  scanf("%d %d", &n, &m);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      g[i][j] = 0;
    }
  }
  for(int i = 0; i < m; i++){
    scanf("%d %d", &a[i], &b[i]);
    g[a[i] - 1][b[i] - 1] = 1;
    g[b[i] - 1][a[i] - 1] = 1;
  }

  struct queue que;
  int x; int visitedf[50], visiteds[50];

  for(int i = 0; i < m; i++){
    g[a[i] - 1][b[i] - 1] = 0;
    g[b[i] - 1][a[i] - 1] = 0;
  

    for(int j = 0; j < n; j++){
      visitedf[j] = 0;
      visiteds[j] = 0;
    }
    init_q(&que);
    enq(a[i] - 1, &que);
    while(empty_q(&que) == 0){
      x = deq(&que);
      visitedf[x] = 1;
      for(int j = 0; j < n; j++){
	if(g[x][j] == 1 && visitedf[j] == 0){
	  enq(j, &que);
	  visitedf[j] = 1;
	}
      }
    }
    
    init_q(&que);
    enq(b[i] - 1, &que);
    while(empty_q(&que) == 0){
      x = deq(&que);
      visiteds[x] = 1;
      for(int j = 0; j < n; j++){
	if(g[x][j] == 1 && visiteds[j] == 0){
	  enq(j, &que);
	  visiteds[j] = 1;
	}
      }
    }

    for(int j = 0; j < n; j++){
      if(visitedf[j] + visiteds[j]  > 1) break;
      else if(j == n - 1) ans++;
    }

    g[a[i] - 1][b[i] - 1] = 1;
    g[b[i] - 1][a[i] - 1] = 1;
  }

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

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

template<class T>
struct SegmentTree {
    int size;
    vector<T> data;
    function<T(T,T)> merger;
    T ident;
    SegmentTree(int n, function<T(T, T)> merge_func, T identity_element) : merger(merge_func), ident(identity_element) {
        size = 1;
        while (size < n) size <<= 1;
        data.resize(size * 2, ident);
    }
    void update(int i, T x) {
        i += size - 1;
        data[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = merger(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }
    T query(int wishL, int wishR, int watchL = 0, int watchR = -1, int k = 0) {
        if(watchR == -1) watchR = size;
        if(watchR <= wishL || wishR <= watchL) return ident;
        if(wishL <= watchL && watchR <= wishR) return data[k];
        T ld = query(wishL, wishR, watchL, (watchL + watchR) / 2, k * 2 + 1);
        T rd = query(wishL, wishR, (watchL + watchR) / 2, watchR, k * 2 + 2);
        return merger(ld, rd);
    }
};
signed main() {
    int n,q;
    cin>>n>>q;
    SegmentTree<int> rmq(n, [&](int a,int b) { return min(a, b); }, (1LL<<31)-1);
    while(q--) {
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0) rmq.update(x,y);
        else {
            int mn=rmq.query(x,y+1);
            cout<<mn<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4928
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll D, T, S;
    cin >> D >> T >> S;
    cout << (D <= T * S ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

void swap(int *, int *);

int selectionSort(int [], int);

void printArray(int [], int);

int main()
{
    int n, i, count, arr[100];
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", arr + i);
    }
    count = selectionSort(arr, n);
    printArray(arr, n);
    printf("%d\n", count);
    return 0;
}

void swap(int *ap, int *bp)
{
    int tmp;
    tmp = *ap;
    *ap = *bp;
    *bp = tmp;
}

int selectionSort(int arr[], int n)
{
    int i, j, min, count = 0;
    for (i = 0; i < n; i++) {
	min = i;
        for (j = i + 1; j < n; j++) {
	    if (arr[j] < arr[min]) {
		min = j;
	    }
	}
	swap(&(arr[i]), &(arr[min]));
	if (i != min)
	    count++;
    }
    return count;
}

void printArray(int arr[], int n)
{
    int i;
    for (i = 0; i < n; i++){
	printf("%d", arr[i]);
	if (i < n - 1) {
	    printf(" ");
        } else {
            printf("\n");
	}
    }
}



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

long fact(int n)
{
  if(n==1) return 1;
  return (n * fact(n-1)) % (1000000007);
}

int main()
{
  int n;
  cin >> n;
 
  long ans;
  ans = fact(n);
  cout << ans << endl;
  
}

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

int main(){
    int n;
    string s,t;
    cin >> n;
    cin >> s;
    for(int i=0; i<n/2; i++){
        t = t+s.at(i);
    }   
    if(s==t+t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    
}

Measured memory_bytes: 256
N = int(input())
x_list, y_list = [], []
for _ in range(N):
    x, y = map(int, input().split(" "))
    x_list.append(x)
    y_list.append(y)

vec_counts = {0: 0}
for x1, y1 in zip(x_list, y_list):
    for x2, y2 in zip(x_list, y_list):
        v = x1 - x2, y1 - y2
        if v != (0, 0):
            if v in vec_counts:
                vec_counts[v] += 1
            else:
                vec_counts[v] = 1

print(N - max(vec_counts.values()))

Measured memory_bytes: 3444
#include <stdio.h>

#define N 8
#define NOT_FREE 1
#define FREE 0

void putQueen(int);
void PrintBoard();
int num;
int BLOCK[N][N];
int col[N];
int row[N];
int dpos[15];
int dneg[15];


int main(){
  int i,j,u,k;
  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d%d",&u,&k);
    BLOCK[u][k]=1;
  }

  putQueen(0);

  return 0;
}

void putQueen(int i){
int j;
  if(i==N){
    PrintBoard();
    return;
  }

  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE){
      continue;
    }
      //put queen at (i,j)
      row[i] = j;
      col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    putQueen(i+1);
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

void PrintBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(BLOCK[i][j] == 1 && row[i] != j){
        return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j){
        printf("Q");
      }
      else printf(".");
    }
      printf("\n");
  }
}

Measured memory_bytes: 572
n = int(input())
for num in range(1,n+1):
    tmp = 0
    th = set([])
    for x in range(1,int(num**0.5)+1):
        for y in range(1,x+1):
            if (4*num-2*x*y-3*(x**2+y**2)) < 0:
                break
            z = ((4*num-2*x*y-3*(x**2+y**2))**0.5-(x+y))/2
            #print('#######N=',num)
            #print(z)
            if z >= 1:
                if z.is_integer():
                    if x**2+y**2+z**2+x*y+y*z+z*x == num:
                        a = [x,y,z]
                        a.sort()
                        a = tuple(a)
                        if a not in th:
                            th.add(a)
                            if x==y and y==z:
                                #print("pl1")
                                tmp += 1
                            elif x!=y and y!=z and z!=x:
                                #print('pl3')
                                tmp += 6
                            else:
                                #print('pl2')
                                tmp += 3
    print(tmp)

Measured memory_bytes: 71276
N = int(input())
memo = [[]for i in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        memo[i] += [(x-1, y)]

ans = 0
for i in range(2**N):
    flag = False
    cnt = 0
    bit = bin(i)[2:].zfill(N)
    memo2 = [int(b) for b in bit]
    # print(i, ans)
    for ii, b in enumerate(memo2):
        cnt += b
        if b:
            for x, y in memo[ii]:
                if memo2[x] == y:
                    continue
                else:
                    flag = True
                    break
        else:
            continue
            # for x, y in memo[ii]:
            #     if memo2[x] != y:
            #         continue
            #     else:
            #         flag = True
            #         break
        if flag:
            break
    if flag:
        continue
    ans = max(ans, cnt)
print(ans)
    

Measured memory_bytes: 46556
#include"bits/stdc++.h"
using namespace std;
#define rep(i, N) for(int i=0; i<N; ++i)
typedef unsigned long ul;

int main() {
    ul n;
    cin >> n;
    vector<pair<ul, ul>> v;
    ul i = 1;
    while(true) {
        if (n % i == 0) v.emplace_back(i, n/i);
        ++i;
        if (i > sqrt(n)) break;
    }

    ul ans = n;
    for(auto&& i : v) {
        ans = min(ans, (i.first + i.second - 2));
    }
     cout << ans;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  int A, B;
  cin >> A >> B;

  int price;
  if (A >= 13) {
    price = B;
  } else if (A <= 5) {
    price = 0;
  } else {
    price = B / 2;
  }
  cout << price;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
const long long NR=210000;
long long n,l,r,mid,ans,a[NR],s1[NR],s2[NR];
int main()
{
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		s1[i]=s1[i-1]+a[i];
		s2[i]=s2[i-1]^a[i];
	}
	for(long long i=1;i<=n;i++)
	{
		l=i;
		r=n+1;
		while((r-l)>1)
		{
			mid=(l+r)>>1;
			if((s1[mid]-s1[i-1])==(s2[mid]^s2[i-1]))
			{
				l=mid; 
			}
			else
			{
				r=mid;
			}
		}
		ans+=(l-i+1);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

vi G[200100];

int main() {
  int n;
  ll k;
  cin>>n>>k;
  vi a(n);
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }
  vi c(n,-1);
  int pos = 0;
  int f = 0;
  int start = 0;
  vi town(n,0);
  vi check(n,0);
  vi loop;
  rep(i,2*n){
    pos = a[pos];
    if(c[pos] != -1){
      if(f==0)f = i-c[pos];
      if(start == 0)start = i;
      town[pos] = 1;
      if(!check[pos])loop.push_back(pos);
      check[pos] = 1;
    }
    else{
      c[pos] = i; 
    }
  }
  // show(f);
  // show(start);
  // for(auto e:loop)show(e);
  if(k<start){
    pos = 0;
    rep(i,k){
      pos = a[pos];
    }
    cout<<pos+1<<endl;
    return 0;
  }
  else{
    k-=start+1;
    k%=f;
    cout<<loop[k]+1<<endl;
  }
  return 0;
}

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

int main(){
  int a,b,c,d; cin>>a>>b>>c>>d;
  bool T_win=true,A_win=true;
  while(T_win||A_win){
    c-=b;
    if(c<=0){
      A_win=false;
      break;
    }
    a-=d;
    if(a<=0){
      T_win=false;
      break;
    }
  }
  if(T_win)
    cout<<"Yes"<<endl;
  if(A_win)
    cout<<"No"<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
int n,a[200005],c[22];
long long ans;
bool check(int x){
	for (int i=0;i<=20;i++)
		if ((x&(1<<i)) && c[i]) return 0;
	return 1;
}
void modify(int x,int y){
	for (int i=0;i<=20;i++)
		if (x&(1<<i)) c[i]+=y;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int p=0;
	for (int i=1;i<=n;i++){
		while (p<n && check(a[p+1])) 
			p++,modify(a[p],1);
		ans=ans+p-i+1;
		modify(a[i],-1);
	}
	printf("%lld\n",ans);
}

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

void swap(int* a1, int* a2) {
    int tmp;
    tmp = *a1;
    *a1 = *a2;
    *a2 = tmp;
}

int main()
{
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if(a1 > a2) {
        swap(&a1, &a2);   
    }
    if(a2 > a3) {
        swap(&a2, &a3);   
    }
    if(a1 > a2) {
        swap(&a1, &a2);   
    }
    cout << abs(a2 - a1) + abs(a3 - a2)  << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int v;
  cin >> v;
  bool good = false;
  if ((v % 1000) % 111 == 0) {
    good = true;
  }
  if ((v / 10) % 111 == 0) {
    good = true;
  }
  cout << (good ? "Yes" : "No") << "\n";
}


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

//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
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...);
}
#else
#define trace(...)
#endif

#define LL long long

int main() {
	int x,y,a,b,c;
	vector<int> A;
	vector<int> B;
	vector<int> C;
	cin >> x >> y;
	cin >> a >> b >> c;

	int num;
	for(int i=0;i<a;i++) {
		cin >> num;
		A.push_back(num);
	}
	for(int i=0;i<b;i++) {
		cin >> num;
		B.push_back(num);
	}
	for(int i=0;i<c;i++) {
		cin >> num;
		C.push_back(num);
	}

	sort(A.begin(), A.end(), greater<int>());
	sort(B.begin(), B.end(), greater<int>());
	sort(C.begin(), C.end(), greater<int>());

	vector<int> ans;
	for(int i=0;i<x;i++) {
		ans.push_back(A[i]);
	}
	for(int i=0;i<y;i++) {
		ans.push_back(B[i]);
	}
	sort(ans.begin(), ans.end());

	int st = 0;
	for(int i=0;i<C.size();i++) {
		if(st >= x+y) break;
		if(C[i] > ans[st]) {
			ans[st] = C[i];
			st++;
		}
	}

	LL sum = 0;
	for(int i=0;i<ans.size();i++) {
		sum += 1LL * ans[i];
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 2552