akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
long long INF= 1e11;


int main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<long long>s(A+2), t(B+2), x(Q),ans(Q,INF);
    for (int i = 1; i <= A; i++)cin >> s[i];
    for (int i = 1; i <= B; i++)cin >> t[i];
    s[0] = t[0] = -INF;
    s[A + 1] = t[B + 1] = INF;
    for (int i = 0; i < Q; i++) {
        long long x;
        cin >> x;

        size_t spos = distance(s.begin(), lower_bound(s.begin(), s.end(), x));
        size_t tpos = distance(t.begin(), lower_bound(t.begin(), t.end(), x));

        long long c[4];
        c[0] = max(s[spos], t[tpos]) - x;
        c[1] = x - min(s[spos - 1], t[tpos - 1]);
        c[2] = s[spos] - t[tpos - 1] + min(abs(x - s[spos]), abs(x - t[tpos - 1]));
        c[3] = t[tpos] - s[spos - 1] + min(abs(x - s[spos - 1]), abs(x - t[tpos]));

        for (int j = 0; j < 4; j++)if (c[j] < ans[i])ans[i]= c[j];
    }

    for (int i = 0; i < Q; i++)cout << ans[i] << "\n";

    return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    int k;cin>>k;
    if(k%2==0){cout<<-1<<endl;return 0;}
    ll t=0;
    ll tmp=7;
    rep(i,MAX_6){
        t+=tmp%k;
        tmp=(tmp%k)*10;
        if(t%k==0){cout<<i+1<<endl;return 0;}
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 3628
INF = float('inf')

n, k = list(map(int, input().split()))
P = list(map(int, input().split()))
P = list(map(lambda x: x-1, P))
C = list(map(int, input().split()))


def simulate(start, k):
    result = -INF
    cur = start
    score = 0

    turn = 0
    cycle_check = False
    while turn < k:
        turn += 1
        cur = P[cur]
        score += C[cur]
        result = max(result, score)
        # サイクル時の処理短縮
        if cur == start and cycle_check == False:
            cycle_check = True
            # １周して減ってるなら回す必要なし
            if score <= 0:
                break
            # 1周して増えるなら最後の1周 + αだけ試す
            cycle_cnt = (k // turn) - 1
            if cycle_cnt < 1:
                cycle_cnt = 0
            # break
            turn = cycle_cnt * turn
            score = cycle_cnt * score

    return result


result = -INF
for i in range(n):
    # if i != 2:
    #     continue
    result = max(result, simulate(i, k))

print(result)


Measured memory_bytes: 74476
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp(" %s = %s\n", #x, to_string(x).data())
/* ==================== */ 
int main() {
	char s[1000];
	scanf("%s", s);
	int n = strlen(s);
	int ans = 0;
	for (int i = 0; i < n / 2; i++)
		ans += (s[i] != s[n - i - 1]);
	printf("%d\n", ans);
}



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

int main(){
    int n; cin>>n;
    map<string,int> hantei;
    rep(z,n){
        string s; cin>>s;
        hantei[s]++;
    }

    cout << "AC x " << hantei["AC"] <<endl;
    cout << "WA x " << hantei["WA"] <<endl;
    cout << "TLE x " << hantei["TLE"] <<endl;
    cout << "RE x " << hantei["RE"] <<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

int dp[100][10];
int Log(int n){
	int m = 1, res = 0;
	while(m <= n){
		m <<= 1;
		res++;
	}
	return res;
}

signed main(){
	int n;
	scanf("%lld", &n);
	int m = Log(n);
	dp[0][0] = 1;
	rep(i,m){
		bool bit = n&(1LL<<(m-i-1));
		dp[i+1][2] += 3*dp[i][2];
		if(bit == false){
			dp[i+1][0] += dp[i][0]+dp[i][1];
			dp[i+1][1] += dp[i][1];
			dp[i+1][2] += dp[i][1];
		}else{
			dp[i+1][0] += dp[i][0];
			dp[i+1][1] += dp[i][0]+dp[i][1];
			dp[i+1][2] += 2*dp[i][1];
		}
		rep(j,3)dp[i+1][j] %= mod;
	}
	
	int ans = 0;
	rep(i,3)ans += dp[m][i];
	printf("%lld\n", ans%mod);
	return 0;
}


Measured memory_bytes: 256
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>
#include <sstream>
#include <unistd.h>

#define ll long long
#define Int ll
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define rep(n) for(int __x = 0; __x < n; __x++)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (x.at(x.size()-1))

using namespace std;

#define EPS 0.0000000001
#define MOD 1000000007

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

#define MAX_N 205

Int N, M;
vector<Int> P({300000, 200000, 100000, 0});

void input() {
  cin >> N >> M;
  N--, M--;
  if (N > 3) N = 3;
  if (M > 3) M = 3;
}

void solve() {
  if (N == 0 && M == 0) {
    cout << 1000000 << endl;
    return;
  }

  cout << P.at(N) + P.at(M) << endl;
}

int main(void) {
  input();
  solve();
  return 0;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 4e5 + 5;

int n,k,a[maxn];

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

  cin>>n>>k;
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }

  if (k>=n) out(1);

  int ans = ((n-1)+(k-2))/(k-1);
 

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 640
(let ((s (concatenate 'list (read-line))))

  (defun solve (lst &optional flag ans)
    (cond
      ((null lst) (concatenate 'string (reverse ans)))
      ((null flag) (solve (cdr lst) t (cons (car lst) ans)))
      (t           (solve (cdr lst) nil ans))))

  (format t "~A~%"
          (solve s)))


Measured memory_bytes: 29036
n, *h = map(int, open(0).read().split())
dp = [1e9] * n
dp[0] = 0
for i in range(n):
    if i+2 < n:
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i]-h[i+2]))
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i]-h[i+1]))
    elif i+1 < n:
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i]-h[i+1]))
print(dp[n-1])

Measured memory_bytes: 20340
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int b[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",b+i);
	for(int i=0;i<a;i++)if(i%2)b[i]^=1;
	int cur=0;
	vector<int>v;
	for(int i=0;i<a;i++){
		if(i&&b[i]!=b[i-1]){
			v.push_back(cur);
			cur=1;
		}else cur++;
	}
	v.push_back(cur);
	int ret=v[0];
	if(v.size()>1){
		for(int i=0;i<v.size()-1;i++)ret=max(ret,v[i]+v[i+1]);
		for(int i=1;i<v.size()-1;i++){
			ret=max(ret,v[i-1]+v[i]+v[i+1]);
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 1656
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int x;
  cin >> x;
  if(x>=1200) cout << "ARC" << endl;
  else  cout << "ABC" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

int main(void){
	char s[20];
	int i,j,l;
	long long t,ans=0;
	chin(s);
	l=strlen(s);
	rep(i,1<<l-1){
		t=s[0]-'0';
		rep(j,l-1){
			if(i&1<<j){
				ans+=t;
				t=s[j+1]-'0';
			}
			else
				t=t*10+s[j+1]-'0';
		}
		ans+=t;
	}
	llprint(ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

int main(){
  int w,a,b;
  cin>>w>>a>>b;
  if(abs(b - a)< w){
    cout<<0<<endl;
  } else if(w + a > b){
    cout<<abs(b + w - a)<<endl;
  } else {
    cout<<abs(a + w - b)<<endl;
  }
}

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

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

        var num = int.Parse(input[0]);
        var tickets = int.Parse(input[1]);

        var prices = Console.ReadLine().Split(' ');

        var priorityQueue = new PriorityQueue<long>(PriorityQueueTypeOrderType.Descending);

        foreach (var price in prices)
        {
            priorityQueue.Enqueue(long.Parse(price));
        }

        for (var i = 0; i < tickets; i++)
        {
            var p = Math.Floor((double)priorityQueue.Dequeue() / 2);
            priorityQueue.Enqueue((long)p);
        }

        long ans = 0;
        foreach (var p in priorityQueue.Heap)
        {
            ans += p;
        }

        Console.WriteLine(ans);
        Console.ReadLine();

    }
}

public class PriorityQueue<T> where T : IComparable
{

    public IComparer<T> Comparer { get; set; }

    public List<T> Heap { get; set; }

    //0=デフォルトで昇順、1で降順
    public int Type { get; set; }

    public PriorityQueue()
    {
        //this.Heap = new T[maxSize];
        this.Heap = new List<T>();
        this.Type = 0;
    }

    public PriorityQueue(int type)
    {
        this.Heap = new List<T>();
        this.Type = type;
    }

    public PriorityQueue(PriorityQueueTypeOrderType type)
    {
        this.Heap = new List<T>();
        this.Type = (int)type;
    }

    public int Compare(T x, T y)
    {
        return this.Type == 0 ? x.CompareTo(y) : y.CompareTo(x);
    }

    public void Enqueue(T n)
    {
        this.Heap.Add(n);

        var child = this.Heap.Count - 1;

        while (child > 0)
        {
            var parent = (child - 1) / 2;

            if (this.Compare(n, this.Heap[parent]) >= 0)
            {
                break;
            }
            var temp = this.Heap[child];
            this.Heap[child] = this.Heap[parent];
            this.Heap[parent] = temp;
            child = parent;

        }
    }

    public T Dequeue()
    {
        var last = this.Heap.Count - 1;
        var result = this.Heap[0];
        this.Heap[0] = this.Heap[last];
        this.Heap.RemoveAt(last);
        last--;
        var parent = 0;
        while (true)
        {
            var child = parent * 2 + 1;
            if (child > last)
            {
                break;
            }
            var rightChild = child + 1;
            if (rightChild <= last && Compare(this.Heap[rightChild], this.Heap[child]) < 0)
            {
                child = rightChild;
            }
            if (Compare(this.Heap[parent], this.Heap[child]) <= 0)
            {
                break;
            }

            var temp = this.Heap[child];
            this.Heap[child] = this.Heap[parent];
            this.Heap[parent] = temp;

            parent = child;
        }
        return result;
    }
}

public enum PriorityQueueTypeOrderType
{
    Ascending = 0,
    Descending = 1,
}




Measured memory_bytes: 29276
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n, m;
  cin>>n>>m;
  int edge[n][n];
  int dist[n][n];

  REP(i, n)REP(j, n){
    edge[i][j]=-1;
    dist[i][j]=100000;
  }
  int a[m], b[m];
  int s, t, u;
  REP(i, m){
    cin>>s>>t>>u;
    --s;
    --t;
    edge[s][t]=u;
    edge[t][s]=u;
    dist[s][t]=u;
    dist[t][s]=u;
    a[i]=s;
    b[i]=t;
  }

  REP(k, n){
    REP(i, n){
      REP(j, n){
        dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
        dist[j][i] = dist[i][j];
      }
    }
  }
  int ans=m;

  REP(k, m){
    REP(i, n){
      int l = a[k];
      int r = b[k];
      if(dist[i][l] + edge[l][r] == dist[i][r] || dist[l][r]==edge[l][r]){
        --ans;
        break;
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 384
#E
N,M = map(int,input().split())

if N%2 == 1:
    for i in range(1,M+1):
        print(i,N+1-i)
        
else:
    f = True
    l,r = 1,N
    for i in range(1,M+1):
        print(l,r)
        l+=1
        r-=1
        if f and (4*l > N):
            l+=1
            f = False



Measured memory_bytes: 9260
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			double w=sc.nextDouble();
			if(w<=48){
				System.out.println("light fly");
			}else if(w<=51){
				System.out.println("fly");
			}else if(w<=54){
				System.out.println("bantam");
			}else if(w<=57){
				System.out.println("feather");
			}else if(w<=60){
				System.out.println("light");
			}else if(w<=64){
				System.out.println("light welter");
			}else if(w<=69){
				System.out.println("welter");
			}else if(w<=75){
				System.out.println("light middle");
			}else if(w<=81){
				System.out.println("middle");
			}else if(w<=91){
				System.out.println("light heavy");
			}else{
				System.out.println("heavy");
			}
		}
	}
}

Measured memory_bytes: 19292
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
#define n first
#define cnt second

int main() {
  int D; cin >>D;
  vector<P> ps;
  int x, y, n; cin >>x;
  string s;
  REP(i, x){
    cin >>s >>n;
    if(s[0] == 'D') ps.push_back(P(n, 1));
  }
  cin >>y;
  REP(i, y){
    cin >>s >>n;
    if(s == "DD") ps.push_back(P(n, 2));
  }
  int ans = 0;
  int N = ps.size();
  REP(i, (1 << N)){
    int cnt = 0, sum = 0;
    REP(j, N) if((1 << j) & (i)) { cnt += ps[j].cnt; sum += ps[j].n; }
    if(cnt <= D) ans = max(ans, sum);
  }
  cout <<ans <<endl;
  return 0;
}

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

using namespace std;

const int N = 234567;

int n, a, p[N], r;
vector<pair<int, int> > b;

int main() {

  cin >> n;
  for (int i = 0; i < n; ++i) { cin >> a; b.push_back(make_pair(a, i)); }

  sort(b.begin(), b.end());
  for (int i = 0; i < n; ++i) {
    p[b[i].second] = i;
  }

  for (int i = 0; i < n; ++i) {
    if (p[i] <= n / 2 - 1) { r = b[n / 2].first; }
    else { r = b[n / 2 - 1].first; }  
    cout << r << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4720
n,x=map(int,input().split())
while n!=0 or x!=0:
    ans=0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k==x:
                    ans+=1
    print(ans)
    n,x=map(int,input().split())



Measured memory_bytes: 5596
N = int(input())
E = [[] for _ in [0]*N]
for _ in [0]*(N-1):
    a,b = map(int,input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
V = [0]*N
V[0] = 1
V[-1] = -1
q = [0,N-1]
while q:
    qq = []
    for i in q:
        Vi = V[i]
        for j in E[i]:
            if not V[j]:
                V[j] = Vi
                qq.append(j)
    q = qq
print("Fennec" if sum(V)>0 else "Snuke")


Measured memory_bytes: 60128
# include <iostream>
# include <cstdio>
using namespace std;
const int N = 2e5 + 12;
int fa[N],n,m,a[N],in[N],ans;
int find(int x){return fa[x] == x ? x : fa[x] = find(fa[x]);}
int main(){
  scanf("%d %d",&n,&m);
  for(int i = 1;i <= n;i++)scanf("%d",&a[i]),in[a[i]] = fa[i] = i;
  int x,y;
  for(int i = 1;i <= m;i++)scanf("%d %d",&x,&y),fa[find(y)] = find(x);
  for(int i = 1;i <= n;i++)if(find(in[i]) == find(i))ans++;
  printf("%d\n",ans);
}

Measured memory_bytes: 1408
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define LOG
#define PRINT
#define LCERR
#include <iostream>
auto optimize_cpp_stdio = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ);
    return 0;
}();
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

class Solution {
public:
    uint64_t xxor(uint64_t K, const vector<uint64_t>& a) {
        uint64_t pow = uint64_t(1) << 42u;
        uint64_t optx = 0;
        while(pow > 0) {
            int num0 = 0;
            int num1 = 0;
            for (auto num : a) {
                ((num & pow) > 0 ? num1 : num0) += 1;
            }
            if (num0 > num1 && optx + pow <= K) {
                optx += pow;
            }
            pow >>= 1u;
        }
        uint64_t f = 0;
        for (auto num : a) {
            f += (num ^ optx);
        }
        return f;
    }
private:

};

int solve() {
    Solution solution;
    // handle IO here
    size_t N;
    uint64_t K;
    cin >> N >> K;
    vector<uint64_t> a(N);
    for (size_t i = 0; i < N; ++i) {
        cin >> a[i];
    }
    cout << solution.xxor(K, a);
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <unordered_set>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) { cin >> a[i]; }

  std::sort(a.begin(), a.end());
  cout << a[a.size() - 1] - a[0] << endl;
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*/
#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
    vector <string> v;
    stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x);
    return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
    cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
    err(++it, args...);
}
 
int ini(){int x; scanf("%d",&x);return x;}
long long inl(){ long long x;scanf("%lld",&x); return x;}
double ind(){double x; scanf("%lf",&x);return x;}
#define Iin ini();
#define Lin inl();
#define Din ind();

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;

int a[N];

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int t=1,te=0;
    //cin>>t;
    while(t--){
        double l;
        cin>>l;
        double x=l/3.0;
        double r= l - x*3;
        printf("%.10f\n", x*x*(x+r));

        //printf("Case %d: ",++te);
    }
    return 0;
}




Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main(String[] args) {
		try {
	        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	        int n = Integer.parseInt(in.readLine());
	        String A = new String(in.readLine());
	        String B = new String(in.readLine());
	        String C = new String(in.readLine());
	        char[] charA = new char[n];
			char[] charB = new char[n];
			char[] charC = new char[n];
			charA = A.toCharArray();
			charB = B.toCharArray();
			charC = C.toCharArray();
			
			int ret = 0;
			for (int i = 0; i < n; i++) {
				if (charA[i] != charB[i] && charA[i] != charC[i] && charB[i] != charC[i] ) {
					ret = ret + 2;
				} else if (charA[i] != charC[i] || charA[i] != charB[i]) {
					ret++;
				}
			}
			System.out.println(String.valueOf(ret));

		} catch (Exception ex) {}
	}	
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int a, b; cin >> a >> b;
    int n = b - a - 1;
    int ans = n * (n + 1) / 2 - a;
    cout << ans << endl;
    return 0;
}

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

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(N)
    {
        cin >> A[i];
    }
    auto maxEl_A = max_element(A.begin(), A.end());
    vector<int> B;
    rep(N)
    {
        if (A.begin() + i != maxEl_A)
            B.push_back(A[i]);
    }
    auto maxEl_B = max_element(B.begin(), B.end());
    rep(N)
    {
        if (A.begin() + i == maxEl_A)
            cout << *maxEl_B;
        else
            cout << *maxEl_A;
        cout << endl;
    }

    //cout << *max_element(A.begin(), A.end()) << endl;
}

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
//Longest Common Prefix(s,s.substr(i)) O(|s|)
#include<vector>
vector<int>Zalgo(const vector<int>&s)
{
	vector<int>ret(s.size());
	ret[0]=s.size();
	int i=1,j=0;
	while(i<s.size())
	{
		while(i+j<s.size()&&s[j]==s[i+j])j++;
		ret[i]=j;
		if(j==0)
		{
			i++;
			continue;
		}
		int k=1;
		while(i+k<s.size()&&k+ret[k]<j)ret[i+k]=ret[k],k++;
		i+=k;j-=k;
	}
	return ret;
}
int N,A[2<<17],B[2<<17];
main()
{
	cin>>N;
	vector<int>a(3*N);
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
	}
	for(int i=0;i<N;i++)
	{
		cin>>B[i];
	}
	for(int i=0;i<N;i++)
	{
		a[i+N]=a[i+2*N]=A[i]^A[(i+1)%N];
		a[i]=B[i]^B[(i+1)%N];
	}
	vector<int>L=Zalgo(a);
	for(int k=0;k<N;k++)
	{
		if(L[k+N]>=N)
		{
			cout<<k<<" "<<(A[k]^B[0])<<endl;
		}
	}
}


Measured memory_bytes: 9728
#include <stdio.h>
#include <iostream>
using namespace std;

#define N_MAX 100
#define W_MAX 10000

int v_i[N_MAX + 1];
int w_i[N_MAX + 1];
int dp[N_MAX + 1][W_MAX + 1];

int main(void){
    int N, W;
    scanf("%d %d", &N, &W);

    for(int i = 1; i <= N; i++){
        scanf("%d %d", &v_i[i], &w_i[i]);
    }

    for(int i = 0; i <= N; i++){
        dp[i][0] = 0;
    }
    for(int j = 0; j <= W; j++){
        dp[0][j] = 0;
    }

    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= W; j++){
            if(j - w_i[i] < 0){
                dp[i][j] = dp[i - 1][j];
            }else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - w_i[i]] + v_i[i]);
            }
        }
    }

    printf("%d\n", dp[N][W]);
}



Measured memory_bytes: 7140
class Program
    {
        static void Main(string[] args)
        {
            string[] temp = System.Console.ReadLine().Split(' ');
            int a = int.Parse(temp[0]);
            int b = int.Parse(temp[1]);
            if (b % a == 0) { System.Console.WriteLine(a + b); }
            else { System.Console.WriteLine(b-a); }
        }
    }

Measured memory_bytes: 11092
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int s[] = new int[N];
		int sum = 0;
		for(int i = 0; i < N; i++) {
			s[i] = sc.nextInt();
			sum += s[i];
		}
		
		Arrays.sort(s);
		int cnt = 0;
		while(true) {
			if(sum % 10 != 0) {
				break;
			}
			if(s[cnt] % 10 != 0) {
				sum -= s[cnt];
			}
			if(cnt == N - 1) {
				sum = 0;
				break;
			}
			cnt++;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 22868
x=int(input())
List=[input() for i in range (x)]
List=sorted(List)
sum=-1
count=1
ans=[]
for i in range (x-1):
    if List[i] == List[i+1]:
        count+=1
    elif sum>count:
        count=1
    elif sum==count:
        count=1
        ans+=[List[i]]
    else:
        sum=count
        count=1
        ans=[]
        ans+=[List[i]]
if sum==count:
    ans+=[List[-1]]
elif sum<count:
        sum=count
        count=1
        ans=[]
        ans+=[List[i]]
ans=sorted(ans)
for i in ans:
    print(i)

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

int main(void){
  char n[3];
  for(int i = 0; i < 3; i++)
    cin >> n[i];
  for(int i = 0; i < 3; i++){
    if(n[i] == '1')
      n[i] = '9';
    else if(n[i] == '9')
      n[i] = '1';
  }
  for(int i = 0; i < 3; i++)
    cout << n[i];
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3488
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		String[] cards = new String[52];
		Boolean[] flags = new Boolean[52];

		String[] suit = {"S","H","C","D"};

		for(int i=0 ; i<suit.length; i++) {
			for (int num=1; num<=13; num++){
				cards[i*13 + num-1] = suit[i] + " " + num;
				flags[i*13 + num-1] = false;
			}
		}

		for(int j = 0; j<N; j++){
			String set = br.readLine();
			for(int k = 0; k<cards.length; k++) {
				if(set.equals(cards[k])) {
						flags[k] = true;
						break;
				}
			}
		}

		for(int l=0 ; l<cards.length; l++) {
			if(!flags[l]){
				System.out.println(cards[l]);
			}
		}
	}
}

Measured memory_bytes: 24132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
  int64_t n,m;
  cin >> n >> m;
  
  int64_t p[m];
  string s[m];
  rep(i,m) cin >> p[i] >> s[i];
  
  int64_t acnum[n+1];
  for(int64_t i = 0; i < m; i++){
    if(s[i] == "AC"){
      acnum[p[i]] = 1;
    }
  }
  
  int64_t ac = 0, wa = 0;
  int64_t ok[n+1];
  for(int64_t i = 1; i <= n; i++) ok[i] = 0;
  for(int64_t i = 0; i < m; i++){
    if(s[i] == "WA" && ok[p[i]] == 0 && acnum[p[i]] == 1){
      wa++;
    }
    if(s[i] == "AC" && ok[p[i]] == 0){
      ok[p[i]] = 1;
      ac++;
    }
  }
  
  cout << ac << " " << wa << endl;
}

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

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Printv(v)                                                              \
    {                                                                          \
        REP(x, v.size()) { cout << v[x] << (x == v.size() - 1 ? "\n" : " "); } \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<double> VD;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};
#define PI 3.141592653589793238

ll par[100000], dp[100000], dist, N;
VVL G(100000);

ll dfs(ll now, ll pre, ll depth) {
    ll &res = dp[now];
    if(now == N - 1) dist = depth;
    par[now] = pre;
    FOREACH(to, G[now]) {
        if(to == pre) continue;
        dfs(to, now, depth + 1);
        dp[now] += dp[to];
    }
    return ++res;
}

signed main() {
    cin >> N;
    REP(i, N - 1) {
        LCIN(a, b);
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    dfs(0, -1, 0);
    ll v = N - 1;
    REP(loop, (dist - 1) / 2) v = par[v];
    cout << (dp[0] - dp[v] > dp[v] ? "Fennec" : "Snuke") << "\n";
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 998244353;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

ll L, a[MAX_N], dp[MAX_N][5];

int main() {
    cin >> L;
    REP(i,L) cin >> a[i];
    REP(i,L)fill(dp[i+1],dp[i+1]+5,IINF);
    
    REP(i,L){
        REP(j,5){
            switch(j){
                case 0:
                    dp[i+1][0] = min(dp[i+1][0],dp[i][j]+a[i]);
                    dp[i+1][1] = min(dp[i+1][1],dp[i][j]+(a[i]>0?a[i]%2:2));

                case 1:
                    dp[i+1][1] = min(dp[i+1][1],dp[i][j]+(a[i]>0?a[i]%2:2));
                    dp[i+1][2] = min(dp[i+1][2],dp[i][j]+(a[i]>0?(a[i]+1)%2:1));

                case 2:
                    dp[i+1][2] = min(dp[i+1][2],dp[i][j]+(a[i]>0?(a[i]+1)%2:1));
                    dp[i+1][3] = min(dp[i+1][3],dp[i][j]+(a[i]>0?a[i]%2:2));

                case 3:
                    dp[i+1][3] = min(dp[i+1][3],dp[i][j]+(a[i]>0?a[i]%2:2));
                    dp[i+1][4] = min(dp[i+1][4],dp[i][j]+a[i]);

                case 4:
                    dp[i+1][4] = min(dp[i+1][4],dp[i][j]+a[i]);
                    break;
            }
        }
    }
    ll ans = IINF;
    REP(i,5) ans = min(ans, dp[L][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    ll n;cin>>n;
    string s;cin>>s;
    ll cnt=0;
    rep(i,n){
        if(s[i]=='R')cnt++;
    }
    if(cnt==n||cnt==0){
        cout<<0<<endl;
        return 0;
    }
    priority_queue<ll>r;
    priority_queue<ll,vector<ll>,greater<ll> >w;
    rep(i,n){
        if(s[i]=='W')w.push(i);
        else r.push(i);
    }
    ll ans=0;
    while(r.top()>w.top()){
        ans++;
        ll s=w.top();
        w.pop();
        ll a=r.top();
        r.pop();
        swap(a,s);
        r.push(a);
        w.push(s);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5784
N = int(input())
D1 = []
D2 = []
count = 0
flag = 0
for i in range(N):
    d1, d2 = input().split()
    if int(d1) == int(d2):
        count = count + 1
        if count >= 3:
            flag = 1
    else:
        count = 0
if flag == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9176
N = int(input())

L0 = 2
L1 = 1

i = N
while i-1 > 0:
    Ln = L0 + L1
    i -= 1
    L0 = L1
    L1 = Ln

if N == 0:
    print(2)
elif N == 1:
    print(1)
else:
    print(Ln)

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys

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


NAME = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
DIC = dict(zip(NAME, range(7, 0, -1)))


def main():
    S = readline().rstrip().decode()
    print(DIC[S])


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n = int(input())
hat_list = list(map(int, input().split()))
#print(hat_list)
b_list = []
for h in hat_list:
    #print(format(h,'b').zfill(10))
    b_list.append(format(h,'b').zfill(30))
#print(b_list)
for n in range(30):
    test_list = []
    for b in b_list:
        test_list.append(b[n])
    if test_list.count('1') > 0:
        if test_list.count('1') != test_list.count('0') * 2:
            print("No")
            break
else:
    print("Yes")


Measured memory_bytes: 16644
import sys
from collections import defaultdict
from heapq import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    to = defaultdict(list)
    n, m = map(int, input().split())
    for _ in range(m):
        l, r, c = map(int, input().split())
        l, r = l - 1, r - 1
        to[l].append([r, c])
    for u in range(1, n):
        to[u].append([u - 1, 0])
    costs = [-1] * n
    hp = []
    heappush(hp, [0, 0])
    while hp:
        # print(hp)
        c, u = heappop(hp)
        if u == n - 1:
            print(c)
            # print(costs)
            exit()
        if costs[u] != -1: continue
        costs[u] = c
        for v, dc in to[u]:
            if costs[v] != -1: continue
            heappush(hp, [c + dc, v])
    print(-1)

main()


Measured memory_bytes: 61832
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

pair<string, int> gs(const string& s, int i) {
  string res = "";
  if (i == (int)s.size()) return make_pair(res, i);
  if('0' <= s[i] && s[i] <= '9') {
    int v = 0;
    while('0' <= s[i] && s[i] <= '9') {
      v *= 10;
      v += s[i] - '0';
      ++i;
    }
    if (s[i] == '(') {
      string ss;
      int j;
      tie(ss, j) = gs(s, i+1);
      REP(k,v) {
        if (res.size() > 1100000) break;
        res += ss;
      }
      i = j+1;
    } else {
      res += string(v, s[i]);
      ++i;
    }
  } else {
    res += s[i];
    ++i;
  }
  if (i == (int)s.size()) return make_pair(res, i);
  if (s[i] != ')') {
    string ss;
    int j;
    tie(ss, j) = gs(s,i);
    if (res.size() <= 1100000)
      res += ss;
    i = j;
  }
  return make_pair(res, i);
}

int main() {
  while(1){
    string s;
    int i;
    cin>>s>>i;
    if(s=="0"&&i==0) break;
    string h1e6 = gs(s, 0).first;
    if (i >= (int)h1e6.size()) cout << "0" << endl;
    else cout << h1e6[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 8148
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int count = 1;
		int s = 7;
		
		if(k % 2 == 0 || k % 5 == 0){
			System.out.println("-1");
		}else if(k == 1 || k == 7){
        	System.out.println("1");
        }else{
			while(count <= k){
				if(s % k == 0){
					System.out.println(count);
					break;
				}
				count++;
				s = ((s * 10) + 7) % k;
				
			}
		}
	}
}

Measured memory_bytes: 35592
s = input()

def palind(word):
    l = len(word)
    i=0
    j=l-1 
    while i <= j:
        if word[i] != word[j]:
            return False
        i += 1
        j -= 1
    return True

n = len(s)

if palind(s) and palind(s[:(((n-1)//2))]) and palind(s[(((n+3)//2)-1):]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
N = int(input())
D = {i: [0] for i in range(N)}
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].append(b-1)
  D[a-1][0] += 1
  D[b-1].append(a-1)
  D[b-1][0] += 1
m = 0
nod = -1
for i in D:
  if m < D[i][0]:
    m = D[i][0]
    nod = i
c = list(map(int, input().split()))
c.sort(reverse=True)
pnt = 0
cnt = 1
p = [nod]
L = [-1 for _ in range(N)]
L[nod] = c[0]
while cnt < N:
  n = cnt
  for i in range(pnt, cnt):
    for j in range(1, D[p[i]][0]+1):
      if L[D[p[i]][j]] == -1:
        L[D[p[i]][j]] = c[cnt]
        cnt += 1
        p.append(D[p[i]][j])
  pnt = n
S = 0
for i in D:
  for j in range(1, D[i][0]+1):
    S += min(L[i], L[D[i][j]])
print(S//2)
for i in range(N):
  print(L[i], end = ' '*(i != N - 1))
print()

Measured memory_bytes: 12508
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vl vector<long long>
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define all(x) (x).begin(),(x).end()
const long long INF=2305843009213693951;

struct WarshallFloyd{
    int V;
    vector<vector<long long>> d;
    WarshallFloyd(int n){
        start(n);
    }
    void start(int x){
        V=x;
        vector<vector<long long>> e(x,vector<long long>(x,INF));
        for(int i=0;i<x;i++){
            e[i][i]=0;
        }
        swap(d,e);
    }
    void add1(int x,int y,long long c){
        d[x][y]=c;
    }
    void add2(int x,int y,long long c){
        d[x][y]=c;
        d[y][x]=c;
    }
    void build(){
        for(int k=0;k<V;k++){
            for(int i=0;i<V;i++){
                for(int j=0;j<V;j++){
                    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
                }
            }
        }
    }
    long long dist(int x,int y){
        return d[x][y];
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,m,r;
    cin>>n>>m>>r;
    vl R(r);
    rep(i,r)cin>>R[i];
    sort(all(R));
    WarshallFloyd G(n);
    rep(i,m){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G.add2(a,b,c);
    }
    G.build();
    ll res=INF;
    do{
        ll co=0;
        rep(i,r-1){
            co+=G.dist(R[i]-1,R[i+1]-1);
        }
        res=min(res,co);
    }while(next_permutation(all(R)));
    cout<<res<<endl;
}

Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int K, M;
  cin >> K >> M;
  int arr[M], temp, maximum = 0;
  for (int i = 0; i < M; i++){
    cin >> temp;
    arr[i] = ((temp > K / 2)? temp - K : temp);
  }
  sort(arr, arr + M);
  for (int i = 1; i < M; i++)
    if (arr[i] - arr[i - 1] > maximum)
      maximum = arr[i] - arr[i - 1];
  cout << min(K - maximum, arr[M - 1] - arr[0]);
  return 0;
}


Measured memory_bytes: 4432
from collections import defaultdict
from itertools import accumulate
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))

A_acc = [0]+list(accumulate(A))


ans = 0
D = defaultdict(int)
for l in range(N+1):
    t = (A_acc[l]-l) % K
    if l>=K:
      r = (A_acc[l-K]-(l-K))
      D[r%K]-=1
    ans += D[t]
    D[t] += 1


print(ans)


Measured memory_bytes: 105548
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7
    from collections import defaultdict
    A = XLMIIS(3)

    exists = defaultdict(lambda : False)

    N = II()
    for _ in range(N):
        exists[II()] = True
    

    #上横、中横、下横
    for i in range(3):
        if exists[A[i][0]] and exists[A[i][1]] and exists[A[i][2]]:
            print('Yes')
            return
    #左縦、中縦、右縦
    for i in range(3):
        if exists[A[0][i]] and exists[A[1][i]] and exists[A[2][i]]:
            print('Yes')
            return
    #ナナメ
    if exists[A[0][0]] and exists[A[1][1]] and exists[A[2][2]]:
        print('Yes')
        return
    if exists[A[0][2]] and exists[A[1][1]] and exists[A[2][0]]:
        print('Yes')
        return
    print('No')
    return 
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, k;
	cin >> n >> k;
	vi a(n);
	rep(i, n) cin >> a[i];
	int tot = n;
	int ans = 1;
	tot -= k;
	ans += (tot + k - 2) / (k - 1);
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 640