akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 220
// 44

using namespace std;

const int MAXN = 2000;

int arr[MAXN + 1], aux[MAXN + 1];
int ans;

inline bool check(int a, int b, int n, int k, int q) {
    int cnt = 0;
    int i = 1;
    vector <int> v;
    while(i <= n) {
        int j = i;
        vector <int> vals;
        while(j <= n && aux[a] <= arr[j] && arr[j] <= aux[b]) {
            vals.push_back(arr[j]);
            j++;
        }
        cnt += max(0, j - i - k + 1);
        if(vals.size()) {
            sort(vals.begin(), vals.end());
            for(int p = 0; p < max(0, j - i - k + 1); p++) {
                v.push_back(vals[p]);
            }
        }
        i = j + 1;
    }
    if(cnt < q)
        return 0;
    sort(v.begin(), v.end());
    ans = min(ans, v[q - 1] - v[0]);
    return 1;
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int n, k, q, i;
    ios::sync_with_stdio(false);
    cin >> n >> k >> q;
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
        aux[i] = arr[i];
    }
    sort(aux + 1, aux + n + 1);
    ans = 1e9;
    for(i = 1; i <= n; i++) {
        check(i, n, n, k, q);
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 384
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 0
sum_a = [0]
for i in range(n):
  if t + a[i] <= k:
    t += a[i]
    sum_a.append(t)
  else:
    break
sum_b = [0]
t = 0
for i in range(m):
  if t + b[i] <= k:
    t += b[i]
    sum_b.append(t)
  else:
    break
ans = []
j = 0
for i in range(len(sum_a)):
  while sum_a[i] + sum_b[len(sum_b) - j - 1] > k:
    j += 1
  ans.append(i + len(sum_b) - j - 1)
print(max(ans))

Measured memory_bytes: 48220
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){

    ll N;
    cin >> N;
    vector<string> S(N," ");
    ll S_alpha[N][26];
    memset(S_alpha,0,sizeof(S_alpha));

    for(int i = 0; i < N; i++){
        cin >> S[i];
        for(int j = 0; j < 26; j++){

            for(int k = 0; k < S[i].size(); k++){
                if(S[i][k] - 'a' == j){
                    S_alpha[i][j]++;
                }
            }

        }

    }

    ll ans_alpha[26];
    memset(ans_alpha,0,sizeof(ans_alpha));
    for(int i = 0; i < 26; i++){
        ll tmp = 100;
        for(int j = 0; j < N; j++){
            tmp = min(S_alpha[j][i], tmp);
        }
        ans_alpha[i] += tmp;
    }

    string ans = "";

    for(int i = 0; i < 26; i++){
        for(int j = 0; j < ans_alpha[i]; j++){
            ans += char('a' + i);
        }
    }

    cout << ans << endl;




}   


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e9 + 7)
using namespace std;

long long a, b, ans = 0, mod = 1e9 + 7;

int main()
{
    scanf("%lld%lld", &a, &b);
    if(a > b)
        swap(a, b);
    if(b - a > 1)
    {
        puts("0");
        return 0;
    }
    if(b != a)
    {
        ans = b;
        b--;
        while(a)
            ans = ans * b, ans %= mod, ans = ans * b, ans %= mod, b--, a--;
        if(ans < 0)
            ans += mod;
        printf("%lld\n", ans);
    }
    else
    {
        ans = 1;
        while(a)
            ans = ans * a, ans %= mod, ans = ans * a, ans %= mod, a--;
        ans *= 2;
        ans %= mod;
        if(ans < 0)
            ans += mod;
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int A,B,K,i,temp;
    
    scanf("%d %d %d",&A,&B,&K);
    
    for(i=0;i<K;i++){
        if(A%2==1){
        A=(A-1)/2;
        temp=A;
        B+=A;
        A=B;
        B=temp;
        }
        else{
        A=A/2;
        temp=A;
        B+=A;
        A=B;
        B=temp;
        }
    }
    
    if(K%2==1)
    printf("%d %d",B,A);
    else
    printf("%d %d",A,B);
    
    return(0);
}

Measured memory_bytes: 128
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(string[] g) {
    int rows = cast(int) g.length;
    int cols = cast(int) g[0].length;

    auto hash = (int row, int col) => row * cols + col;

    auto uf = new UnionFind(rows * cols);
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            if (i + 1 < rows && g[i][j] != g[i + 1][j])
                uf.unite(hash(i, j), hash(i+1, j));

            if (j + 1 < cols && g[i][j] != g[i][j + 1])
                uf.unite(hash(i, j), hash(i, j+1));
        }
    }

    long ans = 0;
    bool[int] used;
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            int root = uf.root(hash(i, j));
            if (root in used) continue;
            used[root] = true;

            long a = 0; // 黒の個数
            long b = 0; // 白の個数
            // root に属する全てのノード
            uf.doEach(root, (node) {
                int row = node / cols;
                int col = node % cols;
                if (g[row][col] == '#') a++; else b++;
            });
            ans += a * b;
        }
    }
    return ans;
}

void main() {
    auto hw = readints;
    int h = hw[0], w = hw[1];
    string[] g;
    for (int i = 0; i < h; i++) {
        g ~= read!string;
    }
    writeln(calc(g));
}

class UnionFind {
    private int[] _data;
    private int[] _nexts; // 次の要素。なければ -1
    private int[] _tails; // 末尾の要素

    this(int n) {
        _data  = new int[](n + 1);
        _nexts = new int[](n + 1);
        _tails = new int[](n + 1);

        _data[] = -1;
        _nexts[] = -1;
        for (int i = 0; i < _tails.length; i++)
            _tails[i] = i;
    }

    int root(int a) {
        if (_data[a] < 0) return a;
        return _data[a] = root(_data[a]);
    }

    bool unite(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra != rb) {
            if (_data[rb] < _data[ra]) swap(ra, rb);
            _data[ra] += _data[rb]; // ra に rb を繋げる
            _data[rb] = ra;
            // ra の末尾の後ろに rb を繋げる
            _nexts[_tails[ra]] = rb;
            // ra の末尾が rb の末尾になる
            _tails[ra] = _tails[rb];
        }
        return ra != rb;
    }

    bool isSame(int a, int b) {
        return root(a) == root(b);
    }

    /// a が属する集合のサイズ
    int groupSize(int a) {
        return -_data[root(a)];
    }

    /// a が属する集合の要素全て
    void doEach(int a, void delegate(int) fn) {
        auto node = root(a);
        while (node != -1) {
            fn(node);
            node = _nexts[node];
        }
    }
}


Measured memory_bytes: 19836
n,k = map(int,input().split())
mod = 10**9+7
arr = [0]*(k+1) ##arr[i]はgcdがiの個数
for i in range(k,0,-1):
    l = k//i
    arr[i] = pow(l,n,mod)
    for j in range(2,l+1):
        arr[i] -= arr[i*j]
        arr[i] %= mod
ans = 0
for i,a in enumerate(arr):
    ans+=i*a
    ans%=mod
print(ans) 


Measured memory_bytes: 11228
#include <stdio.h>
 
int main()
{
  int A, B;
  scanf("%d %d", &A, &B);
 
  int count = 0;
  int next = 1;
  while(next < B)
  {
    next += (A-1);
    count++;
  }
  
  printf("%d\n", count);
  return 0;  
}

Measured memory_bytes: 128
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
p = LI()
q = LI()

cnt = 0
for i in permutations(range(1,n+1)):
    if list(i) == p:
        x = cnt
    if list(i) == q:
        y = cnt
    cnt += 1
print(abs(x-y))

Measured memory_bytes: 42352
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

K = int(sys.stdin.buffer.readline())
S = sys.stdin.buffer.readline().decode().rstrip()
if len(S) <= K:
    print(S)
else:
    print(S[:K] + '...')


Measured memory_bytes: 27128
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int n, k;
	string str;
	cin >> n >> k >> str;
	str[k - 1] = tolower(str[k - 1]);
	cout << str << endl; 
}

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

int main() {
    int n; cin >> n;
    string a, b, c; cin >> a >> b >> c;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        vector<int> cnt(26, 0);
        cnt[a[i] - 'a']++;
        cnt[b[i] - 'a']++;
        cnt[c[i] - 'a']++;
        ans += 3 - *max_element(cnt.begin(), cnt.end());
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d %d", &a, &b)
#define sc3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define prie(x) printf("%d ", x)
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false);
#define db(x) cerr<< #x <<" == "<< x <<endl;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const ld pi = acos(-1);
const int MOD = 1e9+7;
int main()
{
	int n, a, b;
	sc3(n, a, b);
	int difi = b-a;
	if(difi%2==0) puts("Alice");
	else puts("Borys");

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<iterator>

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

using namespace std;

int main(){
	string s; int N; cin >> N >> s;
	vector<int> counts(30, 0);
	rep(i, s.size()){
		if(s[i] != '+'){
			counts[s[i]-'a']++;
		}
	}
	//sort(counts.begin(), counts.end());
	/*
	int res = 0; int now = -1; int now_no = 0;bool flag_2 = false; bool flag_4 = false;
	rep(i, 30){
		if(counts[i] == 0)
			continue;
		if(now == -1){
			now = counts[i];
			now_no++;
			continue;
		}
		if(counts[i] == now){
			now_no++;
			continue;
		}

		if(counts[i] != now_no){
			if(now_no == 1){
				if(now == 1)
					res += 2;
				else
					res += 4;
			}
			else{
				if(now == 1)
					res += 2* now_no;
				else{
					res += 4 + 2* now_no;
				}
			}

			now = counts[i];
			now_no = 1;
		}
	}

	if(now_no == 1){
				if(now == 1)
					res += 1;
				else
					res += 3;
			}
		else{
				if(now == 1)
					res += 2* now_no - 1;
				else if(now == 4){
				
				}
				else{
					res += 4 + 2* now_no - 1;
				}
			}
			
	cout << res << endl;
	*/
	vector<int> groups(10,0);
	rep(i, counts.size()){
		groups[counts[i]]++;
	}
	int res = 0;
	rep(i, 10){
		if(i == 0)
			continue;
		else if(i == 1)
			res += groups[1] * 2;
		else{
			if(groups[i] == 0)
				continue;
			else if(groups[i] == 1)
				res += 4;
			else{
				res += 2*groups[i] + 4;
			}
		}
	}
	cout << res-1<<endl;

}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define X real()
#define Y imag()
#define cp(a,b)	( (conj(a)*(b)).imag() )
#define length(a) (hypot((a).imag(), (a).real()))
typedef complex<double> point;
typedef long long ll;
typedef unsigned long long ull;
double PI = 3.141592653589793;
const double EPS = 1e-9;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

string s1, s2;

bool check(int l) {
	string s = "";
	for (int i = l; i < s1.size(); i++)
		s += s1[i];
	for (int i = 0; i < l; i++)
		s += s1[i];
	return s == s2;
}

int main() {
	cin >> s1 >> s2;
	loop(i, 0, s1.size() - 1) {
		if (check(i)) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

using namespace std;

int n;
long long int h;

vector<pair<long long int, long long int> > v;

int main() {
	cin >> n >> h;
if(h==0){
cout<<"0"<<endl;
return 0;
}
	int ans = LLONG_MIN;
	for (int i = 0; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		v.push_back(make_pair(b, a));
		ans = max(ans, a);
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	long long int cnt = LLONG_MAX;
	long long int sum = 0;
	for (int i = 0; i < v.size(); i++) {
		sum += v[i].first;
		long long int rest = h - sum;
		rest = max(rest, 0LL);
		cnt = min(cnt, i + 1 + (rest + ans - 1) / ans);
	}
	printf("%lld\n", cnt);
	return 0;
}

Measured memory_bytes: 2420
W=str.lower(input())
a=len(W)
if a<=10:
    sum=0

    while True:
        T=input()
        if T=="END_OF_TEXT":
            break
        if len(T)<=1000:
            T=str.lower(T)
            T=T.split()
            x=T.count(W)
            sum+=x
print(sum)


Measured memory_bytes: 5556
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int count = 0;
		
		while(sc.hasNext()){
			char[] ch = sc.next().toCharArray();
			
		for(int i = 0; i < ch.length; i++){
			
			if(Character.isDigit(ch[i])){
				int x = ch[i++]-'0';
				
				while(i<ch.length&&Character.isDigit(ch[i])){
					x*=10;
					x+=ch[i++]-'0';
			}
				count += x;
		}
		}
		}
		System.out.println(count);
		
		sc.close();
	}
}

Measured memory_bytes: 17160
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/operators.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#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 MOD 1000000007

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

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> v(n+1);
  rep(i, n+1) cin >> v[i];
  // dp[i] = 上から見た時のi番目の最大頂点数
  vector<ll> dp(n+10, -1);
  dp[0] = 1;

  // n == 0の時の処理
  if(n == 0 && v[0] > 1){
    cout << -1 << endl;
    return 0;
  }else if(n == 0 && v[0] == 1){
    cout << 1 << endl;
    return 0;
  }else if(n == 0){
    cout << -1 << endl;
    return 0;
  }

  ll res = 0;
  // 上から見るか
  for (int i = 0; i < n; ++i) {
    if(dp[i] - v[i] > LLONG_MAX / 2) dp[i+1] = LLONG_MAX;
    else dp[i+1] = (dp[i] - v[i]) * 2;
  }

  // ans[i] = 深さiの最大頂点数
  vector<ll> ans(n+1);
  // 下から見るか
  ans[n] = v[n];
  for (int i = n; i >= 1 ; --i) {
    // cout << dp[i-1] << ' ' << ans[i]+v[i-1] << endl;
    ans[i-1] = ans[i] + v[i-1];
  }
  rep(i, n+1) chmin(ans[i], dp[i]);
  // print(dp);
  // print(ans);

  // 構築できるかチェック
  bool flag = false;
  for(int i = 0; i < n; i++){
    res += ans[i];
    if(ans[i] <= v[i]) flag = true;
  }
  if(ans[n] != v[n]) flag = true;
  res += ans[n];
  // res += ans[n];
  // print(ans);

  if(flag) cout << -1 << endl;
  else cout << res << endl;
}


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

using namespace std ;

int n ;
const int N = 2e5 + 10 ;
struct Node {
  int v , nxt ;
} ;
Node e[N << 1] ;
int head[N] , cnt = 0 ;
void add(int u , int v) {
  e[++ cnt] = { v , head[u] } ;
  head[u] = cnt ;
}
int num = 0 ;
int cr[N] ;
void dfs(int u , int las , int fa) {
  int tot = 0 ;
  for(int i = head[u] ; i ; i = e[i].nxt) {
    int v = e[i].v ;
    if(v == fa) continue ;
    ++ tot ; if(tot == las) ++ tot ;
    cr[i] = tot ; num = max(num , tot) ;
    dfs(v , tot , u) ;
  }
}
signed main() {
  ios :: sync_with_stdio(false) ;
  cin.tie(nullptr);
  cout.tie(nullptr) ;
  cin >> n ;
  for(int i = 1 ; i < n ; i ++) {
    int u , v ;
    cin >> u >> v ;
    add(u , v) ;
    add(v , u) ;
  }
  dfs(1 , 0 , 0) ;
  cout << num << '\n' ;
  for(int i = 1 ; i < n ; i ++) {
    if(cr[(i - 1) << 1 | 1]) cout << cr[(i - 1) << 1 | 1] << '\n' ;
    else cout << cr[i << 1] << '\n' ;
  }
  return 0 ;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 1e9  //
#define INFLL 4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define PB(a) push_back(a)
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
    char a, b, c, d;
    cin >> a >> b >> c >> d;
    bool good = 0;
    if (a == b && b == c) {
        good = 1;
    } else if (b == c && c == d) {
        good = 1;
    }
    
    Yes(good);

    return 0;
}

Measured memory_bytes: 256
N=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
t=0
ans=[0]*N
while t<N:
    ans[t]=v[t]-c[t]
    t=t+1
kotae=0
s=0
while s<N:
    if ans[s]>=0:
        kotae=kotae+ans[s]
    s=s+1
print(kotae)


Measured memory_bytes: 3064
def get_alphabet(n)
  ("A".."Z").to_a[n] || n.to_s
end

h, w = gets.chomp.split.map(&:to_i)

for a in 1..h
  b = gets.chomp.split.map(&:to_s)
  if b.index("snuke") != nil
    puts "#{get_alphabet(b.index("snuke"))}#{a}"
    exit
  end
end


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

int main(){
    int N, K;
    cin >> N >> K;

    vector<int> l(N);
    for (int i = 0; i < N; i++) {
        cin >> l.at(i);
    }

    sort(l.begin(), l.end());

    int ans = 0;
    for (int i = 0; i < K; i++) {
        ans += l.at(N - 1 - i);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n, d = map(int, input().split())

points = []
for i in range(n):
  x, y = map(int, input().split())
  points.append([x, y])

d = d*d
def dist(x, y):
    return x*x + y*y

ans = sum([1 for p in points if dist(p[0], p[1]) <= d])
print(ans)

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

int main()
{
    ll n,d;
    cin >> n >> d;
    ll x[n][d];

    rep(i,n)rep(j,d)cin >> x[i][j];

    ll ans = 0;
    rep(i,n){
        REP(j,i,n){
            if(j == i)continue;
            double dis = 0;
            rep(k,d)dis += pow(x[i][k] - x[j][k],2);
            
            dis = sqrt(dis);

            if(dis - (ll)dis == 0){
                ans++;
                //cout << i << " " << j << endl;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define inside sl<=l&&r<=sr
#define outside r<sl||sr<l
#define INF 1000000009
using namespace std;
typedef long long ll;

ll arr[3003];
int n;
ll dp[3003][3003];

int main(){
	//freopen("stl.gir", "r", stdin);
	
	cin >> n;
	for (int i = 0; i < n; i++) cin >> arr[i];
	
	for (int k = 1; k <= n; k++){
		for (int i = n-1; i >= 0; i--){
			if ((n-k)%2 == 0){
				// first player
				if (k == 1) dp[i][k] = arr[i];
				else if (i+k-1 < n) dp[i][k] = max(dp[i][k-1]+arr[i+k-1], dp[i+1][k-1]+arr[i]);
			} else {
				// second player
				if (k == 1) dp[i][k] = -arr[i];
				else if (i+k-1 < n) dp[i][k] = min(dp[i][k-1]-arr[i+k-1], dp[i+1][k-1]-arr[i]);
			}

		}
	}
	
	cout << dp[0][n] << endl;
	
}

Measured memory_bytes: 70016
# coding: utf-8
N = int(input())
info = []
for i in range(N):
    info.append(list(map(int, input().split())))
# s = False
info.sort(key=lambda x: x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        flag = True
        s = False
        for i in range(N):
            x, y, h = info[i]
            # if x < 0 or y < 0 or h <= 0:
            #     continue
            if not s:
                H = h + abs(cx - x) + abs(cy - y)
                s = True
                continue
            else:
                if h != max(H - abs(cx - x) - abs(cy - y), 0):
                    flag = False
        if flag:
            print(cx, cy, H)
            exit()
ans = info[0]
for i in range(1, N):
    if ans[2] > info[i][2]:
        ans = info[i]
print(*ans)


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

int main(){
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    --s;--t;
    vector<int> v[n];
    rep(i,m){
        int x,y;
        cin>>x>>y;
        --x;--y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    vector<int> ds(n,inf),dt(n,inf);
    queue<int> q;
    ds[s]=0;q.push(s);
    while(q.size()){
        int x=q.front();q.pop();
        for(auto to : v[x]){
            if(ds[to]>ds[x]+1){
                ds[to]=ds[x]+1;
                q.push(to);
            }
        }
    }
    dt[t]=0;q.push(t);
    while(q.size()){
        int x=q.front();q.pop();
        for(auto to : v[x]){
            if(dt[to]>dt[x]+1){
                dt[to]=dt[x]+1;
                q.push(to);
            }
        }
    }
    vector<ll> cnts(n+1),cntt(n+1);
    rep(i,n){
        if(ds[i]<inf)cnts[ds[i]]++;
        if(dt[i]<inf)cntt[dt[i]]++;
    }
    ll ans=0;
    int x = ds[t];
    rep(i,x-1){
        ans+=cnts[i]*cntt[x-2-i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11724
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CSentou solver = new CSentou();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSentou {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long T = in.nextInt();
            long[] t = new long[n];

            for (int i = 0; i < n; i++)
                t[i] = in.nextInt();

            long off = 0;
            long answer = 0;
            for (long time : t) {
                answer += T;

                answer -= Math.max(0, off - time);
                off = time + T;
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main() {
  int N, a = 0;
  cin >> N;
  string S;
  
  for (int i = 0; i < N; i++) {
    cin >> S;

    if (S == "Y") {
      a = 1;
    }
  }

  if (a == 0) {
    cout << "Three" << endl;
  } else {
    cout << "Four" << endl;
  }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>=1&&a<=13&&b>=1&&b<=13){
	
		if(a==b)
        printf("Draw");	
		else if(a==1)
		printf("Alice");
		else if(b==1)
		printf("Bob");
		else if(a>b)
	    printf("Alice");
	    else
	    printf("Bob");
		}}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int X, isOk;

int main(void) {
    cin >> X;
    if (X < 2000) {
        int prod_count = X / 100;
        if (X <= prod_count * 105) {
            isOk = 1;
        }
    } else
        isOk = 1;
    
    cout << isOk;
    return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');

        var n = int.Parse(input[0]);
        var x = int.Parse(input[1]);
        var t = int.Parse(input[2]);

        var a = Math.Ceiling((n / (double)x));

        var ans = a * t;

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 27392
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
XY = [lr() for _ in range(N)]
XY.sort()
answer = float('inf')
# 端の4点、まずはx軸の2点を選ぶ
for left,right in itertools.combinations(range(N),2):
  xleft = XY[left][0]
  xright = XY[right][0]
  pts = sorted(XY[left:right+1], key = lambda xy: xy[1])
  if len(pts) < K:
    continue
  for D in range(len(pts) - K + 1):
    y_max = pts[D+K-1][1]
    y_min = pts[D][1]
    area = (y_max - y_min) * (xright - xleft)
    if area < answer:
      answer = area
    
print(answer)


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
const int sz=1e5+9;
int n;
long long a[sz],sum;
long long mn=1e10;
int cnt;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(a[i]<0){
            sum-=a[i];
            cnt++;
        }
        else sum+=a[i];
        mn=min(abs(a[i]),mn);
    }
    if(cnt&1) sum-=2*mn;
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
#define MOD 1000000007
#define MSG(a) cout << #a << " " << a << endl;
#define print(a) cout << a << endl;
template <class T, class C>
void chmax(T &a, C b) { a > b ?: a = b; }
template <class T, class C>
void chmin(T &a, C b) { a < b ?: a = b; }

// const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
// const int dx[]{0, 1, 0, -1}, dy[]{1, 0, -1, 0};

// vector の出力
template<typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
    size_t last = v.size() - 1;
    for(size_t i = 0; i < v.size(); ++i) {
        out << v[i];
        if (i != last) 
            out << " ";
    }
    return out;
}


int main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //////////////////////////////////////////


    // string a, b;
    // cin >> a >> b;
    int n;
    cin >> n;
    int a[n];
    rep(i,n){
        int x;
        cin>>x;
        a[i]=x-1;
    }
    int c=0;
    rep(i,1e5+1){
        c = a[c];
        if(c==1){
            print(i+1);
            return 0;
        }
    }
    print(-1);
    return 0;

}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define int long long
#define double long double
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

int n;
vector<int> x(n);
vector<int> y(n);
vector<char> c(n);

double calc(double steps) {
    double ax = 1e15;
    double bx = -1e15;
    double ay = 1e15;
    double by = -1e15;
    for (int i = 0; i < n; i++) {
        double X = x[i];
        double Y = y[i];
        if (c[i] == 'L') X -= steps;
        if (c[i] == 'R') X += steps;
        if (c[i] == 'D') Y -= steps;
        if (c[i] == 'U') Y += steps;
        ax = min(ax, X);
        bx = max(bx, X);
        ay = min(ay, Y);
        by = max(by, Y);
    }
    return (by - ay) * (bx - ax);
}

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

    cin >> n;
    x.resize(n);
    y.resize(n);
    c.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> c[i];
    }
    double s = 0;
    double e = 2e8;
    while (true) {
        double a = (s * 2 + e) / 3.0;
        double b = (s + e * 2) / 3.0;
        double fa = calc(a);
        double fb = calc(b);
        if (abs(fa - fb) <= 1e-20) {
            cout << fixed << setprecision(3) << fa << endl;
            return 0;
        }
        if (fa <= fb) {
            e = b;
        } else {
            s = a;
        }
    }

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 5208
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

//
// solution 
//
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        K: usize,
    }

    let num = N / K;
    let mut ans = if num == 0 { 0 } else { num.pow(3) };
    if K % 2 == 0 {
        let num = (N + K / 2) / K;
        ans += if num == 0 { 0 } else { num.pow(3) };
    }
    println!("{}", ans);
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 1e8
#define ALL(a) a.begin(), a.end()
#define MAXEL max_element
#define MINEL min_element
#define POW (long long)pow
#define BIT(i) (long long)pow(2, i)
typedef long long Lint;

int main() {
  int n;
  cin >> n;
  vector<int> vcModified; // A_1-1, A_2-2, ..., A_n-n
  REP(i, n) {
    int a;
    cin >> a;
    vcModified.push_back(a - (i + 1));
  }
  sort(ALL(vcModified));
  int median = vcModified[(n - 1) / 2];
  Lint ans = 0;
  REP(i, n) { ans += abs(vcModified[i] - median); }
  cout << ans << endl;
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

#define MAX(a, b) ((a>b) ? a : b)

int main() {
  int a1, a2, a3;
  scanf("%d%d%d", &a1, &a2, &a3);
  int s12, s23, s13, ans;
  s12 = abs(a1-a2);
  s23 = abs(a2-a3);
  s13 = abs(a1-a3);
  ans = s12 + s23 + s13 - MAX(MAX(s12, s23), s13);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

struct Edge { int src, dst; };

int main() {
  int n, k;
  while (cin >> n >> k) {
    vector<Edge> v;
    REP(i,n-1) v.push_back((Edge) { i + 1, n });

    int result = (n - 1) * (n - 2) / 2;
    REP(i,n-1) REP(j,i) if (result > k) {
      result--;
      v.push_back((Edge) { j + 1, i + 1 });
    }

    if (result == k) {
      cout << v.size() << endl;
      REP(i,v.size()) cout << v[i].src << ' ' << v[i].dst << endl;
    } else {
      cout << -1 << endl;
    }
    // cout << v.size() << " edges" << endl;
    // check
    // static int dp[128][128];
    // REP(i,n) REP(j,n) dp[i][j] = 1 << 20;
    // REP(i,n) dp[i][i] = 0;
    // REP(i,v.size()) dp[v[i].src-1][v[i].dst-1] = 1;
    // REP(i,v.size()) dp[v[i].dst-1][v[i].src-1] = 1;
    // //REP(i,n) pp(dp[i],n);

    // REP(k,n) REP(i,n) REP(j,n) ls(dp[i][j], dp[i][k] + dp[k][j]);
    // int cnt = 0;
    // REP(i,n) REP(j,i) if (dp[i][j] == 2) cnt++;
    // if (cnt == k) cout << "ac" << endl;
    // else cout << "wa" << ' ' << cnt << endl;
    //REP(i,n) pp(dp[i],n);
  }
}


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

using namespace std;

int main(){
	int n,j;
	cin>>n;
	for(j=0;j<n;j++){

		int millennium = 196471;
		int NoD[]={19,20,200,195};
		int year,month,day,sum=0,i;
		cin >> year >> month >> day;
		for(i=1;i<year;i++){
			if(!(i%3))
				sum+=NoD[2];
			else
				sum+=NoD[3];
		}
		for(i=1;i<month;i++){
			if(!(year%3))
				sum+=NoD[1];
			else
				sum+=NoD[i%2];
		}
		sum+=day;

		cout << millennium - sum <<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;

int main(void) {
    ll i, j, N;
    ll c[500], s[500], f[500];
    cin >> N;
    for(i=1; i<N; i++) {
        cin >> c[i] >> s[i] >> f[i];
    }
    ll t;
    ll k;
    for(i=1; i<N; i++) {
        t=s[i]+c[i];
        for(j=i+1; j<N; j++) {
            if(t<s[j]) {
                t=s[j];
            }else {
                k=1;
                while(s[j]+f[j]*k<t) {
                    k++;
                }
                t+=s[j]+f[j]*k-t;
            }
            t+=c[j];
        }
        
        cout << t << endl;
    }
    cout << 0 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#define mem(a, b) memset(a, (b), sizeof(a))

using namespace std;


typedef long long ll;
const int Maxn = 1e9 + 10;
const int N = 1e6 + 10;
const int INF=(0x7fffffff)/2;
const int MOD = 1000000007;
const int MaxN = 1000;
 
int a[110];
int main(){
	int n, k;
	while(~scanf("%d %d", &n, &k)){
		mem(a, 0);
		for(int i = 0; i < n; i++)
			scanf("%d", &a[i]);
		sort(a, a + n);
		int kk = k;
		int cnt = 0;
		for(int i = 0; i < n; i++){
			int x = kk - a[i];
			if(x >= 0){
				cnt++;
				kk -= a[i];
			}
			else{
				break;
			}
		}
		if(cnt >= n){
			int x = kk / a[0];
			cnt += x;
		}
		printf("%d\n", cnt);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ps push
#define pf push_front
#define mp make_pair
#define And &&
#define Or ||
#define inf INT_MAX
#define sz(name) name.size()
#define len(name) name.length()
#define ig cin.ignore()
#define sc1(name) scanf("%d",&name)
#define sc2(name1,name2) scanf("%d%d",&name1,&name2)
#define sc3(name1,name2,name3) scanf("%d%d%d",&name1,&name2,&name3)
#define scl1(name) scanf("%lld",&name)
#define scl2(name1,name2) scanf("%lld%lld",&name1,&name2)
#define scl3(name1,name2,name3) scanf("%lld%lld%lld",&name1,&name2,&name3)
#define Sort(name) sort(name.begin(),name.end())
#define SSort(name) sort(name.rbegin(),name.rend())
#define For(name,start,finish) for(int name=start;name<finish;name++)
#define Forr(name,start,finish) for(int name=start;name>=finish;name--)
#define fast_in_out ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


int row[]={0,1,0,-1,-1,-1,1,1};
int col[]={1,0,-1,0,1,-1,-1,1};

const ll N=2e5+10;
const ll M=1e18+7;
const ll H=1e9+7;
const ll base=131;

ll logx(ll a,ll bs){return log(a)/log(bs);}
ll Max(ll a,ll b){if(a>b)return a;return b;}
ll Min(ll a,ll b){if(a>b)return b;return a;}
ll big_mul(ll a,ll b,ll m){ll x=0,y=a%m;while(b>0){if(b&1)x=(x+y)%m;y=(2*y)%m;b>>=1;}return x%m;}
ll big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=(x*y)%m;y=(y*y)%m;b>>=1;}return x%m;}
ll Big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=big_mul(x,y,m);y=big_mul(y,y,m);b>>=1;}return x%m;}
ll mod_inverse(ll a,ll m){return big_mod(a,m-2,m);}  //a^-1 mod m = a^(m-2) mod m
ll GCD(ll a,ll b){if(!a)return b;return GCD(b%a,a);}



int main()
{
    fast_in_out;

    int k;
    cin>>k;

    if(k%2==0 Or k%10==5)
    {
        cout<<"-1"<<endl;
        return 0;
    }


    int r=0;
    int cnt=0;

    while(1)
    {
        cnt++;
        r=(r*10+7%k)%k;

        if(!r)
            break;

    }

    cout<<cnt<<endl;


    return 0;
}



Measured memory_bytes: 3700
N = int(input())
L = list(map(int, input().split(" ")))

max_idx = -1
max_len = -1 
for i in range(N):
    if max_len < L[i]:
        max_len = L[i]
        max_idx = i
        
if sum(L) > max_len * 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
a=input()
b=input()
c=input()
# a="aca"

# b="accc"

# c="ca"



A=len(a)
B=len(b)
C=len(c)
flag=0
x=a[0]

while True:
    if x=="a":
        if a=="":
            print("A")
            break
        else:
            x=a[0]
            a=a[1:]
    if x=="b":
        if b=="":
            print("B")
            break
        else:
            x=b[0]
            b=b[1:]
    if x=="c":
        if c=="":
            print("C")
            break
        else:
            x=c[0]
            c=c[1:]


       

Measured memory_bytes: 61692
S = input()
ans = "Yes"
for i in range((len(S)-1)//2):
    if S[i] != S[(len(S)-1)//2-i-1] or S[-(1+i)] != S[-((len(S)-1)//2-i)] or S[i] != S[-(1+i)]:
        ans ="No"
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

ll gcd(ll num1, ll num2){
  if(num1 > num2){
    swap(num1, num2);
  }
  ll r = num2 % num1;
  while(r != 0){
    num2 = num1;
    num1 = r;
    r = num2 % num1;
  }
  return num1;
}

ll lcm(ll num1, ll num2){
  return num1 * num2 / gcd(num1, num2);
}

int main(){
  ll A,B,C,D;
  cin >> A >> B >> C >> D;

  ll c_r = B / C;
  ll c_l = (A - 1) / C;
  ll d_r = B / D;
  ll d_l = (A - 1) / D;
  ll cd_r = B / lcm(C, D);
  ll cd_l = (A - 1) / lcm(C, D);

  ll tmp = c_r - c_l + d_r - d_l - (cd_r - cd_l);
  cout << B - A + 1 - tmp << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
    int A, B;
    scanf("%d",&A);
    scanf("%d",&B);
    if(A>=13){
        printf("%d\n",B);
    }else if(A>=6){
        printf("%d\n",B/2);
    }else{
        printf("%d\n",0);
    }
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        ArrayList<Node> nodes = new ArrayList<>();
        PriorityQueue<Node> q = new PriorityQueue<>();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        try {
            String line;
            line = br.readLine();
            st = new StringTokenizer(line);
            int v = Integer.parseInt(st.nextToken());
            int e = Integer.parseInt(st.nextToken());
            int r = Integer.parseInt(st.nextToken());
            for (int i = 0; i < v; i++) {
                Node node = new Node();
                if (i == r) {
                    node.confirmed = true;
                    node.minCost = 0;
                    nodes.add(node);
                } else {
                    nodes.add(node);
                }
            }
            for (int i = 0; i < e; i++) {
                line = br.readLine();
                st = new StringTokenizer(line);
                int s = Integer.parseInt(st.nextToken());
                int t = Integer.parseInt(st.nextToken());
                int d = Integer.parseInt(st.nextToken());
                nodes.get(s).addEdge(t, d);
            }
            
            q.add(nodes.get(r));

            while (!q.isEmpty()) {
                Node confirmedNode = q.poll();
                confirmedNode.confirmed = true;
                for (int i = 0; i < confirmedNode.edgeTo.size(); i++) {
                    int to = confirmedNode.edgeTo.get(i);
                    int cost = confirmedNode.minCost + confirmedNode.edgeCost.get(i);
                    if (cost < nodes.get(to).minCost) {
                        nodes.get(to).minCost = cost;
                        if (!q.contains(nodes.get(to))) {
                            q.add(nodes.get(to));
                        }
                    }
                }
            }
            for (Node node : nodes) {
                if (node.minCost == Integer.MAX_VALUE) {
                    System.out.println("INF");
                } else {
                    System.out.println(node.minCost);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

class Node implements Comparable<Node> {
    ArrayList<Integer> edgeTo = new ArrayList<>();
    ArrayList<Integer> edgeCost = new ArrayList<>();
    int minCost;
    boolean confirmed;

    Node() {
        minCost = Integer.MAX_VALUE;
        confirmed = false;
    }
    
    void addEdge(int t, int d) {
        edgeTo.add(t);
        edgeCost.add(d);
    }

    @Override
    public int compareTo(Node that) {
        if (this.minCost < that.minCost) {
            return -1;
        } else if (this.minCost > that.minCost) {
            return 1;
        }
        return 0;
    }
}

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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){
    if(a>b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

// 最大公約数を求める GCD
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
// loopで書くなら
/*
 * int gcd(int a, int b){
 *     int r;
 *     while( (r = a % b) != 0 ) {
                a = b;
                b = r;
       }
       return b;
 * }
 *
 * */

/*
 * 複数の最大公約数に関して　前提知識として配列[a,b,c]のgcdはgcd(gcd(a,b),c)であることは知っておこう
 * つまり、累積和を用いる
 *
 * 問題は「N 個の値の中から 1 個だけ取り除いた N−1 個の整数の最大公約数の最大値を求める」こととなる
 *
 * つまり i番目を除いた、最大公約数を求めて、i:0->Nまで動かして最大公約数の最大を取ればよい
 * i番目を除いた最大公約数を累積和(累積GCDといった方が正確)を求めておく
 *
 * この際にA1, A2, ... Ai-1, Ai, Ai+1, ... An-1
 *        -------①--------     ------②-------
 *  ①と⓶の部分のGCDを求めておくと、楽にできる
 *
 *  left[p] := 区間 [0,p) の最大公約数
 *  right[p] := 区間 [p,N) の最大公約数
 *
 *  こうしておけば、

    前処理: O(NlogA)
    集計: O(NlogA)

    で求められる
    
    
    ----------------------なぜ右からの累積 GCD も必要か----------------------------
    今回の問題が累積 GCD じゃなくて、累積和だったなら、実は
    
    right[p] := 区間 [p,N) の累積和
    は要らなくて、
    
    left[p] := 区間 [0,p) の累積和
    だけで OK。これで区間 [l,r) の和は
    
    left[r]−left[l]
    で求められるのだ。だが今回の累積 GCD には「 - 」に対応する機能がない。引き算ができない。よって、区間 [p,N) についての GCD を求めるには右からの累積 GCD が必要になる。
 *
 * */

int main() {

    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];

    // 累積GCD
    vector<int> left(N+1, 0);
    vector<int> right(N+1, 0);
    for (int i = 0; i < N; ++i) {
        left[i+1] = GCD(left[i], A[i]);
    }
    for (int i = N-1; i >= 0; --i) {
        right[i] = GCD(right[i+1], A[i]);
    }
    // 集計
    int res = 0;
    for (int i = 0; i < N; ++i) {
        // 左側
        int l = left[i];

        // 右側
        int r = right[i+1];

        // 更新
        chmax(res, GCD(l, r));
    }
    cout << res << endl;
}

Measured memory_bytes: 1408