akhauriyash/Code-Regression huggingface dataset:
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <sstream>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t H, W;

int map[500][500];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> H >> W;

	for (int32_t i = 0;i < H; i++)
	{
		for (int32_t j = 0; j < W; j++)
		{
			in >> map[i][j];
		}
	}

	std::vector<std::string> buf;
	for (int32_t i = 0; i < H; i++)
	{
		int32_t x1 = -1;
		for (int32_t j = 0; j < W; j++)
		{
			if (map[i][j] % 2 == 1)
			{
				if (x1 == -1) {
					x1 = j;
				}
				else {
					int32_t x2 = j;
					while (x1 < x2) {
						std::stringstream ss;
						ss << i+1 << ' ' << x1 + 1 << ' ' << i + 1 << ' ' << x1 + 1 + 1 << '\n';
						buf.push_back(ss.str());
						++x1;
					}
					while (x2 < x1) {
						std::stringstream ss;
						ss << i + 1 << ' ' << x1 + 1 << ' ' << i + 1 << ' ' << x1 + 1 - 1 << '\n';
						buf.push_back(ss.str());
						--x1;
					}

					x1 = -1;
				}
			}
		}
		if (x1 != -1 && i+1<H) {
			std::stringstream ss;
			ss << i + 1 << ' ' << x1 + 1 << ' ' << i + 2 << ' ' << x1 + 1 << '\n';
			buf.push_back(ss.str());
			map[i + 1][x1]++;
		}
	}
	out << buf.size() << endl;
	for (auto& i : buf)
	{
		out << i;
	}

	return 0;
}
#endif


Measured memory_bytes: 6128
package main

import (
	"fmt"
	"sort"
)

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

	poll := make(map[string]int, n)
	max := 0
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		poll[s]++
		if max < poll[s] {
			max = poll[s]
		}
	}

	ans := make([]string, 0, n)
	for k, v := range poll {
		if v == max {
			ans = append(ans, k)
		}
	}
	sort.Strings(ans)

	for _, v := range ans {
		fmt.Println(v)
	}
}


Measured memory_bytes: 23040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  int a = N;
  
  while (a > 10) {
    sum += a % 10;
    a /= 10;
  }
  sum += a;
  
  if (N % sum == 0) {
    cout << "Yes" <<endl;
  }
  else {
  cout << "No" << endl;
  }


  
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
	input!(n: usize);
	input!(s: String);

	let mut v: Vec<char> = s.chars().collect();

	let mut max = 0;
	let mut x:isize = 0;
	for i in 0..n {
		if v[i] == 'I' {
			x += 1;
			max = std::cmp::max(max, x);
		}
		else {
			x -= 1;
		}
	}
	println!("{}", max);
}



Measured memory_bytes: 2084
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var N = cin.ReadInt;
            var valueList = cin.ReadIntArray(2);
            var T = valueList[0];
            var A = valueList[1];
            
            //var ans = cin.ReadIntArray(N).Select(x =>Math.Abs(A - (T - (x*0.006)))).Min();
            var ans = cin.ReadIntArray(N)
            .Select((item, index) => new { Index = index, Value = Math.Abs(A - (T - (item*0.006)))})
            .Aggregate((min, working) => (min.Value < working.Value) ? min : working).Index;
            
            WriteLine(ans+1);
            
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13456
#include <iostream>
#include <queue>
#include <vector>
#define INF 10e6;
using namespace std;

int cost[101][101][2];  //0距離　1人数
int check[101][101];

int N,M,L;

struct node{
	int dis;
	int n;
	int cost;
	bool operator <(node a)const{
    return dis < a.dis;
  	}
	bool operator >(node a)const{
    return dis > a.dis;
  	}
};


int dijkstra(int g,int l){
	node start;
	int ans;
	start.dis=0,start.n=1,start.cost=l;
	priority_queue < node,vector<node>, greater<node> > p;
	p.push(start);
	while(!p.empty()){
		node tmp=p.top();
		p.pop(); 
		if(check[tmp.n][tmp.cost]<=tmp.dis)
			continue;
		else
			check[tmp.n][tmp.cost]=tmp.dis; 
		if(tmp.n == g){
			ans=tmp.dis;
			return ans;
		}
		for(int i=1;i<=g;i++){
			if(tmp.n == i)
				continue;
			node next;
			next.n=i;
			if(tmp.cost >= cost[tmp.n][i][0]){
				next.cost=tmp.cost-cost[tmp.n][i][0];
				next.dis=tmp.dis;
				p.push(next);
			}
			next.cost=tmp.cost;
			next.dis=tmp.dis+cost[tmp.n][i][1];
			p.push(next);
		}
	}
}

int main(void){
	while (cin >> N >> M >> L,N|M|L){
		for(int i=0;i<101;i++)
			for(int j=0;j<101;j++)
				check[i][j]=cost[i][j][0]=cost[i][j][1]=INF;
		for(int i=0;i<M;i++){
			int a,b,d,e;
			cin >> a >> b >> d >> e;
			cost[a][b][0]=cost[b][a][0]=d; 
			cost[a][b][1]=cost[b][a][1]=e;
		}
		int res=dijkstra(N,L);
		cout << res <<endl;
	}
	return 0;
}

Measured memory_bytes: 23844
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

const int MAXN = 1001;
int match_id[MAXN][MAXN];
vi adj[MAXN*MAXN];
int deg[MAXN*MAXN];

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

	int n;
	scanf("%d", &n);
	int m = 0;
	for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++)
			match_id[i][j] = match_id[j][i] = m++;
	for (int i = 1; i <= n; i++) match_id[i][i] = -1;

	vi a(n-1);
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < n-1; j++) {
			scanf("%d", &a[j]);
			if (j > 0) {
				int u = match_id[i][a[j-1]];
				int v = match_id[i][a[j]];
				adj[u].push_back(v);
				deg[v]++;
			}
		}
	}

	queue<ii> q;
	for (int i = 0; i < m; i++) if (!deg[i]) q.push({i, 1});
	int day = 0;
	while (!q.empty()) {
		auto x = q.front();
		q.pop();
		m--;
		day = x.second;
		for (int v : adj[x.first])
			if (--deg[v] == 0) q.push({v, day + 1});
	}

	printf("%d\n", (m == 0)? day : -1);
}


Measured memory_bytes: 47104
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	
	int h1, m1, s1, h2, m2, s2;
	
	for(int loop = 0; loop < 3; loop++){
		
		cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;
		
		int ans = (h2 - h1) * 3600 + (m2 - m1) * 60 + (s2 - s1);
		
		printf("%d %d %d\n", (ans / 3600), (ans / 60 % 60), (ans % 60));
		
	}
	return 0;
}

Measured memory_bytes: 1144
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(ll a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define int_maxvalue numeric_limits<int>::max()
ll mod = 1e9 + 7;
ll Comb(ll n) {
	return n*(n - 1) / 2;
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll>dp(n+1);
	for (int i = 0; i < n; i++) {
		dp[i + 1]= 0;
	}
	dp[0] = 0;
	rep(i, n) {
		cin >> dp[i + 1];
		dp[i + 1] += dp[i];

	}
	ll ans = 0;
	Sort(dp);
	ll thiscontinue=0;
	for (int i = 1; i < n + 1; ++i) {
		if (dp[i] == dp[i - 1]) { thiscontinue++; }
		else {
			ans += Comb(thiscontinue + 1);
			thiscontinue = 0;
		}
	}
	ans += Comb(thiscontinue + 1);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
/* ex3_2
   offNaria */
#include <stdio.h>
int main(void){
  int input; //整数inputを定義
  scanf("%d", &input); //入力を変数に代入
  
  input = input % 10; //inputの1の位のみを取得
  if(input == 3){
    printf("bon\n"); //3はbon
  } else if(input == 0 || input == 1 || input == 6 || input == 8){
    printf("pon\n"); //0,1,6,8はpon
  } else {
    printf("hon\n"); //それ以外はhon
  }
  return 0;
}


Measured memory_bytes: 1616
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string alphabet = "abcdefghijklmnopqrstuvwxyz";
            string s = Console.ReadLine();

            Console.WriteLine(
                alphabet.Substring(alphabet.IndexOf(s) + 1, 1)
            );

        }
    }
}


Measured memory_bytes: 13280
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int N = 1e5+10;
map<int,int> a;
int main() {
	int n,b;
	cin>>n;
	for(int x=0;x<n;x++){
		cin>>b;
		a[b]++;
	}
	int m;
	cin>>m;
	for(int x=0;x<m;x++){
		cin>>b;
		if(a[b]>0){
			a[b]--;
		}else{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}

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

const ll mod = 1e9 + 7;

ll dp[101010][13];

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

    ll a = 0;

    string tmp = s;
    reverse(tmp.begin(), tmp.end());

    ll b = 1;
    rep(i, tmp.size()) {
        if (tmp[i] == '?') {
            if (i == 0) {
                for (ll a=0; a<=9; ++a) {
                    dp[i][a] = 1;
                }
            }
            else {
                for (ll a = 0; a<=9; ++a) {
                    ll tmpa = (a * b) % 13;
                    for (int j=0; j<13; ++j) {
                        if (dp[i-1][j] > 0) {
                            dp[i][(tmpa + j) % 13] += dp[i-1][j];
                            dp[i][(tmpa + j) % 13] %= mod;
                        }
                    }
                }
            }

        }
        else {
            ll a = ((tmp[i] - '0') * b) % 13;

            if (i == 0) {
                dp[i][a] = 1;
            }
            else {
                for (int j=0; j<13; ++j) {
                    if (dp[i-1][j] > 0) {
                        dp[i][(j + a)%13] += dp[i-1][j];
                        dp[i][(j + a)%13] %= mod;
                    }
                }
            }

        }

        b *= 10;
        b %= 13;
    }

    cout << dp[tmp.size()-1][5] % mod << endl;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
//    std::sort(a.begin(), a.end(), std::greater<int>() );
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int hoge = 0;
    int n;
    string a, b;
    cin >> n >> a >> b;
    rep(i, a.size())
    {
        rep(j, b.size() - i)
        {
            if (a[i + j] == b[j])
            {
                if (j == (b.size() - i) - 1)
                {
                    hoge = max(hoge, ((int)b.size() - i));
                }
                continue;
            }
            else
            {
                break;
            }
        }
    }
    cout << n * 2 - hoge << endl;
    return 0;
}

Measured memory_bytes: 256
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,tune=native")
// #define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = (1e-9);
typedef long long ll;
typedef unsigned long long ull;
#define flush fflush(stdout), cout.flush()
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).rbegin()),((v).rend())
#define clr(v,line) memset(v,line,sizeof(v))
#define rep(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define RT(x) return x, 0;
//#define lcm(a,b) (a*(b/__gcd(a,b)))
#define P 1000000007
#define endl '\n'
// const int dx[] = {1,-1,0,0,1,-1,1,-1};
// const int dy[] = {0,0,1,-1,1,-1,-1,1};
// const int dxhorse[] = {-2,-2,-1,-1,1,1,2,2};
// const int dyhorse[] = {1,-1,2,-2,2,-2,1,-1};

void file() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
}

int main(int argc, char const *argv[])
{   
    int n, m; cin>>n>>m;
    std::vector<ll> v(n);
    std::vector<pair<ll, ll> > d(m);
    rep(i, n)cin>>v[i];
    sort(all(v));
    for (int i = 0; i < m; ++i)
    {
        cin>>d[i].second>>d[i].first;
    }
    sort(rall(d));
    int idx = 0;
    ll ans = 0;
    for (int i = 0; i < n; ++i)
    {
        idx+=!d[idx].second;
        if (v[i] <  d[idx].first and idx < m)
        {
            v[i]=d[idx].first, d[idx].second--;
        }
        ans+=v[i];
    }
    cout<<ans;

}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  ll N , M ;
  ll ans = 0 ;
  cin >> N >> M ;
  vector<ll> A(N) ;
  rep(i,N) cin >> A.at(i) ;
  sort(A.begin(),A.end()) ;
  if( N - M > 0) rep(i,N-M) ans += A.at(i) ;
  else ans = 0  ;
  cout << ans << endl;
}

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

int main()
{
  char C;
  cin >> C;
  if(C == 'A' ||C == 'B' ||C == 'C' ||C == 'D' ||C == 'E' ||C == 'F' ||C == 'G' ||C == 'H' ||C == 'I' ||C == 'J' ||C == 'K' ||C == 'L' ||C == 'M' ||C == 'N' ||C == 'O' ||C == 'P' ||C == 'Q' ||C == 'R' ||C == 'S' ||C == 'T' ||C == 'U' ||C == 'V' ||C == 'W' ||C == 'X' ||C == 'Y' ||C == 'Z' )
  {
    cout << 'A' << endl;
  }
  else
  {
    cout << 'a' << endl;
  }
  
}


Measured memory_bytes: 3636
#pragma GCC optimize("O3")

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

# include <stdio.h>
# include <bits/stdc++.h>


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace __gnu_pbds;
using namespace std;
 
typedef
tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;

int main () {
	SpeedForce;
	cin >> n >> s;
	if (n < 3200) puts("red");
	else cout << s;

	return Accepted;
}

// B...a

Measured memory_bytes: 18688
#include <iostream>
#include <stdio.h>

using namespace std;

int n, m;
double l[20], a[20], b[20];

int main(void)
{
  cin >> n >> m;
  for(int i = 0; i < n; i++){
    cin >> l[i] >> a[i] >> b[i];
  }
  double ans = 0;
  int N = 1<<n;
  for(int i = 0; i < N; i++){
    int pop = 0;
    for(int j = 0; j < n; j++){
      if(i & (1<<j)) pop++;
    }
    if(pop != m) continue;
    double tmp = 0;
    for(int j = 0; j < n; j++){
      if((i & (1<<j)) == 0) continue;
      for(int k = 0; k < n; k++){
        if(j >= k) continue;
        if((i & (1<<k)) == 0) continue;
        tmp += (l[j]-l[k])*(l[j]-l[k]) + (a[j]-a[k])*(a[j]-a[k]) + (b[j]-b[k])*(b[j]-b[k]);
      }
    }
    ans = max(ans, tmp);
  }
  printf("%.11f\n", ans);

  return 0;
}



Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    ll N, M, X;
    cin >> N >> M >> X;
    vector<ll> A(M);
    repi(i, M, 0)
    {
        cin >> A[i];
    }
    ll g1 = 0, g2 = 0;
    for (auto a : A)
    {
        (a < X ? g1 : g2)++;
    }
    cout << min(g1, g2) << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np

N, M = list(map(int, input().split()))
H = [0] + list(map(int, input().split()))
A = []
B = []
for i in range(M):
  a, b = list(map(int, input().split()))
  A.append(a)
  B.append(b)

memo = [False] + [True]*N
for a, b in zip(A, B):
  if H[a] < H[b]:
    memo[a] = False
  elif H[a] > H[b]:
    memo[b] = False
  else:
    memo[a] = memo[b] = False

print(sum(memo))

Measured memory_bytes: 41316
N = input()
M = [map(int, raw_input().split()) for i in xrange(N)]
cache = {}
for i in xrange(N):
    cache[(i, i+1)] = 0
def dfs(left, right):
    if (left, right) in cache:
        return cache[(left, right)]
    min_cost = float("inf")
    for mid in xrange(left+1, right):
        tmp = M[left][0] * M[mid-1][1] * M[right-1][1]
        tmp += dfs(left, mid)
        tmp += dfs(mid, right)
        if min_cost > tmp:
            min_cost = tmp
    cache[(left, right)] = min_cost
    return min_cost
print dfs(0, len(M))

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

int main( ){
  int n,Y,M,D,sum,i;
  cin>>n;
  for(i=0;i<n;i++){
    sum=0;
    cin>>Y>>M>>D;
    sum+=(Y-1)*195+(Y-1)/3*5;
    sum+=(M-1)*20-(M-1)/2+D;
    if(Y%3==0)sum+=(M-1)/2;
    sum=196470-sum;
    cout<<sum+1<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 3088
#![allow(unused)]

use std::io::{Read, Stdin, StdinLock};
use std::iter::{FromIterator, Iterator};
use std::str::{FromStr};
use std::string::String;

macro_rules! debug {
    ($($a:expr),*) => {
	eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

struct TokenReader<'a> {
    lock: StdinLock<'a>,
}

impl<'a> TokenReader<'a> {
    fn new(s: &'a Stdin) -> TokenReader<'a> {
        TokenReader { lock: s.lock() }
    }

    fn read_chars<T: FromIterator<char>>(&mut self) -> T {
        self.lock
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<T>()
    }

    fn read_str(&mut self) -> String {
        self.read_chars::<String>()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read_str().parse().ok().unwrap()
    }
}

//==============================================================================
//
// Problem specific code
//
//==============================================================================

fn main() {
    let sin = std::io::stdin();
    let mut tr = TokenReader::new(&sin);

    let s: Vec<usize> = tr.read_chars::<Vec<char>>()
        .into_iter()
        .map(|c| c.to_digit(10).unwrap() as usize)
        .collect();
    let n = s.len();

    let mut ans: i64 = 0;
    let mut dp = vec![0i64; 2019];
    for i in 0..n {
        let mut dp_ = vec![0i64; 2019];
        dp_[s[i]] += 1;
        if i >= 1 {
            for r in 0usize..2019 {
                dp_[(r * 10 + s[i]) % 2019] += dp[r];
            }
        }
        ans += dp_[0];
        dp = dp_;
    }

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


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

int N, K;
int A[200100];
int main(){
  cin >> N >> K;
  for(int i=0; i<N; ++i){
    cin >> A[i];
  }
  int num[200100] = {0};
  for(int i=0; i<N; ++i){
    num[A[i]]++;
  }
  int counter =0;
  for(int i=0; i<200100; ++i){
    if (num[i] > 0) ++counter;
  }
  int ans =0;
  int counter2 =0;
  sort(num, num+200100);
  if (counter >K){
    bool flag = false;
    int counter3=0;
    while(true){
      if (num[counter3] >0){
        ++counter2;
        ans += num[counter3];
      }
      if (counter2 == (counter -K)) flag = true;
      if (flag == true) break;
      ++counter3;
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

h = list(map(int, input().split()))

count = 0

for i in range(n - 1):
    if h[i+1] > h[i]:
        h[i+1] -= 1
    if (h[i+1] - h[i]) < 0:
        count += 1

if count == 0:
    print('Yes')
else:
    print('No')

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

int main(){
	int a, b;
	int d, r;
	double f;

	cin >> a >> b;
	d = a / b;
	if (a >= b){
		r = a - (b * d);
	}
	else{
		r = a;
	}
	f = (double)a / b;

	cout << d << " " << r << " " << fixed << f << endl;

	return 0; 
}

Measured memory_bytes: 1244
from collections import defaultdict
import sys

input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(input())

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
  prev_i = 1
  W = B
  for i in range(1, N+1):
    if i in g:
      W = (W * pow(B, i-prev_i, M)) % M
      sum_g[g[i]] = (sum_g[g[i]] + W) % M
      sum_g[0]  = (sum_g[0] - W) % M
      prev_i, W = i, W
  
  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret

edge = [read_edge() for i in range(3)]

print(solve(N, edge))

Measured memory_bytes: 63360
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline bool read(ll &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&c^-1;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5;
char c[yuzu|10];

int main(){
scanf("%s",c+1);
int i,n=strlen(c+1);
puts(c[1]!=c[n]^(n&1)?"Second":"First");
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdio>


using namespace std;

int N, M;
int p[200010], q[200010];

int main() {

    cin >> N;
    for (int i = 0; i < N; i++) {
        scanf("%d", &p[i]);
    }
    sort(p, p+N);
    
    cin >> M;
    for (int i = 0; i < M; i++) {
        scanf("%d", &q[i]);
    }
    sort(q, q+M);

    int cur = 0;
    for (int i = 0; i < N; i++) {
        if (q[cur] == p[i]) cur++;
        if (cur >= M) break;
    }

    if (cur == M) cout << "YES\n";
    else cout << "NO\n";
}


Measured memory_bytes: 1792
import math
import sys
from collections import *
from itertools import *

N = int(input())

OVERFLOW = 10 ** 18

seq = list(map(int, input().split()))
seq.sort()
if seq[0] == 0:
    print(0)
    sys.exit(0)

result = 1
for n in reversed(seq):
    result *= n
    if result > OVERFLOW:
        print(-1)
        sys.exit(0)
print(result)

Measured memory_bytes: 22372
#include<bits/stdc++.h>
#define fo(i, n) for(int i = 1; i <= (n); i ++)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar();bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}

int n, ans = 0;
main(void) {
  read(n);
  for(int i = 1; i <= n; i ++) {
    ans += i;
    if(ans >= n) {cout << i << "\n"; break;}
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main(){
    ll N,Q;
    cin >> N >> Q;
    vector<ll> c(N), l(Q), r(Q), pi(N+1,-1);
    rep(i,N){
        cin >> c[i];
    }
    vector<vector<Pll>> qs(N);
    rep(i,Q){
        cin >> l[i] >> r[i];
        l[i]--;r[i]--;
        qs[l[i]].push_back(Pll(r[i],i));
    }
    vector<vector<ll>> ps(N);
    rep(i,N){
        ll t = pi[c[i]];
        if(t != -1) ps[t].push_back(i);
        pi[c[i]] = i;
    }
    BIT<ll> d(N);
    vector<ll> ans(Q);
    for(ll i = N-1;i>=0;i--){
        for(auto&y:ps[i]) d.add(y,1);
        for(auto&p:qs[i]){
            ans[p.se] = p.fi - i + 1 - d.sum(p.fi);
        }
    }
    rep(i,Q){
        cout << ans[i] << endl;
    }
}

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

using namespace std;
const int MAX = 31;
int main() {
    int n, m;
    cin >> n >> m;
    int liked[MAX];
    for(int i=0; i< MAX;i++) {
        liked[i] = 0;
    }
    for (int i =0; i< n;i++) {
        int k;
        cin >> k;
        for(int j=0; j< k;j++) {
            int a;
            cin >> a;
            liked[a]++;
        }
    }
    int cnt = 0;
    for(int i=0;i<MAX;i++) {
        if (liked[i] == n) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  ll x;
  cin >> x;
  ll tmp = 100;
  int cnt = 0;
  while(true){
  	tmp += tmp / 100;
  	++cnt;
  	if(tmp >= x)break;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3620
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << '\n';
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll d = 0;
  while(a >= b){
    b *= 2;
    d++;
  }
  while(b >= c){
    c *= 2;
    d++;
  }
  Pr(d <= k);
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 1e5+10, mod = 1e9+7;
vector<int>a(maxn);
string s;
int n;



int32_t main(){
	IOS
	cin >> s;
	n = s.length();
	s = '$' + s;
	
	a[0]=1;
	for(int i=1;i<maxn;i++){
		a[i]=a[i-1]*3%mod;
	}
	
	int l = 0 , r = 0 , A = 0 , C = 0;
	for(int i=1;i<=n;i++){
		r += s[i]=='?';
		C += s[i]=='C';
	}
	int ans = 0;
	for(int i=1;i<=n;i++){
		r -= s[i]=='?';
		C -= s[i]=='C';
		
		if( s[i] == 'B' || s[i] == '?' ){
			ans += ( l * a[l-1] % mod + A*a[l] % mod ) * ( r * a[r-1] % mod + C*a[r] % mod ) % mod;
			ans %= mod;
		}
		
		l += s[i]=='?';
		A += s[i]=='A';
	}
	
	cout << ans ;
	
	
	
	
}
 
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




int main()
{
    string S,T;
    cin >> S >> T;

    string ans = "Yes";
    rep(i,S.size()){
        if(S[i] != T[i]){
            ans = "No";
            break;
        }
    }


    cout << ans << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 3600
a = input()
a = int(a)
b = input()
b= b.rstrip().split(" ")

bi =[]
for i in range(len(b)):
    bi.append(int(b[i]))
    i+=1
    
#print(bi)
bs =sorted(bi)
#print(bs)
for j in range(int(a)):
    if bi[j]>=bs[int(len(bs)/2)]:
        print(bs[int(len(bs)/2-1)])
        j+=1
    else:
        print(bs[int(len(bs)/2)])
        j+=1

Measured memory_bytes: 30036
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Coastline
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int T, D, L;
			StringTokenizer st = new StringTokenizer(line);
			T = parseInt(st.nextToken());
			D = parseInt(st.nextToken());
			L = parseInt(st.nextToken());
			if ((T | D | L) == 0) break;

			int[] elapsed = new int[T + D + 1];

			for (int i = 1; i <= T; i++) {
				int x = parseInt(br.readLine());
				if (x >= L) {
					elapsed[i]++;
					elapsed[i + D]--;
				}
			}

			int ans = 0;

			for (int i = 1; i < T; i++) {
				elapsed[i] += elapsed[i - 1];
				if (elapsed[i] > 0) ans++;
			}

			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 64488
from sys import setrecursionlimit
from bisect import bisect_left

setrecursionlimit(10 ** 6)
INF = float("inf")

N, *I = map(int, open(0).read().split())
A, UV = I[:N], I[N:]

E = [[] for _ in range(N + 1)]
for u, v in zip(*[iter(UV)] * 2):
    E[u - 1].append(v - 1)
    E[v - 1].append(u - 1)

dp = [INF] * N
ans = [0] * N
def dfs(cur, visited):
    idx = bisect_left(dp, A[cur])
    pre = dp[idx]
    dp[idx] = A[cur]
    ans[cur] = bisect_left(dp, INF)
    for c in E[cur]:
        if c != visited:
            dfs(c, cur)
    dp[idx] = pre

dfs(0, -1)
for a in ans:
    print(a)

Measured memory_bytes: 244408
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;
const ll INF = 2e+18;

ll calc(ll v) {
    ll k[] = { 1, 2, 4, 7, 8, 11, 13, 14 };
    ll ans = 32 * v;
    if (ans < 0) return INF;
    loop (18, i) {
        ll base = pow(10, i);
        ll n = (base - 1) / 15;
        if (n >= v) break;
        ll m = 0;
        while (15 * n + k[m] < base) m++;
        ll nbase = base * 10;
        ll nn = min((nbase - 1) / 15, v - 1);
        if (i == 17) nn = v - 1;
        ll nm = 0;
        while (nm < 8 && 15 * nn + k[nm] < nbase) nm++;
        ll cnt = 0;
        if (n != nn) cnt = (nn - n - 1) * 8 + (8 - m) + nm;
        else cnt = nm - m;
        ans += cnt * (i + 1);
        if (ans < 0) return INF;
    }
    return ans;
}

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

    ll l = 0, r = (2e+18)/15;
    while (l + 1 < r) {
        ll m = (l + r) / 2;
        if (s <= calc(m)) r = m;
        else l = m;
    }
    string ans;
    for (int i = 1; i <= 30; i++) {
        if (i % 3 == 0) ans.append("Fizz");
        if (i % 5 == 0) ans.append("Buzz");
        if (i % 3 && i % 5) ans.append(to_string(i + 15 * l));
    }
    cout << ans.substr(s - calc(l) - 1, 20) << endl;
    return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  string s; cin >> s;
  if(s=="Sunny") cout << "Cloudy" << endl;
  else if(s=="Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) ;
#define MOD 1000000007
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define ff first
#define ss second
#define INF (1LL<<61)

using namespace std;

int r , c;
string grid[1010];
int dp[1010][1010];

int solve(int i , int j) {
	if (i > r || j > c)return 0;
	if (i == r && j == c)return 1;
	if (grid[i][j] == '#')return 0;

	if (dp[i][j] != -1) return dp[i][j];

	return dp[i][j] = (solve(i + 1 , j) + solve(i , j + 1)) % MOD;
}

int32_t main() {

	fastio
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt","w", stdout);
// #endif

	cin >> r >> c;
	for (int i = 1 ; i <= r; i++) {
		string s ; cin >> s;
		grid[i] = '?' + s;
	}
	memset(dp , -1, sizeof(dp));
	cout << solve(1, 1) << '\n';



	return 0;
}


Measured memory_bytes: 12748
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N, X, M = in_nn()

    num_set = set()
    num_set.add(X)

    nums = [0] * (10**6)
    nums[0] = X

    now = X
    roop = -1
    for i in range(1, N):
        now = (now**2) % M
        if now in num_set:
            start = nums.index(now)
            pre_sum = sum(nums[:start])
            roop = i - start
            roop_sum = sum(nums[start:])
            break
        else:
            nums[i] = now
            num_set.add(now)
    else:
        print(sum(nums))
        exit()

    ans = pre_sum
    N -= start
    ans += roop_sum * (N // roop)

    N -= roop * (N // roop)
    ans += sum(nums[start:start + N])

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 88584
#!/usr/bin/env python3
#
# Author: Tetsuya Ishikawa <tiskw111@gmail.com>
# Date  : June 30, 2020
##################################################### SOURCE START #####################################################

N = int(input().strip())
ds = [int(input().strip()) for _ in range(N)]

ds = sorted(ds, reverse=True)
es = [ds.pop(0)]

for d in ds:
    if d < es[-1]: es.append(d)

print(len(es))

##################################################### SOURCE FINISH ####################################################
# vim: expandtab tabstop=4 shiftwidth=4 fdm=marker


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

int main(){
    int n;
    cin >> n;
    int A[n], ma = -1e9;
    for(int i = 0; i < n; i++){
        cin >> A[i];
        ma = max(ma, A[i]);
    }
    int tmp = 0;
    for(int i = 0; i < n; i++){
        if(abs(ma / 2 - tmp) > abs(ma / 2 - A[i])){
            tmp = A[i];
        }
    }
    cout << ma << " " << tmp << endl;

    return 0;
}

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

int N;
int A, B, C;
int l[8];

int dfs(int k, int a, int b, int c) {
    if (k == N) {
        if (a == 0 || b == 0 || c == 0)
            return 1000000000;
        return abs(a - A) + abs(b - B) + abs(c - C);
    }
    int ans = 1000000000;
    ans = min(ans, dfs(k + 1, a + l[k], b, c) + (a > 0 ? 10 : 0));
    ans = min(ans, dfs(k + 1, a, b + l[k], c) + (b > 0 ? 10 : 0));
    ans = min(ans, dfs(k + 1, a, b, c + l[k]) + (c > 0 ? 10 : 0));
    ans = min(ans, dfs(k + 1, a, b, c));
    return ans;
}

int main() {
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++) {
        cin >> l[i];
    }
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>

using namespace std;

int main() {

	int N, K;
	cin >> N;

	vector<int> vNum(N, 0);
	for (int i = 0; i < vNum.size(); i++)
	{
		cin >> vNum[i];
	}

	int halfNum = N / 2;
	sort(vNum.begin(), vNum.end());

	int first = vNum[halfNum - 1];
	int second = vNum[halfNum];

	cout << abs(first-second) << endl;

	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pi;

#define maxn 1000005

int main()
{
    i64 n , m , d ;

    scanf("%lld %lld %lld",&n,&m,&d) ;

    double ans = (m-1.0) ;

    if(d!=0) ans *= ( (2.00*(n-d+0.0))/(n*n+0.0) ) ;
    else ans *= (1.0/n) ;

    printf("%0.10f\n",ans) ;

    return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
typedef long long LL;

int main() {
    string s;
    cin >> s;
    int ans = 753;
    for(int i=0; i<s.length()-2; i++) {
        int tmp = stoi(s.substr(i, 3));
        ans = min(ans, abs(tmp - 753));
    } 
    cout << ans << endl;
}


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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int ans=0;


int main() {
    int h,w;
    cin>>h>>w;

    vector<string> matrix;
    for(int i=0;i<h;i++) {
        string s;
        cin>>s;
        matrix.push_back(s);
    }

    int ans=0;
    queue<pair<int, pair<int,int>>> q;

    for(int i=0;i<h;i++) {
        for(int j=0;j<w;j++) {
            vector<vector<bool>> path(h, vector<bool>(w,false));

            if(matrix[i][j]=='.') {
                q.push({i,{j,0}});
            }

            while(!q.empty()) {
                int x=q.front().first;
                int y=q.front().second.first;
                int l=q.front().second.second;

                q.pop();

                if(path[x][y]==true) continue;
                else path[x][y]=true;

                if(x>0&&matrix[x-1][y]=='.') q.push({x-1, {y, l+1}});
                if(x<h-1&&matrix[x+1][y]=='.') q.push({x+1, {y, l+1}});
                if(y>0&&matrix[x][y-1]=='.') q.push({x, {y-1, l+1}});
                if(y<w-1&&matrix[x][y+1]=='.') q.push({x, {y+1, l+1}});

                ans=max(ans, l); 
           }


        }
    }
    cout<<ans<<endl;

}




Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long h = scanner.nextLong();
		long w = scanner.nextLong();
		long h_odd = (h + 1) / 2;
		long h_even = h / 2;
		long w_odd = (w + 1) / 2;
		long w_even = w / 2;
		
		if(h==1||w==1) {
			System.out.println(1);
			return;
		}
		
		System.out.println(h_odd * w_odd + h_even * w_even);

	}

}


Measured memory_bytes: 21972
import copy
N=int(input())
SP=list(list(input().split()) for _  in range(N))
SSP=copy.deepcopy(SP)
SP.sort(key=lambda x:int(x[1]),reverse=True)
SP.sort(key=lambda x:x[0])

for i in SP:
    print(SSP.index(i)+1)

Measured memory_bytes: 3444
#include<string>
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
    string n;
    while(cin>>n)
    {
        if(n[n.length()-1] == 's')
        {
            n+="es";
        }
        else
        {
            n+='s';
        }
        
        cout<<n<<endl;
        
    }
}


Measured memory_bytes: 3632
import sys

H,W,K=map(int,input().split())
if W==1:
    print(1)
    sys.exit()
elif W==2:
    print(2**(H-1))
    sys.exit()

dic=[1,2,3,5,8,13,21,34,55,1]

a=[[0]*W for i in range(H+1)]
a[0][0]=1

for i in range(1,H+1):
    a[i][0] = a[i-1][0]*dic[W-2] + a[i-1][1]*dic[W-3]
    for j in range(1,W-1):
        a[i][j]=a[i-1][j-1]*dic[j-2]*dic[W-j-2] + a[i-1][j]*dic[j-1]*dic[W-j-2] + a[i-1][j+1]*dic[j-1]*dic[W-j-3]
    a[i][W-1] = a[i-1][W-1]*dic[W-2] + a[i-1][W-2]*dic[W-3]


print(a[H][K-1]%1000000007)

Measured memory_bytes: 3064