akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define inputv(arr,n) for(ll i=0;i<n;i++){ll value;cin>>value;arr.pb(value);}
#define sz(a) ((ll)(a).size())
#define len(a) ((ll)(a).length())
#define F first
#define S second
#define vi vector <int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
#define nl cout<<"\n"
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
// hashing for pairs
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
//sort in reverse order
bool compare(ll x, ll y){
    return x>y;
}
void solve()
{
  ll n,k;
  cin>>n>>k;
  vl arr;
  inputv(arr,n);
  sort(all(arr));
  ll sum=0;
  for (ll i = 0; i < k; i++)
  {
    sum+=arr[i];  }
  cout<<sum;nl;
  return;
}
int main()
{
    IOS;
    int T=1;
   // cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3840
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := Scan()
	x := 0
	for _, v := range n {
		x += stringToInt(string(v))
	}
	if x%9 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 2432
CHARACTER(200) S
INTEGER N
READ*,S
N = LEN_TRIM(S)/2
DO I=1, LEN_TRIM(S)/2
  N=N-1
  IF (S(1:N)==S(N+1:2*N)) THEN
    PRINT"(I0)",N*2
    STOP
  ENDIF
ENDDO
END

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

const int MOD = 1000000007;

int f[100][3][3];

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

    string mp[2];
    cin >> mp[0];
    cin >> mp[1];

    vector<int> v;

    for (int i = 0; i < n; ) {
        if (mp[0][i] == mp[1][i]) {
            v.push_back(0);
            ++i;
        } else {
            v.push_back(1);
            i += 2;
        }
    }

    n = v.size();

    if (v[0] == 0) {
        f[0][0][0] = 1;
        f[0][1][1] = 1;
        f[0][2][2] = 1;
    } else {
        f[0][0][1] = 1;
        f[0][1][0] = 1;
        f[0][1][2] = 1;
        f[0][2][1] = 1;
        f[0][0][2] = 1;
        f[0][2][0] = 1;
    }

    for (int i = 1; i < n; ++i) {
        if (v[i] == 0) {
            for (int j = 0; j < 3; ++j) {
                for (int j1 = 0; j1 < 3; ++j1) {
                    for (int j2 = 0; j2 < 3; ++j2) {
                        if (j != j1 && j != j2)
                            f[i][j][j] = (f[i][j][j] + f[i - 1][j1][j2]) % MOD;
                    }
                }
            }
        } else {
            for (int j1 = 0; j1 < 3; ++j1)
                for (int j2 = 0; j2 < 3; ++j2)
                    for (int pj1 = 0; pj1 < 3; ++pj1)
                        for (int pj2 = 0; pj2 < 3; ++pj2) {
                            if (j1 != j2 && j1 != pj1 && j2 != pj2) {
                                f[i][j1][j2] = (f[i][j1][j2] + f[i - 1][pj1][pj2]) % MOD;
                            }
                        }
        }
    }

    int ans = 0;
    for (int i1 = 0; i1 < 3; ++i1)
        for (int i2 = 0; i2 < 3; ++i2)
            ans = (ans + f[n - 1][i1][i2]) % MOD;

    cout << ans << endl;
}

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

int hantei(int data){
  int i = 3;
  if(data == 2){
    return 1;
  }
  if(data < 2 || data % 2 == 0){
    return 0;
  }
  while(i <= sqrt(data)){
      if(data % i == 0){
        return 0;
      }
      i = i + 2;
  }
return 1;
}

int main(void){
   int data;
   int num,i;
   int sum=0;
   while(1){
      scanf("%d",&num);
      if(num >= 1 && num <= 10000){
        break;
      }
   }

  for(i = 0 ; i < num ; i++){
     while(1){
     scanf("%d",&data);
     if(data >= 2 && data <= 100000000){
       break;
     }
     }
     sum += hantei(data);
  }
   printf("%d\n",sum);
   return 0;
}



Measured memory_bytes: 2124
def e_payment():
    N = input()

    dp = (0, 1)  # 「最下位桁の 1 つ下の桁」を仮想した場合分けを省くための初期化
    for k, ch in enumerate(N[::-1]):  # 最下位の桁から見る
        n = int(ch)
        t1, t2 = dp
        a = min(t1 + n, t2 + n + 1)
        b = min(t1 + (10 - n), t2 + (10 - (n + 1)))
        dp = (a, b)
    return min(dp[0], dp[1] + 1)

print(e_payment())

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

int main()
{
	int x, y;
	cin >> x >> y;
	int ax2 = 4 * x - y;
	int bx2 = y - 2 * x;
	if(ax2 % 2 == 0 && ax2 >= 0 && bx2 % 2 == 0 && bx2 >= 0){
		cout << "Yes " << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

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

#define ll long long

int main()
{
    ll A, B, C, K;
    std::cin >> A >> B >> C >> K;

    ll sum = 0;

    if(K <= A) {
        sum = K;
    }
    else if(K <= A+B) {
        sum = A;
    }
    else {
        sum = A;
        ll tmp = K - (A+B);
        sum  = sum - tmp;
    }

    std::cout << sum << std::endl;
}

Measured memory_bytes: 3568
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        l: i64
    }

    let mut m = std::i64::MAX;
    let mut mi = 0;
    for i in 1..n as i64+1 {
        if m > i64::abs(l + i - 1) {
            m = i64::abs(l+i-1);
            mi = i;
        }
    }

    let mut sum = 0;
    for i in 1..n as i64+1 {
        if mi != i {
            sum += l+i-1;
        }
    }
    println!("{}", sum);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <assert.h>
#include <stdlib.h>

using namespace std;

#define MOD 1000000007

const int INF = 1e9;

typedef long long ll;
typedef pair<int, int> pii;
int n,h;
int dp[(ll)1e3+1][(ll)1e4+1];
int a[(ll)1e3+1];
int b[(ll)1e3+1];

int f(int i , int health) {
    if(health <= 0) return 0;
    if(i >= n) return INF;
    int &ret = dp[i][health];
    if(ret != -1) return ret;
    
    ret = min(b[i] + f(i+1, health - a[i]), b[i] + f(i, health - a[i]));
    ret = min(ret, f(i+1, health));

    return ret;

}
int main() {
    // oh hi mark
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp, -1, sizeof dp);

    cin >> h >> n;
    for(int i = 0;i < n; i++) {
        cin >> a[i] >> b[i];
    }
    cout << f(0, h);
    
    return 0;
}


Measured memory_bytes: 40064
#include <iostream>

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

using namespace std;

int main(){
    string strN,res;
    cin >> strN;

    ll N;
    N = stoi(strN);

    ll wa = 0;
    //10^8は最大9桁

    for(char a: strN)
    {
        wa += a - '0';
    }

    if(N % wa == 0)res = "Yes";
    else res = "No";

    cout << res << endl;

}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int r, d, x, a;
    cin >> r >> d >> x;
    a=r*x-d;
    cout << a << '\n';
    for(int i=0; i<9; i++)
    {
        a=r*a-d;
        cout << a << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
S = [0]
T = [0]
for i in range(N):
    S.append((p[i]+1)/2 + S[-1])

for i in range(N+1-K):
    T.append(S[i+K]-S[i])

print(max(T))

Measured memory_bytes: 24548
#include <bits/stdc++.h>
#define long long long
using namespace std;
const int N = 2e5+1;

int n, k, f[N];
long ans;
int main() {
	cin >> n >> k;
	for(int i = 0; i < k; i++) f[i] = n / k;
	int mod = n % k;
	for(int i = 1; i <= mod; i++) ++f[i];
	for(int i = 0; i < k; i++) if(2*i % k == 0) ans += 1ll * f[i] * f[i] * f[i];
	cout << ans;
}

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

int main(){
	
	int N,k;
	int x,y;
	
	cin >> N >> k ;
	while( k-- ){
		cin >> x >> y ;
		
		if( N/2+N%2 < x ) x = N+1-x ;
		if( N/2+N%2 < y ) y = N+1-y ;
		
		if( x < y ){
			  cout << (x-1)%3+1 << endl ;
		}else cout << (y-1)%3+1 << endl ;
	}
}

Measured memory_bytes: 1160
def solve(A, B):
    t = 0
    s = 0
    for a, b in zip(A, B):
        if a > b:
            s += a - b
        if b > a:
            x = b - a
            t += x // 2
    if s <= t:
        return True
    else:
        return False

N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

if solve(A, B):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 4600
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
vl spf;
map<ll,ll> mp(ll n){ // nの素因数分解を求める
        map<ll, ll> m;
        while (n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        return m;
}
int main(){
  ll N;cin>>N;
  ll tot=0;
  vl spff(N+1);
  rep(i,N+1)spff[i]=i;
  spf =spff;
  for(int i=2; i*i<=N;i++){
    if(spf[i]==i){
      for(int j=i*i;j<=N;j+=i){
        if(spf[j]==j){
          spf[j]=i;
        }
      }
    }
  }
  for(ll i=2;i<=N;i++){
    ll cnt=1;
    for(auto p:mp(i)){
       cnt*= (ll)p.second +1LL;
 
    }
    tot += (ll)i*cnt;
  }
  cout<<tot+1<<endl;
 

}








Measured memory_bytes: 159564
#include<bits/stdc++.h>
using namespace std;
int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string str;
    cin>>str;
    int n=str.size()-1,counter=0;
    for(int i=0;i<str.size()/2;i++)
    {
       if(str[i]!=str[n--])
          counter++;
    }
    cout<<counter<<"\n";




    return 0;
}



Measured memory_bytes: 256
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,x]=i2()
a=i2()
a.sort()
b=0
for i in range(n):
 x-=a[i]
 if x<0:
    break
 b+=1
if x>0 and b==n:
   print(b-1)
else:
   print(b)

Measured memory_bytes: 38512
#include <iostream>

using namespace std;

char board[101][101] = {{0}};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> board[i][j];
    }
  }
  for (int i = 0; i < H + H; ++i) {
    for (int j = 0; j < W; ++j) {
      printf("%c", board[i / 2][j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

struct state {
  int cost, use, pos;
  state(int c, int u, int p) : cost(c), use(u), pos(p){}
};

vector<int> bfs(vector<vector<pair<int, bool>>>& G, int s, int t, int& shortestLen) {
  vector<int> dist(G.size(), inf), d2cnt(G.size()+1);
  dist[s] = 0;

  queue<state> q;
  q.emplace(0, 0, s);

  while(!q.empty()) {
    const state s = q.front(); q.pop();
    d2cnt[s.cost]++;
    for(auto& e: G[s.pos]) {
      const int next = e.first;
      if(dist[next] > s.cost + 1) {
        dist[next] = s.cost + 1;
        q.emplace(dist[next], 0, next);
      }
    }
  }

  shortestLen = dist[t];
  return move(d2cnt);
}

int main() {

  int N, M, s, t; cin >> N >> M >> s >> t; s--, t--;
  vector<vector<pair<int, bool>>> G(N);
  rep(i, M) {
    int x, y; cin >> x >> y;
    G[x-1].emplace_back(y-1, false);
    G[y-1].emplace_back(x-1, false);
  }

  int shortestLen;
  auto && d2cnt1 = bfs(G, s, t, shortestLen);
  auto && d2cnt2 = bfs(G, t, s, shortestLen);

  ll ans = 0;

  rep(i, N) {
    if(shortestLen-i-2 >= 0)
      ans += (ll)d2cnt1[i] * d2cnt2[shortestLen-i-2];
  }

  cout << ans << endl;

  return 0;
}

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

struct node{
	int key;
	struct node *next;
	struct node *prev;
};

typedef struct node *NodePointer;

NodePointer nil;

void init(){
	nil = malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
}

void deleteNode(NodePointer t){
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void insert(int key){
	NodePointer x;
	x = malloc(sizeof(struct node));
	x->key = key;
	x->next = nil->next;
	x->prev = nil;
	x->next->prev = x;
	nil->next = x;
}

void deleteFirst(){
	NodePointer t = nil->next;
	if(t == nil){
		return;
	}
	deleteNode(t);
}

int main(int argc, char **argv)
{
	int key, i = 0;
	int size = 0;
	char com[100];
	int ans = 0;

	init();
	NodePointer t = nil->next;

	while(scanf("%s", com) != EOF){
		
		if(com[0] == '+'){
			ans = t->next->key + t->key;
			deleteNode(t->next);
			t->key = ans;
		}
		else if(com[0] == '-'){
			ans = t->next->key - t->key;
			deleteNode(t->next);
			t->key = ans;
		}
		else if(com[0] == '*'){
			ans = t->next->key * t->key;
			deleteNode(t->next);
			t->key = ans;
		}
		else{
			insert(atoi(com));
		}
		t = nil->next;
	}
	printf("%d\n", t->key);
	deleteFirst();
	return 0;
}








Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define t_case ll test;cin>>test;while(test--)
#define left(nod) 2*nod
#define right(nod) 2*nod+1
#define ss second
#define ff first
#define pb push_back
#define pll pair<ll,ll>
#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define deb(a) cout<<#a<<": "<<a;cout<<endl;
#define deba(a) cout<<#a<<": ";for(auto it:a)cout<<it<<" ";cout<<endl;

ll mod(ll n,ll k)
{
	if(n==0)return 1;
	
	ll te=mod(n/2,k);
	
	if(n&1)return (te*te*10)%k;
	else return (te*te)%k;
}
	


int main()
{
	FAST;
	
	ll k;cin>>k;
	
	ll prev=0;
	
	for(ll i=1;i<=1000009;i++)
	{
		ll mo = ((mod(i-1,k)+prev))%k;
		prev=mo;
		mo=(mo*7)%k;
		
		if(mo==0){cout<<i;exit(0);}
		
	}
	cout<<-1;
	
}


Measured memory_bytes: 3688
//  main.cpp
//  DPT5
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod = 1e9+7;
// mint
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
//istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[3010][3010]={};
mint sum[3010][3010]={};
int main(int argc, const char * argv[]) {
    int n;
    cin>>n;
    string s;
    cin>>s;
    // i桁目を決めたとき、その数より大きな数がj個残る数 dp[i][j]
    // １桁目として１を選べば、2,3,4の3つが残る　dp[1][3]=1;
    // １桁目として２を選べば、3,4の2つが残る　dp[1][2]=1;
    // １桁目として３を選べば、dp[1][1]=1;
    // １桁目として４を選べば、dp[1][0]=1;
    rep(j,n){
        dp[1][j]=1;
        sum[1][j]=j+1;
    }
    for (int i=2; i<=n; i++) {
        if(s.at(i-2)=='<'){
            for (int j=n-i; j>=0; j--) {
                /*
                                for (int j=0; j<=n-i; j++) {
                                    for(int k=j+1;k<=n-i+1;k++){
                                    dp[i][j]+=dp[i-1][k];
                                    }
                                }
                            */
                // 累積和を使うとループを減らすことができた
                dp[i][j]=dp[i-1][j+1]+sum[i][j+1];
                sum[i][j]=dp[i][j];
            }
        } else {
            for (int j=0; j<=n-i; j++) {
                /*
                                for (int k=0; k<=j; k++) {
                                    dp[i][j]+=dp[i-1][k];
                                }
                            */
                // 累積和を使うとループを減らすことができた
            if(j==0) {
                dp[i][j]=sum[i-1][j];
                sum[i][j]=dp[i][j];
            } else {
                dp[i][j]=sum[i][j-1]+dp[i-1][j];
                sum[i][j]=dp[i][j];
                }
            }
        }
    }
        cout << dp[n][0]<<endl;
    return 0;
}


Measured memory_bytes: 95508
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    int x = 0;
    rep(i, n) {
        if (s[i] == 'I'){
            x++;
            ans = max(ans, x);
        }else{
            x--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.length();i++)
	{
		char k=s[0];
	    for(int j=1;j<s.length();j++)
		s[j-1]=s[j];
	    s[s.length()-1]=k;
	    if(s==t)
		{
		cout<<"Yes";
		return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> x(n),y(n);
  for(Int i=0;i<n;i++) cin>>x[i]>>y[i];
  auto NO=[](){cout<<-1<<endl;exit(0);};
  for(Int i=0;i<n;i++)
    if(abs(x[0]+y[0]+x[i]+y[i])&1) NO();
  
  vector<Int> d;
  for(Int i=0;i<35;i++)
    d.emplace_back(1LL<<i);

  d.emplace_back(1);
  if(abs(x[0]+y[0])&1) d.emplace_back(1);
  
  sort(d.rbegin(),d.rend());
  
  Int m=d.size();
  cout<<m<<endl;
  for(Int i=0;i<m;i++){
    if(i) cout<<" ";
    cout<<d[i];
  }
  cout<<endl;

  for(Int i=0;i<n;i++){
    string s(m,'#');
    Int u=x[i]+y[i],v=x[i]-y[i];
    for(Int j=0;j<(Int)d.size();j++){      
      if(u>=0&&v>=0){
	u-=d[j];
	v-=d[j];
	s[j]='R';
      }else if(u>=0&&v<0){
	u-=d[j];
	v+=d[j];
	s[j]='U';	
      }else if(u<0&&v>=0){
	u+=d[j];
	v-=d[j];
	s[j]='D';
      }else if(u<0&&v<0){
	u+=d[j];
	v+=d[j];
	s[j]='L';	
      }else{
	assert(0);
      }
    }    
    cout<<s<<endl;
  }
  
  return 0;
}


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

int main() {


    int n, x; cin >> n;
    map<int,int>mp, np;
    for( int i = 0 ; i < n ; ++i ){
        cin >> x;
        ++mp[x];
    }
    vector<int>v;
    for( auto it: mp ){
        v.push_back(it.second);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for( int i = 0 ; i < v.size() ; ++i ){
        if( v[i] > 2 ){
            v[i]-=2;
            i--;
        }
        else{ if( v[i] > 1 ){
            v[i]--;
            vector<int>k =v;
            for( int j = 0 ; j < v.size() ; ++j ){
                if( v[j] > 1 ){
                    v[j]--;
                    goto g;
                }
            }
            for( int j = 0 ; j < v.size() ; ++j ){
                if( v[j] ){
                    v[j]--;
                    goto g;
                }
            }
            g:;
            i--;
        }}

    }
    int cont = 0;
    for( int i = 0 ; i < v.size() ; ++i ){
        if( v[i] ) cont++;
    }
    cout << cont << '\n';
}


Measured memory_bytes: 5628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H;
		int W;

		while (true) {
			H = sc.nextInt();
			W = sc.nextInt();

			if (H == 0 && W == 0)
				break;

			printRectangle(H, W);

		}

	}

	public static void printRectangle(int H, int W) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				System.out.print("#");

				if (j == (W - 1))
					System.out.println("");
			}
		}
		System.out.println();
	}

}

Measured memory_bytes: 32404
use proconio::{input, fastout};
use std::cmp::*;

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

#[fastout]
fn main() {
    input!{
        x1: i64,
        y1: i64,
        x2: i64,
        y2: i64,
    }

    let x3 = x2 - y2 + y1;
    let y3 = x2 - x1 + y2;
    let x4 = x1 - y2 + y1;
    let y4 = y1 + x2 - x1;

    println!("{} {} {} {}", x3,y3,x4,y4);

}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a > b) {
    int a1,a2;
    a1 = a;
    a2 = b;
    a = a2;
    b = a1;
  }
  if (b > c){
    int a1,a2;
    a1 = b;
    a2 = c;
    b = a2;
    c = a1;
  }
    if (a > b) {
    int a1,a2;
    a1 = a;
    a2 = b;
    a = a2;
    b = a1;
  }

  cout << a << " "<< b << " " << c << endl;
  return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <utility>
#include <map>

int main() {
    long long n, m, ret = 0, sum = 0, a;
    std::cin >> n >> m;
    std::map<long long, long long> s;
    
    s[0]++;
    for (auto i = 0ll; i < n; i++) {
        std::cin >> a;
        sum += a;
        s[sum % m]++;
    }

    for (auto it = s.begin(); it != s.end(); it++) {
        if (it->second > 1) ret += it->second * (it->second - 1) / 2;
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 4224
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = min(A) + min(B)

for i in range(m):
    x, y, c = map(int, input().split())
    ans = min(ans, A[x-1]+B[y-1]-c)

print(ans)


Measured memory_bytes: 18736
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define s(x, n) memset(x, n, sizeof(x));
#define pb(x) push_back(x)
#define NIL -1
#define MAXN 11

void solve()
{
    ll n;
    cin >> n;
    pair<ll, ll> p[n];
    for (int i = 0; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;
        p[i].first = x + y;
        p[i].second = x - y;
    }
    ll x1 = INT_MIN, x2 = INT_MAX;
    ll y1 = INT_MIN, y2 = INT_MAX;
    for (int i = 0; i < n; i++)
    {
        x1 = max(p[i].first, x1);
        x2 = min(p[i].first, x2);
        y1 = max(p[i].second, y1);
        y2 = min(p[i].second, y2);
    }
    cout << max(abs(x1 - x2), abs(y1 - y2)) << "\n";
}
int main()
{
#ifdef WIN32
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

#ifndef WIN32
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#endif
    int t;
    t = 1;
    /// cin >> t;
    for (int I = 1; I <= t; I++)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 6784
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
x=(a1-b1)*t1
y=(a2-b2)*t2
if x+y==0:
  print('infinity')
elif x*(x+y)>0:
  print(0)
else:
  k=x//(-x-y)
  if x%(-x-y)==0:
    print(k*2)
  else:
    print(k*2+1)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,dp[100005],h[100005];
int main(void){
    scanf("%lld",&n);
    for(int i=0;i<n;i++)scanf("%lld",h+i);
    for(int i=0;i<=n;i++)dp[i]=INF;
    dp[0]=0;
    for(int i=0;i<n-1;i++){
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    }
    printf("%lld\n",dp[n-1]);
}


Measured memory_bytes: 1792
target_word = raw_input()
text = ''
while True:
    raw = raw_input()
    if raw == "END_OF_TEXT":
        break
    text += raw.strip('.') + ' '

# ans = 0
print(text.lower().split().count(target_word))
# for word in text.lower().split():
#     if word == target_word:
#         ans += 1
# print(ans)

Measured memory_bytes: 6396
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
float polydiagonal(float n, float a) 
{ 
  
  
    if (a < 0 && n < 0) 
        return -1; 
  
   
    return 2 * a * sin((((n - 2) * 180) / (2 * n)) * 3.14159 / 180); 
}

void solve()
{
  int k ;
  cin>>k ; 
  string s ; 
  cin>>s ; 
  if(s.length()<=k){
  	cout<<s;
  }
  else{
  	rep(i,k)cout<<s[i];
  	cout<<"...";

  }
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3804
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

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

const int MAX_N = 110;
const int MAX_W = 100010;
int N, W;
vector<pii> WV;
ll dp[MAX_N][MAX_W];
void init()
{
    for (int i = 0; i < MAX_N; i++)
    {
        for (int j = 0; j < MAX_W; j++)
        {
            dp[i][j] = -1;
        }
    }
}
int main()
{
    cin >> N >> W;
    for (int i = 0; i < N; i++)
    {
        int w, v;
        cin >> w >> v;
        WV.emplace_back(mp(w, v));
    }
    ll result = 0;
    for (int i = 0; i < N; i++)
    {
        int w, v;
        tie(w, v) = WV[i];
        for (int j = 0; j <= W; j++)
        {
            if (dp[i][j] == -1)
            {
                continue;
            }
            if (j + w <= W)
            {
                dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v);
            }
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }
    for (int i = 0; i < MAX_N; i++)
    {
        for (int j = 0; j < MAX_W; j++)
        {
            result = max(result, dp[i][j]);
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 79360
import java.util.*;
	
	
	import java.io.*;
	
	public class Main {
	
		static int n;
		static long memo[][];
		static int p;
		static int pl[][];
		static pair[] a;
		static int k;
	
		public static long dp(int msk, int idx) {
			if (idx == n)
				return 0;
			if (memo[msk][idx] != -1)
				return memo[msk][idx];
			long max = k - (idx - Integer.bitCount(msk)) > 0 ? dp(msk, idx + 1) + a[idx].x : dp(msk, idx + 1);
	
			for (int i = 0; i < p; i++) {
				if (((msk >> i) & 1) == 0) {
					max = Math.max(max, pl[a[idx].y][i] + dp(msk | 1 << i, idx + 1));
				}
			}
			return memo[msk][idx] = max;
	
		}
	
		public static void main(String[] args) throws NumberFormatException, IOException {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			PrintWriter pw = new PrintWriter(System.out);
			String s = br.readLine();
			int n = Integer.parseInt(br.readLine());
			int a[] = new int[n + 1];
			String[] b = new String[n];
			for (int i = 0; i < n; i++) {
				String w = br.readLine();
				int x = w.length();
				if (x == 1) {
					a[i + 1]++;
				}
				b[i] = w;
			}
			a[n] = a[n] % 2;
			for (int i = n - 1; i >= 0; i--) {
				a[i] += a[i + 1];
				a[i] = a[i] % 2;
			}
			if (a[0] == 1)
				s = new StringBuilder(s).reverse().toString();
			StringBuilder sb = new StringBuilder(s);
			Stack<String> v = new Stack<>();
			for (int i = 0; i < b.length; i++) {
				if (b[i].length() == 1)
					continue;
				int t = Integer.parseInt(b[i].charAt(0) + "");
				int w = (Integer.parseInt(b[i].charAt(2) + "") + a[i + 1]) % 2;
				String r = b[i].charAt(4) + "";
				if (w == 0)
					sb.append(r);
				else
					v.add(r);
			}
			while (!v.isEmpty())
				System.out.print(v.pop());
			System.out.println(sb.toString());
		}
	
		static int gcd(int a, int b) {
			if (b == 0)
				return a;
			return gcd(b, a % b);
		}
	
		static class pair {
			int x;
			int y;
	
			pair(int r, int t) {
				x = r;
				y = t;
			}
	
			public String toString() {
				return "(" + x + "," + y + ")";
			}
	
		}
	}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  string s;cin>>s;
  int result=0;

  int l=0, r = s.size()-1;
  while(r>l){
    if(s[l]==s[r]){
      l++;
      r--;
      continue;
    }
    if(s[l]!=s[r]){
      if(s[l]=='x'){
        l++;
        result++;
      }else if(s[r]=='x'){
        r--;
        result++;
      }else{
        cout<<-1<<endl;return 0;
      }
    }
//cout<<l<<' '<<r<<endl;
  }

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 512
from collections import Counter
N = int(input())
dic = []
for _ in range(N):
    s = input()
    dic.append(s)
ans = Counter(dic)
st = ans.most_common(N)

anser = []
max_num = st[0][1]
for a,b in st:
    if max_num == b:
        anser.append(a)

anser.sort()
for i in anser:
    print(i)

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

int main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	int a[n];
	long long tot=1,x=1;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		if(a[i]%2==0) x*=2;
		tot*=3;
	}
	cout<<tot-x<<endl;
	return 0;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
using namespace std;
using ll=int64_t;
using vi=vector<int>;
using VI=vector<ll>;
using vis=vector<string>;
using vvi=vector<vi>;
int main(){
    int l,r,d,ans=0;
    cin>>l>>r>>d;
    for(int i=l;r>=l;++l){
        if(l%d==0)
        ++ans;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-18;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int Nparent[100010], Oparent[100010];
vint edge[100010];
bool visited[100010];
int color[100010];

void dfs(int cur,int p,bool ON) {
	visited[cur] = true;
	(ON ? Nparent[cur] : Oparent[cur]) = p;
	rep(i, edge[cur].size()) {
		int to = edge[cur][i];
		if (!visited[to])	dfs(to, cur, ON);
	}
}

int main() {
	int n;	cin >> n;
	srep(i, 1, n) {
		int a, b;	cin >> a >> b;	a--;	b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	rep(i, n)	visited[i] = false;
	dfs(n - 1, n - 1, true);
	rep(i, n)	visited[i] = false;
	dfs(0, 0, false);
	stack<int> f, s;	f.push(0);	s.push(n - 1);
	color[0] = 1;	color[n - 1] = -1;
	bool turn = true;
	while (true) {
		int pos = (turn ? f.top() : s.top());	(turn ? f.pop() : s.pop());
		if (color[(turn?Nparent[pos]:Oparent[pos])] == 0) {
			color[(turn ? Nparent[pos] : Oparent[pos])] = (turn ? 1 : -1);
			(turn ? f.push(pos) : s.push(pos));
			(turn ? f.push(Nparent[pos]) : s.push(Oparent[pos]));
			turn ^= 1;
			continue;
		}
		bool flag = false;
		rep(i, edge[pos].size()) {
			int to = edge[pos][i];
			if (color[to] != 0)	continue;
			color[to] = (turn ? 1 : -1);
			(turn ? f.push(pos) : s.push(pos));
			(turn ? f.push(to) : s.push(to));
			turn ^= 1;
			flag = true;
			break;
		}
		if (flag)	continue;
		if ((turn ? f.empty() : s.empty())) {
			cout << (turn ? "Snuke" : "Fennec") << endl;
			return 0;
		}
	}
}

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

typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N = 3e5+5;

void solve() {

}

string s, t;
vector<vector<int>> indexes(26);

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

    cin >> s >> t;
    int n = s.size();
    int m = t.size();

    for (int i=0; i<n; i++) {
        indexes[s[i]-'a'].push_back(i);
    }
    for (int i=0; i<m; i++) {
        int c = t[i] - 'a';
        if (indexes[c].empty()) {
            cout << -1;
            return 0;
        }
    }

    int cur = -1;
    ll ans = 0LL;
    for (int i=0; i<m; i++) {
        int c = t[i] - 'a';
        auto it = upper_bound(indexes[c].begin(), indexes[c].end(), cur);
        if (it == indexes[c].end()) {
            ans++;
            cur = indexes[c][0];
        } else {
            cur = *it;
        }
    }

    cout << ans*n + (cur + 1);

    return 0;
}


Measured memory_bytes: 1228
l = []
l.append(int(input()))

def next(i:int):
    if l[i-1]%2 == 0:
        return l[i-1]//2
    else:
        return (3*l[i-1])+1

i = 0
while True:
    i += 1
    if next(i) in l:
        print (i+1)
        exit ()
    else:
        l.append(next(i))

Measured memory_bytes: 3060
// Akshit Awasthi
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define deb(...) cerr << "[" << #__VA_ARGS__ << ": " << (_VA_ARGS__) << "]\n"
#define deb2(x, y) cerr << #x << " = " << x << "\t" << #y << " = " << y << endl
#define fastio                    \
    std::ios::sync_with_stdio(0); \
    std::cin.tie(NULL);           \
    std::cout.tie(NULL)
#define mod1 1000000007
#define mod2 998244353
#define MAX (int)1e3

using namespace std;

void solve() {
    int n;
    cin >> n;
    string s;
    set<string> se;
    while (n--) {
        cin >> s;
        se.insert(s);
    }
    cout << se.size() << '\n';
}

int32_t main(void) {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
    fastio;
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 19204
#include <cstdio>
using namespace std;
int main()
{
	int a, b, c, d, e, f;
	while (scanf("%d%d%d%d%d%d", &a,&b,&c,&d,&e,&f) != EOF) {
		double x, y;
		if (a != 0 && d != 0) {
			y = ((double)c / a - (double)f / d) / ((double)b / a - (double)e / d);
			x = (double)c / a - y * (double)b / a;
		}
		else if (b != 0 && e != 0) {
			x = ((double)c / b - (double)f / e) / ((double)a / b - (double)d / e);
			y = (double)c / b - x * (double)a / b;
		}
		else if (a == 0) {
			y = (double)c / b;
			x = (f - e * y) / (double)d;
		}
		else if (d == 0) {
			y = (double)f / e;
			x = (c - b * y) / (double)a;
		}
		else if (b == 0) {
			x = (double)c / a;
			y = (f - d * x) / (double)e;
		}
		else if (e == 0) {
			x = (double)f / d;
			y = (c - a * x) / (double)b;
		}
		printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

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

using namespace std;

using int64 = long long;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

struct UnionFind {
  vector< int > data;

  UnionFind(int sz) {
    data.assign(sz, -1);
  }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) {
    return (-data[find(k)]);
  }
};


template< typename T >
T kruskal(Edges< T > &edges, int V) {
  sort(begin(edges), end(edges), [](const edge< T > &a, const edge< T > &b) {
    return (a.cost < b.cost);
  });
  UnionFind tree(V);
  T ret = 0;
  for(auto &e : edges) {
    if(tree.unite(e.src, e.to)) ret += e.cost;
  }
  return (ret);
}

int main() {
  int N, X[15], Y[15], A[15];


  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i] >> A[i];
  }
  double dp[1 << 15] = {};
  fill_n(dp, 1 << 15, -1e30);
  for(int i = 1; i < (1 << N); i++) {
    Edges< double > edges;
    int64 sum = 0;
    for(int j = 0; j < N; j++) {
      if((i >> j) & 1) {
        sum += A[j];
        for(int k = j + 1; k < N; k++) {
          if((i >> k) & 1) {
            edges.emplace_back(j, k, hypot(X[j] - X[k], Y[j] - Y[k]));
          }
        }
      }
    }
    dp[i] = (sum - kruskal(edges, N)) / __builtin_popcount(i);
  }

  for(int bit = 0; bit < (1 << N); bit++) {
    for(int i = bit; i > 0; i = (i - 1) & bit) {
      int other = i ^bit;
      dp[bit] = max(dp[bit], min(dp[i], dp[other]));
    }
  }
  cout << fixed << setprecision(12) << dp[(1 << N) - 1] << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=2000+10;
const int inf=0x7fffffff;
int n,m,q;
int N,Ans=inf;
int a[maxn],b[maxn],c[maxn];

inline void file() {
	freopen("ARC098E.in","r",stdin);
	freopen("ARC098E.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

inline int solve(int p) {
	int l=1; N=0;
	For (r,1,n+1) {
		if (a[r]<a[p]) {
			int len=r-l;
			if (len>=m) {
				For (i,l,r-1) b[i-l+1]=a[i];
				sort(b+1,b+len+1);
				For (i,1,len-m+1) c[++N]=b[i];
			}
			if (l) l=r+1;
		}
	}
	sort(c+1,c+N+1);
	if (N<q) return inf;
	return c[q]-a[p];
}

int main() {
//	file();
	n=read(); m=read(); q=read();
	For (i,1,n) a[i]=read();
	For (i,1,n) chkmin(Ans,solve(i));
	printf("%d",Ans);
	return 0;
}

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

int main(void){
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); ++i){
		if(s[i]=='9') s[i]='1';
		else s[i] = '9';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
program String_Formation
    implicit none
    character(100000):: s
    character(1):: fs(200000), bs(200000), ss(300000)
    character(5):: cq
    integer(4):: q
    integer(4):: i, fi, bi
    logical:: flip

    flip = .false.

    read*, s
    read*, q

    fi=0
    bi=0

    do i=1, q
        read(*,'(5a)') cq
        if (cq(1:1) == '1') then
            flip = .not. flip
            cycle
        end if

        if (cq(3:3) == '1' .neqv. flip) then
            fi=fi+1
            fs(fi) = cq(5:5)
        else
            bi=bi+1
            bs(bi) = cq(5:5)
        end if
    end do

    do i=1, len_trim(s)
        ss(i) = s(i:i)
    end do



    if (flip) then
        print*, bs(bi:1:-1) , ss(len_trim(s):1:-1) , fs(1:fi)
    else
        print*, fs(fi:1:-1) , ss(1:len_trim(s)) , bs(1:bi)
    end if
end program String_Formation

Measured memory_bytes: 1444
#include <iostream>
#include <vector>

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

using namespace std;

int dp[101][10001];

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

  int v[N + 1], w[N + 1];
  for (int i = 1; i <= N; ++i) cin >> v[i] >> w[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) {
      dp[i][j] = dp[i - 1][j];
      if (j - w[i] < 0) continue;
      dp[i][j] = max(dp[i][j],
                     max(dp[i - 1][j - w[i]] + v[i], dp[i][j - w[i]] + v[i]));
    }
  }

  // rep(i, N + 1) {
  //   rep(j, W + 1) cout << dp[i][j] << " ";
  //   cout << '\n';
  // }

  cout << dp[N][W] << '\n';

  return 0;
}



Measured memory_bytes: 7048