akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
                using namespace std;
                typedef long long ll;
                #define INPUT()              freopen("input.txt", "r", stdin)
                #define OUTPUT()             freopen("output.txt", "w", stdout)
                #define F                    first
                #define S                    second
            //Templatefunctions
                template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y);}
                template <class T> T euclideanDistance(T x1 , T x2 , T y1 , T y2){return sqrt(( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ));}
                template <class T> T digitSum(T n){T sum = 0;while(n > 0)sum += n % 10,n /= 10;return sum;}
            //datatypes
                typedef long long int ll;
                typedef unsigned long long int ull;
                typedef long double ld;
            //constants
                const double INF = 1e+9;
                const double INFLL = 1e+18;
                const double EPS = 1e-9;
                const double PI = acos(-1);
                const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
                       //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
                       //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
                const int dx[] = {0 , 1 , 0 , -1};
                const int dy[] = {1 , 0 , -1 , 0};
            //helpers
                //#define MOD         1000000007LL
                #define MAX         1000005
                const ll MOD = 998244353;
                int arr[MAX];
            //Global Variables



                int main()
                {

                        string s;
                        cin>>s;

                        int len = s.length() , firstA , lastZ;

                        for(int i = 0 ; i < len ; i++)
                        {
                            if(s[i] == 'A')
                            {
                                firstA = i+1;
                                break;
                            }
                        }
                        for(int i = len-1 ; i >= 0 ; i--)
                        {
                            if(s[i] == 'Z')
                            {
                                lastZ = i+1;
                                break;
                            }
                        }
                        printf("%d\n",lastZ - firstA + 1);
                }


Measured memory_bytes: 640
#include <iostream>
#include <iterator>
#include <algorithm>
#include <map>
using namespace std;

int main(void){
    // Your code here!
    string s;
    cin >> s;
    for(int i =0; i < s.size(); i++){
        if(s[i] == '9'){
            cout << 1;
        }else if(s[i] == '1'){
            cout << 9;
        }else{
            cout << s[i];
        }
    }
    cout << endl;

    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())
 
int main() {
  int n,m;
  cin >> n >> m;

  vector<string> ab(m);
  rep(i,m){
    string a,b;
    cin >> a>> b;
    ab.at(i) = a + b;
  }

  vector<int> edge(n);
  rep(i,n) edge.at(i) = i+1;
  srt(edge);

  int cnt=0;
  do{
    if(edge.at(0)!=1) continue;

    bool isAll = true;;
    for(int i=0; i<n-1; i++){
      int ai = edge.at(i);
      int bi = edge.at(i+1);

      bool isCon = false;
      for(string tmp: ab){
        if((ai==(tmp.at(0)-'0') && bi==(tmp.at(1)-'0') )||
           (ai==(tmp.at(1)-'0') && bi==(tmp.at(0)-'0') )) {
          isCon = true; 
          break;
        }
      }
      if(!isCon){
        isAll = false;
        break;
      }
    }

    if(isAll) cnt++;

  }while(next_permutation(edge.begin(), edge.end()));

  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf INT_MAX
using namespace std;
int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//memset(sum,0,sizeof sum);
	int x,b,i,m,good=0,c,n;
	cin>>n>>m;
	int a[n+3];
	for(i=0;i<n;i++)
	cin>>a[i+1];
	//for(i=1;i<=n;i++)
	//cout<<a[i]<<" ";
	vector<int>g[n+1];
	for(i=0;i<m;i++){
		cin>>x>>b;
		g[x].pb(b);
		g[b].pb(x);
	}
	for(i=1;i<=n;i++){
		if(g[i].size()==0){
			//cout<<i<<endl;
			good++;
			continue;
		}
		c=0;
		for(auto k:g[i]){
			//cout<<k<<" ";
			if(a[k]<a[i])
			c++;
		}
		if(c==g[i].size()){
			//cout<<i<<endl;
		good++;
	}
	}
	cout<<good<<endl;
}


Measured memory_bytes: 9128
#include <cstdio>

const int MN = 200005;

char s[MN], t[MN];
int tp;

int main() {
	scanf("%s", s + 1);
	for (int i = 1; s[i]; ++i) {
		if (tp && t[tp] == 'S' && s[i] == 'T') --tp;
		else t[++tp] = s[i];
	}
	printf("%d\n", tp);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> X(N);
    REP(i,N) cin >> X[i];
    ll ans = LINF;
    for(int i=-100;i<=100;i++){
        ll tmp = 0;
        REP(j,N) tmp += (X[j] - i) * (X[j] - i);
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayDeque<Integer>deq = new ArrayDeque<Integer>();
		
		int n = sc.nextInt();
		
		if(n % 2 == 0) {
			for(int i = 0 ; i < n/2 ; i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				deq.add(a);
				deq.addFirst(b);
			}
			for(int i = 0; i < n ; i++) {
			System.out.print(deq.poll()+" ");
			}
		}
		
		if(n % 2 == 1) {
			int a = sc.nextInt();
			deq.add(a);
			for(int i = 0 ; i < (n - 1)/2 ; i++ ) {
				int b = sc.nextInt();
				int c = sc.nextInt();
				deq.add(b);
				deq.addFirst(c);
			}
			for(int i = 0; i < n ; i++) {
				System.out.print(deq.poll()+" ");
				}
		}
 
	}

}


Measured memory_bytes: 99332
#include <iostream>

using namespace std;

#define int long long

const int N = 2e5 + 10;

int n, k, a[N];

bool f(int m) {
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += (a[i] + m - 1) / m - 1;
  }
  return ans <= k;
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);    
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int l = 1, r = 1e9;
  while ((r - l) > 3) {
    int m = (l + r) >> 1;
    if (f(m)) r = m;
    else l = m + 1;
  }
  while (l <= r) {
    if (f(l++)) {
      cout << l - 1;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 5092
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();

		int sum = 0;

		sum =(int)(t / a) * b;

		System.out.println(sum);
	}
}



Measured memory_bytes: 23636
#dame datta...
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
def main():
    N, M, L = map(int, input().split())
    l = [[0] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        if c > L:
            continue
        l[a-1][b-1] = c
        l[b-1][a-1] = c
    G = csr_matrix(l)
    d = floyd_warshall(G)
    l = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                l[i][j] = 1
    G = csr_matrix(l)
    d = floyd_warshall(G)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        x = d[s][t]
        if x != float('inf'):
            print(int(x)-1)
        else:
            print(-1)
main()


Measured memory_bytes: 20276
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

const int Maxn = 60;
ll dp[Maxn][Maxn][3000];
int x[Maxn];

int main(){
    int n, a;
    cin >> n >> a;
    REP(i,0,n){
        cin >> x[i];
    }

    memset(dp, 0, sizeof(dp));
    REP(i,0,n + 1) dp[i][0][0] = 1;
    REP(i,1,n + 1){
        REP(j,1,n + 1){
            REP(k,0,3000){
                dp[i][j][k] = dp[i - 1][j][k];
                if (k >= x[i - 1]) dp[i][j][k] += dp[i - 1][j - 1][k - x[i - 1]];
            }
        }
    }
    
    ll ans = 0;
    REP(j,1,n + 1){
        if (j * a < 3000){
            ans += dp[n][j][j * a];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 84608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=2e3+5;
const int MD=1e9+7;
ll a[M],b[M],c[M],k;
ll ans=0,tmp;
int main()
{
	int n;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	tmp=k*(k-1)/2;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<i;j++)
		{
			if(a[i]<a[j]) b[i]++;
		}
		for(int j=1;j<=n;j++)
		{
			if(a[i]<a[j]) c[i]++;
		}
		//cout<<b[i]<<" "<<c[i]<<endl;
	}
	for(int i=1;i<=n;i++)
	{
		ans=(ans+(k*b[i])%MD)%MD;
		ans=(ans+(tmp%MD*c[i])%MD)%MD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M = LI()

    M_div = []
    for i in range(1, int(M ** 0.5) + 1):
        if M % i == 0:
            M_div.append(i)
            M_div.append(M // i)

    # Mの約数の中でMを割った時の値がN以上になるような最大のもの
    ans = 1
    for i in M_div:
        if M // i >= N:
            ans = max(i, ans)

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10272
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e18+7
#define lim (lld)1e9+7
#define MAX2 (int)2e5+9
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const lld mod=lim;

lld power(lld x, lld y, lld p)  
{   lld res = 1;     x = x % p; if (x == 0) return 0;  
  
    while (y > 0)  
    { if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;   }  
    return res;  } 


int extend_gcd(int a, int b, int& x, int& y) {
    if (b == 0) { x = 1;y = 0;return a;}
    int x1, y1;
    int d = extend_gcd(b, a % b, x1, y1);
    x = y1; y = x1 - y1 * (a / b);return d;	}

int rowNum[]={-1,0,0,1};
int colNum[]={0,-1,1,0};

int main()
{
	fastio
    int x,y,ans;
    cin>>x>>y;

    if((y-2*x)>=0 && (y-2*x)%2==0 && (4*x-y)>=0 && (4*x-y)%2==0)
        cout<<"Yes"<<endl;

    else cout<<"No"<<endl;

}

Measured memory_bytes: 3648
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] array = new int[100];

		while (sc.hasNext()) {
			int number = Integer.parseInt(sc.nextLine());
			array[number-1] += number;
		}

		for(int i = 0 ; i < array.length ; i++){
			if(array[i] > 0 ){
					array[i] /= i+1;
			}
		}
		int max = 0;
		for(int ary : array){
			if (ary > max) {
				max = ary;
			}
		}
		for (int i = 0; i < array.length; i++) {
			if(array[i] == max){
				System.out.println(i+1);
			}
		}
	}

}

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

int main (){
    
	int N;cin>>N;
	vector<pair<int,int>> A(N);
	for(int i=0;i<N;++i){
		int a;cin>>a;
		A[i]=make_pair(a,i);
	}
	sort(A.begin(),A.end());
	for(int i =0;i<N;++i){
		cout<<A[i].second+1<<endl;
	}
	return 0;
}

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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    uint32_t N ;
    cin >> N;
    std::unordered_map<int32_t, uint32_t> data;

    for(uint32_t i = 0 ; i < N ; i++){
        int32_t a;
        cin >> a;
        if(data.find(a) == data.end()){
            data[a] =  1;
        }else{
            data[a] = data[a] + 1;
        }
    }
    uint32_t Q;
    uint64_t sum = 0;
    for(auto it = data.begin(); it != data.end() ; it++){
        sum += (*it).first * (*it).second;
    }
    cin >> Q;
    while(Q--){
        int32_t B, C;
        cin >> B >> C;
        uint32_t count_before = data[B];
        data.erase(B);
        if( data.find(C) == data.end()){
            data[C] = count_before;
        }else{
            data[C] = data[C] + count_before;
        }
        sum = sum + C * count_before - B * count_before;
        cout << sum << endl;
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 3;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 6588
#include<bits/stdc++.h>
#define MOD 1000000007
#define EPS (1e-10)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int a[100000];
int main() {
	int n, t; scanf("%d%d", &n, &t);
	rep(i, n)scanf("%d", &a[i]);
	priority_queue<P>se;
	map<int, vector<P>>mp;
	for (int i = n - 2; i >= 0; i--) {
		se.push(P(a[i + 1], i + 1));
		mp[se.top().first - a[i]].push_back(P(i, se.top().second));
	}
	vector<P> v = (*mp.rbegin()).second;
	set<int>s[2];
	for (auto p : v) {
		s[0].insert(p.first);
		s[1].insert(p.second);
	}
	int cnts = s[0].size(), cntg = s[1].size();
	for (int i : s[0]) {
		bool d = 1;
		int k = i;
		set<int>::iterator itr;
		while ((itr = s[d].find(k)) != s[d].end()) {
			cnts++;
			k = *itr;
			d = !d;
		}
	}
	for (int i : s[1]) {
		bool d = 0;
		int k = i;
		set<int>::iterator itr;
		while ((itr = s[d].find(k)) != s[d].end()) {
			cntg++;
			k = *itr;
			d = !d;
		}
	}
	printf("%d\n", min(cnts, cntg));
}

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

int main()
{
    int a, b, x;
    cin >> a >> b >> x;
    double da = a;
    double db = b;
    double dx = x;
    if (x <= da * da * db / 2)
    {
        double y;
        y = 2.0 * dx / (da * db);
        double ans = atan(db / y) * 180.0 / M_PI;
        cout << fixed << setprecision(10) << ans << endl;
    }
    else
    {
        double y;
        y = 2.0 * dx / (da * da) - db;
        double ans = 90.0 - atan(da / (db - y)) * 180.0 / M_PI;
        cout << fixed << setprecision(10) << ans << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <numeric>
#include <complex>
using namespace std;

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

char field[200][200];

int main() {
    int N, M;
    cin >> N >> M;
    int road[110];
    rep(i, M*2) {
        cin >> road[i];
    }
    rep(i, N) {
        cout << count(road, road + M*2, i+1) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない




int main() {

	int m, n;
	cin >> n >> m;
	int l = 1;
	rep(i, 0, m) {
		l = l * 2;
	}

	cout << (1900 * m + 100 * (n - m))*l << endl;

	return 0;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
ans = 0
for i in range(n+1):
    if x > 2 ** (n + 1 - i) - 1:
        x -= 2 ** (n + 1 - i) - 1
        ans += 2 ** (n - i)
    elif x == 2 ** (n + 1 - i) - 1:
        ans += 2 ** (n - i)
        break
    elif x == 2 ** (n + 1 - i) - 2:
        ans += 2 ** (n - i) - 1
        break
    else:
        x -= 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	int a,p;
	cin >> a >> p;
	cout << (a*3+p)/2 << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                string[] input = line.Split(' ');
                int a = int.Parse(input[0]);
                int b = int.Parse(input[1]);
                string num = "" + (a + b);
                Console.WriteLine(num.Length);
            }
        }
    }
}

Measured memory_bytes: 5616
import sys
import numpy as np


def input():
    return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    al = sorted([int(e) for e in input().split()])

    ans = 0
    size = 0
    for a in al:
        if size * 2 < a:
            ans = 1
        else:
            ans += 1
        size += a
    print(ans)


main()


Measured memory_bytes: 23132
#include<bits/stdc++.h>
#define pb push_back
#define p(x,y) ((x-1)*n+y)
using namespace std;
typedef double db;
const int P=1010,N=P*P,U=2e7+10;
int n,tot=0,B,las;
int pl[N],del[N];
struct Data
{
	vector<int> s[2];
}f[N];
struct MSolve
{
	int D,top,cnt;
	int cx[50],cy[50],col[N],vis[N];
	void dfs(int x,int y)
	{
		int id=p(x,y),i,v,t1,t2,nx,ny;
		vis[id]=1;
		//printf("P%d %d  %d\n",x,y,col[id]);
		f[tot].s[col[id]].pb(id);
		for(i=1;i<=top;i++)
		{
			for(t1=0;t1<2;t1++)
			{	
				for(t2=0;t2<2;t2++)
				{
					nx=x+(t1==0?cx[i]:-cx[i]);ny=y+(t2==0?cy[i]:-cy[i]);
					if(nx>=1&&nx<=n&&ny>=1&&ny<=n) 
					{
						v=p(nx,ny);col[v]=col[id]^1;
						if(!vis[v]) dfs(nx,ny);
					}
				}
			}
		}
	}
	void solve()
	{
		int i,j,w;
		cin>>D;
		if(D==las) return ;
		las=D;
      	
		for(i=0;i<n&&i*i<=D;i++)
		{
			w=floor(sqrt(D-i*i)+0.5);
			if(i*i+w*w==D) 
			{
				top++;cx[top]=i;cy[top]=w;
			}
		}
		
        tot++;f[tot].s[0].clear();f[tot].s[1].clear();
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(vis[p(i,j)]) continue;
				dfs(i,j);
			}
		}
       
		//en=clock();
		//printf("time%d\n",(int)(en-st));
	}
}h1,h2;
bool cmp(const int &a,const int &b){return f[a].s[0].size()+f[a].s[1].size()>f[b].s[0].size()+f[b].s[1].size();}
void dfs(int xh,int nas)
{
  //printf("tot%d\n",tot);
  
  //puts("OK");exit(0);
	if(nas<B) return ;
	if(xh==tot+1)
	{
         
		int num=0;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(del[p(i,j)]==0) num++,printf("%d %d\n",i-1,j-1);
				if(num==B) exit(0);
			}
		}
		return ;
	}
	int val,i,j,id,vsi,x;
	for(i=0;i<2;i++)
	{
		id=pl[xh];
      
        vsi=f[id].s[i].size();
		val=nas;
		for(j=0;j<vsi;j++)
		{
          	x=f[id].s[i][j];
			if(!del[x]) val--;
			del[x]++;
		}
        
		dfs(xh+1,val);
		for(j=0;j<vsi;j++)
		{
          	x=f[id].s[i][j];
			del[x]--;
         	if(!del[x]) val++;
          	
		}
	}
}
int main()
{

	int i;
	cin>>n;n*=2;
	B=(n>>1)*(n>>1);
	h1.solve();h2.solve();
	for(i=1;i<=tot;i++) pl[i]=i;
	sort(pl+1,pl+tot+1,cmp);
   
	dfs(1,n*n);

	return 0;
}

Measured memory_bytes: 86036
import std.stdio;
import std.conv;
import std.string;

int main(string[] argv)
{
	immutable MAX_HIGHT = 10000;
	immutable INPUT = 10;

    int[] hill;
	int count = 0;

	while(count < 10){
		int temp = readln().chomp().to!int();
		if(0 <= temp && temp <= MAX_HIGHT){
			hill ~= temp;
			count++;
		}
	}

	int temp;
	for(int i = 0;i < INPUT - 1;i++){
		for(int j = INPUT - 1;j > i;j--){
			if(hill[j-1] < hill[j]){
				temp = hill[j];
				hill[j] = hill[j-1];
				hill[j-1] = temp;
			}
		}
	}

	for(int i = 0;i < 3;i++){
		writeln(hill[i]);
	}

    return 0;
}

Measured memory_bytes: 2416
#include<iostream>
#include<cstdio>
#define MN 100000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int f[11][MN+5],c[MN+5],n,m,q,head[MN+5],cnt=0;
struct edge{int to,next;}e[MN*2+5];
inline void ins(int f,int t)
{
	e[++cnt]=(edge){t,head[f]};head[f]=cnt;
	e[++cnt]=(edge){f,head[t]};head[t]=cnt;	
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;++i) ins(read(),read());
	q=read();
	for(int i=1;i<=q;++i)
	{
		int x=read(),d=read();c[i]=read();
		f[d][x]=i;
	}
	for(int i=10;i;--i)
		for(int j=1;j<=n;++j)
		{
			f[i-1][j]=max(f[i-1][j],f[i][j]);
			for(int k=head[j];k;k=e[k].next)
				f[i-1][e[k].to]=max(f[i-1][e[k].to],f[i][j]);	
		}
	for(int i=1;i<=n;++i) printf("%d\n",c[f[0][i]]);
	return 0;
}

Measured memory_bytes: 7296
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

bool cmp(int a, int b){
  return b < a;
}

int main(){
  vector<int> sticks;
  int n, k;
  scanf("%d %d", &n, &k); 
  for(int i = 0; i < n ; i++){
    int tmp;
    scanf("%d", &tmp);
    sticks.push_back(tmp);
  }
  sort(sticks.begin(), sticks.end(), cmp );

  int sum = 0;
  for(int i = 0; i < k; i++){
    sum += sticks[i];
  }
  printf("%d\n", sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
	}
	sort(vec.begin(), vec.end());
	int res = 0;
	for(int i = 0; i < n; ++i){
		for(int j = i + 1; j < n; ++j){
			int l = j + 1;
			int r = n;
			int a = vec[i];
			int b = vec[j];
			while(l <= r){
				int m = l + (r - l) / 2;
				int c = vec[m];
				if(a < b + c && b < c + a && c < a + b){
					l = m + 1;
				}
				else{
					r = m - 1;
				}
			}
			if(r > j){
				res += (r - j);
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


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

int a[5555], b[5555], c[5555], d[3333], e[3333];
int main() {
	int n, m, p;
	cin >> n >> m >> p;
	for (int i = 0; i < m; i++)
		cin >> a[i] >> b[i] >> c[i];
	e[n] = 1;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			e[a[j]] |= e[b[j]];
	fill(d, d + n + 1, -21e8);
	d[1] = 0;
	e[1] |= 2;
	for (int i = 0; i < n; i++) {
		int u = 1;
		for (int j = 0; j < m; j++) {
			e[b[j]] |= e[a[j]] & 2;
			if (d[a[j]] + c[j] - p > d[b[j]]) {
				d[b[j]] = d[a[j]] + c[j] - p;
				if (e[b[j]] > 2) u = 0;
			}
		}
		if (u) goto pnz;
	}
	cout << -1 << endl;
	return 0;
pnz:
	cout << max(d[n], 0) << endl;
	return 0;
}


Measured memory_bytes: 384
import math
k = int(input())

def gcd_3(a,b,c):
    x = math.gcd(a,b)
    y = math.gcd(x,c)
    return y
li = []
count = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        li.append(math.gcd(i,j))
for i in range(1,len(li)+1):
    for j in range(1,k+1):
        count += math.gcd(li[i-1],j)
print(count)

Measured memory_bytes: 9364
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;
const long MOD = 1000000007;

vector<vector<ll>> v;

int main(){
    ll N,M;
    cin>>N>>M;
    v.resize(N);

    for(ll i=0;i<M;i++){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll res[N];
    vector<ll> dist(N, -1);
    dist[0] = 0; 
    queue<ll> que;
    que.push(0);
    while(!que.empty()){
        ll cur = que.front();que.pop();
        for(ll next:v[cur]){
            if(dist[next] != -1) continue;
            dist[next] = dist[cur] + 1;
            res[next] = cur;
            que.push(next);
        }
    }
    bool ok=true;
    for(ll i=1;i<N;i++){
        if(res[i]==-1)ok=false;
    }
    if(!ok){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
        for(ll i=1;i<N;i++){
            cout<<(res[i]+1)<<"\n";
        }
    }
}


Measured memory_bytes: 13692
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;

// a と b の最大公約数を返す
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}


ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}



// 素数判定
bool is_prime(ll N) {
    if (N == 1) return false;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}


// 約数列挙
vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll N){
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= N; i++){
        if(N % i != 0)  continue;
        ll ex = 0;

        while(N % i == 0){
            ex++;
            N /= i;
        }

        res.push_back({i, ex});
    }

    if(N != 1)  res.push_back({N, 1});
    return res;
};



int main(){
    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;

    return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	int a, b;
	cin >> a >> b;

	cout << (a + b) % 24 << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	long n, m, ans;
	scanf("%ld%ld", &n, &m);
	if(n>=m/2){
		ans=m/2;
	}else{
		ans=n+(m-n*2)/4;
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
    int count=0;
    int a,b,c;
    
    cin >> a >> b >> c;
    for(int i = a;i<=b;i++){
        if(c%i==0){
            count++;
        }
    }
    
    cout << count <<endl;
    
    return 0;
}


Measured memory_bytes: 3108
#!/usr/bin/env python3
import sys


def solve(S: int, W: int):
    if S <= W:
        print("unsafe")
    else:
        print("safe")

    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(S, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61716
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
#define pb push_back
#define endl '\n'
bool cmp(char a, char b){
	return a<b;
}
ll modex(ll a, ll b, ll mod){
	ll ans=1;
	while(b){
		if(b%2) ans=(ans*a)%mod;
		a=(a*a)%mod;
		b/=2;
	}
	return ans;
}
bool flag=0;
ll solve(){
	ll k;
	cin>>k;
	if(k%2==0||k%5==0) cout<<"-1";
	else{
		ll val=7,n=1;
		while(1){
			val=modex(10,n,9*k);
			val=(7*val)%(9*k);
			if(val==7) break;
			n++;
		}
		cout<<n;
	}
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3568
/*input

*/
#include <iostream>
#include <fstream>
#include <bitset>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <utility>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <assert.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define MOD 1000000007ULL
#define MOD2 1000000009ULL
#define INF 1000000000ULL
#define F first
#define S second
#define eps 1e-9
#define PI 3.14159265358979
#define gcd __gcd
#define sd(x) scanf("%d", &(x))
#define slld(x) scanf("%lld", &(x))
#define ss(x) scanf("%s", x)
#define sc(x) scanf(" %c", &x)
#define pd(x) printf("%d\n", (x))
#define plld(x) printf("%lld\n", (x));
#define gc getchar

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<int, int> vii;
typedef vector<ll, ll> vll;

void scanint(int &x)
{
    register int c = gc();
    bool flag = false;
    x = 0;
    for(;((c<48 && c!=45) || c>57);c = gc());
    if(c==45)
    {
		flag = true;
		c = gc();
    }
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(flag)
    	x = x - (x<<1);
    return;
}

void scanll(ll &x)
{
	register long long c;
	bool flag = false;
	x = 0;
	for(;((c<48 && c!=45) || c>57);c = gc());
	if(c==45)
	{
		flag = true;
		c = gc();
	}
	for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
	if(flag)
    	x = x - (x<<1);
	return;
}

const int N = 100005;
int id[N], sz[N], comp;
vector<ll> v[N];
vector<ll> temp;
ll A[N];

int root(int a) // Path Compression
{
    int ans = a, temp;
    while(id[ans]!=ans) ans = id[ans];
    while(a!=ans)
    {
        temp = a;
        a = id[a];
        id[temp] = ans;
    }
    return a;
}

void merge(int a, int b)
{
    a = root(a);
    b = root(b);

    if(a == b)
    	return;

    if(sz[a] < sz[b])
    {
        sz[b] += sz[a];
        id[a] = b;
        comp--;
        return;
    }
    sz[a] += sz[b];
    id[b] = a;
    comp--;
    return;
}

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

	// clock_t clk;
	// clk = clock();
	// freopen("in.in", "r", stdin);
	// freopen("out.out", "w", stdout);
	
	int n, m, a, b;
	cin >> n >> m;
	comp = n;
	for(int i = 1; i<=n; i++)
	{
		sz[i] = 1;
		id[i] = i;
	}
	for(int i = 1; i<=n; i++)
		cin >> A[i];
	for(int i = 1; i<=m; i++)
	{
		cin >> a >> b;
		a++;
		b++;
		merge(a, b);
	}
	int x = 2*(comp-1);
	if(n < x)
	{
		cout << "Impossible\n";
		return 0;
	}
	if(x == 0)
	{
		cout << "0\n";
		return 0;
	}
	for(int i = 1; i<=n; i++)
		v[root(i)].pb(A[i]);
	ll ans = 0LL;
	for(int i = 1; i<=n; i++)
	{
		if(v[i].size() > 0)
		{
			sort(v[i].begin(), v[i].end());
			ans += v[i][0];
			for(int j = 1; j<v[i].size(); j++)
				temp.pb(v[i][j]);
		}
	}
	sort(temp.begin(), temp.end());
	for(int i = 0; i<(comp-2); i++)
		ans += temp[i];
	cout << ans << "\n";

	// clk = clock() - clk;
	// cout << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	// printf("Time: %lf", ((double)clk)/CLOCKS_PER_SEC);
	return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

vector<vector<Edge>> ReadUndirectedGraph(
    int n, int m, bool is_one_indexed=false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge(v1, v2));
    graph[v2].push_back(Edge(v2, v1));
  }
  return graph;
}

constexpr int INVALID = -1E9;

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

  int n;
  cin >> n;
  auto graph = ReadUndirectedGraph(n, n - 1, true);
  int k;
  cin >> k;
  vector<int> xs(n, INVALID);
  for (int i = 0; i < k; i++) {
    int v, p;
    cin >> v >> p;
    v--;
    xs[v] = p;
  }
  
  vector<int> ls(n, INVALID);
  vector<int> us(n, INVALID);
  bool fail = false;
  function<void(int, int)> dfs_1_fn = [&](int v, int p) {
    int l = xs[v];
    int u = xs[v];
    for (const auto& e : graph[v]) {
      if (e.to == p) continue;
      dfs_1_fn(e.to, v);
      if (fail) return;
      if (l == INVALID) {
        if (ls[e.to] == INVALID) {

        } else {
          l = ls[e.to] - 1;
          u = us[e.to] + 1;
        }
      } else {
        if (ls[e.to] != INVALID && l % 2 == ls[e.to] % 2) {
          fail = true;
          return;
        }
        if (ls[e.to] != INVALID) {
          l = max(ls[e.to] - 1, l);
          u = min(us[e.to] + 1, u);
        }
      }
    }
    if (l > u) {
      if (DEBUG) cout << "v: " << v << " l: " << l << " u: " << u << endl;
      fail = true;
      return;
    }
    ls[v] = l;
    us[v] = u;
  };
  dfs_1_fn(0, -1);

  if (fail) {
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (DEBUG) cout << "i: " << i << " ls[i]: " << ls[i] << " us[i]: " << us[i] << endl;
  }

  function<void(int, int)> dfs_2_fn = [&](int v, int p) {
    if (xs[v] == INVALID) {
      xs[v] = ls[v];
    }
    for (const auto& e : graph[v]) {
      if (e.to == p) continue;
      if (ls[e.to] != INVALID && ls[e.to] % 2 == ls[v] % 2) {
        fail = true;
        return;
      }
      if (ls[e.to] == INVALID) {
        ls[e.to] = ls[v] - 1;
        us[e.to] = us[v] + 1;     
      } else {
        ls[e.to] = max(ls[v] - 1, ls[e.to]);
        us[e.to] = min(us[v] + 1, us[e.to]);
      }
      dfs_2_fn(e.to, v);
      if (fail) return;
    }
  };
  dfs_2_fn(0, -1);

  if (fail) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  for (int i = 0; i < n; i++) {
    cout << xs[i] << "\n";
  }
}

Measured memory_bytes: 17024
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100000

int n,m,x,y,ans=1;
int cnt[MAXN+3];
bool vis[MAXN+3];
int main() {
	vis[1]=1;fill(cnt,cnt+MAXN+1,1);
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++) {
		scanf("%d %d",&x,&y);
		cnt[x]--,cnt[y]++;
		if(vis[x]&&!vis[y])
			vis[y]=1,ans++;
		if(cnt[x]==0&&vis[x])
			vis[x]=0,ans--;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
	int N;
	cin>>N;
	int num4=0;
	int num2=0;
	int num0=0;
	long tmp;
	for(int i=0;i<N;++i){
		cin>>tmp;
		if(tmp%4==0){
			num4++;
		}
		else if(tmp%2==0){
			num2++;
		}
		else{
			num0++;
		}
	}
	if(num0<=num4)cout<<"Yes"<<endl;
	else if(num0==num4+1 && num2==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

long long gcd(long long _x, long long _y){
    long long _r = _x % _y;
    while(_r != 0LL){
        _x = _y;
        _y = _r;
        _r = _x % _y;
    }
    return _y;
}

inline long long lcm(long long _x, long long _y){
    return _x / gcd(_x, _y) * _y;
}

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

    lint a, b, c, d;
    cin >> a >> b >> c >> d;

    lint dd = b / d - (a - 1LL) / d;
    lint cc = b / c - (a - 1LL) / c;
    lint cd = b / lcm(c, d) - (a - 1LL) / lcm(c, d);
    cout << b - a + 1LL - dd - cc + cd << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

std::vector<long long> divisors(long long n) {
	std::vector<long long> ret(0), st(0);
	for (int i = 1; i <= n / i; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i < n / i) st.push_back(n / i);
		}
	}
	while (st.size()) {
		ret.push_back(st.back());
		st.pop_back();
	}
	return ret;
}

bool is_prime(long long n) {
	if (n < 2) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (int i = 3; i <= n / i; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

int main() {
	long long a, b;
	std::cin >> a >> b;
	std::vector<long long> v = divisors(a), w = divisors(b);
	long long ans = 1;
	for (auto i : v) {
		auto itr = lower_bound(w.begin(), w.end(), i);
		if (itr != w.end() && *itr == i && is_prime(i)) ans++;
	}
	std::cout << ans << '\n';
 
	return 0;
}

Measured memory_bytes: 3720
main = do
    [m,n] <- fmap (map read.words) getLine
    print $ powMod 1000000007 m n

powMod :: Integer -> Integer -> Integer -> Integer
powMod _ _ 0 = 1
powMod p m n
  | even n =let x' = powMod p m (n `div` 2) in x'^2 `mod` p
  | odd n = let x' = powMod p m ((n-1) `div` 2) in m*x'^2 `mod` p



Measured memory_bytes: 3848
n = gets.chomp.to_i
s = []
ssum = 0
n.times do
  x = gets.chomp.to_i
  ssum += x
  s << x
end

s.sort!
if ssum % 10 == 0 then
  while x = s.shift
    if x % 10 != 0 then
      puts ssum - x
      exit
    end
  end
  puts 0
else
  puts ssum
end


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
 
int main() {
    ll h, w;
    cin >> h >> w;
    
    vector<string> board(h);
    ll cnt = 0;  // 黒マスの個数
    rep(i, h) {
        cin >> board[i];
        rep(j, w) {
            if(board[i][j] == '#') {
                cnt++;
            }
        }
    }

    vvl dist(h, vl(w, -1));  // dist[i][j] : (sx, sy)から(i, j)への最短距離(未訪問のとき-1)
    queue<P> Q;
    const ll sx = 0, sy = 0;
    Q.push(make_pair(sx, sy));
    dist[sx][sy] = 1;
    while(!Q.empty()) {
        ll x = Q.front().first;
        ll y = Q.front().second;
        rep(dir, 4) {
            ll nx = x + dx[dir];
            ll ny = y + dy[dir];
            if(nx < 0 || h <= nx || ny < 0 || w <= ny) {
                continue;
            }
            if(board[nx][ny] == '#') {
                continue;
            }
            if(0 <= dist[nx][ny]) {
                continue;
            }
            dist[nx][ny] = dist[x][y] + 1;
            Q.push(make_pair(nx, ny));
        }
        Q.pop();
    }
    
    if(dist[h-1][w-1] == -1) {
        out(-1);
    }
    else {
        out(h*w - cnt - dist[h-1][w-1]);
    }
    
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 2005
using namespace std;

long long n, m, M=1e9+7, a[N], b[N], d[N][N];
int main() {
	long long i, j;
	cin >> n >> m;
	for(i=1; i<=n; i++) cin >> a[i];
	for(i=1; i<=m; i++) cin >> b[i];
	for(i=0; i<=n; i++) for(j=0; j<=m; j++) {
		if(i<1 || j<1) d[i][j] = 1;
		else d[i][j] = (d[i-1][j] + d[i][j-1] - (a[i]==b[j] ? 0 : d[i-1][j-1]) + M) % M;
	}
	cout << d[n][m];
	return 0;
}

Measured memory_bytes: 31616
import java.util.Scanner;

public class Main{
	
	static int[] p;
	
	static int root(int a) {
		if(p[a]==a) return a;
		return (p[a]=root(p[a]));
	}
	
	static void unite(int x, int y) {
		p[root(x)]=root(y);
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n=sc.nextInt();
			int q=sc.nextInt();
			p=new int[n+1];
			
			for(int i=0; i<n; i++) {
				p[i]=i;
			}
			for(int i=0; i<q; i++) {
				int com=sc.nextInt();
				int x=sc.nextInt();
				int y=sc.nextInt();
				if(com==0) {
					unite(x, y);
				}
				if(com==1) {
					System.out.println((root(x)==root(y))? 1:0);
				}
			}
			

		}
	}
}


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

bool kaibun( string str ){
    string rts = str ;
    reverse(rts.begin(),rts.end()) ;
    if( str == rts )return true ;
    else return false ;
}

int main(){
    int a , b ;
    cin >> a >> b ;
    int count = 0 ;
    for(int i = a ; i <= b ; i++ ){
        string s = to_string(i) ;
        if(kaibun(s))count++  ; 
    }
    cout << count << endl;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
// Int MOD = 998244353;
 
int main() {
    ios::sync_with_stdio(false);
    double a, b, c;
    cin >> a >> b >> c;
    dump(a * b / 2);
    return 0;  
} 

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

using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define ar array
#define pb push_back
#define sz(X) ((int)(X).size())
#define pcnt __builtin_popcount
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define get_pos(c, x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define all(X) (X).begin(), (X).end()
#define ms(c,x)  memset(c,x,sizeof c)
#define  No cout<<"NO"<<endl;
#define  Yes cout<<"YES"<<endl;
#define  nl cout<<endl;
template<typename T>
using orderedSet=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T>
ostream &operator+(ostream &out, const vector<T> &vec) {
    for (const auto &x : vec) {
        out << x << " ";
    }
    out << "\n";
    return out;
}

template<typename T>
ostream &operator*(ostream &out, const vector<T> &vec) {
    for (const auto &x : vec) {
        out + x;
    }
    return out;
}

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

template<class T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }

template<class T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }


const int mod = 1e9 + 7;
const int mod2 = 998244353;
const ll INF = 1e9 + 6;

ll add(ll a, ll b) {
    a += b;
    return a % mod;
}

ll mul(ll a, ll b) {
    a *= b;
    return a % mod;
}

inline ll power(ll x, ll y, ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

inline ll modInverse(ll x, ll p) {
    return power(x, p - 2, p);
}
const int MXN=1e6+5;
int a[100];
int cache[MXN];
int n,k;
int dp(int x){
    if(cache[x]!=-1)return cache[x];
    if(x==0)return 2;

    for(int i=1;i<=n;i++){
        if(a[i]<=x){
            if(dp(x-a[i])==2){
                return cache[x]=1;
            }
        }
    }
    return cache[x]=2;
}
void solve() {
  
   cin>>n>>k;
   for(int i=1;i<=n;i++){
       cin>>a[i];
   } 
   ms(cache,-1);
   if(dp(k)==1){
       cout<<"First"<<endl;
   }else{
       cout<<"Second"<<endl;
   }

}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--)solve();
#ifndef ONLINE_JUDGE
    cerr << endl << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
#endif
    return 0;
}
//look if it requires ll

Measured memory_bytes: 10668
package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var (
		n int
		s string
	)
	fmt.Scan(&n, &s)

	b := make([]int, n+1)

	for i, v := range s {
		if v == '#' {
			b[i+1] = b[i] + 1
		} else {
			b[i+1] = b[i]
		}
	}

	a := n
	for i := 0; i < n+1; i++ {
		a = min(a, b[i]+n-i-(b[n]-b[i]))
	}
	fmt.Println(a)
}


Measured memory_bytes: 3584
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A_cnt = Counter(A)
ans_list = []
for key, val in A_cnt.items():
    if val >= 2:
        ans_list.append(key)
    if val >= 4:
        ans_list.append(key)
if len(ans_list)>=2:
    ans_list.sort()
    print(ans_list[-1]*ans_list[-2])
else:
    print(0)

Measured memory_bytes: 18600
N = int(input())
S = input()

codes = set()

S1 = S[:N-2]
for i in set(S1):
  idx1 = S1.index(i)
  S2 = S1[idx1+1:] + S[N-2]
  for j in set(S2):
    idx2 = S2.index(j)
    S3 = S2[idx2+1:] + S[N-1]
    for k in set(S3):
      pin = i + j + k
      codes.add(pin)
      
print(len(codes))

Measured memory_bytes: 3316
# abc112_b

INITIAL_COST = 1001

def main():

    # costs and times storage
    costs = []
    times = []

    N, T = map(int, input("").split())

    for i in range(N):
        c, t = map(int, input("").split())
        costs.append(c)
        times.append(t)

    # map with the routes after reading input
    routes = dict(zip(costs, times))

    current_cost = INITIAL_COST
    for c, t in routes.items():
        if t <= T and c < current_cost:
            current_cost = c

    if current_cost == INITIAL_COST:
        print("TLE")
    else:
        print(current_cost)


if __name__ == "__main__": main()


Measured memory_bytes: 3064
N = int(input())

a_list = list(map(int, input().split()))
a_list.sort(reverse = True)

count = 0
allice_total = 0
bob_total = 0
for a in a_list:
    if count % 2 == 0:
        allice_total += a
    else:
        bob_total += a
    count += 1

print(allice_total - bob_total)





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

using namespace std;

int main() {
	long long a, b, k;
	cin >> a >> b >> k;
	if (k <= a) {
        cout << a - k << ' ' << b;
	}
	else {
        cout << 0 << ' ' << max(0ll, b - (k - a));
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int h,w,i,j;
    cin>>h>>w;
    char g[60][60];
    for (i=1;i<=h;i++)
    {
        for (j=1;j<=w;j++)
            cin>>g[i][j];
    }
    int cnt=0;
    for (i=1;i<=h;i++)
    {
        for (j=1;j<=w;j++)
        {
            if (g[i][j]=='#' && g[i-1][j]!='#' && g[i+1][j]!='#' && g[i][j-1]!='#' && g[i][j+1]!='#')
                cnt++;
        }
    }
    if (cnt==0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n; cin >> n;
  vector<pair<int,int>> v(n);
  for(int i = 0; i < n; i++){
    int a,b; cin >> a >> b;
    v[i] = {b,a};
  }
  sort(v.begin(),v.end());

  int t = 0;
  for(int i = 0; i < n; i++){
    t += v[i].second;
    if(v[i].first < t){
      cout << "No" << endl;
      //cout << v[i].first << " " << t << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3328