akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
int a[maxn];
ll ans=1;
int main(){
    boost;
    
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    if(n%2&&a[1]!=0){
        cout<<"0\n";
        return 0;
    }
    if(n%2){
        int cur=2;
        for(int i=2;i<=n;i+=2,cur+=2,ans=(ans*2)%mod){
            if(a[i]==cur&&a[i+1]==cur)continue;
            cout<<"0\n";
            return 0;
        }
    }
    else{
        int cur=1;
        for(int i=1;i<=n;i+=2,cur+=2,ans=(ans*2)%mod){
            if(a[i]==cur&&a[i+1]==cur)continue;
            cout<<"0\n";
            return 0;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){
    int a,b,k,tmp;
    cin>>a>>b;

    tmp=a+b;
    k=(a+b)/2;
    if(tmp==k*2){
        cout<<k<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define frpn(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout);
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define fornd(i, n) for(int i=(int)(n)-1; i>=0; --i)
#define forabd(i, a, b) for(int i=(int)(a); i>=(int)(b); --i)
const int INF = (int)1e6+5;
const int NAX = (int)3e5+5;
const int MOD = (int)1e9+7;

template <class T>
inline void rem(T &n){
   n = (-MOD <= n && n <= MOD) ? n : n%MOD ;
  if(n < 0) n += MOD; 
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll l, r; cin >> l >> r;
    if((l-1)/2019 != r/2019){
       cout << 0 << "\n";
       return 0;
    }
    l %= 2019, r %= 2019;
    if(l > r)
      r += 2019;
    ll res = (l*r)%2019;
    for(int i=l; i<=r; ++i){
      for(int j=l; j<=r; ++j){
        if(i!=j && (i*j)%2019 < res){
          res = (i*j)%2019;
        }

      }
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	map<int, int> cou;
	int n;
	cin >> n;
	vi a(n);
	rep(i, 0, n) {
		cin >> a[i];
		if (!cou.count(a[i])) {
			cou[a[i]] = 0;
		}
		cou[a[i]]++;
	}
	int ans = 0;
	for (auto x : cou) {
		int i = x.first;
		int j = x.second;
		if (i > j) {
			ans += j;
		}
		else {
			ans += j - i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  REP(i, s.size()) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3844
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>> ab(m);
  rep(i,m) {
    int a,b;
    cin>>a>>b;
    ab[i]=make_pair(a,b);
  }
  sort(ab.begin(),ab.end());
  int a,b;
  int c=1;
  tie(a,b)=ab[0];
  repeat(i,1,m) {
    int aa,bb;
    tie(aa,bb)=ab[i];
    // a<=aa
    if(b<=aa) {
      c++;
      a=aa;
      b=bb;
    } else {
      if(bb<=b) {
        a=aa;
        b=bb;
      } else {
        a=aa;
      }
    }
    //cout << "a=" << a << ",b=" << b << endl;
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 1152
N=int(input())
refer_List=[1,2,3,4,5,6,7,8,9]

flag=0

Ans_List=[]    
for i in range(1,10):
    if N%i==0:
        Ans_List.append(N//i)

for i in Ans_List:
    if refer_List.count(i)!=0:
        flag=1
        break
    
print("Yes" if flag==1 else "No")

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner = new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int c=scanner.nextInt();
        int k=scanner.nextInt();
        int max=Math.max(Math.max(a,b),c);
        System.out.println((int)(a+b+c+max*Math.pow(2,k)-max));
    }
}


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

#define ll long long
#define pb push_back
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = c/b;
    if(c%b != 0) x ++;
    int y = a/d;
    if(a%d != 0) y++;
    if(x <= y) {
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	
	bool flag = false;
	for (int i = 1; i <= 9; ++i)
	{
		for (int j = 1; j <= 9; ++j)
		{
			if (i * j == n)
			{
				cout << "Yes" << endl;
				return 0;
			}
			else
			{
				flag = false;
			}
		}
	}
	
	if (!flag)
	{
		cout << "No" << endl;
	}
	
	return 0;
}


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

#define fast ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define fl(i,a,n) for(int i=a; i<n; i++)
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define test()  int tt;  cin>>tt;  while(tt--)
#define nl  cout<<"\n"
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)    {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}
const int mod=1e9+7;

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

Measured memory_bytes: 2560
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define M 100010


int main(){
	IOS;
	tihs;

	
	ll n;cin>>n;
	ll a[n];
	rep(i,0,n)cin>>a[i];
	ll mn=inf;
	rep(i,0,101){
		ll ans=0;
		rep(j,0,n)ans+=(i-a[j])*(i-a[j]);
		mn=min(mn,ans);
	}
	cout<<mn;
	return 0;
}

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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

	var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long T = inputArray[0];
			var ans = new List<long>();
			for (int i = 0; i < T; i++) {
				var s = Solve();
				ans.Add(s);
			}
			foreach (var item in ans) {
				Console.WriteLine(item);
			}
		}

		/// <summary>
		/// 1つのテストケースについて説く
		/// </summary>
		private static long Solve() {
			var input = retreiveLongArray();
			long N = input[0];
			two = input[1];
			three = input[2];
			five = input[3];
			plusOne = input[4];

			var minCost = long.MaxValue;
			_memoDic = new Dictionary<long, long>();
			//メモ付きDFSで解く
			minCost = DFS(N);
			return minCost;

		}

		private static long DFS(long n) {

			if (n == 1) {
				return plusOne;
			}
			if (n==0) {
				return 0;
			}

			if (_memoDic.ContainsKey(n)) {
				return _memoDic[n];
			}

			var cost2 = subDFS(n, two,2);
			var cost3 = subDFS(n, three, 3);
			var cost5 = subDFS(n, five, 5);

			var cost = Math.Min(Math.Min(cost2, cost3),cost5);
			_memoDic.Add(n, cost);
			return cost;

		}

		private static long subDFS(long n, long shoricost,long divide) {

			checked {
				//divideで割る場合
				var amari = n % divide;
				if (amari == 0) {
					var normal = DFS(n / divide) + shoricost;
					var Jimichi = long.MaxValue;
					if (n-n/divide < shoricost / plusOne + 1) {//オーバーフロー対策である程度まともな時しか計算しない
						Jimichi = DFS(n / divide) + (n - n / divide) * plusOne;
					}
					return Math.Min(normal, Jimichi);

				}
				else {
					var Normal =  shoricost + plusOne * amari;
					
					var costfloor = subDFS(n - amari,shoricost,divide) + plusOne * amari; 

					var costsail = subDFS(n + divide - amari, shoricost, divide) + plusOne * (divide - amari);

					return Math.Min(costfloor, costsail);
				}
			}

		}

		//計算用メモ
		private static Dictionary<long, long> _memoDic;
		//必要コイン
		private static long two;
		private static long three ;
		private static long five ;
		private static long plusOne ;

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}

Measured memory_bytes: 32556
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mp make_pair

using namespace std;

int main() {
	int n; cin >> n;
	ll h[n];
	for(ll i = 0; i < n; i++) cin >> h[i];
	ll dp[n];
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]); 
	for (ll i = 2; i < n; i++) {
		dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]);
	}
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1792
<?php

// ax + by = c
// dx + ey = f

function x($a, $b, $c, $y) {
    return ($c - ($b * $y)) / $a;
}

function y($a, $b, $c, $d, $e, $f) {
    return (($c * $d) - ($a * $f)) / (($b * $d) - ($a * $e));
}

for (;fscanf(STDIN,"%d %d %d %d %d %d",$a,$b,$c,$d,$e,$f);) {
    $y = y($a, $b, $c, $d, $e, $f);
    $x = x($a, $b, $c, $y);
    printf("%.03f %.03f" . PHP_EOL, $x, $y);
}

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

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

int main(){
	int p, q;
	cin >> p >> q;
	q /= GCD(p, q);
	map<int, int> mpa;
	for(int i = 2; i * i <= q; i++){
		while(q % i == 0){
			mpa[i]++;
			q /= i;
		}
	}
	if(q != 1) mpa[q]++;
	map<int, int>::iterator it;
	int ans = 1;
	for(it = mpa.begin(); it != mpa.end(); it++){
		ans *= it->first;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n;
    ll k;
    cin >> n >> k;

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

    vector<int> s;
    vector<int> ord(n+1, -1);
    int c = 1, l = 0;
    int v = 1;
    while (ord[v] == -1) {
        ord[v] = s.size();
        s.push_back(v);
        v = a[v-1];
    }
    c = s.size() - ord[v];
    l = ord[v];


    if (k < l) {
        cout << s[k] << endl;
    }
    else {
        k -= l;
        k %= c;
        cout << s[l+k] << endl;
    }


    return 0;
}

Measured memory_bytes: 5892
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> v(n);
    rep(i,m){
        int x,y;
        cin>>x>>y;
        --x;--y;
        v[x].push_back(y);
    }
    vector<vector<int>> dist(n,vector<int>(n,inf));
    rep(i,n){
        dist[i][i]=0;
        queue<int> q;
        q.push(i);
        while(q.size()){
            int x = q.front();q.pop();
            for(auto to : v[x]){
                if(dist[i][to]>dist[i][x]+1){
                    dist[i][to]=dist[i][x]+1;
                    q.push(to);
                }
            }
        }
    }
    int st = -1, en = -1, c = inf;
    rep(i,n)rep(j,i){
        if(dist[i][j]+dist[j][i]<c&&dist[j][i]==1){
            st=i;
            en=j;
            c=dist[i][j]+dist[j][i];
        }
    }
    if(c==inf){
        cout<<-1<<endl;
        return 0;
    }
    vector<int> ans;
    ans.push_back(st);
    int tmp = st;
    while(st!=en){
        for(auto to : v[st]){
            if(dist[to][en]==dist[st][en]-1&&dist[tmp][to]==dist[tmp][st]+1){
                st=to;
                break;
            }
        }
        ans.push_back(st);
    }
    cout<<ans.size()<<endl;
    for(auto e : ans){
        cout<<e+1<<endl;
    }
    return 0;
}

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


int main(){
  ll N, M;
  cin >> N >> M;
  vector<ll> L(M); vector<ll> R(M);
  rep(i, M) cin >> L.at(i) >> R.at(i);
  
  ll res, res_L, res_R;
  res_L = L.at(0); res_R = R.at(0);
  
  rep(i, M){
    if(L.at(i) > res_L) res_L = L.at(i);
    if(R.at(i) < res_R) res_R = R.at(i);
  }
  
  if(res_L > res_R){
    res = 0;
  }else{
    res = res_R - res_L + 1;
  }
  
  cout << res;
  
}

Measured memory_bytes: 1792
import sys
 
N = int(sys.stdin.readline())
 
# 4*h*n*w = N * (h*n + n*w + w*h)
# (4*h*n - N*n - N*h) * w = N*h*n
# w = N*h*n / (4*h*n - N*n - N*h)
 
for h in range(1, 3501):
    for n in range(1, 3501):
        a = N*h*n
        b = (4*h*n - N*n - N*h) 
        # print(h, n, a, b)
        if b > 0 and a % b == 0:
            w = a // b
            # print(4/N, 1/h + 1/n + 1/w)
            print(h, n, w)
            sys.exit()

Measured memory_bytes: 66548
#include<stdio.h>
#define pd(x) printf("%d",x)
#define sd(x) scanf("%d",x) 

int main(){
  int N,K,l,ans=0;
  scanf("%d%d",&N,&K);
  int S[100]={};
  int d;
  for(int i=0;i<K;i++){
    scanf("%d",&d);
    for(int j=0;j<d;j++){
      scanf("%d",&l);
      S[l-1]++;
    };
  };
  for(int y=0;y<N;y++){
    if(S[y]==0)ans++;
  };
  pd(ans);
};

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define mp(x,y)         make_pair(x,y)
#define all(c)          c.begin(), c.end()
#define ff              first
#define ss              second
#define nl              '\n'
#define inf             1e9+7
 
int main()
{
	ninja
	int t; 
	int x,y,z; cin>>x>>y>>z;
	swap(x,y);
	swap(x,z);
	cout<<x<<" "<<y<<" "<<z;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
    ll n,x,m;
    cin>>n>>x>>m;
    ll ans=0;
    map<ll,int> mp;
    ll cnt=0;
    V<ll> d;
    for(int i=0;i<n;i++){
        mp[x]++;
        if(mp[x]==2){
            cnt+=x;
            if(d.size()==0)d.push_back(x);
            else {
                d.push_back(d.back()+x);
            }
        }
        if(mp[x]==3){
            ll len=d.size();
            ans+=cnt*((n-i)/len);
            if((n-i)%len!=0){
             //   cout<<d[(n-i)%len-1]<<"\n";
               // cout<<ans<<"\n";
                ans+=d[(n-i)%len-1];
            }
            break;
        }
        ans+=x;
        x*=x;
        x%=m;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 6964
# AOJでnumpyが使えないから自力で内積を求める
import sys
# import numpy as np
import math

input = sys.stdin.readline
n = int(input())
# ベクトルの60度回転で使う
cos60 = math.cos(math.radians(60))
sin60 = math.sin(math.radians(60))
# k = np.array([[cos60, -(sin60)], [sin60, cos60]])
k = ([[cos60, -(sin60)], [sin60, cos60]])


def main():
    start = [0.00000000, 0.00000000]
    end = [100.00000000, 0.00000000]
    print(' '.join(map(str, start)))
    Koch(start, end, 0)
    print(' '.join(map(str, end)))


def Koch(start, end, layer):
    layer += 1
    if layer > n:
        return
    point1 = [((end[0] - start[0]) / 3) + start[0], ((end[1] - start[1]) / 3) + start[1]]
    Koch(start, point1, layer)
    print(' '.join(map(str, point1)))
    point3 = [((end[0] - start[0]) / 3 * 2) + start[0], ((end[1] - start[1]) / 3 * 2) + start[1]]
    # vec = np.array([[point3[0] - point1[0]], [point3[1] - point1[1]]])  # vecは一旦原点に戻す
    vec = ([[point3[0] - point1[0]], [point3[1] - point1[1]]])  # vecは一旦原点に戻す
    point2 = [[k[0][0] * vec[0][0] + k[0][1] * vec[1][0]], [k[1][0] * vec[0][0] + k[1][1] * vec[1][0]]]  # 内積をとって60度左回転する
    point2 = [point2[0][0] + point1[0], point2[1][0] + point1[1]]  # 元あった点に戻す
    Koch(point1, point2, layer)
    print(' '.join(map(str, point2)))
    Koch(point2, point3, layer)
    print(' '.join(map(str, point3)))
    Koch(point3, end, layer)


if __name__ == '__main__':
    main()



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

int main() {
  int n, m, c, num = 0;
  cin >> n >> m >>c;
  int array[21][21];
  for(int i = 0;i <= n; i++){
      for(int j = 0;j < m;j++){
          cin >> array[i][j]; 
      }
  }
  for(int i = 1;i <= n; i++){
      int sum = c;
      for(int j = 0;j < m;j++){
          sum += array[0][j]*array[i][j]; 
      }
      if(sum > 0) num += 1;
  }
  cout << num << endl;
}

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

int main() {
  int x1, y1, x2, y2, x3, y3, x4, y4;
  cin >> x1 >> y1 >> x2 >> y2;
  x3 = x2 + y1 - y2;
  y3 = y2 - x1 + x2;
  x4 = x3 + y2 - y3;
  y4 = y3 - x2 + x3;
  cout << x3 << endl << y3 << endl << x4 << endl << y4 << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

class AtCoder
{
    static void Main()
    {
        string[] s;       
        s = NextS();
        int[] a = new int[4];
        for (int i = 0; i < 4; i++) a[i] = int.Parse(s[i]);
        Array.Sort(a);
        if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
            Console.WriteLine("YES");
        else Console.WriteLine("NO");
    }

    static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
    static string[] NextS() { return Console.ReadLine().Trim().Split(' '); }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
const int INF = 10000;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  string s;
  cin>>s;
  char tmp = s[0];
  int cnt = 0;
  for(int i = 0; i < s.length(); i++){
    if(s[i]!=tmp){
      tmp = s[i];
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 512
q,h,s,d=map(int,input().split())
n=int(input())
 
l=min(q*n*8,h*n*4,s*n*2,d*n)
if l != d*n:
    print(l//2)
else:
    m=min(q*4,h*2,s)
    print((d*(n-1))//2+m if n%2==1 else l//2)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;

  ll b = 1;

  while(b*b < N) b++;

  if(b*b == N){
    cout << b*b << endl;
  } else{
    cout << (b - 1)*(b - 1) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
class UnionFind {
  public:
    vector<int> parent;
    UnionFind(int n) {
        parent = vector<int>(n, -1);
    }
    int root(int a) {
        if (parent[a]<0) return a;
        return parent[a] = root(parent[a]);
    }
    int size(int a) {
        return -parent[root(a)];
    }
    bool is_connected(int a, int b) {
        return root(a) == root(b);
    }
    bool connect(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) {
            return false;
        }
        if (size(a)<size(b)) swap(a, b);
        parent[a] += parent[b];
        parent[b] = a;
        return true;
    }
};
int ans;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    for (auto &p : P) cin >> p;
    UnionFind UF(N+1);
    int x, y;
    while (M--) {
        cin >> x >> y;
        UF.connect(x, y);
    }
    for (int i = 0; i < N; i++) if (UF.is_connected(i+1, P[i])) ans++;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int> > G(10, vector<int>(10, 0));
vector<int> visited(10, 0);
int N;
int ans = 0;
/* function */
void dfs(int from, int cnt) {
    cnt++;
    if (cnt == N) {
        ans++;
        return;
    }
    visited[from] = 1;
    for (int to = 0; to < N; to++) {
        if (G[from][to] == 0) continue;
        if (visited[to]) continue;
        dfs(to, cnt);
    }
    cnt--;
    visited[from] = 0;
}
/* main */
int main(){
    int M, a, b;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        a--; b--;
        G[a][b] = 1;
        G[b][a] = 1;
    }
    int st = 0;
    for (int i = 0; i < N; i++) if (G[i].size() == 1) st = i;
    dfs(st, 0);
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <chrono>
#include<math.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std::chrono;
using namespace std;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// declaration: ordered_set os;  methods->  1. *os.find_by_order(x)   2. os.order_of_key(k) ->return int

#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
#define ld long double
const ll mod=998244353;
ll f(ll x,ll n){
    ll r=1;
    while(n){
        if(n&1)
        r=(r*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return r;
}
void solve(){
    int n;
    cin>>n;
    ll a[n],b[n];
    fr(i,0,n)
    cin>>a[i]>>b[i];
    sort(a,a+n);
    sort(b,b+n);
    if(n&1){
        cout<<b[n/2]-a[n/2]+1;
    }
    else{
        ld mn=(a[n/2-1]+a[n/2])/2.0;
        ld mx=(b[n/2-1]+b[n/2])/2.0;
        ll ans=2*(mx-mn)+1;
        cout<<ans;
    }

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
//    build();
    int t=1;
//    cin>>t;
    while(t--)
    solve();

}


Measured memory_bytes: 6780
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)
#define add(x,y)(x=(x+y)%MOD)

ll a[100010];
int main(){
	int n;
	scanf("%d",&n);
	ll sum=0;
	rep(i,0,n){
		int t;
		scanf("%d",&t);
		a[t]++;
		sum+=t;
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int b,c;
		scanf("%d%d",&b,&c);
		a[c]+=a[b];
		sum+=(c-b)*a[b];
		a[b]=0;
		printf("%lld\n",sum);
	}
}

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

const int INF=2e9,N=5005;
int n,a,b,k,ans=INF;
char s[N];
int head[N],d[N],f[N],size[N];
struct edge{int v,next;}e[N<<1];

inline void add(int u,int v)
{
    e[++k]=(edge){v,head[u]};
    head[u]=k;
}

inline void prepare(void)
{
    memset(d,0,sizeof(d));
    memset(size,0,sizeof(size));
    memset(f,0,sizeof(f));
}

inline int min(int a,int b)
{
	return a<b?a:b;
}

inline void DFS(int u,int fa)
{
    size[u]=s[u]-'0';
    register int son=0;
    for(register int i=head[u];i;i=e[i].next)
    {
        if(e[i].v==fa) continue;
        DFS(e[i].v,u);
        size[u]+=size[e[i].v];
        d[e[i].v]+=size[e[i].v],d[u]+=d[e[i].v];
        if(d[son]<=d[e[i].v]) son=e[i].v;
    }
    if(!son) f[u]=0;
    else if(d[u]>=d[son]<<1) f[u]=d[u]>>1;
    else f[u]=d[u]-d[son]+min(f[son],((d[son]<<1)-d[u])>>1);
}

int main(void)
{
    scanf("%d%s",&n,s+1);
    for(register int i=1;i<n;++i)
    {
        scanf("%d%d",&a,&b);
        add(a,b),add(b,a);
    }
    for(register int i=1;i<=n;++i)
    {
        prepare();
        DFS(i,0);
        if(d[i]&1) continue;
        if(f[i]<<1>=d[i]) ans=min(ans,d[i]>>1);
    }
    printf("%d\n",ans==INF?-1:ans);
    return 0;
}

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

using namespace std;

typedef long long ll;

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

	string s, t;
	cin >> s >> t;

	int cnt = 0;
	rep(i, 3){
		if(s[i] == t[i]) cnt++;
	}

	cout << cnt << endl;


}


Measured memory_bytes: 764
/* ************************************************************************
	> File Name: b.cpp
	> Author: caowushang
	> Mail: 15630929347@163.com 
	> Created Time: 2017年02月18日 星期六 20时06分40秒
 ************************************************************************/

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int main()
{
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
	long long n;
	cin >> n;
	long long ans=1;
	for(int i=2;i<=n;i++)
		ans=(ans*i)%mod;
	cout << ans << endl;
	return 0;
}


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

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> x(m),y(m-1);
    for(int i = 0; i < m; i++) cin >> x[i];
    sort(x.begin(),x.end());
    for(int i = 0; i < m-1; i++){
        y[i] = x[i+1]-x[i];
    }
    sort(y.begin(),y.end());
    int ans = 0;
    for(int i = 0; i < max(m-n,0); i++){
        ans += y[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import numpy as np

def calc(X, p):
  ans = 0
  for x in X:
    ans += (x-p)**2   
  print(int(ans))
  
n = int(input())
X = list(map(int, input().split()))

p = np.mean(X)
p1 = np.floor(p)
p2 = np.ceil(p)

if p <= p1 + 0.5:
  calc(X, p1)
else:
  calc(X, p2)

Measured memory_bytes: 12496
# 解説を参考に作成
# https://atcoder.jp/contests/abc112/submissions/16922570 を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, xyh):
    xyh.sort(reverse=True, key=lambda x: x[2])
    for X in range(101):
        for Y in range(101):
            H = xyh[0][2] + abs(X - xyh[0][0]) + abs(Y - xyh[0][1])
            for x, y, h in xyh:
                if h != max(0, H - abs(X - x) - abs(Y - y)):
                    break
            else:
                print(X, Y, H)
                return


if __name__ == '__main__':
    N = int(input())
    xyh = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, xyh)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep2(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const ll mod = 1e9+7;
int gcd(int a, int b){if(a<b) swap(a,b); if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

long long N, M, K, H, W, L, R;

int main(){
  cin >> N >> H;
  int at1 = 0;
  vi at2(N);
  rep(i,N){
    int a; cin >> a;
    at1 = max(at1, a);
    cin >> at2[i];
  }
  sort(all(at2),greater<int>());
  int chkat = 1e9;
  rep(i,N){ 
    if(at2[i]<at1){chkat=i; break;}
  }
  int cnt = 0;
  rep(i,N){
    if(i==chkat){ 
      break;
    }
    H = H-at2[i];
    cnt++;
    if(H<=0) break;
  }
  
  if(H>0) cnt += (H+at1-1)/at1;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
bool judge(vector<vector<pair<int,int> > > v,int n,int bit)
{
    for(int i = 0;i < n;i++)
    {
        if(!(bit & (1 << i)))
        {
            continue;
        }
        for(int j = 0;j < v[i].size();j++)
        {
            if(v[i][j].second == 1 && !(bit & (1 << v[i][j].first)))
            {
                return false;
            }
            if(v[i][j].second == 0 && bit & (1 << v[i][j].first))
            {
                return false;
            }
        }
    }
    return true;
}
int main()
{
    int n;
    cin >> n;
    vector<vector<pair<int,int> > > v(n);
    for(int i = 0;i < n;i++)
    {
        int a;
        cin >> a;
        v[i].resize(a);
        for(int j = 0;j < a;j++)
        {
            cin >> v[i][j].first >> v[i][j].second;
            v[i][j].first--;
        }
    }
    int ans = 0;
    for(int bit = 0;bit < (1 << n);bit++)
    {
        if(judge(v,n,bit))
        {
            int count = 0;
            for(int i = 0;i < n;i++)
            {
                if(bit & (1 << i))
                {
                    count++;
                }
            }
            if(count > ans)
            {
                ans = count;
            }
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
#define vvv vector<vector<vector<long long int>>>
#define vvvl(a, b, c, d) vector<vector<vector<long long int>>>(a, vector<vector<long long int>>(b, vector<long long int> (c, d)));

int main(int argc, char const *argv[]) {
  ll a, b, c;std::cin >> a >> b >> c;
  set<ll> s;
  s.insert(a), s.insert(b), s.insert(c);
  std::cout << (s.size()==2?"Yes":"No") << '\n';
  return 0;
}


Measured memory_bytes: 888
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll H,W;
	cin >>H>>W;
	string S[H];
	ll map[H+2][W+2] = {0};
	REP(i,H)REP(j,W) map[i][j] = 0;
	for (ll i = 0; i < H; ++i) cin >> S[i];
 
	// 解法
	REP(i,H){
		REP(j,W){
			if (S[i][j]=='#'){
				map[i][j  ]++;map[i+1][j  ]++;map[i+2][j  ]++;
				map[i][j+1]++;map[i+1][j+1]++;map[i+2][j+1]++;
				map[i][j+2]++;map[i+1][j+2]++;map[i+2][j+2]++;
			}
		}
	}
	
	REP(i,H){
		REP(j,W){
			if (S[i][j]=='.') printf("%lld", map[i+1][j+1]);
			else  printf("#");
		}
		printf("\n");
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int max(int a , int b){
	return a > b ? a : b;
}

int main(void){
	int n , i , j , num[5001];
	long long int sum , m;
	while(1){
		scanf("%d" , &n);
		if(n == 0) break;
		for(i=1;i<=n;i++){
			scanf("%d" , &num[i]);
		}
		m = num[1];
		for(i=1;i<=n;i++){
			sum = 0;
			for(j=i;j<=n;j++){
				sum += num[j];
				m = max(sum , m);
			}
		}
		printf("%lld\n" , m);
	}
	return 0;
}

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

class D2
{
	static void Main()
	{
		Console.ReadLine();
		var d = Console.ReadLine().Select((c, i) => new { c, i }).ToLookup(_ => _.c, _ => _.i);

		var q = from i1 in d.Select(g => g.First())
				from i2 in d.Select(g => Find(g.ToArray(), i1 + 1)).Where(x => x > 0)
				select d.Count(g => g.Last() > i2);
		Console.WriteLine(q.Sum());
	}

	static int Find(int[] a, int v)
	{
		var i = Array.BinarySearch(a, v);
		if (i < 0) i = ~i;
		return i < a.Length ? a[i] : 0;
	}
}


Measured memory_bytes: 14048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int prime[200005] = {};
void seive()
{
    prime[1] = 1;
    for(int i = 2; i <= sqrt(200005); i++)
    {
        for(int j = i * i; j <= 200005; j += i)
        {
            prime[j] = 1;
        }
    }
}
int main()
{
    seive();
    int n;
    cin >> n;
    int v = n;
    for(int i = n; i <= 200000; i++)
    {
        if(prime[i] == 0)
        {
            v = i;
            break;
        }
    }
    cout << v << endl;
    return 0;
}


Measured memory_bytes: 1024
def call2(n):
    for i in range(1,n+1):
        x = i
        if i%3 == 0:
            print(' {}'.format(i), end='')
        else:
            while x:
                if x%10 ==3:
                    print(' {}'.format(i), end='')
                    break
                x = x//10
    print()

call2(int(input()))

Measured memory_bytes: 7956
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int inf=1e9;
const int N=2e3+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,sz[N],sd=0;
pii f[N];
char s[N];
vector<int> E[N];

void dfs(int u,int fa,int dep) {
	f[u]=mp(0,0),sz[u]=s[u]-'0';
	if(sz[u]) sd+=dep;
	for(auto v:E[u]) if(v^fa) dfs(v,u,dep+1),f[u].se+=f[v].se+sz[v],sz[u]+=sz[v];
	int mx=-1,w=0;
	for(auto v:E[u]) if(v!=fa&&f[v].fi+sz[v]>mx) mx=f[v].fi+sz[v],w=v;
	bool fl=1;
	for(auto v:E[u]) if(v!=fa&&v!=w&&f[v].se+sz[v]>=f[w].fi+sz[w]) fl=0;
	if(fl) {
		f[u].fi=f[w].fi+sz[w];
		for(auto v:E[u]) if(v!=fa&&v!=w) f[u].fi-=f[v].se+sz[v];
		f[u].fi=max(f[u].fi,0);
	}
	if(((f[u].fi)&1)!=((f[u].se)&1)) ++f[u].fi;
}

int main() {
	cin>>n;
	scanf("%s",s+1);
	for(int i=1,u,v;i<n;i++) u=gi(),v=gi(),E[u].pb(v),E[v].pb(u);
	int ans=inf;
	for(int i=1;i<=n;i++) {
		sd=0,dfs(i,0,0);
		if(f[i].fi==0) ans=min(ans,sd/2);
	}
	if(ans==inf) ans=-1;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int linearSerch(int S[],int key,int n){
  int i;
  for(i = 0; i < n; i++){
    if(S[i] == key)
      return 1;
  }
  return 0;
}

    


int main(){
  int i,n,q,key,S[100000],sum=0;
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &S[i]);
  
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &key);
    if(linearSerch(S,key,n))
      sum++;
  }
  

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

  return 0;
}





Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Dice d=new Dice(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
		String ord=sc.next();
		for(int i=0; i<ord.length(); i++){
			if(ord.charAt(i)=='E'){
				d.TurnE();
			}else if(ord.charAt(i)=='W'){
				d.TurnW();
			}else if(ord.charAt(i)=='N'){
				d.TurnN();
			}else if(ord.charAt(i)=='S'){
				d.TurnS();
			}

		}

		System.out.println(d.Top);

	}

}

 class Dice{
	 int Top;
	    int Bottom;
	    int N;
	    int S;
	    int W;
	    int E;
	    Dice(int a, int b, int c, int d, int e, int f) {
	        Top = a;
	        S = b;
	        E = c;
	        W = d;
	        N = e;
	        Bottom = f;
	    }
	    public void TurnN() {
	        int tmp = Top;
	        Top = S;
	        S = Bottom;
	        Bottom = N;
	        N = tmp;
	    }
	    public void TurnW() {
	        int tmp = Top;
	        Top = E;
	        E = Bottom;
	        Bottom = W;
	        W = tmp;
	    }
	    public void TurnE() {
	        int tmp = Top;
	        Top = W;
	        W = Bottom;
	        Bottom = E;
	        E = tmp;
	    }
	    public void TurnS() {
	        int tmp = Top;
	        Top = N;
	        N = Bottom;
	        Bottom = S;
	        S = tmp;
	    }

}


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

int main(){
    int n;
    int ans=100;
    cin>>n;
    vector<int>w(n);
    rep(i,n)cin>>w[i];
    rep(i,n){
        int s1=0;
        int s2=0;
        for(int j=0;j<=i;j++){
            s1=s1+w[j];
        }
        for(int k=i+1;k<n;k++){
            s2=s2+w[k];

        }
    ans=min(ans,abs(s1-s2));


    }
    cout<<ans;


}

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

int main()
{
    int A,B;
    cin >> A >> B;
    if(A>B)
    {
        int tmp = A;
        A = B;
        B = tmp;
    }
    if((B - A)%2 == 0)
    {
        cout << A + (B-A)/2 << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[114514] = { 0 };
	int b[114514] = { 0 };
	int c;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	rep(i, n) {
		if (a[i] > b[i]) {
			c += a[i] - b[i];
		}
	}
	cout << c << endl;
}

Measured memory_bytes: 1152
def main():
    n, k = map(int, input().split())
    *a, = map(int, input().split())

    size = 40
    dp = [[-1 for _ in range(2)] for _ in range(size+1)]
    dp[0][0] = 0
    for i in range(size):
        biti = 2 ** (size - i - 1)
        nbit = sum([1 for aa in a if aa & biti])
        score0 = biti * nbit
        score1 = biti * (n - nbit)

        # equal -> equal
        if k & biti:
            dp[i+1][0] = max(dp[i+1][0], dp[i][0] + score1)
        else:
            dp[i+1][0] = max(dp[i+1][0], dp[i][0] + score0)

        # equal -> small
        if k & biti:
            dp[i+1][1] = max(dp[i+1][1], dp[i][0] + score0)

        # small -> small
        if dp[i][1] != -1:
            dp[i+1][1] = max(dp[i+1][1], dp[i][1] + max(score0, score1))
    print(max(dp[size]))


main()


Measured memory_bytes: 14596
## coding: UTF-8

N = int(input())
mod = 10**9 + 7

#print(-3%mod)


ten = 1
nine = 1
eight = 1

if(N == 1):
    print(0)
else:
    for i in range(N):
        ten *= 10 
        ten %= mod
        nine *= 9
        nine %= mod
        eight *= 8
        eight %= mod
        ret = ten + eight - 2* nine
    print(ret % mod)



Measured memory_bytes: 63684
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int n;
    long long z,w, tmp, ans;
    vector<long long> v;
    cin >> n >> z >> w;
    for(int i=0;i<n;i++){
        cin >> tmp;
        v.push_back(tmp);
    }
    if(v.size() == 1){
        cout << abs(v[0] - w) << endl;
    } else {
        if(abs(v[n-2]-v[n-1]) < abs(v[n-1]-w))
            cout << abs(v[n-1] -w) << endl;
        else
            cout << abs(v[n-2]-v[n-1]) << endl;
    }
}


Measured memory_bytes: 256
program main
      implicit none
      integer(4) :: k, a, b, mab, c, mabc
      integer(8) :: cnt

      read *, k
      cnt = 0
      do a = 1, k
        do b = 1, k
          do c = 1, k
            call gcd(a,b,mab)
            call gcd(mab, c, mabc)
            cnt = cnt + mabc
          end do
        end do
      end do
      print *, cnt

      contains

      subroutine gcd(m,n,j)
        implicit none
        integer, intent(in) :: m, n
        integer, intent(out) :: j
        integer :: i, l, x, y

        x = m
        y = n
        do 
          l = mod(x,y)
          if ( l == 0 ) exit
          x = y
          y = l
        end do
        j = y

      end subroutine gcd

end program main


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, tmp;
  cin >> n;
  tmp = n;

  int ans = 0;
  for (int i = 0; tmp > 0; ++i) {
    ans += tmp % 10;
    tmp /= 10;
  }

  cout << (n % ans == 0 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256