akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep0(i, n) for(int i=0; i<(int)(n);i++)

using namespace std;

int main(){
//////////////////////////////////////////////////////
    int n;
    cin >> n;
    int a[n],mi = INT_MAX,mc = 0;
    long long sum = 0, ans;
    rep0(i,n)
    {
        cin >> a[i];
        mi = min(mi, abs(a[i]));
        if(a[i]<0)mc ++;
        sum += abs(a[i]);
    }
    cout << sum-(mc%2?mi*2:0) << endl;
    return 0;
}


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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  if(b<=a){
    for(int i = 0 ;i <7;i++){
      b *= 2;
      ans++;
      if(b>a){
        break;
      }
    }
  }
  if(c<=b){
    for(int i = 0 ;i <7;i++){
      c *= 2;
      ans++;
      if(c>b){
        break;
      }
    }
  }
  if(ans <= k){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
void NG(void)
{
    cout << "Invalid value!!" << endl;
    return;
}

bool linearSearch(int *Sequence, int target, int key)
{
    bool result = false;
    for(int targetS = 0; targetS < target; targetS++)
    {
        if(Sequence[targetS] == key)
        {
            result = true;      //target found
        }
    }
    return result;
}

int main(void)
{
    int n, q = 0;      //integer
    int SequenceS[10000], SequenceT[500];  //Sequence
    
    //Input Data
    cin >> n;       //Number of enter into SequenceS 
    if(n > 10000)
    {
        NG();
        return 0;
    }
    
    for(int i = 0; i < n; i++)
    {
        cin >> SequenceS[i];
    }
    
    cin >> q;       //Number of enter into SequenceT
    if(q > 500)
    {
        NG();
        return 0;
    }
    
    for(int i = 0; i < q; i++)
    {
        cin >> SequenceT[i];
    }
    
    //Search
    int count = 0;
    for(int targetT = 0; targetT < q; targetT++)
    {
        bool result = linearSearch(SequenceS, n, SequenceT[targetT]);
        if(result == true)
        {
            count++;
        }
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3128
v = require('fs').readFileSync('/dev/stdin', 'utf8').split(' ');
f = false;
for (var i = 0; i < v[1]; i++) {
    if ((v[0] * i - v[2]) % v[1] == 0) {
        f = true;
    }
}
console.log(f ? 'YES' : 'NO');

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

int main(){
    stack<int> S1;
    stack<pair<int, int> > S2;
    char ch;
    int sum = 0;
    
    for(int i=0; cin >> ch; i++){
        if(ch == '\\') S1.push(i);
        else if(ch == '/' && S1.size() > 0){
            int j = S1.top(); S1.pop();
            sum += i - j;
            int a = i - j;
            while(S2.size() > 0 && S2.top().first > j){
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }
    
    vector<int> ans;
    while(S2.size() > 0){ ans.push_back(S2.top().second); S2.pop();}
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i=0; i<ans.size(); i++){
        cout << " ";
        cout << ans[i];
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3192
import sys
input = lambda: sys.stdin.readline().rstrip()

# UnionFind
class UnionFind:
    def __init__(self,n):
        self.n=n
        self.a=[-1]*n
        self.siz=n
    def root_find(self,x):
        if self.a[x]<0:
            return x
        else:
            self.a[x]=self.root_find(self.a[x])
            return self.a[x]
    def unite(self,x,y):
        x=self.root_find(x)
        y=self.root_find(y)
        if x==y:
          return
        elif self.a[x]<self.a[y]:
            self.a[x]+=self.a[y]
            self.a[y]=x
        else:
            self.a[y]+=self.a[x]
            self.a[x]=y
        self.siz-=1
    def root_same(self,x,y):
        return self.root_find(x)==self.root_find(y)

n,q=map(int,input().split())
u=UnionFind(n)
for _ in range(q):
    t,a,b=map(int,input().split())
    if t==0:
        u.unite(a,b)
    else:
        print(u.root_same(a,b)+0)


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

char intToSuit(int i){
  char buf;

  switch(i){
  case 0:
    buf='S';
    break;
  case 1:
    buf='H';
    break;
  case 2:
    buf='C';
    break;
  case 3:
    buf='D';
    break;
  }
  return buf;
}

int suitToInt(char c){
  int buf;

  switch(c){
  case 'S':
    buf=0;
    break;
  case 'H':
    buf=1;
    break;
  case 'C':
    buf=2;
    break;
  case 'D':
    buf=3;
    break;
  }
  return buf;
}


int main(){
  bool card[4][13]={false};
  int n;
  char s_buf;
  int n_buf;

  cin >> n;
  
  for(int i=0;i<n;i++){
    cin >> s_buf;
    cin >> n_buf;
    card[suitToInt(s_buf)][n_buf-1]=true;
  }

  for(int i=0;i<4;i++){
    for(int j=0;j<13;j++){
      if(card[i][j] == false){
        cout << intToSuit(i) << " " << j+1 << endl;
      }
    }
  }
  
  return 0;
}

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

int H,W,K;
char t[50][50];
char tmp[50][50];

void down(){
  for(int j=0;j<W;j++){
    int cc=H-1;
    for(int i=H-1;i>=0;i--){
      if(t[i][j]=='.')continue;
      t[cc--][j]=t[i][j];
    }
    for(int i=cc;i>=0;i--)t[i][j]='.';
  }
}

int del(int depth){
  int res=0;
  for(int i=0;i<H;i++){
    int cnt=0;
    char key='.';
    
    for(int j=0;j<=W;j++){
      if(j<W&&key==t[i][j])cnt++;
      else{
        if(key!='.'&&cnt>=K){
          for(int k=0;k<cnt;k++){
            t[i][j-1-k]='.';
            res+=(1<<depth)*(key-'0');
          }
        }
        key=t[i][j];
        cnt=1;
      }
    }
    
  }
  return res;
}

int solve(int sy,int sx){
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)tmp[i][j]=t[i][j];
  t[sy][sx]='.';
  down();
  int res=0;
  for(int i=0;;i++){
    /*
    if(sy==3&&sx==2){
      for(int y=0;y<H;y++){
        for(int x=0;x<W;x++){
          cout<<t[y][x];
        }
        cout<<endl;
      }
      cout<<endl;
    }
    */
    int num=del(i);
    if(num==0)break;
    res+=num;
    down();
  }
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)t[i][j]=tmp[i][j];
  return res;
}

int main(){
  cin>>H>>W>>K;
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      cin>>t[i][j];

  int ans=0;
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      ans=max(ans,solve(i,j));

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;

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

    int slen = s.length();
    set<string> st;
    for(int i = 0; i < slen; ++i) {
        string tmp;
        for(int j = 0; i + j < slen && j < K; ++j) {
            tmp += s[i + j];
            if(st.size() == K){
                auto itr = st.end();
                itr--;
                if(*itr<tmp)
                    break;
            }
            st.insert(tmp);
            if(st.size() > K) {
                auto itr = st.end();
                itr--;
                st.erase(itr);
            }
        }
    }
    auto itr = st.end();
    itr--;
    cout << *itr << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
import operator
n,m=map(int,input().split())
l_ab=[0]*m
for i in range(m):
    l_ab[i]=list(map(int,input().split()))

l_ab.sort(key=operator.itemgetter(1))
#l_br=[]
l_br_last=0
num_br=0
for i in range(m):
    #if bisect.bisect_left(l_br,l_ab[i][0])==len(l_br):
    #if l_br[-1]<l_ab[i][0]:
        #l_br.append(l_ab[i][1]-1)
    if l_br_last<l_ab[i][0]:
        l_br_last=l_ab[i][1]-1
        num_br+=1
print(num_br)


Measured memory_bytes: 29120
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>
#include <complex>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define iceil(x,y) (x+y-1)/y

using namespace std;
typedef pair<int, int> PII;
typedef long long int ll;

const int N = 2e5+100;
int n,k,x,F[N],a[N],pre[N];

void upd(int x) {
	// cout << "x="<<x<<"\n";
	for(; x<N; x += (x&-x)) {
		F[x]++;
		// cout << "F["<<x<<"]="<<F[x]<<"\n";
		// cout << "-x="<<-x<<"\n";
		// cout << "x&-x="<<(x&-x) << "\n";
	}
}

int que(int x) {
	int ans = 0;
	for(; x>0; x-=(x&-x))
		ans += F[x];
	return ans;
}

ll get(int x) {
	memset(pre, 0, sizeof(pre));
	rep(i,1,n+1) {
		if(a[i]>x) pre[i] = -1;
		else pre[i] = 1;
		pre[i] += pre[i-1];
	}
	int T = min(*min_element(pre+1, pre+n+1),0);
	rep(i,n+1) pre[i] -= T-1;
	memset(F,0,sizeof(F));
	ll cur=0; upd(pre[0]);
	rep(i,1,n+1) {
		cur += que(pre[i]-1);
		upd(pre[i]);
	}
	return cur;
}

int main() {
	FAST;
	cin >> n;
	rep(i,1,n+1) {
		cin >> a[i];
	}
	int bas=1, son=1e9;
	ll look = n*(ll)(n+1) / 2 / 2 + 1;
	while(bas < son) {
		int mid = (bas+son)/2;
		if (get(mid)>=look) son = mid;
		else bas = mid+1;
	}
	cout << bas << "\n";

	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    LL ans = 0;
    vector<LL> vec;
    REP(i, n){
        LL sum = a[i];
        vec.pb(a[i]);
        FOR(j, i+1, n){
            sum += a[j];
            vec.pb(sum);
        }
    }

    sort(all(vec), greater<LL>());
    LL num = 0;
    for(int i = 60; i >= 0; i--){
        LL sum = (1LL << 60) - 1;
        int cnt = 0;
        REP(j, vec.size()){
            if((vec[j] & num) == num && vec[j] & (1LL << i)){
                sum &= vec[j];
                cnt++;
                if(cnt >= k) break;
            }
        }
        if(cnt >= k){
            num += 1LL << i;
        }
    }
    cout << num << endl;
}


Measured memory_bytes: 6384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<map>
using namespace std;
struct data{
    int cnt;string str;
    data(int a,string b):cnt(a),str(b){}
    data(){}
    bool operator<(const data &d)const{
        if(cnt!=d.cnt)return cnt<d.cnt;
        return str>d.str;
    }
};
int main(){
    int n;
    while(cin>>n,n){
        map<string,int>M;
        vector<data>V[26];
        cin.ignore();
        while(n--){
            string s;
            getline(cin,s);
            stringstream ss(s);
            while(ss>>s){
                M[s]++;
            }
        }
        map<string,int>::iterator it;
        for(it=M.begin();it!=M.end();it++){
            string s=it->first;
            V[s[0]-'a'].push_back(data(it->second,s));
        }
        for(int i=0;i<26;i++)sort(V[i].rbegin(),V[i].rend());
        char t;
        cin>>t;
        for(int i=0;i<min((int)V[t-'a'].size(),5);i++){
            if(i)cout<<" ";
            cout<<V[t-'a'][i].str;
        }
        if(V[t-'a'].size()==0)cout<<"NA"<<endl;
        else cout<<endl;

    }
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  string C,CC;
  cin>>C>>CC;
  string ans="YES";
  if(C[0]!=CC[2]||C[1]!=CC[1]||C[2]!=CC[0])ans="NO";
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cmath>
#include <map>
#include <tuple>

using namespace std;

typedef long long ll;
int H, W, D, Q;

vector<tuple<int, int, int>> A;
vector<ll> cum_mp;

bool compare(tuple<int, int, int> &lhs, tuple<int, int, int> &rhs) {
    return get<0>(lhs) < get<0>(rhs);
}

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

    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            int tmp;
            cin >> tmp;
            A.push_back(make_tuple(tmp, h, w));
        }
    }

    sort(A.begin(), A.end(), compare);

    for(int i = 0; i < D; i++) {
        cum_mp.push_back(0);
    }

    for(int i = D; i < H*W; i++) {
        cum_mp.push_back(cum_mp[i-D] + (ll)(abs(get<1>(A[i]) - get<1>(A[i-D])) + abs(get<2>(A[i]) - get<2>(A[i-D]))));
    }
    
    cin >> Q;

    for(int i = 0; i < Q; i++) {
        int L, R;
        cin >> L >> R;
        cout << cum_mp[R-1] - cum_mp[L-1] << endl;
    }



    return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  if (n/10 == 9 || n%10 == 9) dump("Yes");
  else dump("No");
  return 0;
}


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

int main() {
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;
    if(S.size() != A + B + 1) {
        cout << "No" << endl;
        return 0;
    }
    if(S.at(A) != '-') {
        cout << "No" << endl;
        return 0;
    }
    for(int i = 0;i < S.size();i++) {
        if(S.at(i) == '-' && i != A) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		int count=0;
		int E[] =  new int[N];
		int W[] =  new int[N];
		for (int i=0;i<N-1;i++) {
			if (s.charAt(i)=='W') {
				count++;
			}
			E[i+1]=count;
		}
		count =0;
		for (int i=N-1;i>=1;i--) {
			if (s.charAt(i)=='E') {
				count++;
			}
			W[i-1]=count;
		}
		int min = Integer.MAX_VALUE;
		for (int i=0;i<N;i++) {
			if (E[i]+W[i]<min) {
				min = E[i]+W[i];
			}
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 30688
#include<stdio.h>
#define Num 100

int main(){
   int i,j,m[Num][Num],n,x,y,z;

   scanf("%d",&n);

   for(i=0;i<n;i++){
      for(j=0;j<n;j++){
         m[i][j] = 0;
      }
   }

   for(i=0;i<n;i++){
      scanf("%d %d",&x,&y);
      x--;
      for(j=0;j<y;j++){
         scanf("%d",&z);
         z--;
         m[x][z]=1;
      }
   }


   for(i=0;i<n;i++){
      for(j=0;j<n-1;j++){
         printf("%d ",m[i][j]);
      }
      printf("%d\n",m[i][n-1]);
   }

   return 0;


}

Measured memory_bytes: 1776
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1e9+7;

const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

//********************************template END****************************************//

void solve(void){

	ll N;
	cin >> N;

	if (N == 0)
	{
		putln(0);
		return;
	}

	string ans;

	while(N != 0)
	{
		if (abs(N % (-2)))
		{
			ans.pb('1');
			N--;
		}
		else
		{
			ans.pb('0');
		}
		N /= -2;
	}

	reverse(all(ans));
	putln(ans);

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct data{ 
	int number;
	int point;
};
bool operator<(const data &data1,const data &data2){
	return data1.number < data2.number;
};

int main(){
	int n;
	cin >> n;
	priority_queue<data> q;
	int a,b;
	for(int i = 0; i < n; i++){
		cin >> a >> b;
		data c;
		c.number = a;
		c.point = b;
		q.push(c);
	}
	data x = q.top();
	cout << x.number + x.point << endl;
	return 0;
}

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

using namespace std;

int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    string s; 
    cin >> s;
    for(auto &i: s){
        if(i >= 'a' && i <= 'z') cout << (char)(i-'a'+'A');
        else
        if(i >= 'A' && i <= 'Z') cout << (char)(i-'A'+'a');
        else                     cout << (char)i; 
    }
    while(cin >> s){
        cout << " ";
        for(auto &i: s){
            if(i >= 'a' && i <= 'z') cout << (char)(i-'a'+'A');
            else
            if(i >= 'A' && i <= 'Z') cout << (char)(i-'A'+'a');
            else                     cout << (char)i; 
        }
    }
    cout << '\n';
    return 0;
}






Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

int w0, n, W;
vector<int> x[4];

int main(){
	scanf("%d%d", &n, &W);
	f(i, 0, n){
		int a, b;
		scanf("%d%d", &a, &b);
		if (!i)w0 = a;
		x[a - w0].push_back(b);
	}
	f(i, 0, 4){
		sort(x[i].begin(), x[i].end());
		reverse(x[i].begin(), x[i].end());
		f(j, 1, x[i].size())x[i][j] += x[i][j - 1];
		x[i].insert(x[i].begin(), 0);
	}
	int an = 0;
	f(i, 0, x[0].size())f(j, 0, x[1].size())f(k, 0, x[2].size())f(w, 0, x[3].size()){
		if ((ll)i * w0 + (ll)j * (w0 + 1) + (ll)k * (w0 + 2) + (ll)w * (w0 + 3) > W)break;
		an = max(an, x[0][i] + x[1][j] + x[2][k] + x[3][w]);
	}
	printf("%d\n", an);
}

Measured memory_bytes: 256
N=gets.to_i
A=gets.split.map(&:to_i)
A.sort!
exists=Hash.new(0)
used=Hash.new(0)
A.each do |a|
	exists[a]+=1
end
ans=0
A.reverse_each do |a|
	next if used[a]==exists[a]
	used[a]+=1
	target=1
	b=a
	while b!=0
		b>>=1
		target<<=1
	end
	if exists[target-a]>used[target-a]
		ans+=1
        used[target-a]+=1
	end
end
p ans

Measured memory_bytes: 41964
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    ll h, w;
    cin >> h >> w;
    
    ll ans;
    
    if ((h == 1) || (w == 1)) {
        ans = 1;
    } else {
        ans = (h * w + 1) / 2;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;

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

    int n, m, q, s[2100][2100], apx[2100][2100], v[2100][2100], h[2100][2100];

    cin >> n >> m >> q;

    fill(apx[0], apx[n], 0);
    fill(v[0], v[n], 0);
    fill(h[0], h[n], 0);

    FOR(i, 1, n + 1)
    {
        string s_;
        cin >> s_;

        s_ = '0' + s_;

        apx[i][0] = 0;
        h[i][0] = 0;
        v[i][0] = 0;

        s[i][0] = 0;

        FOR(j, 1, m + 1)
        {
            s[0][j] = 0;

            s[i][j] = (int)(s_[j] == '1');

            apx[i][j] = apx[i][j - 1] + s[i][j];

            h[i][j] = (int)(s[i][j - 1] + s[i][j] == 2) + h[i][j - 1];

            v[i][j] = (int)(s[i - 1][j] + s[i][j] == 2) + v[i][j - 1];
        }
    }

    FOR(i, 1, n + 1)
    REP(j, m + 1)
    {
        apx[i][j] += apx[i - 1][j];
        h[i][j] += h[i - 1][j];
        v[i][j] += v[i - 1][j];

        //cout << apx[i][j] << endl;
    }

    int ans[212345];
    int a__[212345];
    int h__[212345];
    int v__[212345];

    REP(i, q)
    {
        int x1, x2, y1, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        int a_ = apx[x2][y2] - apx[x1 - 1][y2] + apx[x1 - 1][y1 - 1] - apx[x2][y1 - 1];

        int h_ = h[x2][y2] - h[x1 - 1][y2] + h[x1 - 1][y1] - h[x2][y1];

        int v_ = v[x2][y2] - v[x1][y2] + v[x1][y1 - 1] - v[x2][y1 - 1];

        //cout << a_ << " " << h_ << " " << v_ << endl;

        //cout << a_ - (h_ + v_) << endl;

        ans[i] = a_ - (h_ + v_);

        a__[i] = a_;
        h__[i] = h_;
        v__[i] = v_;
    }

    REP(i, q)
    {
        //cout << a__[i] << " " << h__[i] << " " << v__[i] << endl;
        cout << ans[i] << endl;
    }

    /*
    FOR(i, 0, n + 1)
    {
        FOR(j, 0, m + 1)
        {
            cout << v[i][j] << (j == m ? "\n" : " ");
        }
    }
    */

    return 0;
}

Measured memory_bytes: 71168
/*
    Reference :-
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;
ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}
struct da{
    int x,y,c;
};
int main(){
    //std::ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a,b,m;
    cin>>a>>b>>m;
    int ar[a],br[b],mi1=INT_MAX,mi2=INT_MAX;
    forn(i,a){cin>>ar[i];mi1=min(mi1,ar[i]);}
    forn(i,b){cin>>br[i];mi2=min(mi2,br[i]);}
    //da cr[m];
    int ans=INT_MAX;
    forn(i,m){
        int a1,b1,c1;
        cin>>a1>>b1>>c1;
        int x1=ar[a1-1];
        int y1=br[b1-1];
        ans=min((x1+y1-c1),ans);
    }
    ans=min(ans,mi1+mi2);
    cout<<ans;


	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>//小数精度 	cout << fixed << setprecision(5) << tmp << endl;
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define All(X)      (X).begin(),(X).end()
const ll int INF =1000000001;

int n,q;
int bit[100010]={0};

void add(int i,int x){
	while(i<=n){
		bit[i] += x;
		i += i& -i;
	}
}

ll int getsum(ll int i){
	ll int s = 0;
	while(i>0){
		s += bit[i];
		i -= i& -i;
	}
	return s;
}

int main(){
	cin >> n >> q;
	REP(i,q){
		ll int tmp,x,y;
		cin >> tmp >> x >> y;
		if(tmp==0){
			//add
			add(x,y);
		}else{
			//getsum
			cout << getsum(y)-getsum(x-1) << endl;
		}
	}
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    vector<string> weathers = {"Sunny", "Cloudy", "Rainy"};
    int idx = (find(weathers.begin(), weathers.end(), S) - weathers.begin() + 1) % 3;
    cout << weathers[idx] << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,m;
  cin>>n>>m;
  vector<int> a(n),b(n);
  rep(i,m){
    int x,y;
    cin>>x>>y; --x; --y;
    if(x==0) a[y]=1;
    if(y==n-1) b[x]=1;
  }
  int re=0;
  rep(i,n)if(a[i]&&b[i]) re=1;
  cout<<(re?"POSSIBLE":"IMPOSSIBLE")<<endl;
  return 0;
}


Measured memory_bytes: 1792
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 100000 + 5, MOD = 1000000007;

const int offset = NAX / 2, maxLen = 2001;

bool ab[NAX], ac[NAX], bc[NAX];

class Solution
{
private:
    bool match(char c1, char c2)
    {
        return c1 == '?' || c2 == '?' || c1 == c2;
    }

public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        string a, b, c;
        cin >> a >> b >> c;
        int A = a.length();
        int B = b.length();
        int C = c.length();
        for (int i = 0; i < A; i++)
            for (int j = 0; j < B; j++)
                if (!match(a[i], b[j]))
                    ab[i - j + offset] = true;

        for (int i = 0; i < A; i++)
            for (int j = 0; j < C; j++)
                if (!match(a[i], c[j]))
                    ac[i - j + offset] = true;

        for (int i = 0; i < B; i++)
            for (int j = 0; j < C; j++)
                if (!match(b[i], c[j]))
                    bc[i - j + offset] = true;

        int ans = 3 * maxLen;

        for (int startB = -2 * maxLen; startB <= 2 * maxLen; startB++)
            for (int startC = -2 * maxLen; startC <= 2 * maxLen; startC++)
                if (!ab[startB + offset] && !ac[startC + offset] && !bc[startC - startB + offset])
                {
                    int L = min({0, startB, startC});
                    int R = max(A, max(B + startB, C + startC));
                    ans = min(ans, R - L);
                }
        cout << ans << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int ans = 0;
  string s;
  string t;
  int n;
  cin >> n;
  cin >> s;
  int num = 0;
  int i,j;
  int left = 0;
  int right = 0;
  for(i=0;i<n;i++){
    if(s[i]=='('){
      num++;
      t += "(";
    }else{
      if(num==0)left++;
      else {
        num--;
      }
      t += ")";
    }
  }
  for(i=0;i<num;i++){
    t += ")";
  }
  for(i=0;i<left;i++){
    t = "(" + t;
  }

cout << t<<endl;
}


Measured memory_bytes: 256
# Wrote in Feb 29, 2020 13:33 by reetok
require 'time'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=:to_i)
  t = []
  n.times do
    t.push(eval("gets.chomp.#{datatype.to_s}"))
  end
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
#---------------

a,b,c = inp
ynju( (a<b&&b<c) )


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

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const int INF = (1<<29);
int cost[201][201], r[8];
int N, R, ans;
bool visited[201];

void dfs(int cnt, int last, int dist){
    if(cnt == R){
        ans = min(ans, dist);
        return;
    }

    for(int i=0; i<R; i++){
        if(visited[r[i]] == false){
            visited[r[i]] = true;
            if(last == -1) dfs(1, r[i], 0);
            else dfs(cnt+1, r[i], dist+cost[last][r[i]]);
            visited[r[i]] = false;
        }
    }
}

void floyd(){
    for(int k=1; k<=N; k++){
        for(int i=1; i<=N; i++){
            if(cost[i][k] == INF) continue;

            for(int j=1; j<=N; j++){
                if(cost[k][j] == INF) continue;

                cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
            }
        }
    }
}

int main(){
    int M; cin >> N >> M >> R;
    for(int i=0; i<R; i++) cin >> r[i];

    for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) cost[i][j] = ((i == j)? 0:INF);

    for(int i=0; i<M; i++){
        int a,b,c; cin >> a >> b >> c;
        cost[a][b] = cost[b][a] = c;
    }

    ans = INF;

    floyd();
    dfs(0, -1, 0);
    cout << ans << endl;
}

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


signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    int r[n];
    for(int i=0;i<n;i++) cin>>r[i];
    int a[n][3];
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    int ans = 1e9;
    for(int c=0;c<3;c++){
        int p[n]={};
        // 変更させる奴以外の得点を求める
        for(int d=0;d<3;d++){
            if(d==c)continue;
            pair<int,int> pa[n]={};
            for(int i=0;i<n;i++){
                pa[i] = make_pair(a[i][d],i);
            }
            sort(pa,pa+n,greater<pair<int,int>>());
            int now = 0;
            for(int i=0;i<n;i++){
                if(i && pa[i].first != pa[i-1].first) now=i;
                p[pa[i].second] += r[now];
            }
        }
        for(int x=1;x<=100;x++){
            pair<int,int> totori[n];
            for(int i=0;i<n;i++){
                if(i==0) totori[i] = make_pair(a[i][c]+x,i);
                else totori[i] = make_pair(a[i][c],i);
            }
            sort(totori,totori+n,greater<pair<int,int>>());
            int now = 0;
            pair<int,int> nyaa[n]={};
            for(int i=0;i<n;i++){
                if(i && totori[i].first != totori[i-1].first) now=i;
                int idx = totori[i].second;
                nyaa[idx] = make_pair(r[now]+p[idx],idx);
            }
            sort(nyaa,nyaa+n,greater<pair<int,int>>());
            // if(x<=2){
            //     for(int i=0;i<n;i++){
            //         cout <<c<< "deeeee " << x << " " << nyaa[i].first << " " << nyaa[i].second << endl; 
            //     }
            // }
            int wow=0,cnt=1;
            wow=nyaa[0].first;
            if(nyaa[0].second == 0){
                ans = min(ans,x);
                break;
            }
            for(int i=1;i<n;i++){
                if(i>=8 && nyaa[i].first != wow) break;
                wow=nyaa[i].first;
                if(nyaa[i].second==0){
                    ans = min(ans,x);
                    break;
                }
            }
            if(ans<=x) break;
        }
    }
    if(ans==1e9){
        cout << "Saiko" << endl;
        return 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3212
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000
#define N 2000001
int n;

void CountingSort(short *A,short *B,int k){
  int i,j;
  int C[MAX+1];

  for(i=0;i<=k;i++){
    C[i]=0;
  }

  for(j=1;j<=n;j++){
    C[A[j]]++;
  }

  for(i=1;i<=k;i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    printf("%hu",B[i]);
    if(i<n)
      printf(" ");
  }

}


int main(){

  int i;
  unsigned short *A,*B;

  scanf("%d",&n);
  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

  for(i=0;i<n;i++){
    scanf("%hu",&A[i+1]);
  }

  CountingSort(A,B,MAX);
  printf("\n");

  return 0;
}

Measured memory_bytes: 8468
N = int(input())
d = {}
for n in range(2,N+1):
    i = 2
    while i <= n:
        while n % i == 0:
            n //= i
            if i not in d:
                d[i] = 0
            d[i] += 1
        i += 1

ans_d = {3:0,5:0,15:0,25:0,75:0}    

for p in d:
    for n in ans_d:    
        if d[p] >= n-1:
            ans_d[n] += 1

ans = ans_d[5]*(ans_d[5]-1)*(ans_d[3]-2)//2+ans_d[75]

for n1 in ans_d:
    for n2 in ans_d:
        if n1 < n2 and n1*n2 == 75:
            ans += ans_d[n2]*(ans_d[n1]-1)

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int H, W, N;
	cin >> H >> W >> N;
	int M = max(H, W);
	if (N % M == 0) {
		cout << N / M << endl;
	}
	else {
		cout << N / M + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int ans=10000000000000;
  repi(i,1,sqrt(n)+1 ){
    if(n%i==0){
      ans=min(ans,i+(n/i)-2);
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n;
    typedef tuple<double, double> p;
    vector<p> v;

    cin >> n;
    REP(i, n) {
        double x, y;
        cin >> x >> y;
        v.push_back(make_tuple(x, y));
    }
    sort(ALL(v));
    vector<double> r;
    do {
        double tmp = 0;
        REP(i, v.size()-1) {
            tmp += sqrt(pow(get<0>(v[i+1]) - get<0>(v[i]), 2) + pow(get<1>(v[i+1]) - get<1>(v[i]), 2));
        }
        r.push_back(tmp);
    } while (next_permutation(v.begin(), v.end()));
    cout.precision(17);
    cout << fixed << accumulate(r.begin(), r.end(), (double) 0) / (double) r.size() << endl;
    return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  string rev = readString(), n;
  n = rev;
  reverse(rev.begin(), rev.end());
  if (n == rev)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int cnt[100][26];


int main(){
  int n;
  cin>>n;
  string str[100];
  for(int i=0;i<n;i++){
    cin>>str[i];
    for(int j=0;j<str[i].size();j++)cnt[i][str[i][j]-'a']++;
  }
  
  string ans;
  for(int i=0;i<26;i++){
    int mn = 1000;
    for(int j=0;j<n;j++) mn=min(mn,cnt[j][i]);
    if(mn>=1) ans+=string(mn,i+'a');
  }
  cout<<ans<<endl;  
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

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

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

template<class T, class U>inline bool chmax(T &a, const U &b) { if(a<b){ a=b; return 1; } return 0; }
template<class T, class U>inline bool chmin(T &a, const U &b) { if(b<a){ a=b; return 1; } return 0; }


int main() {
  int n; cin>>n;
  vector<int> p(n), q(n), c(n);
  rep(i, n) cin>>p[i];
  rep(i, n) cin>>q[i];

  int a = 0, b = 0;
  iota(c.begin(), c.end(), 1);
  int i = 0;
  do {
    bool good = true;
    rep(j, n) if (p[j] != c[j]) good = false;
    if (good) a = i;
    good = true;
    rep(j, n) if (q[j] != c[j]) good = false;
    if (good) b = i;
    ++i;
  } while(next_permutation(c.begin(), c.end()));
  print(abs(a-b));

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <numeric>
#include <unordered_map>
using namespace std;
int num(long long int maximum,long long int minimum) {
	int count = 0;
	long long int n = maximum / minimum;
	long long int m = 1;
	while (true) {
		if (m <= n) {
			m *= 2;
			count++;
		}
		else break;
	}
	return count;
}
int main() {
	long long int max, min;
	cin >> min >> max;
	cout << num(max, min);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int n,d,ans,res,a[N][N],b[N][N],c[N][N];
int sumc(int x,int y)
{
    if(x<0||y<0) return 0;
    return c[x][y];
}
int sumb(int x,int y)
{
    if(x<0||y<0) return 0;
    return b[x][y];
}
int getc(int x1,int y1,int x2,int y2)
{
    return sumc(x2,y2)+sumc(x1-1,y1-1)-sumc(x2,y1-1)-sumc(x1-1,y2);
}
int getb(int x1,int y1,int x2,int y2)
{
    return sumb(x2,y2)+sumb(x1-1,y1-1)-sumb(x2,y1-1)-sumb(x1-1,y2);
}
bool judge(int i,int j,int res)
{
    if(getc(i+res+1,j,i+d-1,j+res)+getc(i,j+res+1,i+res,j+d-1)) return false;
    if(getb(i+res+1,j+res+1,i+d-1,j+d-1)) return false;
    return true;
}
int main()
{
    scanf("%d%d",&n,&d);
    int mx=0;
    for(int i=1;i<=n;i++)
    {
        int x,y;scanf("%d%d",&x,&y);
        x%=d;y%=d;
        a[x][y]++;
        mx=max(mx,a[x][y]);
    }
    for(int i=0;i<d;i++)
        for(int j=0;j<d;j++)
        a[i+d][j+d]=a[i+d][j]=a[i][j+d]=a[i][j];
    ans=sqrt(mx);
    if(ans*ans==mx) ans--;
    res=d-1;
    for(int i=0;i<2*d;i++)
        for(int j=0;j<2*d;j++)
    {
        if(a[i][j]>ans*ans) b[i][j]=1;
        if(a[i][j]>ans*(ans+1)) c[i][j]=1;
    }
    for(int i=0;i<2*d;i++)
        for(int j=1;j<2*d;j++)
    {
        b[i][j]+=b[i][j-1];
        c[i][j]+=c[i][j-1];
    }
    for(int i=1;i<2*d;i++)
        for(int j=0;j<2*d;j++)
    {
        b[i][j]+=b[i-1][j];
        c[i][j]+=c[i-1][j];
    }
    for(int i=0;i<d;i++)
        for(int j=0;j<d;j++)
        while(judge(i,j,res-1)) res--;
    printf("%d\n",ans*d+res);
}


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

int main() {
    int n;cin>>n;
    int c[10][10]{};
    for (int i=1;i<=n;i++) {
        string s=to_string(i);
        c[s[0]-'0'][s.back()-'0']++;
    }
    int ans=0;
    for (int i=1;i<=9;i++)
        for (int j=1;j<=9;j++)
            ans+=c[i][j]*c[j][i];
    cout<<ans<<endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  ll n, k, result=1;
  cin>>n>>k;

  result=k;
  rep(i, n-1){
    result *= (k-1);
  }

  cout<<result;

  return 0;
}

Measured memory_bytes: 256
N=int(input())
def gcd(a,b):
  if a==b:
    return a
  else:
    a,b=max(a,b),min(a,b)
    if a%b==0:
      return b
    return gcd(b,a%b)  
lcm=int(2*N/gcd(2,N))
print(lcm)   

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<int>vec(N);
	rep(i, 0, N)cin >> vec[i];
	map<int, ll>mp;
	rep(i, 0, N) {
		mp[vec[i]]++;
	}
	ll ans = 0;
	for (auto p : mp) {
		if (p.second < 2)continue;
		ans += (p.second) * (p.second - 1) / 2;
	}
	rep(i, 0, N) {
		ll x = mp[vec[i]];
		ll hoge = ans - x * (x - 1) / 2;
		--x;
		hoge += x * (x - 1) / 2;
		cout << hoge << "\n";
	}

	return 0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  vector<double>p(N);
  for(int i=0;i<N;i++){
    cin >> p.at(i);
    p.at(i) =0.5*p.at(i)+0.5;
  }

  vector<double>sum(N+1);
  sum.at(0)=0;
  for(int i=1;i<N+1;i++){
    sum.at(i)=sum.at(i-1)+p.at(i-1);
  }
  double max=0;
  for(int i=0;i<N-K+1;i++){
    if(max<sum.at(K+i)-sum.at(i)){
      max=sum.at(K+i)-sum.at(i);
    }
  }
  cout << fixed << setprecision(1) << max << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cmath>
#define eps 1.0e-9

using namespace std;

int N;
double x[305], y[305];

int count(double cx, double cy)
{
	int ret = 0;
	for(int i = 0; i < N; i++){
		if( (cx - x[i])*(cx - x[i]) + (cy - y[i])*(cy - y[i]) <= 1 + eps) ret++;
	}
	return ret;
}

int main(void)
{
	while(1){
		cin >> N;
		if(N == 0) break;
		for(int i = 0; i < N; i++) cin >> x[i] >> y[i];
		
		int ans = 1;
		double cx, cy;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				if(i >= j) continue;
				
				double px = x[j] - x[i];
				double py = y[j] - y[i];
				double pnorm = sqrt(px*px + py*py);
				px /= pnorm;
				py /= pnorm;
				
				double mx = (x[i] + x[j]) / 2.0;
				double my = (y[i] + y[j]) / 2.0;
				
				double qnorm = 1 - pnorm*pnorm/4.0;
				if(qnorm < eps) continue;
				qnorm = sqrt(qnorm);
				double qx = qnorm * py;
				double qy = qnorm * -px;
				
				ans = max(ans, count(mx + qx, my + qy));
				ans = max(ans, count(mx - qx, my - qy));
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3116