akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
vector<int > q;
int main(){
	int n,num;scanf("%d",&n);
	for(int i=0;i<n;i++){
	scanf("%d",&num);
	q.push_back(num);
}
	 make_heap(q.begin(),q.end());
	 for(int i=0;i<n;i++)printf(" %d",q[i]); printf("\n");
	return 0;
} 


Measured memory_bytes: 4800
fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(' ').map { it.toLong() }
    println(Solver(n.toInt()).solve(x))
}

class Solver(private val n: Int) {

    private val a = LongArray(n + 1) { 1L }
    private val p = LongArray(n + 1) { 1L }

    init {
        (0 until n).forEach {
            // B + L-1 Berger + P + L-1 Berger + B
            a[it + 1] = a[it] * 2 + 3
            p[it + 1] = p[it] * 2 + 1
        }
    }

    fun solve(x: Long): Long {
        return f(n, x)
    }

    private fun f(n: Int, x: Long): Long {
        if (n == 0) {
            return if (x > 0) 1 else 0
        }

        // B + L-1 Berger
        if (x <= a[n - 1] + 1) {
            return f(n - 1, x - 1)
        }

        // B + L-1 Berger + P + f(...)
        return p[n - 1] + 1 + f(n - 1, x - a[n - 1] - 2)
    }

}

Measured memory_bytes: 38124
import collections
n = int(input())
a_list = list(map(int,input().split()))
c = collections.Counter(a_list)
result = 0
for i in c.values():
  result += i * (i - 1)//2

for a in a_list:
  print(result - c[a] + 1)
 
    
  
  

Measured memory_bytes: 26780
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val trees = (1..n).map { readLine()!!.toInt() }.sorted()

    var min = trees.max()!! - trees.min()!!
    for (i in 0..(n - k)) {
        val one = trees[i]
        val two = trees[i + k - 1]
        val sub = two - one
        if (sub < min) {
            min = sub
        }
    }
    println(min)
}

Measured memory_bytes: 48184
def check(M):
    global A,B,Data
    plus = 0
    for d in Data:
        left = d - B*M 
        if left > 0:
            q,mod = divmod(left,A-B)
            plus += q
            if mod > 0:
                plus += 1
    return plus <= M

N,A,B = map(int,input().split())
Data = [0]*N
for i in range(N):
    Data[i] = int(input())

min1 = 0
max1 = 10**10

while max1 - min1 > 1:
    mid = (min1 + max1) // 2
    b = check(mid)
    if b == True:
        max1 = mid
    else:
        min1 = mid

print(max1)


Measured memory_bytes: 6992
using System;
using System.Collections.Generic;

class Solver
{
    static Scanner cin;
    public Solver() {}
    public static int Main()
    {
        cin = new Scanner();
        new Solver().solve();
        return 0;
    }
    
    public bool ask(int x, int y) {
        Console.WriteLine("? {0} {1}", x, y);
        string s = cin.next();
        if (s == "Y") {
            return true;
        } else {
            return false;
        }
    }
 
    public void solve()
    {
        int a, b;
        a = cin.nextInt();
        b = cin.nextInt();
        int n = a + b;
        if (a <= b) {
            Console.WriteLine("Impossible");
            return;
        }
        var q = new List<int>();
        for (int i = 0; i < n; ++i) {
            if (q.Count == 0) {
                q.Add(i);
                continue;
            }
            if (ask(q[q.Count - 1], i)) {
                q.Add(i);
            } else {
                q.RemoveAt(q.Count - 1);
            }
        }
        int judge = q[q.Count - 1];
        var result = new List<int>(n);
        string answer = "! ";
        for (int i = 0; i < n; ++i) {
            if (ask(judge, i)) {
                answer += "1";
            } else {
                answer += "0";
            }
        }
        Console.WriteLine(answer);
        return;
    }
}

class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        while (i >= s.Length)
        {
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
        }
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
}

Measured memory_bytes: 17684
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n;
  scan(n);
  vll lucas(n+1, 0);
  lucas[0] = 2;
  lucas[1] = 1;
  FOR (i, 2, n+1) {
    lucas[i] = lucas[i-1] + lucas[i-2];
  }
  print(lucas[n]);

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Words
{
    char	word[31];
    int		page[100];
} WORDS;

WORDS	wordArray[100];

WORDS* printMinWord(WORDS*);
WORDS* printMinPage(WORDS*);

int main()
{
    char	tempWord[31];
    int		tempPage;
    int		wordCnt;
    int		pageCnt;
    int		inputCnt = 0;
	
    while (scanf("%s %d", &tempWord, &tempPage) != EOF)
    {
        wordCnt = 0;
        /*sort page to each words*/
        while(1)
        {
            if(!strcmp(tempWord, wordArray[wordCnt].word))
            {
                for(pageCnt = 1; pageCnt < 100; pageCnt++)
                {
                    if(!(wordArray[wordCnt].page[pageCnt]))
                    {
                        break;
                    }
                }
                wordArray[wordCnt].page[pageCnt] = tempPage;
                break;
            }
            else if(!strcmp("", wordArray[wordCnt].word))
            {
                strcpy(wordArray[wordCnt].word, tempWord);
                wordArray[wordCnt].page[0] = tempPage;
                break;
            }
            wordCnt++;
        }
    }
	
    printMinWord(wordArray);
	

	
	return 0;
} 

WORDS* printMinWord(WORDS* word_array)
{
	int		word_cnt;
	char	min_word[31]	= "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
	int		min_word_index	= -1;
	
	/*find min word and its index*/
	for(word_cnt = 0; word_cnt < 100; word_cnt++)
	{
		if(!strcmp(word_array[word_cnt].word, ""))
		{
			continue;
		}
		if(strcmp(word_array[word_cnt].word, min_word) <= 0)
		{
			strcpy(min_word, word_array[word_cnt].word);
			min_word_index = word_cnt;
		}
	}
	
	/*no recursion if no word content*/
	if(min_word_index == -1)
	{
		return word_array;
	}
	printf("%s\n", word_array[min_word_index].word);
	
	/*print subsequential pages of min word*/
	printMinPage(&word_array[min_word_index]);
	
	strcpy(word_array[min_word_index].word, "");
	
	return printMinWord(word_array);
}

WORDS* printMinPage(WORDS* word_array)
{
	int		page_cnt;
	int		min_page = 1001;
	int		min_page_index	= -1;
		
	/*find min page and its index*/
	
	
	for(page_cnt = 0; page_cnt < 100; page_cnt++)
	{
		if(word_array->page[page_cnt] == 0)
		{
			continue;
		}
		if(word_array->page[page_cnt] < min_page)
		{
			min_page = word_array->page[page_cnt];
			min_page_index = page_cnt;
		}
	}
	
	/*no recursion if no page content*/
	if(min_page_index == -1)
	{
		printf("\n");
		return word_array;
	}
	printf("%d", word_array->page[min_page_index]);
	word_array->page[min_page_index] = 0;
	
	for(page_cnt = 0; page_cnt < 100; page_cnt++)
	{
		if(word_array->page[page_cnt] == 0)
		{
			continue;
		}
		printf(" ");
		return printMinPage(word_array);
	}
	
	return printMinPage(word_array);
}

Measured memory_bytes: 644
#include <iostream>
#include <algorithm>
#include <array>
#include <climits>

using namespace std;

int main() {
  while (true) {
    array<int,8> a = {};
    array<int,8> b = {1, 4, 1, 4, 1, 2, 1, 2};
    for_each(a.begin(), a.end(), [](auto &v) {cin >> v;});

    if (cin.fail())
      break;

    int summin = INT_MAX;
    array<int, 8> c;

    for (int i = 0; i < 8; ++i) {
      int sum = 0;
      for (int j = 0; j < 8; ++j) {
        int tmp = a[j] - b[j];
        sum += (tmp >= 0) ? tmp : 0;
      }

      bool flag = true;
      if (sum == summin) {
        for (int j = 0; j < 9; ++j) {
          if (b[j] == c[j])
            continue;
          flag = b[j] < c[j];
          break;
        }
      }

      if ((sum < summin) || (sum == summin && flag)) {
        summin = sum;
        c = b;
      }

      rotate(b.begin(), b.begin() + 1, b.end());
    }

    cout << c[0];
    for_each(c.begin()+1, c.end(), [](auto &v) { cout << " " << v; });
    cout << endl;
  }
}


Measured memory_bytes: 3164
a,b,c,d=map(int,input().split())
lisa=[]
for i in range(a,b):
  lisa.append(i)
lisb=[]
for j in range(c,d):
  lisb.append(j)
count=0
for k in range(0,len(lisa)):
  if lisa[k] in lisb:
    count+=1
print(count)

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	string s;
	cin >> s;
	sort(all(s));
	if (s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3)) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastIO ios::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define f(i, l, r) for(i = l; i < r; i++)
#define fd(i, l, r) for(i = l; i > r; i--)
#define mod 1000000007
#define pb push_back
using namespace std;
typedef pair <int, int> pi;

int main(){
	fastIO
    int test = 1;
    // cin >> test;
    while(test--){
        int n, w; cin >> n >> w;
        int weight[n], i, j;
        long int value[n];
        f(i,0,n) cin >> weight[i] >> value[i];
        ll knapsack[n+1][w+1];
        f(i,0,n+1){
            f(j,0,w+1){
                if(i==0 || j==0) knapsack[i][j] = 0;
                else if(weight[i-1] <= j)
                    knapsack[i][j] = max(value[i-1] + knapsack[i-1][j-weight[i-1]], knapsack[i-1][j]);
                else knapsack[i][j] = knapsack[i-1][j];
            }
        }
        cout << knapsack[n][w];
    }
}


Measured memory_bytes: 79232
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,M; cin>>N>>M;
    ll L=100*N+1800*M;
    
    rep(i,M) L*=2;
    
    cout<<L<<endl;
}



Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(int argc, char* argv[]){
  int32_t x1, y1, x2, y2;
  std::cin >> x1 >> y1 >> x2 >> y2;
  int32_t v12x = x2 - x1;
  int32_t v12y = y2 - y1;
  int32_t v23x = -v12y;
  int32_t v23y = v12x;
  int32_t v34x = -v23y;
  int32_t v34y = v23x;
  
  int32_t x3, y3, x4, y4;
  x3 = x2 + v23x;
  y3 = y2 + v23y;
  x4 = x3 + v34x;
  y4 = y3 + v34y;

  std::cout << x3 << " " << y3 << " " << x4 << " " << y4 << std::endl;
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int a[4][4];
signed main()
{
    for(ri int i=1;i<=3;i++)
    for(ri int j=1;j<=3;j++)
    a[i][j]=read();
    if(a[1][3]+a[3][1]==a[1][1]+a[3][3]
    &&a[1][2]+a[2][1]==a[1][1]+a[2][2]
    &&a[2][3]+a[3][1]==a[3][3]+a[2][1]
    &&a[3][2]+a[2][1]==a[3][1]+a[2][2]) puts("Yes");
    else puts("No");
    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  set<string> ans;
  for (int i = 0; i < n; i++)
  {
    string s;
    cin >> s;
    ans.insert(s);
  }
  cout << ans.size() << endl;
}


Measured memory_bytes: 19204
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
 
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; }
 
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

int N;
int cnt[101];
ll dp[101]; // dp[i] := 約数がi個になるような素因数の組合わせ方の数

void prime_factorize(){
  for(int i=2;i<=N;i++){
    int x=i;
    for(int j=2;x>1;j++){
      while(x%j==0){
        cnt[j]++;
        x/=j;
      }
    }
  }
}

signed main()
{
  cin>>N;
  prime_factorize();
  
  dp[1]=1;
  for(int i=1;i<=N;i++) if(cnt[i]){
    for(int j=75;j>=1;j--){ // j:約数の個数
      for(int x=1;x<=cnt[i];x++){ // x:n!の中にある約数xの数(指数)
        if(j*(x+1)<=75) dp[j*(x+1)]+=dp[j];
      }
    }
  }

  cout<<dp[75]<<endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Problem {
    public static void Main() {
        Console.ReadLine();
        var data = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Array.Reverse(data);
        for (var i = 0; i < data.Length; Console.Write(++i != data.Length ? " " : "\n")) Console.Write(data[i]);
    }
}


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

int main(){
  int n,m,k;
  cin>>n>>m>>k;
  vector<int> dark(m);
  vector<int> isDark(n,-1);
  for(int i=0;i<m;i++){
    int d;
    cin>>d;
    d--;
    isDark[d]=i;
    dark[i]=d;
  }

  vector<vector<int>> v(n,vector<int>(k));
  for(int i=0;i<n;i++){
    for(int j=0;j<k;j++){
      int val;
      cin>>val;
      val--;
      v[i][j]=val;
    }
  }

  vector<vector<int>> edge(1<<m,vector<int>(k));
  for(int i=0;i<(1<<m);i++){
    for(int j=0;j<k;j++){
      int to=0;
      for(int r=0;r<m;r++){
	if((i&(1<<r)) && isDark[v[dark[r]][j]]!=-1){
	  to|=(1<<isDark[v[dark[r]][j]]);
		      
	}
      }
      edge[i][j]=to;

    }
  }

  const int INF=1e9;
  vector<int> d(1<<m,INF);
  queue<pair<int,int>> que;
  d[(1<<m)-1]=0;
  que.push({(1<<m)-1,0});
  while(!que.empty()){
    auto p=que.front();
    que.pop();
    if(p.first==0){
      cout<<p.second<<endl;
      return 0;
    }
    for(int i=0;i<edge[p.first].size();i++){
      if(d[edge[p.first][i]]>=INF){
	d[edge[p.first][i]]=p.second+1;
	que.push({edge[p.first][i],p.second+1});
      }
		 
    }
  }  
			       
  return 0;
}

Measured memory_bytes: 31752
import java.util.*;

public class Main {
    static int h, w;
    static int[][] map;
    static boolean[][] bmap;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        h = sc.nextInt();
        w = sc.nextInt();
        map = new int[h+2][w+2];
        bmap = new boolean[h+2][w+2];
        for(int i=0; i<h; i++){
            String s = sc.next();
            for(int j=0; j<w; j++){
                if(s.charAt(j) == '#'){
                    map[i+1][j+1] = 1;
                }else{
                    map[i+1][j+1] = -1;
                }
            }
        }
        sc.close();

        long ans = 0;
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(!bmap[i+1][j+1] && map[i+1][j+1] == 1){
                    int[] ret = bfs(i+1, j+1, map[i+1][j+1]);
                    ans += (long)ret[0] * (long)ret[1];
                    // ans += cont * (cont-1) * 2;
                }
            }
        }

        System.out.println(ans);
    }

    public static int[] bfs(int x, int y, int now){
        int next = -now;
        int[] ret = new int[2];
        ret[0] = map[x][y] == -1 ? 1 : 0;
        ret[1] = map[x][y] == 1 ? 1 : 0;
        bmap[x][y] = true;
        if(!bmap[x+1][y] && map[x+1][y] == next){
            int[] mret = bfs(x+1, y, next);
            ret[0] += mret[0];
            ret[1] += mret[1];
        }
        if(!bmap[x-1][y] && map[x-1][y] == next){
            int[] mret = bfs(x-1, y, next);
            ret[0] += mret[0];
            ret[1] += mret[1];
        }
        if(!bmap[x][y+1] && map[x][y+1] == next){
            int[] mret = bfs(x, y+1, next);
            ret[0] += mret[0];
            ret[1] += mret[1];
        }
        if(!bmap[x][y-1] && map[x][y-1] == next){
            int[] mret = bfs(x, y-1, next);
            ret[0] += mret[0];
            ret[1] += mret[1];
        }
        return ret;
    }
}

Measured memory_bytes: 47764
#include <iostream>
using namespace std;
#define ll long long
ll N,x[1001],y[1001],ax,ay,dx,dy;
int main()
{
	cin >> N;
	
	for(int i=0; i<N; i++)
	{
		cin >> x[i] >> y[i];
		if(ax==0&&ay==0)
		ax=x[i],ay=y[i];
		else
		{
			if(ay%y[i])
			dy=ay/y[i]+1;
			else
			dy=ay/y[i];
			
			if(ax%x[i])
			dx=ax/x[i]+1;
			else
			dx=ax/x[i];
			
			ll d=max(dy,dx);
			
			ax=d*x[i],ay=d*y[i];
		}
	}
	cout << ax+ay;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,a,x;
	scanf("%d",&n);
	scanf("%d",&a);
	x=n%500;
	if(x-a<=0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define vc vector<int>
#define um unordered_map<int,int>
#define ll long long 
#define rep(i,a,b) for(__typeof(a) i=a; i<b; i++)
#define si(a) a.size()
#define all(a) a.begin(),a.end()
#define ss(a) a.second
#define ff(a) a.first
#define M 1000000
#define pb push_back
#define repit(i,a) for(auto i=a.begin(); i!=a.end(); i++)
#define take(arr,n) for(int i=0;i<n;i++)cin>>arr[i]
#define out(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<' '
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define reprev(i,b,a) for(__typeof(b) i=b; i>=a; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define doublearray vector<vector<int>>
#define mod 998244353 
using namespace std;
ll max(ll a, ll b){ return a>b?a:b; }
ll min(ll a, ll b){ return a<b?a:b; }
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}
int binaryS(ll x, ll sb[], int m){
    int l = 0, r=m;
    int mid = (l+r)/2;
    while(l<r){
        mid = (l+r)/2;
        if(sb[mid]<x) l= mid+1;
        else if(sb[mid]>x) r = mid-1;
        else return mid;
    }
    return l;
}
int main(){
    fastio;
        int n,m,k; cin>>n>>m>>k;
        ll a[n], b[m]; take(a,n); take(b,m);
        ll sa[n+1], sb[m+1];
        sa[0] = 0; sb[0] = 0;
        rep(i,1,n+1){
            sa[i] = sa[i-1]+a[i-1];
        }
        rep(i,1,m+1) sb[i] = sb[i-1]+b[i-1];
        ll book = 0;
        rep(i,0,n+1){
            if(sa[i]>k) break;
            ll left = k-sa[i];
            int ind = binaryS(left,sb,m);
            if(sb[ind]==left){
                book = max(book,i+ind);
            }
            else if(sb[ind]>left){
                book = max(book,i+ind-1);
            }
            else if(sb[ind]<left){
                book = max(book,i+ind);
            }
        }
        cout<<book<<endl;
    return 0;
}





Measured memory_bytes: 9892
#include<iostream>
#include<algorithm>
using namespace std;
string t,u;
int n,ans=0,ts,us;

int check(){
  for(int i=0;i+ts-1<us;i++){
    for(int j=1;;j++){
      if(i+j*(ts-1)>=us)break;
      string str="";
      for(int k=0;k<ts;k++){
	str.push_back(u[i+j*k]);
      }
      if(str==t)return 1;
    }
  }
  return 0;
}

int main(){
  cin>>n>>t;
  ts=t.size();
  for(int i=0;i<n;i++){
    cin>>u;
    us=u.size();
    ans+=check();
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1220
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
	using u64 = std::int_fast64_t;
public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
#pragma endregion

typedef modint<MOD> m;
m calc(m a, m b) {
	if (b.a == 0) return 1;
	if (b.a % 2 == 0) {
		m d = calc(a, b / 2);
		return (d * d);
	}
	else {
		return (a * calc(a, b - 1));
	}
}
m comb(m n, m r)
{
	if (n.a <= 0 || n.a < r.a)
	{
		return 0;
	}
	m sum = 1;
	for (int i = n.a; i > max(n.a - r.a, r.a); i--) sum *= i;
	for (int i = min(n.a - r.a, r.a); i > 0; i--) sum /= i;
	return sum;
}

int main() {
	cin >> N >> A >> B;
	modint<MOD> sum = calc(2, N) - 1;
	sum -= comb(N, A) + comb(N, B);
	cout << sum.a;
}



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

int main(void){
  string A, B;
  int flag = 0;
  cin >> A >> B;
  if(A.length() != B.length()){
    if(A.length() > B.length()) cout << "GREATER" << endl;
  	else if (A.length() < B.length()) cout << "LESS" << endl;
  }
  else{
   for(int i = 0; i < A.length(); i++){
    if(A[i] > B[i]){
      cout << "GREATER" << endl;
      flag = 1;
      break;
    }
    else if(A[i] < B[i]){
      cout << "LESS" << endl;
      flag = 1;
      break;
    }
   }
   if(flag == 0) cout << "EQUAL" << endl;
    
  }  
}

Measured memory_bytes: 256
s = gets.strip.split('').reverse.map {|c| c=='?' ? nil : c.to_i}
N=13
MOD = 10**9+7

dp = Array.new(13,0)
dp[0] = 1
mul=1
a09 = (0..9).to_a

#p s

s.each do |current_c|
  next_dp = Array.new(13,0)

  (current_c.nil? ? a09 : [current_c]).each do |candidate|

    bigger = candidate*mul
    N.times do |previous|
        next_dp[(bigger + previous)%N] += dp[previous]
    end
  end
  mul = mul * 10 % N
  dp=next_dp.map {|v| v%MOD }

#p dp
end

p dp[5]



Measured memory_bytes: 18428
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
#include<array>
#include<algorithm>
#include<queue>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
#include<bitset>
#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x, y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x, LLI y) {
//	return x / gcd(x, y) * y;
//}

//long nCr(int n, int r) {
//	long ans = 1;
//	for (int i = n; i > n - r; i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; i++) {
//		ans = ans / i;
//	}
//	return ans;
//}
//long nHr(int n, int r) {
//	n = n + r - 1;
//	return nCr(n, r);
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI N, cnt = 0, A, B;
	string S, T;
	cin >> A >> B;
	LLI a = 1;
	while (1) {
		if (a >= B) {
			break;
		}
		a = a + A - 1;
		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int N, W;
    char a[110][110];
    int check;
    int Nx[110], Wx[110];
    int i,j;

    scanf("%d %d", &N, &W);

    for(i=0; i<N; i++){
        check = 0;
        scanf("%s", &a[i]);
        for(j=0; j<W; j++){
            if(a[i][j] == '#'){
                check = 1;
            }
        }
        if(check == 0){
            Nx[i] = 1;
        }else{
            Nx[i] = 0;
        }
    }

    for(j=0; j<W; j++){
        check = 0;
        for(i=0; i<N; i++){
            if(a[i][j] == '#'){
                check = 1;
            }
        }
        if(check == 0){
            Wx[j] = 1;
        }else{
            Wx[j] = 0;
        }
    }

    for(i=0; i<N; i++){
        for(j=0; j<W; j++){
            if(Nx[i] == 0 && Wx[j] == 0)
            printf("%c", a[i][j]);
        }
        if(Nx[i]==0){
            printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define MX 20000000000000005
using namespace std;
int a[200005];
int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	int n,i;
	cin>>n;
	for(i=0;i<n;i++) cin>>a[i];
	for(i=n-1;i>-1;i-=2) cout<<a[i]<<" ";
	for(i=n%2;i<n;i+=2) cout<<a[i]<<" ";
	cout<<endl;
	return 0;
	#ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
}


Measured memory_bytes: 2944
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int main(){
	while(1){
		int a,b;
		cin>>a>>b;
		if(a==0 && b==0)break;
		
		int hav[111]={0};
		int pos=0;
		int val=b;
		while(1){
			if(val==0){
				val = hav[pos];
				hav[pos]=0;
			}else{
				hav[pos]++;
				val--;
			}
			if(val==0){
				
				int sum = 0;
				rep(i,a){
					if(i!=pos)sum+=hav[i];
				}
				
				if(sum==0){
					printf("%d\n",pos);
					break;
				}
			}
			pos = (pos+1)%a;
		}
	}
}

Measured memory_bytes: 1144
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}
//22:38
fn main(){
    let n: usize = read_as_vec()[0];
    let mut a: Vec<usize> = read_as_vec();

    let mut ans = 0;

    for elem in &mut a{
        while *elem%2 == 0{
            *elem /= 2;
            ans += 1;
        }
    }

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


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

#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll h,w;

ll ans = 0;

int main(){
    cin >> h >> w;
    if(h == 1 || w == 1){
        ans = 1;
    }else if(h%2 == 0){
        ans = h/2 * w;
    }else{
        if(w%2 == 0){
            ans = w/2 * h;
        }else{
            ans = (w-1)/2 * h + ((h-1)/2) + 1;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(fst) (int)(fst).size()
#define forn(i, n) for (ll i = 0; i < ll(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(fst) fst.begin(), fst.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   int n;
   cin >> n;
   int x;
   set<int> s;
   forn(i, n) cin >> x, s.insert(x);
   if (sz(s)==n) cout << "YES\n";
   else cout << "NO\n";
    return 0;
}

Measured memory_bytes: 9600
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;   

int arr[7];

ll ans;

ll calc(int a, int b, int c) {
    ll ret = 0;

    ret += (b / 2) * 2;
    ret += (c / 2) * 2;
    ret += (a / 2) * 2;

    return ret;
}

void solve() {                       
    for (int i = 0; i < 7; ++i) {
        scanf("%d", &arr[i]);
    }    
    
    ans = calc(arr[0], arr[3], arr[4]);

    if (arr[3] > 0 && arr[4] > 0 && arr[0] > 0) {
        ans = max(ans, calc(arr[0] - 1, arr[3] - 1, arr[4] - 1) + 3);
    }   
          
    printf("%lld\n", ans + arr[1]);
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

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



int main() {
  int n,k;
  scanf("%d%d", &n, &k);
  double sum = 0;

  for(int i = 1; i <= n; i++){
    double d = i;
    double pi = 1/double(n);
    while(d < k){
        pi *= 0.5;
        d *= 2;
    }
    sum += pi;
  }
  printf("%.9f\n", sum);
}


Measured memory_bytes: 256
N, M = map(int,input().split())

H = [0] + list(map(int,input().split()))

path = [0]
for i in range(1,N+1):
	path.append([])

for i in range(1,M+1):
	A, B = map(int,input().split())
	path[A].append(B)
	path[B].append(A)

count = 0

for i in range(1,N+1):
	if len(path[i]) == 0:
		count += 1
	elif H[i] > max(H[j] for j in path[i]):
		count += 1
	
print(count)

Measured memory_bytes: 29316
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,m,x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n,vector<int>(m));
    vector<int> c(n);
    
    for(int i = 0;i < n;i++){
          cin >> c[i];
          for(int j = 0;j < m;j++){
                cin >> a[i][j];
          }
    }
    
    int ans = 12345678;
    int all = 1 << n;
    
    for(int mask = 0;mask < all;mask++){
          vector<int> level(m);
          int cost = 0;
          for(int i = 0;i < n;i++){
                if((mask >> i) & 1){
                      cost += c[i];
                      for(int j = 0;j < m;j++){
                            level[j] += a[i][j];
                      }
                }
          }
          bool f = true;
          for(int j = 0;j < m;j++){
                if(level[j] < x)f = false;
          }
          if(f)ans = min(ans,cost);
    }
    if(ans == 12345678){
          cout << -1 << endl;
    }else{
          cout << ans<< endl;
    }
}


Measured memory_bytes: 3632
#include <stdio.h>
#define MAX 100000
int main(){
  int a,b,A[MAX]={-1},B[MAX],count=0,i,j,c,t;
  scanf("%d",&a);
  scanf("%d",&A[0]);
  for(i=1,c=1;i<a;i++){
    scanf("%d",&t);
    if(A[c-1]<t){A[c]=t;c++;}
  }

  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&B[i]);
  }
  i=c;
  for(i=0;i<b;i++){
    for(j=0;j<a;j++){
      if(A[j]==B[i]){count++;break;}
      if(A[j]>B[i]){break;}
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(void){
  while( true ){
    int loopStart = -1;
    bool bContDividing = false;
    vector<int> mods, quots;
    unsigned int p, q;
  
    cin >> p >> q;
    if( cin.eof() ) break;

    mods.push_back( p % q );

    do{
      p = mods[mods.size()-1] * 10;
      vector<int>::iterator itSearchRes = find(mods.begin(), mods.end(), p%q);
      if( p % q == 0 ) bContDividing = false;
      else if( p % q != 0 && itSearchRes == mods.end() ) bContDividing = true;
      else{
	loopStart = distance(mods.begin(), itSearchRes);
	bContDividing = false;
      }
      quots.push_back(p / q);
      mods.push_back(p % q);
    }while( bContDividing );

    for(int i = 0; i < quots.size(); i++) cout << quots[i];
    cout << '\n';
    if( loopStart >= 0 ){
      for(int i = 0; i < loopStart; i++) cout << ' ';
      for(int i = loopStart; i < quots.size(); i++) cout << '^';
      cout << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
using ll = long long;

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	int cnt = 0;
	while (A >= B) {
		B *= 2;
		if (++cnt > K) {
			cout << "No" << endl;
			return 0;
		}
	}
	while (B >= C) {
		C *= 2;
		if (++cnt > K) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3636
"""
D - Make Them Even
行列のすべての要素を偶数にする(1つ奇数はok)
別に最低数ではない
一筆書きに総当たりすれば、いつかおわる
"""

height, width = map(int, input().split())

matrix = [[0 for h in range(width)] for w in range(height)]

for h in range(height):
    temp_w = []
    for part in input().split():
        temp_w.append(int(part))

    for w in range(width):
        # 偶奇で処理
        matrix[h][w] = temp_w[w] % 2

move_list = []
for h in range(height):
    for w in range(width):
        cmp_h1 = h
        cmp_h2 = h
        cmp_w1 = w
        cmp_w2 = w + 1

        # 奇数列は折り返す
        if (h % 2) != 0:
            w = width - w - 1
            cmp_w1 = w
            cmp_w2 = w - 1
            end = 0
        else:
            end = width - 1

        # ループの最後
        if end == cmp_w1:
            cmp_h2 = h + 1
            cmp_w2 = cmp_w1
        
        # 枠はみ出した
        if cmp_h2 == height:
            continue
        
        # 奇数だったら
        if matrix[cmp_h1][cmp_w1] != 0:
            matrix[cmp_h2][cmp_w2] ^= 1
            move_list.append([cmp_h1+1, cmp_w1+1, cmp_h2+1, cmp_w2+1])

print(len(move_list))
for move in move_list:
    print("%d %d %d %d" % (move[0], move[1], move[2], move[3]))



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

using namespace std;

const int N = 1e6 + 6;

int a[N], n;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < 3*n; i++)
    scanf("%d", a+i);
  sort(a, a+3 * n);
  long long ans = 0;
  for (int i = 3 * n - 2, j = 0; j < n; j++, i -= 2) {
    ans += a[i];
  } 
  cout << ans << endl;
  return 0;
}

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

using namespace std;



int main(void)
{
    int x;
    cin >> x;

    int num_500 = x / 500;
    int num_5   = (x%500) / 5;
    cout << num_500 * 1000 + num_5 * 5;    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int main(void){

  int K;
  int ji, sum = 0;

  cin >> K;

  for(int i=1; i<=K; i++){
    for(int j=1; j<=K; j++){
      ji = gcd(j, i);
      for(int k=1; k<=K; k++){
        sum+=gcd(k, ji);
      }
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 3532
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter

def main():
    n = int(input().strip())
    v = []
    for i in range(n):
        v.append(input().strip())
    v2 = dict(Counter(v))
    q = []
    for k, w in v2.items():
        q.append([k, w])
    q = sorted(q, key=itemgetter(1), reverse=True)
    # print(q)
    ans = []
    ans.append(q[0][0])
    prev = q[0][1]
    for t in q[1:]:
        if t[1] == prev:
            ans.append(t[0])
    ans = sorted(ans)
    for a in ans:
        print(a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 122580
from collections import deque
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


N = int(input())

G = [[] for _ in range(N + 1)]
for i in range(N - 1):
    a, b, c = [int(_) for _ in input().split()]
    G[a].append((b, c))
    G[b].append((a, c))
Q, K = [int(_) for _ in input().split()]

# make tree
G2 = [10 ** 12] * (N + 1)

G2[K] = 0


def f():
    que = deque()
    que.append((K, 0))
    while que:
        v, p = que.pop()
        for nv, nc in G[v]:
            if nv == p: continue
            G2[nv] = G2[v] + nc
            que.append((nv, v))


f()

for i in range(Q):
    x, y = [int(_) for _ in input().split()]
    print(G2[x] + G2[y])


Measured memory_bytes: 74544
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int s_num;
    std::cin >> s_num;
    std::vector<int> S(s_num);
    for (int i=0; i<s_num; i++) std::cin >> S.at(i);
    
    int t_num;
    std::cin >> t_num;
    std::vector<int> T(t_num);
    for (int i=0; i<t_num; i++) std::cin >> T.at(i);

    int count = 0;
    for (int i=0; i<S.size(); i++) for (int j=0; j<T.size(); j++) {
        if (S.at(i) == T.at(j)) {
            count ++;
            std::vector<int>::iterator it = std::next(T.begin(), j);
            T.erase(it);
            break;
        }
    }
    std::cout << count << std::endl;
}


Measured memory_bytes: 3172
#include<algorithm>
#include<bitset>
#include<chrono>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;

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

	int w,b;
	cin>>w>>b;
	char a[100][100];
	for(int i=0;i<50;i++)
		for(int j=0;j<100;j++)
		{
			a[i][j]='.';
			a[99-i][j]='#';
		}
	w--;b--;

	int x=0,y=0;
	while(b)
	{
		a[x][y]='#';
		b--;
		y+=2;
		if(y>99)
		{
			x+=2;
			y=x%2;
		}
	}

	x=99,y=1;
	while(w)
	{
		a[x][y]='.';
		w--;
		y+=2;
		if(y>99)
		{
			x-=2;
			y=x%2;
		}
	}
	cout<<100<<' '<<100<<'\n';
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++)
			cout<<a[i][j];
		cout<<'\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a[n],i,cnt=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    for(i=0;i<n;i++)
    {
        if(a[i]==a[i+1])
        {
            cnt++;
        }

    }
    if(cnt>0)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;

}


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

public class Main{
	static int gcd(int a,int b) {
		return b==0?a:gcd(b, a%b);
	}
	public static void main(String[] args) throws Exception{
		PrintWriter pw=new PrintWriter(System.out);
		MScanner sc = new MScanner(System.in);
		int n=sc.nextInt();
		long ans=0;
		
		for(int i=1;i<=n;i++) {
			for(int j=1;j<=n;j++) {
				for(int k=1;k<=n;k++) {
					ans+=gcd(i, gcd(j, k));
				}
			}
		}
		pw.println(ans);
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		static void shuffle(int[]in) {
			for(int i=0;i<in.length;i++) {
				int idx=(int)(Math.random()*in.length);
				int tmp=in[i];
				in[i]=in[idx];
				in[idx]=tmp;
			}
		}
		static void shuffle(long[]in) {
			for(int i=0;i<in.length;i++) {
				int idx=(int)(Math.random()*in.length);
				long tmp=in[i];
				in[i]=in[idx];
				in[idx]=tmp;
			}
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void addX(int[]in,int x) {
		for(int i=0;i<in.length;i++)in[i]+=x;
	}
	static void addX(long[]in,int x) {
		for(int i=0;i<in.length;i++)in[i]+=x;
	}
}

Measured memory_bytes: 32904