akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,m,q,i,j1,j2,j3,j4,j5,j6,j7,j8,j9,j10,ans=0,p;
  cin>>n>>m>>q;
  vector<int> a(q),b(q),c(q),d(q),e(n,1);
  for(i=0;i<q;i++) cin>>a.at(i)>>b.at(i)>>c.at(i)>>d.at(i);
  for(j10=1;j10<=m;j10++){
    for(j9=1;j9<=j10;j9++){
      for(j8=1;j8<=j9;j8++){
        for(j7=1;j7<=j8;j7++){
          for(j6=1;j6<=j7;j6++){
            for(j5=1;j5<=j6;j5++){
              for(j4=1;j4<=j5;j4++){
                for(j3=1;j3<=j4;j3++){
                  for(j2=1;j2<=j3;j2++){
                    for(j1=1;j1<=j2;j1++){
                      e.at(0)=j1;
                      if (n>=2) e.at(1)=j2;
                      if (n>=3) e.at(2)=j3;
                      if (n>=4) e.at(3)=j4;
                      if (n>=5) e.at(4)=j5;
                      if (n>=6) e.at(5)=j6;
                      if (n>=7) e.at(6)=j7;
                      if (n>=8) e.at(7)=j8;
                      if (n>=9) e.at(8)=j9;
                      if (n>=10) e.at(9)=j10;
                      p=0;
                      for(i=0;i<q;i++) if (e.at(b.at(i)-1)-e.at(a.at(i)-1)==c.at(i)) p+=d.at(i);
                      if (ans<p) ans=p;
                      if(e.at(0)==m) {j1=m;j2=m;j3=m;j4=m;j5=m;j6=m;j7=m;j8=m;j9=m;j10=m;}
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}

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

signed main(void)
{
	int n;
	cin >> n;
	int tmp, bef;
	bool ok;
	rep(i, 200)
	{
		tmp = n + i;
		ok = true;
		bef = tmp % 10;
		while(tmp / 10)
		{
			tmp /= 10;
			if (bef != tmp % 10)
				ok = false;
			bef = tmp % 10;
		}
		if (ok)
		{
			cout << n + i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 1e6+7;
int n;
long long seed;
inline long long rand(long long l, long long r) {
    static long long mo=1e9+7, g=78125;
    return l+((seed*=g)%=mo)%(r-l+1);
}
long long Max[10];
long long Min[10];
int main(){
    cin >> n;
    for(int i=0;i<10;i++)
        Max[i]=-1e15,Min[i]=1e15;
    long long x,y;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        Max[0]=max(Max[0],x+y);
        Max[1]=max(Max[1],-x+y);
        Max[2]=max(Max[2],x-y);
        Max[3]=max(Max[3],-x-y);
        Min[0]=min(Min[0],x+y);
        Min[1]=min(Min[1],-x+y);
        Min[2]=min(Min[2],x-y);
        Min[3]=min(Min[3],-x-y);
    }
    long long ans = 0;
    for(int i=0;i<4;i++)
        ans=max(Max[i]-Min[i],ans);
    cout<<ans<<endl;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for(int i=0; i<n; ++i) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  
  int check = -1;
  while(m != 0 && check != 0){
    a[0] /= 2;
    -- m;
    check = a[0];
    
    int count = 0;
    int i = 1;
    while(check <= a[i] && i < n && m < n){
      ++ count;
      ++ i;
    }
    
    i = 1;
    if(count <= m){    
      while(m != 0 && check <= a[i] && i < n){
        a[i] /= 2;
        -- m;
        ++ i;
      }
    }
    else{
      sort(a.begin()+1, a.end(), greater<int>());
      while(m != 0){
        a[i] /= 2;
        -- m;
        ++ i;
      }
      break;
    }
  }
  
  long long sum = 0;
  for(int i=0; i<n; ++i) sum += a[i];
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 640
import sys

N=input()
A=map(int, sys.stdin.readline().split())

minus_count=len( filter(lambda x: x<0, A) )

if minus_count%2==0:
	print  sum( map(lambda x: abs(x), A) )
else:
	if 0 in A:
		print  sum( map(lambda x: abs(x), A) )
	else:
		B=map(lambda x: abs(x), A)
		B.sort()
		print sum(B[1:])-B[0]

Measured memory_bytes: 43308
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    double x=0,y=0;
    double r = 90;
    while(1){
        int d,a;
        scanf("%d,%d",&d,&a);
        if(d==0 && a==0) break;

        double dy = d * sin(r / 180.0 * M_PI);
        double dx = d * cos(r / 180.0 * M_PI);

        //cout << r << " " << dx << " " << dy << endl;

        x += dx;
        y += dy;

        r -= a;
    }
    printf("%d\n",(int)x);
    printf("%d\n",(int)y);
}

Measured memory_bytes: 3480
import math

N = int(input())
ARR = []

for i in range(N-1):
    ARR.append([int(s) for s in input().split(" ")])


def calculate(n, arr):
    result = []
    for i in range(n-1):
        m = arr[i][1] + arr[i][0]
        for j in range(i+1,n-1):
            nextStart = arr[j][1]
            nextCost = arr[j][0]
            nextFrequency = arr[j][2]

            if m <= nextStart:
                m = nextStart

            if m  > nextStart:
                m = nextStart + math.ceil((m - nextStart)/ nextFrequency)*nextFrequency

            m = m + nextCost
        result.append(m)

    result.append(0)
    return result


result = calculate(N, ARR)


for res in result:
    print(res)

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderTrain
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());            
            var a = Console.ReadLine().Split().Select(int.Parse).ToList();
            var lgcd = new List<long>(N);
            lgcd.Add(0);
            var rgcd = new List<long>(N);
            rgcd.Add(0);
            for (int i = 0; i < N; ++i)
            {
                lgcd.Add(Gcd(lgcd[i], a[i]));
                rgcd.Add(Gcd(rgcd[i], a[N - (i + 1)]));
            }
            //     0,1     ,2              ,  ,N
            //lgcd:0,a[0]  ,(a[0],a[1])    ,…,(a[0],…,a[N-1])
            //rgcd:0,a[N-1],(a[N-1],a[N-2]),…,(a[N-1],…,a[0])
            long max = 0;
            for (int i = 0; i < N; ++i) 
            {
                max = Math.Max(max, Gcd(lgcd[i], rgcd[N - (i + 1)]));
            }
            Console.WriteLine(max);
        }
        static long Gcd(long a, long b)
        {
            return (a < b) ? Gcd(b, a)
                            : (0 < b) ? Gcd(b, a % b)
                                        : a;
        }
    }
}

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

Measured memory_bytes: 1620
#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 kai(int n){
    int ans;
    ans=1;
    rep(i,n){
    ans*=i+1;
    }
    return ans;
}
int main(){
    int n;
    cin >> n;
    vector <int> p(n),q(n);
    

    rep(i,n){
        cin >> p[i];
    }
    rep(i,n){
        cin >> q[i];
    }
    vector <int> kp(n,0),kq(n,0);
    
    rep(i,n){
        
        rep(j,i){
            if(p[i]>p[j]) ++kp[i];
            if(q[i]>q[j]) ++kq[i];
        }

    }
    rep(i,n){
        p[i]-=kp[i];
        q[i]-=kq[i];
    }
    

    int a,b;
    a=0;
    b=0;
    rep(i,n){
        a+=(p[i]-1)*kai(n-i-1);
        b+=(q[i]-1)*kai(n-i-1);
    }
    
    if(a>=b){
    cout << a-b << endl;
    }
    else{
        cout << b-a << endl;
    }

        

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

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

int gcd(int m, int n) {
    return n == 0 ? m : gcd(n, m % n);
}
int lcm(int m, int n) {
    return (m / gcd(m, n)) * n;
}

signed main() {
    cin >> S;
    cout << "ABC" + S << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int R,G;
  cin >> R >> G;
  int T = G - R;
  cout << G + T << endl;

}

Measured memory_bytes: 256
INF = 10 ** 9 + 7
N, M = list(map(int,input().split()))
A = [1 for _ in range(N + 1)]
for i in range(M):  A[int(input())] = 0
dp = [0 for _ in range(N + 1)]
dp[0] = 1
for i in range(1, N + 1):
    if A[i] == 1:  dp[i] = (dp[i - 1] + dp[i - 2]) % INF
print(dp[N] % INF)

Measured memory_bytes: 50848
from collections import defaultdict
N,M = map(int,input().split())
A = list(map(int,input().split()))
A[0] %= M
for i in range(N-1):
    A[i+1] += A[i]
    A[i+1] %= M
d = defaultdict(lambda:0)
d[0] = 1
ans = 0
for i in range(N):
    ans += d[A[i]]
    d[A[i]] += 1
print(ans)

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

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

  rep(i, n) {
    if (a[i] % 2 == 0) {
      if (!(a[i] % 3 == 0 || a[i] % 5 == 0)) {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }

  cout << "APPROVED" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	char a, b;
	cin >> a >> b;
	cout << (a - b == 0 ? 'H' : 'D') << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#define N 500000
#define INFTY 1000000001
void merge(int *,int,int,int);
void mergesort(int *,int,int);
int n1,n2,left,right,count=0,A[N],R[N],L[N];
int main()
{
  int n,i;
  scanf("%d",&n);
  left=0;
  right=n;
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  mergesort(A,left,right);
  for(i=0;i<n;i++)
    {
    printf("%d",A[i]);
    if(i!=n-1)
      printf(" ");
    }
  printf("\n");
  printf("%d",count);
  printf("\n");
  return 0;
}

void merge(int *A,int left,int mid,int right)
{
  int i,j,k;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<=n1-1;i++)
    L[i]=A[left+i];
  for(i=0;i<=n2-1;i++)
    R[i]=A[mid+i];
  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++)
    {
      if(L[i]<=R[j])
        {
          A[k]=L[i];
          i++;
          count++;
        }
      else
        {
          A[k]=R[j];
          j++;
          count++;
        }
    }
}

void mergesort(int *A,int left,int right)
{
  int mid;
  if(left+1<right)
    {
      mid=(left+right)/2;
      mergesort(A,left,mid);
      mergesort(A,mid,right);
      merge(A,left,mid,right);
    }
}


Measured memory_bytes: 5612
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF = 1e13;
int main() {
    int n,wt;
    cin>>n>>wt;
    vector<ll> w(n);
    vector<ll> v(n);
  	ll v_max=0;
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
      v_max+=v[i];
    } 

    ll dp[v_max+1];
    for(int i=0;i<v_max+1;i++)
    {
        dp[i]=INF;
    }
	dp[0]=0;

    for(int j=0;j<=n-1;j++)
    {
        for(int i=v_max;i>=0;i--)
        {
            if(i>=v[j])
            {
                dp[i]=min(dp[i],dp[i-v[j]]+w[j]);
            }
        }
    }
	
  	for(int i=v_max;i>=0;i--)
    {
      if(dp[i]<=wt)
      {
        cout<<i<<endl;
        break;
      }
    }
    return 0;
}
 


Measured memory_bytes: 4364
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
int a,b,c;
main()
{
	cin>>a>>b>>c;
	int now=0;
	do{
		if(now%60<=c&&c<=now%60+a)
		{
			cout<<now/60*60+c<<endl;
			return 0;
		}
		now+=a+b;
	}while(now%60);
	cout<<-1<<endl;
}


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

using namespace std;

int main(){
	string a, str;
	cin >> a;
	str = a[0] + to_string(a.length()-2) + a[a.length()-1];
	// int count =0;
	// if(a[0]=='1') count++;
	// if(a[1]=='1') count++;
	// if(a[2]=='1') count++;

	cout <<str<<endl;
	// cout <<a[-1];

return 0;
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    char name[h][w];
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            cin >> name[i][j];
        }
    }
    for (int k=0; k<w+2; k++)
    {
        cout << "#";
    }
    cout << "\n";
    for(int i=0; i<h; i++)
    {
        cout << "#";
        for(int j=0; j<w; j++)
        {
            cout << name[i][j];
        }
        cout << "#\n";

    }
    for (int k=0; k<w+2; k++)
    {
        cout << "#";
    }
    return 0;
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const int N = 3100;
const ll MOD = 998244353;

ll dp[N][N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for (int i = a; i <= c; ++i) {
		for (int j = b; j <= d; ++j) {
			if (i == a && j == b) {
				dp[i][j] = 1;
				continue;
			}

			if (i == a) {
				dp[i][j] = dp[i][j - 1] * i % MOD;
			} else if (j == b) {
				dp[i][j] = dp[i - 1][j] * j % MOD;
			} else {
				dp[i][j] = (dp[i - 1][j] * j + dp[i][j - 1] * i - dp[i - 1][j - 1] * (i - 1) * (j - 1)) % MOD;
				if (dp[i][j] < 0) {
					dp[i][j] += MOD;
				}
			}
		}
	}

	cout << dp[c][d] << "\n";
	return 0;
}




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

int N, L[2000];

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

int main() {
	int N, L[2000];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d",&L[i]);
	
	qsort(L, N, sizeof(int), compare);

	int ans = 0,top,under;
	for (int i = 0; i < N-2; i++) {
		for (int j = i + 1; j < N-1; j++) {
			top = N;
			under = j + 1;
			while (under != top) {
				int mid = (top + under) / 2;
				if (L[mid] < L[i] + L[j]) under = mid + 1;
				else top = mid;
			}
			ans += top - j - 1;
		}
	}
	printf("%d", ans);
	return 0;
}


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

typedef long long ll;
#define nl "\n"
#define ff first
#define ss second
#define mod 1e9+7
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define pp pop_back
#define bs binary_search
#define all(x) x.begin(),x.end()
#define loop(i,s,n) for(ll i=s;i<n;i++)
#define test ll t ; cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);

int main() {
	fast_io;
	
	ll k,a,b,ans=0;
	cin>>k>>a>>b;
	loop(i,a,b+1)
	{
	    if(i%k==0)
	    {
	        ans=1;
	        break;
	    } 
	}
	if(ans)     cout<<"OK";
	else    cout<<"NG";
	cout<<nl;
	return 0;
}


Measured memory_bytes: 3648
def countingSort(A, B, k):
    C = [0 for i in range(k+1)]

    for i in A:
        C[i] += 1

    for i in range(1, k+1):
        C[i] += C[i-1]

    for i in A[::-1]:
        B[C[i]-1] = i
        C[i] -= 1

    return B


n = int(input())
A = list(map(int, input().split()))
k = max(A)
B = [0 for x in range(n)]
B = countingSort(A, B, k)
print(*B)



Measured memory_bytes: 224392
N, T = map(int,input().split())
AN = list(map(int,input().split()))

maximum = 0
ans = 0
left = AN[0]

for n in range(1,N):
  if AN[n]-left == maximum:
    ans += 1
  elif AN[n]-left > maximum:
    maximum = AN[n]-left
    ans = 1

  left = min(left,AN[n])

print(ans)

Measured memory_bytes: 20480
n=int(input())

zahyo=[]
for _ in range(n):
  x,y=map(int,input().split())
  zahyo.append([x,y])
  
#print(zahyo)

result=0.0

import itertools
no=[]
for i in range(n):
  no.append([i])

junjo=[]
for i in itertools.permutations(no):
  temp=[]
  for item in i:
    temp.append(item[0])
  junjo.append(temp)
  
#print(junjo)

result=0.0

count=0
for item in junjo:
  i=0
  #print(item)
  temp=0
  while i < n-1:
    start=item[i]
    end=item[i+1]
    #print("start:",zahyo[start][0],zahyo[start][1],"end:",zahyo[end][0],zahyo[end][1])
    temp+=((zahyo[start][0]-zahyo[end][0])**2+(zahyo[start][1]-zahyo[end][1])**2)**(1/2)
    
    i+=1
  #print(temp)
  result+=temp
  count+=1
  #print(result)
print(result/count)

  


Measured memory_bytes: 11124
N = int(input())
S = [input() for i in range(N)]
dictionary = {}
for word in S:
    if word in dictionary:
        dictionary[word] += 1
    else:
        dictionary[word] = 1

maximum = max(dictionary.values())
for key, value in sorted(dictionary.items()):
    if value == maximum:
        print(key)

Measured memory_bytes: 45712
import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int M = scan.nextInt();
			
			int []H = new int[N];
			for(int i = 0;i<N;i++)H[i] = scan.nextInt();
			Map<Integer,ArrayList<Integer>> map = new TreeMap<Integer,ArrayList<Integer>>();
			
			for(int i =0;i<N;i++) {
				map.put(i, new ArrayList<Integer>());
			}
			
			int []A = new int[M];
			int []B= new int[M];
			
			for(int i = 0;i<M;i++) {
				A[i] = scan.nextInt();
				B[i] = scan.nextInt();
				map.get(A[i]-1).add(B[i]-1);
				map.get(B[i]-1).add(A[i]-1);
			}
			
			for(int i = 0;i<N;i++) {
				for(int j = 0;j<map.get(i).size();j++) {
					//System.out.print(map.get(i).get(j));
					//System.out.print(" ");
				}
				//System.out.println();
			}
			
			
			
			
			
			int count = 0;
			
			for(int i = 0;i<N;i++) {
				int ok = 1;
				for(int j = 0;j<map.get(i).size();j++) {
					if(H[map.get(i).get(j)]>=H[i]) {
						ok=0;
						break;
					}
				}
				if(ok==1)count++;
				//System.out.println(count);
			}
			
			System.out.println(count);
			
			
		}
		
		
	}
		

}


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    string v[3] = {"Sunny","Cloudy","Rainy"};
    if (s == v[0]){
        cout << v[1];
    }
    if (s == v[1]){
        cout << v[2];
    }
    if (s == v[2]){
        cout << v[0];
    }
    return 0;
}

Measured memory_bytes: 256
use std::io::{self, BufRead, Write, BufWriter};

fn read<R: BufRead, T: std::str::FromStr>(input: &mut R) -> T {
    let mut s = String::new();
    input.read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let mut a = vec![];
    {
        let input = io::stdin();
        let mut input = input.lock();
        let n = read::<_, usize>(&mut input);
        for _ in 0..n {
            let ai = read::<_, usize>(&mut input);
            a.push(ai);
        }    
    }

    let mut sorted = a.clone();
    sorted.sort_by(|x, y| y.cmp(x));

    let stdout = io::stdout();
    let mut buf = BufWriter::new(stdout.lock());

    for ai in a.into_iter() {
        let res = if ai == sorted[0] {
            sorted[1]
        } else {
            sorted[0]
        };
        writeln!(buf, "{}", res).unwrap();
    }
}

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

signed main(){
	int N; cin>>N;
	vector<int> h(N);
	for(int i=0;i<N;i++)cin>>h[i];
	vector<int> cost(N);
	cost[0]=0;
	cost[1]=llabs(h[1]-h[0]);
	for(int i=2;i<N;i++){
		cost[i]=min(llabs(h[i]-h[i-1])+cost[i-1],llabs(h[i]-h[i-2])+cost[i-2]);
	}
	cout<<cost[N-1]<<endl;

}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

#define N 11

char A[N];
int n, m;
bool mflag[12][12];
bool pflag[12];
int ans = 0;


void binary(int nn) {
	if (nn < 1) {

		A[N - 1] = '\0';
		//cout << A  << endl;

		int cnt = 0;

		for (int i = 0; i < m; i++) {
			int cnt2 = 0;
			for (int j = 0; j < n; j++) {
				if (mflag[i][j] == true && A[j] == '1') {
					cnt2++;
				}
			}

			if (cnt2 % 2 == pflag[i])cnt++;
			//cout << "i->" << i << " cnt->" << cnt << endl;
		}

		if (cnt == m)ans++;

	}
	else {
		A[nn - 1] = '0';
		binary(nn - 1);
		A[nn - 1] = '1';
		binary(nn - 1);
	}
}

signed main() {
	memset(mflag, false, sizeof(mflag));
	memset(pflag, false, sizeof(pflag));

	cin >> n >> m;

	#define N n + 1

	for (int i = 0; i < m; i++) {
		int num;
		cin >> num;
		for (int j = 0; j < num; j++) {
			int num2;
			cin >> num2;
			mflag[i][num2 - 1] = true;
		}	
	}

	for (int i = 0; i < m; i++) {
		cin >> pflag[i];
	}

	binary(N - 1);

	//cout << "ans->" << ans << endl;
	cout << ans << endl;



	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll INF = 1e18;
#define pu push
#define pb push_back
#define mp make_pair
#define print(x) cout << (x) << endl;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define fi first
#define sc second

using Graph = vector<pair<pair<int,int>,vector<int>>>;
//pair<<親ノード, 答え>,<子ノード>>
vector<bool> seen;

void dfs_setP(Graph &G, int v) {
    for (auto nv : G.at(v).second) {
        if (nv != G.at(v).first.first) {
            G.at(nv).first.first = v;
            dfs_setP(G, nv);
        }
    }
}

void dfsplus(Graph &G, int v) {
    for (auto nv : G.at(v).second) {
        if (nv != G.at(v).first.first) {
            G.at(nv).first.second += G.at(v).first.second;
            dfsplus(G, nv);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int N, Q;
    cin >> N >> Q;
    Graph G(N);
    rep(i,N-1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G.at(a).second.push_back(b);
        G.at(b).second.push_back(a);
    }
    G.at(0).first.first = -1;
    dfs_setP(G, 0);
    rep(i,N) {
        G.at(i).first.second = 0;
    }
    rep(j,Q) {
        int p, x;
        cin >> p >> x;
        p--;
        G.at(p).first.second += x;
    }
    dfsplus(G, 0);
    rep(i,N) {
        cout << G.at(i).first.second;
        if (i != N-1) {
            cout << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 27392
import numpy as np
N=int(input())
S=[]
allten=True
for i in range(N):
  s=int(input())
  S.append(s)
  if s%10!=0:
    allten=False
if allten:
  print(0)
  exit()
  
S=sorted(S)
SUM=sum(S)
if SUM%10!=0:
  print(SUM)
else:
  ans=0
  for i in range(N):
    if S[i]%10!=0:
      ans=max(ans, SUM-S[i])
  print(ans)

Measured memory_bytes: 21380
import numpy as np

n,m,q=map(int, input().split())  
a=np.array([list(map(int, input().split())) for i in range(m)])
b=[list(map(int, input().split())) for i in range(q)]

x=np.zeros((501, 501), dtype=np.int)

np.add.at(x, (a[:, 0], a[:, 1]), 1)

np.cumsum(x, axis=0, out=x)
np.cumsum(x, axis=1, out=x)

for i in range(q):
    v1=b[i][0]
    v2=b[i][1]
    
    a1=x[v2, v2]
    a2=x[v2, v1-1]
    a3=x[v1-1, v2]
    a4=x[v1-1, v1-1]
    print(a1-a2-a3+a4)


Measured memory_bytes: 57540
H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input()
T = input()
 
up = [0] * (N+1)
down = [0] * (N+1)
right = [0] * (N+1)
left = [0] * (N+1)
maxU, maxD, maxR, maxL = 0, 0, 0, 0
 
for i in range(N):
    if S[i] == "L":
        left[i+1] = left[i] + 1
        right[i+1] = right[i]
        up[i+1] = up[i]
        down[i+1] = down[i]
        maxL = max(maxL, left[i+1])
    elif S[i] == "R":
        right[i+1] = right[i] + 1
        up[i+1] = up[i]
        down[i+1] = down[i]
        left[i+1]  = left[i]
        maxR = max(maxR, right[i+1])
    elif S[i] == "U":
        up[i+1] = up[i] + 1
        right[i+1] = right[i]
        down[i+1] = down[i]
        left[i+1]  = left[i]
        maxU = max(maxU, up[i+1])
    else:
        down[i+1] = down[i] + 1
        right[i+1] = right[i]
        up[i+1] = up[i]
        left[i+1]  = left[i]
        maxD = max(maxD, down[i+1])
    if T[i] == "L":
        right[i+1] = max(right[i+1] - 1, -sc + 1)
    elif T[i] == "R":
        left[i+1] = max(left[i+1] - 1, sc - W)
    elif T[i] == "U":
        down[i+1] = max(down[i+1] - 1, -sr + 1)
    else:
        up[i+1] = max(up[i+1] - 1, sr - H)
 
if sr + maxD > H or sr - maxU <= 0 or sc + maxR > W or sc - maxL <= 0:
    print("NO")
else:  print("YES")




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

using namespace std;

const int N = 123456;
const string cand[] = {"dream", "dreamer", "erase", "eraser"};

string str;
int n;
int can[N];

int main() {
  string s;
  cin >> s;
  n = s.size();
  can[0] = 1;
  for (int i = 0; i < n; i++) {
    if (!can[i]) {
      continue;
    }
    for (int j = 0; j < 4; j++) {
      if (n - i < (int)cand[j].size() || s.substr(i, cand[j].size()) != cand[j]) {
        continue;
      }
      can[i + (int)cand[j].size()] = true;
    }
  }
  if (can[n]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

int main() {
    int x, a, b;  cin>>x>>a>>b;
    int A=x-a;
    int B=x-b;
    if(A<0) A=0-A;
    if(B<0) B=0-B;
    A-B>0? cout<<'B'<<endl: cout<<'A'<<endl;
}


Measured memory_bytes: 256
use std::collections::*;
use std::cmp::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        x: i64
    }

    let mut res = 0;

    let n = x / 500;
    res += n * 1000;

    let x = x - (x/500) * 500;
    let n = x / 5;
    res += n * 5;

    println!("{}", res);

}


Measured memory_bytes: 4352
a, b = map(int, input().split())
if a * 100 % 8 == 0:
    low = max(a * 100 // 8, b * 10)
else:
    low = max(a * 100 // 8 + 1, b * 10)
if 100 * (a + 1) % 8 == 0:
    a_ = 100 * (a + 1) // 8 - 1
else:
    a_ = 100 * (a + 1) // 8

high = min(a_, 10 * (b+1) -1)

if low <= high:
    print(low)
else:
    print(-1)


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

using namespace std;

int main() {
	static long long int n, dp[100010][3], a[100000], b[100000], c[100000];
	cin >> n;
	for (int i = 0;i < n; i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (int i = 1; i < n; i++){
		dp[i][0] = max(dp[i - 1][1] , dp[i - 1][2]);
		dp[i][1] = max(dp[i - 1][0] , dp[i - 1][2]);
		dp[i][2] = max(dp[i - 1][1] , dp[i - 1][0]);
		dp[i][0] += a[i];
		dp[i][1] += b[i];
		dp[i][2] += c[i];	
	}
	cout << max(dp[n - 1][0]  , max (dp[n - 1][1] , dp[n - 1][2]));
}


Measured memory_bytes: 4992
#include <stdio.h>

int main(void)
{
    long int inputN, answer = 0;
    scanf("%ld", &inputN);
    if ((inputN - 1) % 2 == 0)
    {
        answer = inputN * ((inputN - 1) / 2);
    }
    else
    {
        answer = inputN * (inputN / 2 - 1) + (inputN / 2);
    }
    printf("%ld", answer);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define umap unordered_map
//std::cout << std::setfill('0') << std::right << std::setw(4) << 12; // "0012"

ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int main(){
  int x; cin>>x;
  if(x==7 || x==5 || x==3){cout<<LINY;}
  else{cout<<LINN;}
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> x(n), y(m);
	for (int i = 0; i < n; i++) cin >> x[i];
	for (int i = 0; i < m; i++) cin >> y[i];

	ll sumx = 0, sumy = 0, sum1 = 0, sum2 = 0;

	for (int i = 1; i < n; i++) {
		(sumx += x[i - 1]) %= MOD;
		(sum1 += (x[i] * i % MOD - sumx + MOD) % MOD) %= MOD;
	}

	for (int i = 1; i < m; i++) {
		(sumy += y[i - 1]) %= MOD;
		(sum2 += (y[i] * i % MOD - sumy + MOD) % MOD) %= MOD;
	}

	cout << sum1 * sum2 % MOD << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    char a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    // 1文字でも違えば
    out((a ^ f | b ^ e | c ^ d ? "NO" : "YES"));
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
int main(void){
    // Your code here!
    vi prime(100001,1);
    vi like(100001,0);
    vi ps(100001,0);
    prime[0]=0;prime[1]=0;
    for(int i=4;i<=100000;i+=2){
        prime[i]=0;
    }
    for(int i=3;i<317;i+=2){
        if(prime[i]==1){
            for(int j=i*i;j<=100000;j+=i){
                prime[j]=0;
            }
        }
    }
    for(int i=1;i<=100000;i+=2){
        if(prime[i]==1&&prime[(i+1)/2]==1){
            like[i]=1;
        }
    }
    partial_sum(like.begin(),like.end(),ps.begin());
    int n;
    cin>>n;
    int a,b;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        int ans=0;
        cout<<ps[b]-ps[a-1]<<endl;
    }
}


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

using namespace std;

using ll = long long;
using P = pair<int, int>;

bool dfs(int cur, int par, int goal, const vector< vector<P> >& g, ll& path) {
    if (cur == goal) return true;

    for (const P& p : g[cur]) {
        if (p.first == par) continue;
        if (dfs(p.first, cur, goal, g, path)) {
            path |= (1LL << p.second);
            return true;
        }
    }
    return false;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector< vector<P> > g(n);
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].emplace_back(b, i - 1);
        g[b].emplace_back(a, i - 1);
    }

    int m;
    cin >> m;
    vector<ll> ps(m, 0);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        dfs(u, -1, v, g, ps[i]);
    }

    vector<ll> dp(1 << m, 0);
    for (int i = 0; i < (1 << m); ++i) {
        ll mask = 0;
        for (int j = 0; j < m; ++j) {
            if (i >> j & 1) continue;
            mask |= ps[j];
        }

        int rest = n - 1 - __builtin_popcountll(mask);
        dp[i] = (1LL << rest);
    }

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < (1 << m); ++j) {
            if (j >> i & 1) dp[j]-=dp[j^(1<<i)];
        }
    }
    cout << dp[(1 << m) - 1] << "\n";
    return 0;
}

Measured memory_bytes: 8448
fun main(args: Array<String>) {
    val k = readLine()!!.toLong()
    var seven = 0L
    var ans = 1
    var cnt = 0L
    while (cnt <= k) {
        seven = (seven * 10 + 7) % k
        if (seven % k == 0L) {
            println(ans)
            return
        }
        ans++
        cnt++
    }
    println (-1)
}


Measured memory_bytes: 34496
n = gets.to_i
s = gets.chomp
max = 0
require 'set'
(1...n).each do |i|
  a = Set.new(s[0,i].split('').uniq)
  b = Set.new(s[i,n-i].split('').uniq)
  m = (a & b).size
  max = [max,m].max
end
puts max

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

namespace ALDS1_11A{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var res = new int[N, N].ToJaggedArray();

            for(var i = 0; i < N; i++){
                var u = sr.Next<int>();
                var k = sr.Next<int>();
                for(var j = 0; j < k; j++){
                    var v = sr.Next<int>();
                    res[u - 1][v - 1] = 1;
                }
            }

            foreach(var r in res){
                Console.WriteLine(string.Join(" ", r.Select(x => x.ToString()).ToArray()));
            }
            //---------------------------------
        }
    }

    public static class ExMethod{
        public static T[][] ToJaggedArray<T>(this T[,] src){
            var x = src.GetLength(1);
            var y = src.GetLength(0);
            var ret = new T[y][];

            for(var i = 0; i < y; i++){
                ret[i] = new T[x];
                for(var j = 0; j < x; j++){
                    ret[i][j] = src[i, j];
                }
            }

            return ret;
        } 
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = Console.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 10432
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int n, m, x, y; cin >> n >> m;
    int a[100010]; rep(i,0,n) a[i] = 1;
    bool p[100010] = {};
    p[0] = true;
    rep(i,0,m) {
        cin >> x >> y; x--; y--;
        a[y]++; if(p[x]) p[y] = true;
        if(a[x] > 0) a[x]--;
        if(a[x] == 0) p[x] = false;
    }
    int ans = 0;
    rep(i,0,n) if(p[i]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<2*h;i++){
        for(int j=0;j<w;j++){
            cout<<s[i/2][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
const int N=200010;
struct tree{
	int l,r,ji,ou;
}tr[4*N];
int id[N];
int n,a[N];
bool se=0;
struct node{
	friend bool operator < (node a,node b){return a.x>b.x;}
	int x,y,l,r;
}q,pu;
priority_queue<node> ans;
const int inf=1e9;
void update(int i){tr[i].ji=min(tr[i<<1].ji,tr[i<<1|1].ji);tr[i].ou=min(tr[i<<1].ou,tr[i<<1|1].ou);}
void build(int i,int l,int r)
{
	tr[i].l=l;
	tr[i].r=r;
	if (l==r){if (l&1) tr[i].ji=a[l],tr[i].ou=inf;else tr[i].ji=inf,tr[i].ou=a[l];return;}
	int mid=l+r>>1;build(i<<1,l,mid);build(i<<1|1,mid+1,r);update(i);	
}
int query(int i,int l,int r,int p)
{
	int L=tr[i].l;int R=tr[i].r;
	if (L>r||l>R) return inf;
	if (l<=L && R<=r){if (p) return tr[i].ji; else return tr[i].ou;}
	int ans=inf;ans=min(ans,query(i<<1,l,r,p));ans=min(ans,query(i<<1|1,l,r,p));return ans;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),id[a[i]]=i;
	build(1,1,n);
	int x=query(1,1,n,1);int y=query(1,id[x]+1,n,0);
	q.l=1;q.r=n;q.x=x;q.y=y;ans.push(q);
	for (int i=2;i<=n/2;i++)
	{
		q=ans.top();ans.pop();int ix=id[q.x];int iy=id[q.y];
		if (q.l<ix){se=q.l&1;int x=query(1,q.l,ix-1,se);int y=query(1,id[x],ix-1,se^1);pu.l=q.l;pu.r=ix-1;pu.x=x;pu.y=y;ans.push(pu); }
		if (ix+1<iy){se=(ix+1)&1;int x=query(1,ix+1,iy-1,se);int y=query(1,id[x]+1,iy-1,se^1);pu.l=ix+1;pu.r=iy-1;pu.x=x;pu.y=y;ans.push(pu);}
		if (iy<q.r){se=(iy+1)&1;int x=query(1,iy+1,q.r,se);int y=query(1,id[x]+1,q.r,se^1);pu.l=iy+1;pu.r=q.r;pu.x=x;pu.y=y;ans.push(pu);}
		printf("%d %d ",q.x,q.y);
	}
	while (!ans.empty()){pu=ans.top();ans.pop();printf("%d %d ",pu.x,pu.y);}
}

Measured memory_bytes: 12532
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int N = int.Parse(s[0]);
        int M = int.Parse(s[1]);
        int t = (N - M) * 100;
        int p = Convert.ToInt32(Math.Pow(2, M));
        Console.WriteLine(((1900 * M) + t) * p);
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

int k;
vector<vector<int>>cnt;

vector<vector<int>> grid_bfs(int h,int w,int x,int y,vector<string> &maze,char obstacle='#') {
  const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };//4方向移動
  const int init=1e7;
  vector<vector<int>>d(h,vector<int>(w,init));
  d[x][y]=0;
  queue<pair<int, int>>q;
	pair<int, int>p;
  q.emplace(x,y);
	while (!q.empty()) {
		p = q.front();
		q.pop();
		for (int i = 0; i < 4; ++i) {
			REP(j,1,k+1){
				int nx = p.first+dx[i]*j; int ny = p.second+dy[i]*j;
				if(!(0 <= nx && nx < h && 0 <= ny && ny < w))break;
				if (d[nx][ny] == init) {
					if(maze[nx][ny]==obstacle)break;
					q.emplace(make_pair(nx, ny));
					d[nx][ny] = d[p.first][p.second] + 1;

				}
				else{
					if(cnt[nx][ny]==4)break;
					++cnt[nx][ny];
				}
			}
		}
	}
  return d;//initを含むことに注意
}

void solve()
{
	int h,w;
	cin>>h>>w>>k;
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	x1--;y1--;
	x2--;y2--;
	cnt.resize(h,vector<int>(w));
	vector<string>c(h);
	rep(i,h)cin>>c[i];
	auto d=grid_bfs(h,w,x1,y1,c,'@');
	// rep(i,h){
	// 	rep(j,w){
	// 		if(d[i][j]!=1e7)cout<<d[i][j];
	// 		else cout<<'@';
	// 	}
	// 	cout<<endl;
	// }
	ll ans=d[x2][y2];
	if(ans==1e7)cout<<-1;
	else cout<<ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 17028
#include <stdio.h>

int suit2index(char suit)
{
	switch(suit)
	{
		case 'S': return 0;
		case 'H': return 1;
		case 'C': return 2;
		case 'D': return 3;
	}
	return -1; /* ダミー */
}

char index2suit(int num)
{
	switch(num)
	{
		case 0: return 'S';
		case 1: return 'H';
		case 2: return 'C';
		case 3: return 'D';
	}
	return '\0'; /* ダミー */
}

int main()
{
	int n, num, cards[4][13];
	char suit;

	for(int s = 0; s < 4; ++s)
	{
		for(int i = 0; i < 13; ++i)
		{
			cards[s][i] = 0;
		}
	}


	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
	{
		scanf(" %c %d", &suit, &num); /* 改行無視のため先頭に空白 */
		cards[suit2index(suit)][num-1] = 1;
	}

	for(int s = 0; s < 4; ++s)
	{
		for(int i = 0; i < 13; ++i)
		{
			if(cards[s][i] == 0)
			{
				printf("%c %d\n", index2suit(s), i+1);
			}
		}
	}

	return 0;
}


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

A = [list(map(int,input().split())) for i in range(N)] #N*M配列の取得
B = [list(map(int,input().split())) for i in range(M)] #M*L配列の取得
ANS = [[0]*L for i in range(N)] #N*L

for x in range(N):
    for y in range(L):
        for z in range(M):
            ANS[x][y] += A[x][z]*B[z][y]

for row in range(N):
    print("%d"%ANS[row][0],end = "")
    for col in range(1,L):
        print(" %d"%(ANS[row][col]),end = "")
    print()


Measured memory_bytes: 7052