akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,q;
  while(cin >> n >> q && n+q){
    string s;
    ll a,b;
    vector<pll> x(n);
    vector<pair<ll,string>> v(n);
    rep(i,n){
      cin >> s >> a >> b;
      v[i] = mp(a,s);
      x[i] = mp(b,i);
    }
    ll k;
    sort(all(x));
    rep(i,q){
      cin >> k;
      auto it = lower_bound(all(x),mp(k,-inf));
      auto dis = it->se;
      if(dis < n && v[dis].fi + k - it->fi > 0){
        cout << v[dis].se + " " <<v[dis].fi + ( k - it->fi) << endl;
      }
      else{
        cout << "Unknown" << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3112
def main():
    N, H = map(int, input().split())

    A = [0] * N
    B = [0] * N

    num_list = []
    for i in range(N):
        a, b = map(int, input().split())
        A[i] = a
        B[i] = b

    sort_B = sorted(B, reverse=True)
    max_A = max(A)
    ans = 0
    for b in sort_B:
        if b > max_A:
            ans += 1
            H -= b
        else:
            break
        
        if H <= 0:
            break
    
    if H > 0:
        ans += -(-H // max_A)

    print(ans)

main()

Measured memory_bytes: 47960
n = int(input())
a = list(map(int, input().split()))

ans = 0
#even = []
for i in range(60):
	cnt = 0
	for x in a:
		if (x>>i) & 1:
			cnt += 1
	if cnt%2 == 1:
		ans += (1<<i)
		for j in range(n):
			if (a[j]>>i) & 1:
				a[j] -= (1<<i)
#print(ans, even)

yet = 0
for r in range(59, -1, -1):
	stood = False
	for c in range(yet, n):
		if (a[c]>>r) & 1:
			if not stood:
				stood = True
				a[yet], a[c] = a[c], a[yet]
				yet += 1
	if stood:
		for c in range(n):
			if c == yet-1 or (a[c]>>r) & 1 == 0:
				continue
			#print(c)
			a[c] ^= a[yet-1]

tmp = 0
res = 0
for c in range(n):
	tmp ^= a[c]
	res = max(res, tmp) 

print(ans + (res<<1))

Measured memory_bytes: 79008
s = int(input())

x1 = 0
y1 = 0
x2 = 10 ** 9
y2 = 1

if s < 10 ** 9:
    y3 = 0
    x3 = s
else:
    mod = s % 10 ** 9
    if mod == 0:
        y3 = s // 10 ** 9
        x3 = 0
    else:
        y3 = s // 10 ** 9 + 1
        x3 = 10 ** 9 - mod

print(x1, y1, x2, y2, x3, y3)


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }

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

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll res1 = b - ((b / c) + (b / d) - (b / lcm(c, d)));
  ll res2 = (a - 1) - (((a - 1) / c) + ((a - 1) / d) - ((a - 1) / lcm(c, d)));
  cout << res1 - res2 << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N, X;
int L[100];

signed main()
{
	cin >> N >> X;
	REP(i, N) cin >> L[i];

	int ans = 0;
	int a = 0;
	ans++;
	REP(i, N)
	{
		a += L[i];
		if (a > X) break;
		ans++;
	}

	cout << ans << endl;
}











Measured memory_bytes: 256
import java.util._
import java.lang._

object Main extends App {
  val sc = new Scanner(System.in)
  var n = sc.nextInt()
  var s = sc.next()
  var k = sc.nextInt()
  var change = s(k - 1)
  println(s.replaceAll("[^" + String.valueOf(change) + "]", "*"))
}


Measured memory_bytes: 25764
#include<iostream>
#include<cstdio>
#include<cmath>

double PI = 3.141592653589793238;

int main() {
	double x = 0.0, y = 0.0, dir = PI / 2;
	while (true) {
		int d, a;
		std::scanf("%d,%d", &d, &a);
		if (d == 0 && a == 0) break;
		x += std::cos(dir) * d;
		y += std::sin(dir) * d;
		dir -= a * PI / 180;
	}
	int ix = x, iy = y;
	std::cout << ix << std::endl << iy << std::endl;
	return 0;
}

Measured memory_bytes: 3436
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <bitset>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

string s;
int x;
int y;

bitset<16010> bit[2];


int main(){
	cin >> s >> x >> y;
	x += 8000;
	y += 8000;
	vector<int> vec;
	vec.push_back(0);
	for(char c : s){
		if(c == 'T'){
			vec.push_back(0);
		}
		else{
			vec.back()++;
		}
	}
	bit[0][8000] = 1;
	bit[1][8000] = 1;
	for(int i = 0;i < vec.size();i++){
		if(i == 0){
			bit[i % 2] = (bit[i % 2] << vec[i]);
		}
		else{
			bit[i % 2] = (bit[i % 2] << vec[i]) | (bit[i % 2] >> vec[i]);
		}
	}

	if(bit[0][x] && bit[1][y]){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 384
#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>;
const int INF = 1e9;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> maze(H, vector<char>(W));

  rep(i, H) {
    rep(j, W) {
      cin >> maze.at(i).at(j);
    }
  }

  int ans = 0;
  auto bfs = [&](int sx, int sy) {
    if (maze.at(sx).at(sy) == '#') return;
    vector<vector<int>> d(H, vector<int>(W, -1));
    d.at(sx).at(sy) = 0;
    queue<P> q;
    q.push(P(sx, sy));
    vector<int> dx = {1, -1, 0, 0};
    vector<int> dy = {0, 0, 1, -1};
    while (!q.empty()) {
      int x = q.front().first;
      int y = q.front().second;
      q.pop();
      rep(i, 4) {
        int nx = x + dx.at(i);
        int ny = y + dy.at(i);
        if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
        if (maze.at(nx).at(ny) == '#' || d.at(nx).at(ny) != -1) continue;
        d.at(nx).at(ny) = d.at(x).at(y) + 1;
        ans = max(ans, d.at(nx).at(ny));
        q.emplace(nx, ny);
      }
    }
  };

  rep(i, H) {
    rep(j, W) {
      bfs(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N;
int A[200010];

signed main(){
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    sort(A, A+N);

    rep(i, 0, N-1) if(A[i] == A[i+1]){ NO; return 0; }
    YES;

    return 0;
}

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

using namespace std;
typedef unsigned long long ull;

int main(){
  int n;
  cin >> n;
  if(n%2==1){
    puts("No");
    return 0;
  }
  string s;
  cin >> s;
  rep(i,n/2){
    if(s[i]!=s[i+n/2]){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
llong N, A, B;
int main() {
	cin >> N >> A >> B;
	llong ANS = 0;
	ANS += (N / (A + B)) * A;
	ANS += min(N % (A + B), A);
	cout << ANS;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>

using namespace std;

#define sz			size()
#define lgt			length()
#define rep(i,n)	for (int i = 0; i < (int)(n); i++)
#define ALL(X)		(X).begin(),(X).end()
#define RALL(X)		(X).rbegin(),(X).rend()
#define pb			push_back
#define SORT(a)		sort(ALL(a));
#define RSORT(a)	sort(RALL(a));
#define mp			make_pair
#define dump(x)		cerr<<#x<<" = "<<(x)<<endl;
#define fir			first
#define sec			second

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<string> vs;

int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
vs form(string a,char s){vs v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(b);b="";}else b+=a[i];}v.pb(b);return v;}
vi formint(string a,char s){vi v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(toInt(b));b="";}else b+=a[i];}v.pb(toInt(b));return v;}

const double EPS=1e-10,PI=acos(-1.0);
const int INF=2100000000;

int main(void)
{
	int n, k, tmp;
	while (cin >> n >> k, n && k){
		vi v;
		for (int i = 0; i < k; i++){
			scanf("%d", &tmp);
			v.pb(tmp);
		}
		SORT(v);
		int res = 0;
		if (v[0] != 0){
			int a = 1;
			for (int i = 0; i < n; i++){
				if (v[i] + 1 == v[i + 1] && (i + 1) < n){
					a++;
				}
				else {
					res = max(res, a);
					a = 1;
				}
			}
		}
		else {
			vector <P> m;
			int a = 1;
			for (int i = 0; i < n; i++){
				if (v[i] + 1 == v[i + 1]){
					a++;
				}
				else {
					m.pb(mp(a, i));
					a = 1;
				}
			}
			res = m[0].fir;
			for (int i = 0; i < m.sz; i++){
//				cout << "*" << i << " -> " << m[i].fir << endl;
//				cout << "**" << v[m[i].sec] << " " << v[m[i].sec + 1] << endl;
				if (v[m[i].sec] + 2 == v[m[i].sec + 1] && i + 1 < m.sz){
					res = max(res, (m[i].fir + m[i + 1].fir) + 1);
				}
			}
		}
		
		cout << res << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

#include <iostream>

int main()
{
    int a;
    string s;

    cin >> a;
    cin >> s;

    if (a >= 3200) { cout << s << endl; }
    else { cout << "red" << endl; }

}


Measured memory_bytes: 256
// in the name if Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll INF = 1<<30 ;
const ll N= 1e6 ;
#define f first
#define s second
ll n , a[N] , ans = 0;
vector<char> v ;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n ;
for(int i = 0 ; i < n ; i ++)cin >> a[i] ;
if(n&1)return cout << 0 , 0 ;
sort(a,a+n) ;
cout << a[(n/2)] - a[(n/2) - 1] ;
    return 0;
}
 /*
              _     _   __
        /_\  (_    (_)  __)
       /   \  _) . (_) (__
 */


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
using namespace std;
int main(){
    int N; cin >> N;
    int d[2*N];
    for (int i=0;i<2*N;i++){
        cin >> d[i];
    }
    sort(d,d+2*N);
    int ans=0;
    for (int i=0;i<2*N;i+=2){
        ans += d[i];
    }
    cout << ans << endl;
}
    


Measured memory_bytes: 256
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil, floor, sqrt, gcd
from copy import deepcopy

def main():
    s = input()
    c_zero = s.count("0")
    c_one = s.count("1")
    num = min(c_one,c_zero)
    print(num*2)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9592
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;
const int maxn=100005;
char s[maxn];
int main(){
	int k;
	scanf("%s%d",s,&k);
	int len=strlen(s);
	for(int i=0;i<len;i++){
		if(s[i]=='a') continue;
		int b='z'-s[i]+1;
		if(k>=b){
			s[i]='a';
			k-=b;
		}	
	}
	if(k){
		s[len-1]='a'+(s[len-1]-'a'+k)%26;
	}
	printf("%s\n",s);
	return 0;
}

Measured memory_bytes: 512
#define NAME "a"

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cctype>
#include <cassert>
#include <memory>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <iterator>

#define pb push_back
#define mp make_pair
#define frs first
#define snd second

using namespace std;

#ifdef WIN32
    #define lld "%I64d"
#else
    #define lld "%lld"
#endif

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 7;
const ll INFLONG = (ll) 1e18 + 7;
const double EPS = 1e-9;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<string> vs;

typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;

template <typename T>
T sqr(T a) {
    return a * a;
}

int main() {
    srand(time(0));

//    freopen(NAME".in", "r", stdin);
//    freopen(NAME".out", "w", stdout);

    int n;
    scanf("%d", &n);
    printf("%.9lf\n", 2 * 3.14159265 * n);

//    printf("%.3lf\n", (double) clock() / CLOCKS_PER_SEC);
    return 0;
}


Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    int n;
    cin>>n;
    vi t(n),v(n);
    rep(i,n)cin>>t[i],t[i]*=2;
    rep(i,n)cin>>v[i];
    rep(i,n-1)t[i+1]+=t[i];

    int max_t=t[n-1];
    vector<double> v1(max_t+1,0.0),v2(max_t+1,0.0);
    int cnt=0;
    rep(i,max_t){
        if(i==t[cnt])cnt++;
        v1[i+1]=min((double)v[cnt],v1[i]+0.5);
    }
    for(;i>0;i--){
      if(i==t[cnt-1])cnt--;
      v2[i-1]=min((double)v[cnt],v2[i]+0.5);
    }

    double ans=0;
    rep(i,max_t+1)ans+=min(v1[i],v2[i]);
    cout<<shosu(5)<<ans/2<<endl;
}


Measured memory_bytes: 896
A=[list(map(int, input().split())) for _ in range(3)]
N=int(input())
B=[0]*N
for _ in range(N):
    B[_]=int(input())

G=[['.']*3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        if A[i][j] in B:
            G[i][j]='#'
# print(G)

if any(all(G[i][j]=='#' for i in range(3)) for j in range(3)) or \
   any(all(G[i][j]=='#' for j in range(3)) for i in range(3)) or \
   all(G[i][2-i]=='#' for i in range(3)) or \
   all(G[i][i]=='#' for i in range(3)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62128
#include<stdio.h>
#include<math.h> 
int main()
{
	
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int max1=fabs(a-b);
	int max2=fabs(b-c);
	int max3=fabs(c-a);
	int sum=max1+max2+max3;
	int max;
	if(max1<max2){
		max1=max2; 
	} 
	if(max1<max3){
		max1=max3; 
	} 
	if(max2<max3){
		max2=max3; 
	} 
	printf("%d",sum-max1); 
} 

Measured memory_bytes: 128
import sys
from itertools import accumulate

input = sys.stdin.readline


def dfs(H, W, D, A, Q, LR):
    position = [(-1, -1)] * (H * W + 1)
    for h in range(H):
        for w in range(W):
            position[A[h][w]] = (h, w)

    mp = [0] * (H * W + 1)

    for i in range(1, H * W + 1 - D):
        h, w = position[i]
        y, x = position[i + D]
        mp[i + D] = abs(x - w) + abs(y - h)

    for d in range(1, D + 1):
        mp[d::D] = list(accumulate(mp[d::D]))

    ans = [mp[r] - mp[l] for l, r in LR]
    return ans


def main():
    H, W, D = map(int, input().split())
    A = [None] * H
    for i in range(H):
        A[i] = tuple(map(int, input().split()))
    Q = int(input())
    LR = [None] * Q
    for i in range(Q):
        LR[i] = tuple(map(int, input().split()))

    ans = [0] * Q
    ans = dfs(H, W, D, A, Q, LR)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 41132
long A,B=1,C=6,D=19,E=65,F,M=998244353,m;b,c,N,s[4];
main(f){
	for(m=M-3;read(0,&c,1),c-10;s[c-97]++,f&=b!=c,b=c)
		m=!N|N%3?m:(m+m)%M,
		N++?F=(5*E-6*D+2*C-10*B+12*A)%M,A=B,B=C,C=D,D=E,E=F:0;
	printf("%d\n",!*s+!s[1]+!s[2]>1?:(A+(N%3|*s%3-s[2]%3?f:N>3?m+f:m)+M)%M);
}

Measured memory_bytes: 128
'use strict';
(function(stdin) {
  var inputs  = stdin.toString();
  var cols =inputs.split('/n')[0].split(' ').map(Number);
  var a = cols[0];
  var b =cols[1];
  if(a<b){
    console.log('a < b');
    }
   if(a>b){
     console.log ('a > b');
    }  
    if(a == b){
        console.log ('a == b')   
    }
  
 
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7376
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define _ << " " <<

typedef long long ll;
typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 1<<18;

int dist_down[MAX], dist_up[MAX];
vector <int> V[MAX];
vector <int> Ld[MAX], Rd[MAX];
int poz_par[MAX], par[MAX];
char s[MAX];

void dfs_down(int node, int pr)
{
  par[node] = pr;
  for (auto it = V[node].begin(); it != V[node].end(); it++)
    if (*it == pr) {
      V[node].erase(it);
      break;
    }

  Ld[node].push_back(0);  
  for (auto it : V[node]) {
    dfs_down(it, node);
    poz_par[it] = (int) Ld[node].size();
    Ld[node].push_back(max(Ld[node].back(), dist_down[it] + 1));
  }
  dist_down[node] = Ld[node].back();

  Rd[node].push_back(0);
  for (int i=(int) V[node].size()-1; i>=0; i--) {
    int it = V[node][i];
    Rd[node].push_back(max(Rd[node].back(), dist_down[it] + 1));
  }

  reverse(Rd[node].begin(), Rd[node].end());    
}

P presjek(P a, P b)
{
  return P(max(a.X, b.X), min(a.Y, b.Y));
}

P unija(P a, P b)
{
  if (a.X > a.Y) return b;
  if (b.X > b.Y) return a;
  P tmp = presjek(a, b);
  assert(tmp.X - 1 <= tmp.Y);
  return P(min(a.X, b.X), max(a.Y, b.Y));
}

P razlika(P a, P b)
{
  P tmp = presjek(a, b);
  if (tmp.X > tmp.Y) return a;
  assert(tmp.Y == a.Y || tmp.X == a.X);
  if (tmp.Y == a.Y) return P(a.X, tmp.X - 1);
  return P(tmp.Y + 1, a.Y);
}

P un[MAX];

ll rje = 0;
void dfs_up(int node, int pr)
{  
  if (pr != -1) {
    dist_up[node] = 1 + max(dist_up[pr],
			    max(Ld[pr][poz_par[node]-1], Rd[pr][poz_par[node]]));
  }    

  if (pr != -1) {
    if (dist_down[node] > dist_up[node] - 1) {
      P tmp = presjek(P(dist_up[node], MAX), P(un[pr].X-1, un[pr].Y-1));
      un[node] = unija(un[node], tmp);
    }
    else if (dist_down[node] < dist_up[node] - 1) {
      P tmp = presjek(P(dist_down[node] + 2, MAX), P(un[pr].X+1, un[pr].Y+1));
      un[node] = unija(un[node], tmp);
    }
  }

  P pres = P(0, max(dist_down[node], dist_up[node]) - 1);  
  pres = razlika(pres, un[node]);
  
  if (s[node] == '1') {
    un[node] = unija(un[node], pres);
    rje += max(0, pres.Y - pres.X + 1);  
  }

  for (auto it : V[node])
    dfs_up(it, node);

  if (pr != -1) {
    if (dist_down[node] > dist_up[node] - 1) {
      P tmp = presjek(P(dist_up[node], MAX), un[node]);
      un[pr] = unija(un[pr], P(tmp.X+1, tmp.Y+1));
    }
    else if (dist_down[node] < dist_up[node] - 1) {
      P tmp = presjek(P(dist_down[node] + 2, MAX), un[node]);
      un[pr] = unija(un[pr], P(tmp.X-1, tmp.Y-1));
    }
  }
}

int main()
{
  REP(i, MAX) un[i] = P(0, -1);
  
  int n;
  scanf("%d", &n);
  REP(i, n-1) {
    int a, b;
    scanf("%d%d", &a, &b); a--; b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }

  scanf(" %s", s);

  dfs_down(0, -1);
  dfs_up(0, -1);

  rje++;
  printf("%lld\n", rje);  
  
  return 0;
}


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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  map<ll, ll> mode;
  for (ll x : A) {
    if (!mode.count(x)) {
      mode[x] = 1;
    }
    else {
      mode[x] += 1;
    }
  }
  
  ll pat_all = 0;
  for (auto m : mode) {
    ll c = m.second;
    pat_all += c * (c-1) / 2;
  }

  for (ll k = 0; k < N; k++) {
    ll ex = mode[A[k]] - 1;
    cout << pat_all - ex << endl;
  }
}

Measured memory_bytes: 11008
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1000000007
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll a[4444];
ll cnt[2222];
ll memo[2222];
signed main() {
	ll n, k, ans = 0;
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			if (a[i] > a[j])memo[a[i]]++;
		}
	}
	rep(i, n) {
		rep(j, n) {
			if (a[i] > a[j])cnt[a[i]]++;
		}
	}
	rep(i, 2002) {
		ans += k * memo[i] % inf + k * (k - 1) / 2 % inf * cnt[i] % inf;
		ans %= inf;
	}
	cout << ans << endl;
	ggr
}


Measured memory_bytes: 256
void main() {
  problem();
}

void problem() {
  const N = scan!long;
  const An = scan!long(cast(int)(N-1));

  void solve() {
    long[long] members;

    foreach(i; 1..N+1) members[i] = 0;

    foreach(a; An) {
      members[a]++;
    }

    foreach(i; 1..N+1) writeln(members[i]);
  }

  solve();
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 24464
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,k;
  std::cin>>n>>k;

  ll INF=n*k+1;

  std::vector<ll> a(n);
  rep(i,0,n)std::cin>>a[i];

  std::vector<std::vector<ll>> dbl(n,std::vector<ll>(58,INF));

  std::map<ll,ll> min,min2;

  for(ll i=n-1;i>=0;i--){
    if(min[a[i]]!=0){
      dbl[i][0]=min[a[i]]+1-i;
    }
    min[a[i]]=i;
  }

  if(k!=1){
    rep(i,0,n){
      dbl[i][0]=std::min(dbl[i][0],min[a[i]]+n+1-i);
    }
  }

  rep(i,1,58){
    rep(j,0,n){
      dbl[j][i]=std::min(INF,dbl[j][i-1]+dbl[(j+dbl[j][i-1])%n][i-1]);
    }
  }

  ll now=0;
  for(ll i=57;i>=0;i--){
    if(now+dbl[now%n][i]<=n*k){
      now+=dbl[now%n][i];
    }
  }

  ll i=now;
  while(i<n*k){
    if(i+dbl[i%n][0]<=n*k){
      i+=dbl[i%n][0];
    }else{
      std::cout<<a[i%n]<<" ";
      i++;
    }
  }

  return 0;
}

Measured memory_bytes: 114048
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int INF = 1e15;

int gcd(int a, int b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a % b);
}

signed main(){
    int t;
    cin >> t;
    for(int i = 0; i < t; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        if(a < b) cout << "No" << endl;
        else if(b > d) cout << "No" << endl;
        else if(b <= c) cout << "Yes" << endl;
        else{
            int MAX = a % b + (b - a % b - 1) / gcd(b, d) * gcd(b, d);
            // int MAX = b - max(gcd(b, d), ((b - a % b) % gcd(b, d)));
            if(c + 1 <= MAX && MAX < b) cout << "No" << endl;
            else cout << "Yes" << endl;
        }
    }
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
     nmx  = input[0].split(" ");
     
   // console.log(nmx);
	tmp = input[1].split(" ");
   //  console.log(tmp);
	//文字列から10進数に変換するときはparseIntを使います
	var n = parseInt(nmx[0], 10);
    var m = parseInt(nmx[1], 10);
    var x = parseInt(nmx[2], 10);
   // console.log(n,m,x);
   var M = [];
    for (i=0;i<m-1;i++)
      {var r = parseInt(tmp[i], 10);
       M[i]=r;}
    //   console.log(M);
       
   var cnt = 0;
   for(i=0;i<=m;i++)
     {if(M[i]<x){cnt = cnt +1;}else{break;}
     }    
  //  console.log(cnt)
    var l = 0;
    var l = m-cnt;
 // console.log(l);
    if (cnt <l){console.log(cnt)}else{console.log(l);}

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
// Problem : D - Lunlun Number
// Contest : AtCoder Beginner Contest 161
// URL : https://atcoder.jp/contests/abc161/tasks/abc161_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>


using namespace std;

typedef long long ll;

int main(){
	
    priority_queue<ll,vector<ll>,greater<ll> >pq;

    for(ll i = 1; i <= 9; i++){    
    	pq.push(i);
    }
    ll n;
    
    cin >> n;
    
    if (n <= 10){
    	cout << n << endl;
    	return 0;
    }
    while(n > 1){
        ll x = pq.top();

        pq.pop();

        int last = x % 10;
        
        if (last - 1 >= 0){
        	pq.push(x * 10 + (last - 1));
        }
        
        pq.push(x * 10 + (last));
        
        if (last + 1 <= 9){
        	pq.push(x * 10 + (last + 1));
        }

        n--;
    }


    cout <<  pq.top() << endl;
	return 0;	
}


Measured memory_bytes: 2420
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int a, b, t;
    cin >> a >> b >> t;

    cout << t / a * b << endl;
    return 0;
}


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

def resolve():
    N = I()
    TA = [LI() for _ in range(N)]

    t, a = TA[0]
    for i in range(1, N):
        T, A = TA[i]
        # t/T>a/A
        if t * A > a * T:
            rate = (t - 1) // T + 1
            t = T * rate
            a = A * rate
        else:
            rate = (a - 1) // A + 1
            t = T * rate
            a = A * rate

    print(t + a)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10004
#include<stdio.h>
#define NOTFOUND -100

int n=0;
int binarySearch(int s[],int key){
	int left=0,right=n,mid=0;
	while(left < right){
		mid = (left + right)/2;
		if(s[mid] == key) return mid;
		else if(key < s[mid]) right = mid;
		else left = mid + 1;
	}
	return NOTFOUND;
}
int main(){
	int i,q,s[100000],t[50000],cnt=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",&t[i]);

	for(i=0;i<q;i++){
		if(binarySearch(s,t[i]) != NOTFOUND) cnt++;
	}
	printf("%d\n",cnt);

	return 0;
}


Measured memory_bytes: 2280
/*This Code Is Nude*/
#include <bits/stdc++.h>

#define pb push_back
#define ll long long
#define int long long
#define max(a,b) max((long long) a , (long long) b)
#define min(a,b) min((long long) a , (long long) b)

using namespace std;

const int inf = 1e12 + 10;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;

bool mark [maxn];
vector<int>adj[maxn];
int a[maxn];
int ans[maxn];
int psum [maxn];
int psumm[maxn];

int32_t main(){
    ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n , k;
    cin >> n >> k;
    psum[1] = 0;
    for(int i = 2 ; i <= n+1 ; i++)
        psum[i] = i-1 + psum[i-1];
    int ans = 0;
    for(int i = k ; i <= n+1 ; i++){
        ans = (ans + (psum[n+1] - psum [n + 1 - i]) - psum[i] + 1) % mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9864
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N; ll K;
    cin >> N >> K;
    int MAX = 3e5;
    int A[N];
    vector<int> ids[MAX];
    rep(i, N){
        cin >> A[i];
        ids[A[i]].pb(i);
    }
    int p[60][N]; ll c[60][N];
    rep(i, MAX){
        int n = sz(ids[i]);
        if(n == 0) continue;
        int next;
        rep(j, n){
            if(j != n-1) next = ids[i][j+1]+1;
            else next = N+ids[i][0]+1;
            p[0][ids[i][j]] = next%N;
            c[0][ids[i][j]] = next/N;
        }
    }
    rep(i, 59) rep(j, N){
        p[i+1][j] = p[i][p[i][j]];
        c[i+1][j] = c[i][j]+c[i][p[i][j]];
    }
    ll C = 0; int P = 0;
    rep3(i, 59, 0){
        if(C+c[i][P] < K){
            C += c[i][P];
            P = p[i][P];
        }
    }
    if(C != K-1) {cout << endl; return 0;}
    vector<int> ans;
    for(int i = P; i < N;){
        int j = c[0][i]*N+p[0][i];
        if(j <= N) i = j;
        else ans.pb(A[i]), i++;
    }
    for(auto &e: ans) cout << e << ' '; cout << endl;
}

Measured memory_bytes: 157048
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main(){
	int a, b, ans = 0;
	char op;

	while (1)
	{
		scanf("%d %c %d", &a, &op, &b);

		if (op == '+')
		{
			ans = a + b;
		}
		else if (op == '-')
		{
			ans = a - b;
		}
		else if (op == '*')
		{
			ans = a*b;
		}
		else if (op == '/')
		{
			ans = a / b;
		}
		else if (op == '?')
		{
			return 0;
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n), pairs(0);
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
        if (m[a[i]] % 2 == 0) pairs.push_back(a[i]);
    }
    sort(pairs.begin(), pairs.end(), greater<int>());
    long long ans;
    if (pairs.size() < 2) {
        ans = 0;
    } else {
        ans = (long long)(pairs[0]) * (long long)(pairs[1]);
    }
    cout << ans << endl;
}

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

int main() {
int N;
string S;
cin >> N >> S;

int count = 0;
for (int i = 0; i < N - 2; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B') {
        if (S.at(i + 2) == 'C') {
            count++;
        }
    }
}
cout << count << endl;
}

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

class Program
    {
        static void Main(string[] args)
        {
            double N = int.Parse(Console.ReadLine());
            string[] vals = Console.ReadLine().Split();

            List<int> nums = new List<int>();

            for (int i = 0; i < N; i++)
            {
                nums.Add(int.Parse(vals[i]));
            }

            nums.Sort();

            double ans = (nums[0] + nums[1]) / 2.0;

            nums.RemoveRange(0, 2);
            var len = nums.Count();

            //nums.RemoveRange();
           

            for (int i = 0; i < len; i++)
            {
                ans = (ans + nums[i]) / 2;
            }

            //double ans = (nums[0] + nums[1]) / Math.Pow(2.0 , N-1);

            //for (int i = 2; i < N; i++)
            //{
            //    ans += nums[i] / Math.Pow(2.0, N - i);
            //}

            Console.WriteLine(ans);

        }
    }

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    ll k;
    cin >> k;
    ll tmp = 7;
    ll ans = 1;
    while (tmp < k) {
        tmp *= 10;
        tmp += 7;
        ++ans;
    }
    unordered_set<ll> se;
    ll now = tmp % k;
    while (true) {
        if (now == 0) {
            cout << ans << endl;
            return;
        }
        se.insert(now);
        now = (10 * now + 7) % k;
        if (se.find(now) != se.end()) {
            cout << -1 << endl;
            return;
        }
        ++ans;
    }
}

int main() {
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}


Measured memory_bytes: 42628
import math

N = int(input())
xy = []
for i in range(N):
    x = list(map(int, input().split()))
    xy.append(x)

length = 0

for i in range(N):
    for j in range(N):
        lenlen = math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)
        length += lenlen

print(length/N)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 5;
 
int main()
{
  int k, n;
  cin >> k >> n;
  vector<int> list(n), dis(n);
  for (int i = 0; i < n; i++) {
    cin >> list[i];
  }
 
  for (int i = 0; i < n - 1; i++) {
    dis[i] = list[i + 1] - list[i];
  }
  dis[n - 1] = k - list[n - 1] + list[0];
  sort(dis.begin(), dis.end());
 
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans += dis[i];
  }
  cout << ans << endl;
  return 0;
 
}

Measured memory_bytes: 1792
A, B, C, D, E, F = map(int, input().split())
water = set([])

for i in range(1, F // (100 * A) + 1):
    water1 = i * 100 * A
    for j in range((F - water1) // (100 * B) + 1):
        water2 = j * 100 * B
        water.add(water1 + water2)

ans = [100 * A, 0]
c = 0

for i in water:
    max_sugar = min(i // 100 * E, F - i)
    sugar = [0]
    for j in range(max_sugar // C + 1):
        for k in range((max_sugar - j * C) // D + 1):
            sugar.append(j * C + k * D)
    max_sugar = max(sugar)
    concentration = max_sugar / (i + max_sugar)
    if c < concentration:
        c = concentration
        ans = [i + max_sugar, max_sugar]

print(' '.join(map(str, ans)))

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

int main() {
  int n,m;
  cin >> n;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> s.at(i);
  }
  cin >> m;
  vector<string> t(m);
  for(int i=0;i<m;i++){
    cin >> t.at(i);
  }
  vector<int> ans(n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(s.at(i) == s.at(j)){
        ans.at(i)++;
      }
    }
    for(int j=0;j<m;j++){
      if(s.at(i) == t.at(j)){
        ans.at(i)--;
      }
    }
  }
  sort(ans.begin(),ans.end());
  if(ans.at(n-1) >0){
    cout << ans.at(n-1) << endl;
  }
  else {
    cout << 0 << endl;
  }
   
  return 0;
}


Measured memory_bytes: 256
def solve():
    scr_ini = list(range(1,N+1))
#    print(scr_ini)
    cnt = [0] * N
    ans = [0] * N
    for i in range(N):
        j = 0
        while scr_ini[i]*2**j < K:
            cnt[i] = j
            j += 1
        if scr_ini[i]*2**j >= K:
            cnt[i] = j
            ans[i] = (1/N) * 0.5**j
#    print(cnt) 
#    print(ans)
    print(sum(ans))

if __name__ == "__main__":
    N,K = list(map(int, input().split()))
    solve()  


Measured memory_bytes: 17640
<?php

fscanf(STDIN, "%d %d", $n, $m);
const N_MAX = 100005;
$A = array_map('intval', explode(' ', trim(fgetS(STDIN))));

$map = array_fill(0, N_MAX, 0);
for ($i = 0; $i < $n; ++$i) {
    ++$map[$A[$i]];
}
for ($i = 0; $i < $m; ++$i) {
    fscanf(STDIN, "%d %d", $b, $c);
    $map[$c] += $b;
}

krsort($map);
$sum = 0;
$cnt = 0;
foreach ($map as $key => $val) {
    if ($n <= 0) break;
    if ($val == 0) continue;

    $tmp = min($val, $n);

    $sum += $tmp * $key;

    $cnt += $tmp;
    $n -= $val;
}

echo $sum;


Measured memory_bytes: 30196
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n=int(input())
from collections import Counter as co
ds=co(list(map(int,input().split() ))+[0]).most_common()
if ds[0][1]>=3:print(0)
else:
    nows=[]
    nexts=[]
    for k,v in ds:
        if v==1:nexts.append(k)
        else:
            nows.append(-k)
            nows.append(k)
    def f(k):
        res=24
        for i in range(len(k)-1):
            for j in range(i+1,len(k)):
                #x y  0 y-x 
                res=min(res,-abs(k[i]-k[j])%24 ,abs(k[i]-k[j])%24)
        return res
    from itertools import product as pr
    print(max(f(nows+[v*j  for v,j in zip(nexts,i)])for i in pr((1,-1),repeat=len(ds))))


Measured memory_bytes: 9420
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

import numpy as np  # 1.8.2

def main():
    N, D = i2nn()
    X = ii2nnn(N)
    n = 0
    for i in range(N):
        for j in range(i+1, N):
            a = np.array(X[i])
            b = np.array(X[j])
            c = a - b
            d = np.linalg.norm(c)
            if int(d) == float(d):
                n += 1
    print(n)

main()


Measured memory_bytes: 12344
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
ll fen[2*N];
void add(ll idx,ll val){
    for (idx;idx<2*N;idx+= idx & (-idx)) fen[idx]+=val;
}
ll get(ll idx){
    ll s=0;
    for (;idx;idx-= idx & (-idx)) s+=fen[idx];
    return s;
}
ll a[N];
int32_t main(){
    sync;
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    ll l=0,r=1e9+100;
    while(r-l>1){
        memset(fen,0,sizeof fen);
        ll mid=(r+l)/2;
        ll lazy=0;
        ll s=0;
        for (int i=n;i;i--){
            ll t=0;
            if (a[i]>=mid) t=1;
            else t=-1;
            lazy+=t;
            t=t-lazy;
            add(t+N,1);
            ll z=get(2*N-1)-get(-lazy+N-1);
            s+=z;
        }
        if (s*2>=(n+1)*n/2) l=mid;
        else r=mid;

    }
    cout << l << endl;
}


Measured memory_bytes: 7536
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>=b && a>=c)
    cout<<a*10+(b+c);
  else if(b>=a && b>=c)
    cout<<b*10+(a+c);
  else if(c>=a && c>=b)
    cout<<c*10+(a+b);
}

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


int main() {
	//freopen("in.txt", "r" , stdin);
	int n,w,h;
	while(cin >> n >> w >> h){
        cout << (n - w + 1) * (n - h + 1) << endl;
	}
	return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  string s;
  cin >> s;
  
  int sum = 0;
  
  rep(i, 0, s.size()){
    int n = s[i] - '0';
    sum += n;
  }
  
  if(sum%9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
  
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
	ll a1,m1,a2,m2,a3,m3;
	while(1){
		ll cnt[3]={1,1,1};
		cin>>a1>>m1>>a2>>m2>>a3>>m3;
		if(a1==0&&m1==0)break;
		ll b1=a1,b2=a2,b3=a3;
		while(b1!=1){
			cnt[0]++;
			b1=b1*a1%m1;
		}
//		cout<<cnt[0]<<endl;
		while(b2!=1){
			cnt[1]++;
			b2=b2*a2%m2;
		}
		while(b3!=1){
			cnt[2]++;
			b3=b3*a3%m3;
		}
		sort(cnt,cnt+3);
		cnt[1]=cnt[1]*cnt[2]/gcd(cnt[2],cnt[1]);
		cout<<cnt[0]*cnt[1]/gcd(cnt[1],cnt[0])<<endl;
	}
}

Measured memory_bytes: 1176
D,G = map(int, input().split())
points = [0 for _ in range(D)]
for i in range(D):
    points[i] = list(map(int, input().split()))

def solve(d,g):
    if d <= 0:
        return 10**5
    n = min(g//(100*d), points[d-1][0])
    s = 100 * d * n
    if n == points[d-1][0]:
        s = d * points[d-1][0] * 100 + points[d-1][1]
    
    if g > s:
        n += solve(d-1, g-s)
    
    return min(n, solve(d-1, g))
print(solve(D,G))

Measured memory_bytes: 3064