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


using namespace std;


using ll = long long;


int main() {
    ll N, T;
    cin >> N >> T;
    vector<pair<ll, ll>> foods(N + 1);
    for (ll i = 0; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        foods[i + 1] = make_pair(a, b);
    }

    vector<vector<ll>> dp1(N + 2, vector<ll>(T + 1, 0));
    vector<vector<ll>> dp2(N + 2, vector<ll>(T + 1, 0));

    for (ll n = 1; n <= N; n++) {
        for (ll t = 0; t < T; t++) {
            dp1[n][t] = max(
                            dp1[n - 1][t],
                            t - foods[n].first >= 0 ? dp1[n - 1][t - foods[n].first] + foods[n].second : 0
                    );
        }
    }

    for (ll n = N; n >= 1; n--) {
        for (ll t = 0; t < T; t++) {
            dp2[n][t] = max(
                            dp2[n + 1][t],
                            t - foods[n].first >= 0 ? dp2[n + 1][t - foods[n].first] + foods[n].second : 0
                    );
        }
    }

    vector<ll> score(N + 1, 0);
    for (ll n = 1; n <= N; n++) {
        for (ll t = 0; t < T; t++) {
            score[n] = max(score[n], dp1[n - 1][t] + dp2[n + 1][T - t - 1] + foods[n].second);
        }
    }

    ll ans = *max_element(score.begin(), score.end());
    cout << ans << endl;
}


Measured memory_bytes: 141312
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
    ll h;
    cin >> h;
    ll co = 0;
    while (h > 1)
    {
        co++;
        h /= 2;
    }
    cout << ll(pow(2, co) * 2 - 1) << endl;
}

Measured memory_bytes: 256
#![allow(unused)]
use io::*;
use std::collections::HashMap;

fn main() {
    let buf = read_string();
    let mut sc = Scanner::new(&buf);

    let (n, m, q): (usize, usize, usize) = (sc.next(), sc.next(), sc.next());

    let mut cnt: Vec<Vec<_>> = vec![vec![0usize; n + 1]; n + 1];
    for _ in 0..m {
        let (l, r): (usize, usize) = (sc.next(), sc.next());
        cnt[l][r] += 1;
    }

    cnt = (0..n + 1)
        .map(|i| {
            let mut sum = 0usize;
            cnt[i]
                .iter()
                .map(|c| {
                    sum += *c;
                    sum
                }).collect()
        }).collect();

    for _ in 0..q {
        let (l, r): (usize, usize) = (sc.next(), sc.next());
        let ans: usize = (l..r + 1).map(|i| cnt[i][r] - cnt[i][l - 1]).sum();
        println!("{}", &ans);
    }
}

pub mod io {
    use std;
    use std::io::Read;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(buf: &'a String) -> Scanner<'a> {
            Scanner {
                iter: buf.split_whitespace(),
            }
        }

        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            s.parse().ok().expect("cannot parse string")
        }

        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).ok().unwrap();
        buf
    }

    fn read_line<T: std::str::FromStr>() -> T {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim().parse().ok().unwrap()
    }

    fn read_vec<T: std::str::FromStr>() -> Vec<T> {
        read_line::<String>()
            .split_whitespace()
            .map(|e| e.parse().ok().unwrap())
            .collect()
    }
}


Measured memory_bytes: 13048
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
int vis[N];

int main() {
  int x, n; cin >> x >> n;
  int dd = inf, it = -1;
  for (int i = 0; i < n; i++ ) {
    int p;
    cin >> p;
    vis[p+1000] = 1;
  }
  for (int i = 0;; i++) {
    if (!vis[x-i+1000]) {
      cout << x-i << endl;
      return 0;
    }
    if (!vis[x+i+1000]) {
      cout << x+i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] P = new int[N];
		int[] A = new int[N+1];
		for(int i = 0;i < N;++i) {
			P[i] = Integer.parseInt(sc.next());
			A[P[i]] = i+1;
		}
		sc.close();
		TreeSet<Integer> set = new TreeSet<>();
		set.add(0);
		set.add(N+1);
		set.add(A[N]);
		long sum = 0;
		for(int i = N-1;i >=1;--i) {
			int Xi = A[i];
			long y = set.higher(Xi);
			long z = y < N+1 ? set.higher((int)y) : N+1;
			long x = set.lower(Xi);
			long w = x != 0 ? set.lower((int)x) : 0;
			long C = (x - w)*(y - Xi)+(Xi - x)*(z - y);
			sum += C * i;
			set.add(Xi);
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 50240
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int k,x; cin>>k>>x;
	rep(i,-k+1,k){
		cout<<i+x<<" ";
	}
	
	return 0;
}

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

int main() {
    char b;
    cin >> b;
    string ans;
    if (b == 'A') ans = 'T';
    if (b == 'T') ans = 'A';
    if (b == 'G') ans = 'C';
    if (b == 'C') ans = 'G';
    cout << ans << endl;
    return 0;
}

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

using namespace std;
int a[100005],dp[100005],i,j,k,n;
const int inf=1e9+5;
int main()
{
    cin>>n>>k;
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
        dp[i]=inf;
    }
    dp[1]=0;
    for(i=1; i<=n; i++)
        for(j=i+1; j<=i+k; j++)
          dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
        cout<<dp[n];
            return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<math.h>
#include<x86intrin.h>


int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

void InputIntAry(int *a,int nDigit,int N){      //nDigitは想定される最大桁数
    char *buf,*ptr;

    buf=(char*)malloc( (N*(nDigit+2)) * sizeof(char) );
    my_gets(buf,N*(nDigit+2),stdin);

    ptr=strtok(buf," ");
    while(ptr!=NULL && N-->0){
        *(a++)=atoi(ptr);
        ptr=strtok(NULL," ");
    }
    free(buf);
}

int CmpInt(const void *a, const void *b){        //b-aを返す(qsortなら4321)
    return *((int*)b)- *((int*)a);
}

int CmpChpt(const void *a, const void *b){
    return strcmp(*((char**)a), *((char**)b));
}

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


char StrBody[200000][20];
char* S[200000];

typedef struct{
    int n;
    char Str[20];
} CntStr_t;

CntStr_t cnt[200000];

int CmpCntStr_t(const void *a, const void *b){        //a-bを返す(qsortなら4321)
    CntStr_t s=*((CntStr_t*)a), t=*((CntStr_t*)b);

    return (t.n - s.n)?(t.n - s.n):strcmp(s.Str,t.Str);
}

int main(){
    int N;
    int nType=0;
    char *Prev="Nonsenceaaaaaaaaaaaaa";

    scanf("%d%*c", &N);
    for(int i=0;i<N;i++){
        my_gets(StrBody[i],20,stdin);
        S[i] = StrBody[i];
    }
    qsort(S,N,sizeof(char*),CmpChpt);
    //puts("");

    for(int i=0; i<N; i++){
        if(strcmp(Prev,S[i])){
            Prev = S[i];
            nType++;
            strcpy(cnt[nType-1].Str, S[i]);

            //puts(Prev);
        }
        cnt[nType-1].n++;
        //printf("%d\n",cnt[nType-1].n);
    }
    qsort(cnt, nType, sizeof(CntStr_t), CmpCntStr_t);
    for(int i=0;i<nType;i++){
        if(cnt[0].n != cnt[i].n){
            break;
        }
        puts(cnt[i].Str);
    }

    return 0;
} 

Measured memory_bytes: 13920
#include <stdio.h>
#include <math.h>
int PM(int b){
    int flag = 0;
    if(b == 2){
        flag = 1;
        return flag;
    }
    else if(b%2 == 0) return flag;
    
    double sqrtb = sqrt(b);
    for (int j=3;j<=sqrtb;j+=2){
        if(b%j == 0) return flag;
    }
    flag = 1;
    return flag;
}


int main(void){
    // Your code here!
    int a=0,n,m,i,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&m);
        a = PM(m);
        cnt = cnt+a;
    }
    printf("%d\n",cnt);
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using  namespace std;
int main(){
    long long n, a, sum;
    cin >> n;
    long long A[3]={};
    for(int i=0;i<n;i++){
        cin >> a;
        if(a%2==0){
          	a /= 2;
            if(a%2==0){
                A[0]++;
            }else{
                A[1]++;
            }
        }else{
            A[2]++;
        }
    }
    if(A[2]<=A[0] || (A[1]==0 && A[2]<=(A[0]+1)) || (A[2]==0)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<vector<int>> VII;
typedef pair<int,int> PII;

struct UnionFind{
  VI par;
  UnionFind(int N):par(N){
    rep(i,N) par[i]=i;
  }
  int root(int x){
    if(par[x]==x) return x;
    return par[x]=root(par[x]);
  }
  void unite(int x, int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry) return;
    par[rx]=ry;
  }
  bool same(int x, int y){
    int rx=root(x);
    int ry=root(y);
    return rx==ry;
  }
};
int main(){
  int N,M;
  cin>>N>>M;
  VI X(M),Y(M),Z(M);
  rep(i,M) cin>>X[i]>>Y[i]>>Z[i];
  UnionFind tree(N+1);
  rep(i,M) tree.unite(X[i],Y[i]);
  set<int> A;
  rep(i,N+1) A.insert(tree.root(i));
  cout<<A.size()-1<<endl;
}

Measured memory_bytes: 6400
<?php
$count = [0, 0, 0, 0];
fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
    $result = trim(fgets(STDIN));
    switch ($result) {
        case 'AC':
            $count[0]++;
            break;
        case 'WA':
            $count[1]++;
            break;
        case 'TLE':
            $count[2]++;
            break;
        case 'RE':
            $count[3]++;
            break;
        default:
    }
}
echo 'AC x ', $count[0], PHP_EOL;
echo 'WA x ', $count[1], PHP_EOL;
echo 'TLE x ', $count[2], PHP_EOL;
echo 'RE x ', $count[3], PHP_EOL;


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++){
      cin >> A.at(i).at(j);
    }
    cout << endl;
  }
  
  // 何行目を削るか
  vector<int> B(100, -1);
  int b = 0;

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(A.at(i).at(j) != '.'){
        break;
      }
      if(j == W-1){
        B.at(b) = i;
        b++;
      }
    }
  }

  // 何列目を削るか
  vector<int> C(100, -1);
  int c = 0;

  for(int i = 0; i < W; i++){
    for(int j = 0; j < H; j++){
      if(A.at(j).at(i) != '.'){
        break;
      }
      if(j == H-1){
        C.at(c) = i;
        c++;
      }
    }
  }
  
  b = 0;
  c = 0;

  for(int i = 0; i < H; i++){
    if(B.at(b) == i){
      b++;
      continue;
    }
    for(int j = 0; j < W; j++){
     if(C.at(c) == j){
       if(j == W-1){
         cout << endl;
         c = 0;
         break;
       }
        c++;
        continue;
      }
      cout << A.at(i).at(j);
      if(j == W-1){
        cout << endl;
        c = 0;
        break;
      }
    }
  }

}


Measured memory_bytes: 256
n=input()
a=0
while True:
    s=input()
    if s == 'END_OF_TEXT':
        print(a)
        break
    else:
        x = s.lower()
        l = x.split()    #split()メソッドで単語ごとのリストに変換する
        b = l.count(n)
        a+=b



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

int s[201];
int n, sum;

void input(){
	int i;
	scanf("%d", &n);
	for(i = 0; i < n*2; i++){
		scanf("%d", s+i);
	}
}

int cmp(const void* a, const void* b){
	int av = *(int*)a, bv=*(int*)b;
	return av-bv;
}

int min(int a, int b){
	return a<b? a: b;
}

void calc(){
	int i;
	qsort(s, n*2, sizeof(int), &cmp);
	for(i = 0; i < n; i++)
		sum += min(s[i*2], s[i*2+1]);
}

void output(){
	printf("%d\n", sum);
}

int main(){
	input();
	calc();
	output();
}


Measured memory_bytes: 1716
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

long long gcd(long long a,long long b) {
  if(b == 0) return a;
  else return gcd(b,a%b);
}

int main() {

  long long N,K;
  cin >> N >> K;

  vector<long long> A(N);
  long long maxi = 0;
  for(int i = 0;i < N;i++) {
    cin >> A.at(i);
    maxi = max(maxi,A.at(i));
  }

  for(int i = 0;i < N-1;i++) {
    A.at(i+1) = gcd(A.at(i),A.at(i+1));
  }

  if(K <= maxi && K % A.at(N-1) == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unordered_set<int> uset;

int main( int argc, char* argv[] ){
  int a, b;
  cin >> a >> b;
  int r = max( max( a+b, a-b ), a*b );
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
struct dice{
  int up,s,e,w,n,dn;
  void to(char dir){
    if(dir=='N'){
      int tmp = n;
      n = up;
      up = s;
      s = dn;
      dn = tmp;
    }else if(dir=='S'){
      int tmp = s;
      s = up;
      up = n;
      n = dn;
      dn = tmp;
    }else if(dir=='E'){
      int tmp = e;
      e = up;
      up = w;
      w = dn;
      dn = tmp;
    }else if(dir=='W'){
      int tmp = w;
      w = up;
      up = e;
      e = dn;
      dn = tmp;
    }else if(dir=='R'){
      int tmp = e;
      e = n;
      n = w;
      w = s;
      s = tmp;
    }else if(dir=='L'){
      int tmp = e;
      e = s;
      s = w;
      w = n;
      n = tmp;
    }
  }
  void to(string dirs){
    REP(i,dirs.size()) to(dirs[i]);
  }
  bool operator==(dice di){
    return up==di.up && n==di.n && e==di.e && w==di.w && s==di.s && dn==di.dn;
  }
};
bool check(dice di, dice di2){
  string s = "RRRRNRRRRSERRRRWSRRRRNWRRRRWRRRR";
  REP(i,s.size()){
    di.to(s[i]);
    if(di==di2) {
      return true;
    }
  }
  return false;
}
signed main(){
  int n;
  cin >> n;
  int a[6];
  vector<dice> ds(n);
  REP(j,n){
    REP(i,6)cin >> a[i];
    ds[j] = {a[0],a[1],a[2],a[3],a[4],a[5]};
  }
  bool ans = true;
  REP(i,n)FOR(j,i+1,n){
    if(check(ds[i],ds[j])) ans = false;
  }
  cout << (ans?"Yes":"No") << endl;
}



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

signed main() {
	int n;
	cin >> n;
	vector<pair<int, pair<int, int>>> v;
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		v.push_back(make_pair(a + b, make_pair(a, b)));
	}
	sort(v.begin(), v.end(), greater<pair<int, pair<int, int>>>());
	int aa = 0;
	int ba = 0;
	for(int i = 0; i < n; i++) {
		if(i % 2 == 0) {
			aa += v[i].second.first;
		}
		else {
			ba += v[i].second.second;
		}
	}
	cout << aa - ba << endl;
}


Measured memory_bytes: 4852
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void solve() {
	double n;
	cin >> n;
	cout << ((double)22 / (double) 7)  *(double) 2 * (double) n << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int count=0;
    if (S.at(0)==S.at(1) && S.at(1)==S.at(3)){
    count++;
  }
  
  if (S.at(0)==S.at(1) && S.at(2)==S.at(3) && count==0){
    cout << "Yes" << endl;
  }
  else if(S.at(0)==S.at(2) && S.at(1)==S.at(3)&& count==0){
    cout << "Yes" << endl;
  }
  else if(S.at(0)==S.at(3) && S.at(1)==S.at(2)&& count==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" <<endl;
  }

}
    
    


Measured memory_bytes: 256
import kotlin.math.abs
import kotlin.math.min

object Solve {

  const val INF = (10E17).toLong()

  fun solve() {

    var (x, k, d) = readLine()!!.split(' ').map { it.toLong() }

    x = abs(x)

    val mnum = min(x / d, k)
    k -= mnum
    x -= mnum * d

    val cand = x - (k * d)

    var ans = if (k % 2L == 0L) x else d - x

    println(ans)
  }
}

fun main(args: Array<String>) {
  Solve.solve()
}

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

#define int long long

int d[210][210];

int n, m, r;
void wf() {
    for(int k=1; k<n; ++k) {
        for(int i=0; i<n; ++i) {
            for(int j=0; j<n; ++j) {
                d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
}

signed main() {
    cin >> n >> m >> r;
    for(int i=0; i<201; ++i) {
        for(int j=0; j<201; ++j) {
            if(i==j) d[i][j] = 0;
            else d[i][j] = (1<<30);
        }
    }
    vector<int> v(r);
    for(int i=0; i<r; ++i) {
        cin >> v[i];
        v[i]--;
    }
    sort(v.begin(), v.end());

    for(int i=0; i<m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    wf();

    int ans = (1<<30);
    do {
        int tmp = 0;
        for(int i=1; i<v.size(); ++i) tmp += d[v[i-1]][v[i]];
        ans = min(ans, tmp);
    } while(next_permutation(v.begin(), v.end()));
    cout << ans << endl;
    return 0;
}



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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll a, b, c, ta, tb, tc, r;

int main() {
	cin >> a >> b >> c;
	if (a==b && b==c) {
		if (a%2==0) r = -1;
		else r = 0;
	} else {
		while (true) {
			if (a%2==1 || b%2==1 || c%2==1) break;
			r++;
			ta = (b+c)/2, tb = (c+a)/2, tc = (a+b)/2;
			a = ta, b = tb, c = tc;
		}
	}
	cout << r << ln;
}

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

using namespace std;

constexpr int MAXN = 2E5 + 5;
constexpr int MOD = 1E9 + 7;
int dp[800][2005], sum[2005];
int len, s;

struct BIT2 { //Binary Index Trees, 1based
    int lowbit(int x) { return x & (~x + 1); }
    /* O(n) 建树*/
    void build(int x = 2, int sub = 1) {
        while (x <= n) {
            for (int i = x; i <= n; i += x)
                c[i] += c[i - sub];
            x <<= 1, sub <<= 1;      // 2 ^ n
        }
    }
    /*@param x the position to add val*/
    void add(int x, int val) {
        while (x <= n) c[x] += val, x += lowbit(x);
    }
    /*查询 [1, x] 的前缀和*/
    int query(int x, int res = 0) {
        while (x) res += c[x], x -= lowbit(x);
        return res;
    }
    int n;
    array<int, MAXN> c;
};

template <class T>
void read(T &x, T f = 1, char ch = getchar()) {
    x = 0;
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}


struct BIT { //Binary Index Trees, 1based
    int lowbit(int x) { return x & (~x + 1); }
    /* O(n) 建树*/
    void build(int x = 2, int sub = 1) {
        while (x <= n) {
            for (int i = x; i <= n; i += x)
                c[i] += c[i - sub];
            x <<= 1, sub <<= 1;      // 2 ^ n
        }
    }
    /*@param x the position to add val*/
    void add(int x, int val) {
        while (x <= n) c[x] += val, x += lowbit(x);
    }
    /*查询 [1, x] 的前缀和*/
    int query(int x, int res = 0) {
        while (x) res += c[x], x -= lowbit(x);
        return res;
    }
    int n;
    array<int, MAXN> c;
};

int main() {
    cin >> s;
    len = s / 3;
    dp[0][0] = 1;
    for (int i = 0; i <= s; i++) sum[i] = 1;
    for (int i = 1; i <= len; i++) {
        for (int j = i * 3; j <= s; j++)
            dp[i][j] =
                ((sum[j - 3] - (i > 1 ? sum[(i - 1) * 3 - 1] : 0)) % MOD +
                 MOD) %
                MOD;
        for (int j = 0; j <= s; j++) sum[j] = 0;
        for (int j = i * 3 - 1; j <= s; j++)
            sum[j] = (sum[j - 1] + dp[i][j]) % MOD;
    }
    int ans = 0;
    for (int i = 1; i <= len; i++) ans += dp[i][s], ans %= MOD;
    cout << ans;
    return 0;
}

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

using namespace std;

const int MAXN = 2e5 + 20, MAXM = 124, SZ = 26, L = 32;
const long long inf = 1e9 + 100, mod = 1e9 + 7;
mt19937 rnd;

void solve() {
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    while (n) {
        n /= k;
        ++cnt;
    }
    cout << max(1, cnt) << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}

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

int main() {
	auto inside = [](int a, int b, int alim, int blim) {
		return 0 <= a && a < alim && 0 <= b && b < blim;
	};
	int64_t h, w, n;
	cin >> h >> w >> n;
	pair<int, int> ps[n];
	for (auto &p : ps) {
		cin >> p.first >> p.second;
	}
	sort(ps, ps + n);
	int64_t ans[10]{};
	ans[0] = (h - 2) * (w - 2);
	map<pair<int, int>, int> map;
	for (auto &p : ps) {
		for (int dx = -1; dx <= 1; dx++) {
			for (int dy = -1; dy <= 1; dy++) {
				int nx = p.first + dx, ny = p.second + dy;
				if (nx <= 1 || ny <= 1 || h <= nx || w <= ny) {
					continue;
				}
				int count = 0;
				for (int ddx = -1; ddx <= 1; ddx++) {
					for (int ddy = -1; ddy <= 1; ddy++) {
						int nnx = nx + ddx, nny = ny + ddy;
						count += map[make_pair(nnx, nny)];
					}
				}
				ans[count]--;
				ans[count + 1]++;
			}
		}
		map[p]++;
	}
	for (auto &i : ans) {
		cout << i << endl;
	}
	return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

string S[105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;

    ll H = 100, W = 100;
    REP(i, H) {
        S[i] = "";
        REP(j, W) {
            if (j < W / 2)
                S[i].push_back('#');
            else
                S[i].push_back('.');
        }
    }
    A--;
    B--;

    REP(i, H) {
        if (i % 2 == 0)
            continue;

        REP(j, W / 2) {
            if (j % 2 == 1)
                continue;
            if (A == 0)
                break;

            A--;
            S[i][j] = '.';
        }

        FOR(j, W, W / 2) {
            if (j % 2 == 0)
                continue;
            if (B == 0)
                break;

            B--;
            S[i][j] = '#';
        }
    }
    cout << H << " " << W << endl;
    REP(i, H) {
        cout << S[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
can_div = True
while can_div:
    for i in range(N):
        if A[i] % 2 == 0:
            A[i] = A[i] // 2
        else:
            can_div = False
            break
    if can_div:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

#define MAX_N 105

int par[MAX_N]; // 親
int Rank[MAX_N]; // 木の深さ

void init_union_find(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    Rank[i]=0;
  }
}
int find(int x){
  if(par[x]==x){
    return x;
  }else{
    return par[x]=find(par[x]);
  }
}
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;

  if(Rank[x]<Rank[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(Rank[x]==Rank[y])Rank[x]++;
  }
}
bool same(int x,int y){
  return find(x)==find(y);
}

struct edge{int u,v,cost;};
bool comp(const edge& e1,const edge& e2){
  return e1.cost<e2.cost;
}

edge es[10005];
int V,E;

int kruskall(){
  sort(es,es+E,comp);
  init_union_find(V);
  int res=0;
  for(int i=0;i<E;i++){
    edge e=es[i];
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res+=e.cost;
    }
  }
  return res;
}

int main(){
  int n,m;
  while(cin>>n){
    if(n==0)break;
    cin>>m;
    V=n;E=m;
    rep(i,m){
      scanf("%d,%d,%d",&es[i].u,&es[i].v,&es[i].cost);
      es[i].cost=es[i].cost/100-1;
    }
    cout<<kruskall()<<endl;
  }
  return 0;
}



Measured memory_bytes: 3268
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

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

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

int main() {
  ll a, b;cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}


Measured memory_bytes: 3568
N, K = map(int, input().split())

tmp = [0 for _ in range(10 ** 5 * 3 + 1)]
for i in range(10 ** 5 * 3):
    tmp[i + 1] = tmp[i] + (i + 1)

ans = 1
for i in range(K, N + 1):
    tmp_max = tmp[N] - tmp[N - i]
    ans += tmp_max - tmp[i-1] + 1

print(ans % (10 ** 9 + 7))

Measured memory_bytes: 24880
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int dp[n+1];
	dp[1]=0;
	dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
	{
		dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	}
	
	cout<<dp[n]<<endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    string s;
    int K;
    cin >> s >> K;
    set<string> se;

    for (int i = 0; i < s.size(); i++) {
        for (int j = 1; j <= K && i + j <= s.size(); j++) {
            se.insert(s.substr(i, j));
        }
    }

    int i = 1;
    for (auto w: se) {
        if(i != K) {
            i++;
            continue;
        }
        cout << w << endl;
        break;
    }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll ans = 0, x, y;
  cin >> x >> y;
  if ((0 <= x && x < y) || (x < y && y < 0)) ans = abs(y - x);
  if ((0 < y && y < x) || (y < x && x < 0)) ans = x - y + 2;
  if ((x < 0 && 0 < y) || (y < 0 && 0 < x))
    ans = min(abs(x - y), abs(x + y) + 1);
  if (abs(x) == abs(y)) ans = 1;
  if (x == y) ans = 0;
  if (x == 0 && y < x) ans = -y + 1;
  if (y == 0 && 0 < x) ans = x + 1;
  if (y == 0 && x < 0) ans = -x;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>
 
using namespace std;
 
#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

long long moduloMultiplication(long long a, 
                            long long b, 
                            long long c) 
{ 
    ll res=0;
   res = ( ( a % c ) * ( b % c ) ) % c;
  
    return res; 
} 
int main()
{
    ll sum=0,n,sum1=0;
    cin>>n;
    vector <int> v;
    rep(i,n)
    {
        int x;
        cin>>x;
        v.push_back(x);
        sum1+=x;
    }
    // cout<<sum1<<endl;
    for(ll i = 0; i < (n-1); i++)
    {
        sum1 = (sum1-v[i]);
         sum += moduloMultiplication(v[i],sum1,MOD);
        //  cout<<sum<<endl;
    }
    cout<<sum%MOD<<endl;


}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repn(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define lb lower_bound
#define mp make_pair
#define ite iterator
#define max2(x, y) ((x) > (y)) ? (x) : (y)
#define max3(x,y,z) max2((x), max2((y),(z)))
#define max4(v,w,x,y) max2(max2((v),(w)), max2((x),(y)))
#define min2(x, y) ((x) > (y)) ? (y) : (x)
#define min3(x,y,z) min2((x), min2((y),(z)))
#define min4(v,w,x,y) min2(min2((v),(w)), min2((x),(y)))
#define ul unsigned long
#define ull unsigned long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second

template<typename T>
bool elem(set<T> st, T val){
	return (st.find(val) != st.end());
}

template<typename T>
void printv(vector<T> vt){
    rep(i, vt.size() - 1)
        cout << vt[i] << " ";
    cout << vt[vt.size() - 1] << endl;
}

typedef vector<int> vint;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef pair<int, int> pii;

int main(void){
    rep(i, 9){
        rep(j, 9){
            printf("%dx%d=%d\n", i+1, j+1, (i+1)*(j+1));
        }
    }
    return 0;
}

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

template <typename T>
void print(const T &v);

vector<int> dist(105, INF);
vector<int> grid[105];
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            grid[u].push_back(v);
        }
    }
    queue<int> qe;
    qe.push(1);
    dist[1] = 0;

    while (!qe.empty())
    {
        int now = qe.front();
        qe.pop();
        for (int next : grid[now])
        {
            if (dist[next] <= dist[now] + 1)
            {
                continue;
            }
            if (dist[next] != INF)
            {
                dist[next] = dist[now] + 1;
                continue;
            }
            else
            {
                dist[next] = dist[now] + 1;
            }
            qe.push(next);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (dist[i] != INF)
        {
            cout << i << ' ' << dist[i] << endl;
        }
        else
        {
            cout << i << ' ' << -1 << endl;
        }
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i,N){
        cin >> a[i];
    }
    ll sum=0;
    rep(i,N){
        rep2(j,i+1,N){
            sum+=a[i]*a[j];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
//apigs property
//Happiness can be found, even in the darkest of times, if one only remembers to turn on the light
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second
#define pb push_back
#define vll vector< ll >
#define vi vector< int >
#define pll pair< ll , ll >
#define pi pair< int , int >
#define all(s) s.begin() , s.end()
#define sz(s) s.size()
#define md (s + e) / 2
#define mid (l + r) / 2
#define msdp(dp) memset(dp , -1 , sizeof dp)
#define mscl(dp) memset(dp , 0 , sizeof dp)
#define C continue
#define R return
#define lx node * 2
#define rx node * 2 + 1
using namespace std;
typedef long long  ll;
ll q, dp[105][100005][2], k, n;
string s;
const ll mod = 1e9 + 7;
ll mem(ll sum , ll i , ll op){
	//cout << sum << " " << i << " " << op << endl;
	if(i == n)R (sum == 0LL ? 1LL : 0LL);
	ll &r = dp[sum][i][op];
	if(r != -1)R r;
	r = 0LL;
	ll oo = 9LL;
	if(op) oo = s[i] - '0';
	for(ll j = 0 ; j <= oo ; j++){
		if(op && j == s[i] - '0')r = (r % mod + mem((sum + j) % k , i + 1 , 1) % mod + mod) % mod;
		else r = (r % mod + mem((sum + j) % k , i + 1 , 0) % mod + mod) % mod;
	}
	r = (r + mod) % mod;
	R r;
}
void solve(){
	msdp(dp);
	cin >> s >> k;
	n = sz(s);
	cout << (mem(0 , 0 , 1) - 1 + mod) % mod << endl;
}
int main(){
    fast ;
	// cin >> q;
    q = 1;
    while(q--){
    	solve();
	}
}




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

int N;
bitset<2000 * 2000> dp;
int sum;

int main() {
  scanf("%d", &N);
  dp[0] = 1;
  for(int i = 0; i < N; ++i) {
    int A; scanf("%d", &A); sum += A;
    dp |= dp << A;
  }
  for(int i = (sum + 1) / 2; ; ++i) {
    if(dp[i]) { printf("%d\n", i); break; }
  }
  return 0;
}


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

int main(){
	int  K;
	cin >> K;
	int x = 7%K;
	set<int> s;
	int i=1;
	while(s.count(x)==0){
		if(x==0){
			cout << i << endl;
			return 0;
		}
		s.insert(x);
		x = (x*10+7)%K;
		i++;
	}

	cout << -1 << endl;

	return 0;
}


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

int main() {
  int FirstNumber = 0, NextNumber = 0;
  cin >> FirstNumber >> NextNumber;
  if((FirstNumber * NextNumber)%2 != 0){
  cout << "Odd\n";
  }else{
  cout << "Even\n";
  }
}

Measured memory_bytes: 256
from bisect import bisect_left
n, q = map(int, input().split())
s = list(input())
L = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        L.append(i)
ans = []
for i in range(q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    st = bisect_left(L, l)
    fi = bisect_left(L, r)
    ans.append(fi - st)

for i in ans:
    print(i)

Measured memory_bytes: 87776
# if true

# include <iostream>
# include <unordered_map>

using Int = unsigned long long;

Int combination(Int n, Int k) {
    Int r = 1;
    for (Int d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}


int main()
{

    using Int = unsigned long long;
    std::unordered_map<Int, Int> map{};
    

    int N; std::cin >> N;
    int M; std::cin >> M;

    Int sum{};
    for (int i{}; i < N; ++i)
    {
        Int temp; std::cin >> temp;
        sum += temp;
        temp = sum % M;
        map[temp] = map[temp] + 1;
    }
    

    Int result{ map[0] };
    for (auto& elem : map)
    {
        result += combination(elem.second, 2);
    }

    std::cout << result;

    return 0;


}


# endif

Measured memory_bytes: 3596
# -*- coding:utf-8 -*-


def memoize(proc):
    cache = {}

    def helper(*args, **kargs):
        if args not in cache:
            cache[args] = proc(*args, **kargs)
        return cache[args]

    return helper


@memoize
def fib(n):
    if n < 2:
        return 1
    else:
        return fib(n - 1) + fib(n - 2)


if __name__ == "__main__":
    print(fib(int(input())))

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

using namespace std;

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

int main(){
    int i;
    //入力
    int a,b;
    cin>>a>>b;
    //処理
    //出力
    cout<<max({a+b,a-b,a*b})<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e9;
int main(){
	long T[2];long A[2],B[2];
	cin>>T[0]>>T[1];
	cin>>A[0]>>A[1];
	cin>>B[0]>>B[1];
    if(A[0]>B[0]){ swap(A[0],B[0]); swap(A[1],B[1]); }
	long s=T[0]*(A[0]-B[0])+T[1]*(A[1]-B[1]);
	if(s<0) cout<<0<<endl;
	else if(s==0) cout<<"infinity"<<endl;
	else{
        long t=-T[0]*(A[0]-B[0]);//cout<<s<<" "<<t<<endl;
        if(t%s) cout<<2*(t/s)+1<<endl;
        else cout<<2*(t/s)<<endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int[] vx = {1, 0};
    static int[] vy = {0, 1};
    static int h, w;
    static int[][] root;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        h = sc.nextInt(); w = sc.nextInt();
        root = new int[h+2][w+2];

        int cnt = 0;
        for(int i=1; i<=h; i++){
            String s = sc.next();
            for (int j = 1; j <= w; j++) {
                root[i][j] = ((s.charAt(j-1)=='.')?0:1);
                cnt += root[i][j];
            }
        }

        System.out.println((dfs(1, 1, cnt))?"Possible":"Impossible");
    }

    static boolean dfs(int x, int y, int cnt){
        if(x==w&&y==h){
            return ((cnt==1)?true:false);
        }else if(cnt==1){
            return false;
        }else{
            boolean bool = false;
            for (int i = 0; i < 2; i++) {
                if(root[y+vy[i]][x+vx[i]]==1){
                   if(dfs(x+vx[i], y+vy[i], cnt-1)) bool = true;
                }
            }
            return bool;
        }
    }
}


Measured memory_bytes: 10316
S = input()
length = len(S)

ans1, ans2 = 0, 0

# even: 0, odd: 1
for i in range(length):
    if i % 2 == 0 and S[i] == '0':
        pass
    elif i % 2 == 1 and S[i] == '1':
        pass
    else:
        ans1 += 1

for i in range(length):
    if i % 2 == 0 and S[i] == '1':
        pass
    elif i % 2 == 1 and S[i] == '0':
        pass
    else:
        ans2 += 1
        
print(min(ans1, ans2))
        


Measured memory_bytes: 3188
#include <iostream>

using namespace std;
typedef long long ll;

ll n, x;
ll bn[55];
ll pn[55];

ll solve(ll m, ll k){
//    cout << m << " " << k << endl;
    if(m == 0)
        return 1;

    if(bn[m] <= k){
        return pn[m];
    }

    ll ret = 0;
    k--;
    if(k > 0) {
        if (bn[m - 1] > k) {
            ret += solve(m - 1, k);
        } else {
            ret += pn[m - 1];
            k -= bn[m - 1];

            if(k > 0) {
                k--;
                ret++;

                if (k > 0) {
                    if (bn[m - 1] > k) {
                        ret += solve(m - 1, k);
                    } else {
                        ret += pn[m-1];
                        k -= bn[m-1];
                    }
                }
            }
        }
    }
    return ret;
}

int main() {
    cin >> n >> x;
    bn[0] = 1;
    pn[0] = 1;
    for(int i = 1; i < 55; i++){
        bn[i] = bn[i-1]*2 + 3;
        pn[i] = pn[i-1]*2 + 1;
    }

    cout << solve(n, x) << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split(" ")))
for k in range(len(A)-1):
    print(A[k], end= " ")
print(A[-1])
for i in range(1, N):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    
    for k in range(len(A)-1):
        print(A[k], end= " ")
    print(A[-1])


Measured memory_bytes: 5984
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define all(v) v.begin(), v.end() // sort(all(array))
#define INF 1000000000
#define LINF 1LL << 60
#define mod 1000000007
#define EPS 0.0001
using namespace std;
using ll = long long;
using vi = vector<int>; //vi array(要素数, 初期値)
using vll = vector<ll>; 
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>; //vvi table(行数, vi(列数, 初期値))
using vvc = vector<vc>;
using vvs = vector<vs>;
using vvb = vector<vb>;

int main() {
    int n; cin >> n;
    vvi d(n, vi(2)); rep(i, n) rep(j, 2) cin >> d[i][j];

    string ans = "No";
    rep(i, n - 2) {
        if ((d[i][0] == d[i][1]) && (d[i + 1][0] == d[i + 1][1]) && (d[i + 2][0] == d[i + 2][1])) {
            ans = "Yes";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

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



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
int h, w;


int main() {
	
	cin >> h >> w;
	pii c;
	cin >> c.first >> c.second;
	c.first--;
	c.second--;
	pii d;
	cin >> d.first >> d.second;
	d.first--;
	d.second--;

	vector<string> s(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}

	vector<vector<int>> warp(h, vector<int>(w,BIG_NUM));

	priority_queue<tl3,vector<tl3>,greater<tl3>> q;

	q.push(make_tuple(0, c.first, c.second));
	warp[c.first][c.second] = 0;

	while (!q.empty()) {
		tl3 v = q.top();
		q.pop();

		int x = get<1>(v);
		int y = get<2>(v);

		if (warp[x][y] < get<0>(v)) {
			continue;
		}
		for (int xi = x - 2; xi <= x + 2; xi++) {
			for (int yi = y - 2; yi <= y + 2; yi++) {
				//cout << xi << " " << yi << endl;
				if (xi < 0 || xi >= h || yi <0 || yi >= w) {
					continue;
				}

				if (s[xi][yi] != '.') {
					continue;
				}
				if (abs(xi - x) + abs(yi - y) == 0) {
					continue;
				}
				if (abs(xi - x) + abs(yi - y) == 1) {
					if (warp[xi][yi] > warp[x][y] ) {
						warp[xi][yi] = warp[x][y];
						q.push(make_tuple(warp[xi][yi], xi, yi));


						q.push(make_tuple(warp[xi][yi], xi, yi));
					}
					continue;
				}

				if (warp[xi][yi] > warp[x][y] + 1) {
					warp[xi][yi] =  warp[x][y] + 1;
					q.push(make_tuple(warp[xi][yi], xi, yi));
				}
			}
		}
		//cout << x << " " << y << endl;

	}


	int ans = warp[d.first][d.second];
	if (ans == BIG_NUM) {
		ans = -1;
	}
	cout <<ans << endl;

}


Measured memory_bytes: 9648