akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=list(map(int,input().split()))

a.sort()
import bisect
ans=0
#A=[1,2,3,4,5] #ソート済み
#index = bisect.bisect_left(A, 3) #2 同じ数字があった場合、前側の挿入箇所が返ってきている
#index = bisect.bisect_right(A, 3) # 3 同じ数字があった場合、後ろ側の挿入箇所が返ってきている
#A.insert(index, 3) #挿入
#print(a)
for i in range(len(a)-1):
    for j in range(i+1,len(a)):
        #a[i]<a[j]

        #a[k]<a[i]<a[j]

        #a[k]+a[i]>a[j]
        #=>a[i]> a[k] >a[j]-a[i]

        ll= bisect.bisect_right(a, a[j]-a[i])

        rr= bisect.bisect_left(a, a[i])
        if a[rr+1]==a[i]:
            rr=i
        #print(a[i],a[j],"|",ll,rr,max(0,rr-ll))
        ans+=(max(0,rr-ll))

print(ans)




Measured memory_bytes: 74664
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
#define FS first
#define SC second
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define SQR(x) ((x) * (x))
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
using namespace std;
typedef long long lint;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<bool> VB;
typedef vector<vector<int> > VVI;
typedef vector<vector<LL> > VVLL;
typedef vector<vector<bool> > VVB;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;

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

    long long N, ans = 0;
    cin >> N;
    long long c[10][10] = {{0}};
    FOR(i,1,N+1) {
        long long a = i;
        long long b = a % 10;
        while (a >= 10) a /= 10;
        c[a][b]++;
    }
    REP(i,10) REP(j,10) ans += c[i][j] * c[j][i];
    cout << ans << endl;
}



Measured memory_bytes: 3572
n , a, b = map(int, input().split())
n = int(n)
a = int(a)
b = int(b)


if (a > b ) :
	mx_x = b
else:
	mx_x = a

if ((a+b - n)<0):
	mx_y = 0
else:
	mx_y = a+b-n

print(str(mx_x) + ' ' + str(mx_y))






Measured memory_bytes: 3060
def gcd(a,b) :
    if a%b == 0:
        return b
    else :
        return gcd(b, a%b)

def gcd_array(someArray) :
    result = someArray[0]
    for i in someArray[1:] :
        result = gcd(i, result)
    return result

N = int(input())
AList = input().split(" ")
AList = [int(i) for i in AList]
AList.sort()
print(gcd_array(AList))

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

const int INF = 1001001001;

int main(){
    int a,b;
    cin >>a>>b;

    int ans=a*b;
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3632
s = input()
MOD = 10 ** 9 + 7
dp = [1, 0, 0, 0]

for x in s:
    emp, a, b, c = dp
    if x == 'A':
        dp[1] += emp
    if x == 'B':
        dp[2] += a
    if x == 'C':
        dp[3] += b
    if x == '?':
        dp = [v * 3 for v in dp]
        dp[1] += emp
        dp[2] += a
        dp[3] += b

    dp = [v % MOD for v in dp]

print(dp[3])

Measured memory_bytes: 3188
N = int(input())
A = [int(i) for i in input().split() if int(i) % 2 == 0]

approved = True

for i in A:
    if i % 3 != 0 and i % 5 != 0:
        approved = False

if approved:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
 
int puz[3][3];
int tmp[3][3];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
 
void empty(int *x,int *y) {
  int i,j;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(!puz[i][j]){
        *x=j;
        *y=i;
        return;
      }
    }
  }
}
 
void swap(int *a, int *b) {
  int tmp;
  tmp= *a;
  *a= *b;
  *b=tmp;
}
 
int cal() {
  int i,a;
  int sum=0;
  for(i=0;i<9;i ++){
    a=puz[i/3][i%3];
    if(a){
      a--;
      sum+=abs(i/3-a/3)+abs(i%3-a%3);
    }
  }
  return sum;
}
 
int dfs(int x, int y, int p, int dep, const int lim) {
  int i,h,nx,ny,res;
  h=cal();
  if(h==0){
    return dep;
  }
  if(dep+h>lim){
    return -1;
  }
  for(i=0;i<4;i++){
    nx=x+dx[i];
    ny=y+dy[i];
    if(~p&&i==(p+2)%4) continue;
    if(!(0<=nx&&nx<3&&0<=ny&&ny<3)) continue;
    swap(&puz[y][x],&puz[ny][nx]);
    res=dfs(nx,ny,i,dep+1,lim);
    if(~res){
      return res;
    }
    swap(&puz[y][x],&puz[ny][nx]);
    }
  return -1;
}
 
int main() {
  int i,j,ans,x,y,l;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d",&puz[i][j]);
    }
  }
  empty(&x,&y);
  for(l=0;l<100;l++){
    for(i=0;i<3;i++){
      for(j =0;j<3;j++){
        tmp[i][j] = puz[i][j];
      }
    }
    ans=dfs(x,y,-1,0,l);
    if(ans!=-1){
      printf("%d\n",ans);
      break;
    }
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
        puz[i][j]=tmp[i][j];
      }
    }
    ans= -1;
    if(l==99){
      printf("%d\n",ans);
    }
  }
  return 0;
}



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

#define int long long

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

int N;
int A[2000];
bitset<4000001> dp;

signed main() {
    cin >> N;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    dp = bitset<4000001>(1);
    for (int i = 1; i <= N; i++) {
        dp |= (dp << A[i - 1]);
    }
    int ans;
    for (int i = (sum + 1) / 2; i < 4000001; i++) {
        if (dp[i] == 1) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>

int main(int argc, char** arcv) {
	int n = 0, m = 0, tmp = 0, res = 0;
	scanf("%d", &n);
	scanf("%d", &m);
	tmp= m / n;
	for (int i = tmp; 0 < i; i--) {
		if (!(m % i)) {
			printf("%d\n", i);
			return 0;
		}
	}
	return 0;
}


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

int main(){
    int N, X, *L, i, now=0, count=0;
    cin >> N >> X;
    L = new int[N];
    for(i=0;i<N;i++){
        cin >> L[i];
        if(now<=X){
            count++;
        }
        now += L[i];
    }
    if(now<=X){
        count++;
    }
    cout << count << endl;
    return 0;
}

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

int main(){
	int N, M, X, Y;
	cin>>N>>M>>X>>Y;
	vector<int> Xs;
	vector<int> Ys;
	Xs.push_back(X);
	Ys.push_back(Y);
	for(int i=0;i<N;i++){
		int x;
		cin>>x;
		Xs.push_back(x);
	}
	for(int j=0;j<M;j++){
		int y;
		cin>>y;
		Ys.push_back(y);
	}
	sort(Xs.begin(), Xs.end());
	sort(Ys.begin(), Ys.end());
	int border_x = Xs.back();
	int border_y = Ys.front();
	if(border_y-border_x>0){
		cout<<"No War";
	}	else{
		cout<<"War";
	}
	return 0;
}	


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

A,B,C,X,Y = map(int,readline().split())

XY = 0
ans = 10 ** 9
while XY // 2 <= max(X,Y):
  price = XY * C
  price += max(X - (XY // 2), 0) * A + max(Y - (XY // 2), 0) * B
  if ans > price:
    ans = price
  XY += 1
    
print(ans)

Measured memory_bytes: 9200
int main(int argc, const char * argv[])
{
    int a, b, c, x;
    scanf("%d %d %d", &a, &b, &c);
    if(a > b){
        x=a;
        a=b;
        b=x;
    }if(b > c){
        x=b;
        b=c;
        c=x;
    }if(a > b){
        x=a;
        a=b;
        b=x;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}

Measured memory_bytes: 596
//08
#include<iostream>

using namespace std;

int main(){
  int n;
  cin>>n;
  int p[100003]={};
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    p[a]++;
    p[b+1]--;
  }
  int c=1,r;
  for(int i=0;i<=100001;i++){
    c+=p[i];
    if(c>=i){
      r=i;
    }
  }
  cout<<r-1<<endl;
  return 0;
}

Measured memory_bytes: 1560
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int N;
    cin >> N;
    vector<int> input(N);
    rep0(i, N)
    {
        cin >> input[i];
    }
    int res = input[0];
    rep0(i, N)
    {
        res = __gcd(res, input[i]);
    }
    cout << res;
}


Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

int n;
int lo[400], hi[400], score[400];
int dp[1000];

void calcDP(){
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;

  for(int i = 0; i < 393; i++){
    if(dp[i] == -1) continue;

    for(int j = 0; j < n; j++){
      for(int k = lo[j]; k <= hi[j]; k++){
        if(i + k > 393) continue;
        dp[i + k] = max(dp[i + k], dp[i] + score[j]);
      }
    }
  }
}

int main(){
  while(cin >> n){
    for(int i = 0; i < n; i++){
      cin >> lo[i] >> hi[i] >> score[i];
    }

    calcDP();

    vector<int> v;
    int m;
    cin >> m;

    for(int i = 0; i < m; i++){
      int len;
      cin >> len;
      if(dp[len] != -1){
        v.push_back(dp[len]);
      }
    }

    if(v.size() != m){
      cout << -1 << endl;
      continue;
    }

    for(int i = 0; i < m; i++){
      cout << v[i] << endl;
    }
  }
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main(void) {
    int N,M;cin>>N>>M;
    vector<int> p(M);
    map<int, set<int> > light;
    for (int i = 1; i <= M; i++) {
        int k;cin>>k;
        set<int> tmp;
        for (int j = 1; j <= k; j++) {
            int c;cin>>c;
            tmp.insert(c);
        }
        light[i] = tmp;
    }
    for (int i = 0; i < M; i++) cin>>p[i];

    int result = 0;
    for (int bit = 0; bit < (1 << N); bit++) {
        bool flg = true;
        for (int j = 1; j <= M; j++) {
            int cur = 0;
            set<int> tmp = light[j];
            for (int i = 0; i < N; i++) {
                if ((bit>>i)&1 && (tmp.find(i+1) != tmp.end())) cur++;
            }
            if (cur % 2 != p[j-1]) {
                flg =false;
                break;
            }
        }
        if (flg) result++;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

/// <summary>
/// https://atcoder.jp/contests/dp/tasks/dp_b
/// </summary>
internal static class CR
{
    public static string GetText() { return Console.ReadLine(); }
    public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
    public static long GetLong() { return long.Parse(Console.ReadLine()); }
    public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
}

namespace AtCoder.B
{
    public class Program
    {
        public static long N { get; private set; }
        public static long K { get; private set; }
        public static List<long> H { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = CR.GetLongs();
            N = inputs[0];
            K = inputs[1];
            H = CR.GetLongs();

            var dp = new long[N];
            dp[0] = 0;

            for (int i = 1; i < N; i++)
            {
                var costs = new List<long>();
                for (int j = 1; j <= K && i >= j; j++)
                {
                    costs.Add(Math.Abs(H[i] - H[i - j]) + dp[i - j]);
                }

                dp[i] = costs.Min();
            }

            return dp[N - 1];
        }
    }
}


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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
using ll = long long;
const int INF = 3*1e5 + 5;
const ll MOD = 1e9 + 7;
const int nax = 1e5 + 5;
const float pi = 22/7;
typedef tuple<char, int> tuple_t;

template <class myType> myType max_self(myType & a, myType b) {
	if(a > b) {
		a = b;
	}
}

int main(){
	int N;
	scanf("%d", &N);
	int res = N / 2;
	if(N % 2 == 0) {
		res -= 1;
	}
	cout << res << "\n";
}




Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
ans=int(0)
for i in range(1,n):
    ans+=abs(A[i]-A[i-1])
ans+=abs(A[n-1])
ans+=abs(A[0])

if 0<=A[0]<=A[1] or A[1]<=A[0]<=0:
    print(ans)
elif A[0]>=0 and A[1]<=0:
    print(ans-2*abs(A[0]))
elif A[0]<=0 and A[1]>=0:
    print(ans-2*abs(A[0]))
else:
    print(ans-2*abs(A[0]-A[1]))


for i in range(1,n-1):
    if A[i-1]<=A[i]<A[i+1] or A[i-1]>=A[i]>=A[i+1]:
        print(ans)
    elif A[i+1]<=A[i-1]<=A[i] or A[i]<=A[i-1]<=A[i+1]:
        print(ans-2*abs(A[i]-A[i-1]))
    else:
        print(ans-2*abs(A[i]-A[i+1]))


if 0<=A[n-2]<=A[n-1] or A[n-1]<=A[n-2]<=0:
    print(ans-2*abs(A[n-2]-A[n-1]))
elif A[n-1]>=0 and A[n-2]<=0:
    print(ans-2*abs(A[n-1]))
elif A[n-1]<=0 and A[n-2]>=0:
    print(ans-2*abs(A[n-1]))
else:
    print(ans)

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB") cout << "No" << endl;
    else cout <<"Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
class Node:
    def __init__(self, value, parent):
        self.val = value
        self.left = None
        self.right = None
        self.parent = parent

class BinarySearchTree:
    def __init__(self):
        self.root = None
    
    def insert(self,key):
        node = Node(key, None)
        if self.root == None:
            self.root = node
        else:
            curr_node = self.root
            while curr_node:
                parent_node = curr_node
                if key <= curr_node.val:
                    curr_node = curr_node.left
                else:
                    curr_node = curr_node.right
            node.parent = parent_node
            if key <= parent_node.val:
                parent_node.left = node
            else:
                parent_node.right = node
        
    def preorderTraversal(self, node):
        result = []
        if node == None:
            return result
        result += [node.val]
        result += self.preorderTraversal(node.left)
        result += self.preorderTraversal(node.right)
        return result
        
    def inorderTraversal(self, node):
        result = []
        if node == None:
            return result
        result += self.inorderTraversal(node.left)
        result += [node.val]
        result += self.inorderTraversal(node.right)
        return result

N = int(input())
command = []
for i in range(N):
    command.append(tuple(input().split()))

T = BinarySearchTree()
for com in command:
    if com[0] == 'insert':
        T.insert(int(com[1]))
    if com[0] == 'print':
        In = T.inorderTraversal(T.root)
        Pre = T.preorderTraversal(T.root)
        print(' ' + ' '.join(list(map(str, In))))
        print(' ' + ' '.join(list(map(str, Pre))))


Measured memory_bytes: 238820
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
#define int long long
const LL INF = 999999999999;

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)]);
    }
};

signed main(){
    LL n,m;
    cin >> n >> m;

    UnionFind UF(n+1);
    vector<LL> ans(m, 0);
    ans[m-1] = n*(n-1)/2;
    vector<LL> a(m), b(m);
    rep(i, m) cin >> a[i] >> b[i];
    for(int i=m-1; i>0; i--){
        if(UF.find(a[i]) == UF.find(b[i])){
            ans[i-1] = ans[i];
            continue;
        }
        LL tmp_a = UF.size(a[i]);
        tmp_a = tmp_a*(tmp_a-1)/2;
        LL tmp_b = UF.size(b[i]);
        tmp_b = tmp_b*(tmp_b-1)/2;
        UF.unite(a[i], b[i]);
        LL tmp_mg = UF.size(a[i]);
        tmp_mg = tmp_mg*(tmp_mg-1)/2;
        ans[i-1] = max(0LL, ans[i]-(tmp_mg-tmp_a-tmp_b));
    }
    rep(i, m) cout << ans[i] << endl;
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,K; cin>>N>>K;
	int ret=0;
	while(N)
		N/=K, ret++;
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
package main
 
import (
	"fmt"
	"regexp"
)
 
func main() {
	var wordCount int
    var abcTestStr string
	fmt.Scanf("%d", &wordCount)
	fmt.Scanf("%s", &abcTestStr)

	var sLength = len([]byte(abcTestStr))
	if(sLength < 3 || 50 < sLength) {
        panic("allow length 1 to 50")
    }
	if(sLength != wordCount) {
        panic("allow length wordCount")
    }
	upperCaseAtoZRep := regexp.MustCompile(`^[A-Z]*`)
	if(!upperCaseAtoZRep.MatchString(abcTestStr)) {
		panic("allow AtoZ only")
	}
    splitAtoZRep := regexp.MustCompile(`ABC`)
    result := splitAtoZRep.FindAllStringSubmatch(abcTestStr, -1)  
	fmt.Printf("%d", len(result))
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main( ){
  int W,H,x,y,r;
  cin>>W>>H>>x>>y>>r;
  if(x>=r && x+r<=W && y>=r && y+r<=H){
      cout<<"Yes"<<endl;
  }
  else{
      cout<<"No"<<endl;
  }
}
  


Measured memory_bytes: 3088
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する

vector<ll> inv(vector<ll> v) {
    vector<ll> ret(v.size());

    for (int i = 0; i < v.size(); ++i) {
        ret[v[i]] = i;
    }

    return ret;
}

/*
 * 掛け算
 */

vector<ll> mul(vector<ll> m1, vector<ll> m2) {
    int N = m1.size();
    vector<ll> v(N), tmp(N);
    rep(i, 0, N) v[i] = i;

    for (int i = 0; i < N; ++i) {
        tmp[m1[i]] = v[i];
    }
    swap(tmp, v);
    for (int i = 0; i < N; ++i) {
        tmp[m2[i]] = v[i];
    }

    vector<ll> ret = inv(tmp);
    return ret;
}

/*
 * べき乗
 */
vector<ll> pow(vector<ll> mapping, ll M) {
    vector<ll> base = mapping;
    vector<ll> ret(mapping.size());
    rep(i, 0, ret.size()) ret[i] = i;

    while (M > 0) {
        if (M & 1) {
            ret = mul(ret, base);
        }
        M >>= 1;
        base = mul(base, base);
    }

    return ret;
}


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

//    if(true){
//        vector<ll> hya({0,3,4,1,2});
//        auto a = inv(hya);
//        return 0;
//    }

    ll N;
    cin >> N;

    vector<ll> x(N);
    rep(i, 0, N) cin >> x[i];

    ll M, K;
    cin >> M >> K;
    vector<ll> a(M);
    rep(i, 0, M) {
        cin >> a[i];
        a[i]--;
    }
    vector<ll> d(N - 1);
    rep(i, 0, N - 1) {
        d[i] = x[i + 1] - x[i];
    }

    vector<ll> base(N - 1);
    rep(i, 0, base.size()) base[i] = i;
    for (auto e : a) {
        swap(base[e], base[e - 1]);
    }
    base = inv(base);

    auto powed = pow(base, K);

    vector<ll> ans_k(N - 1);
    for (int i = 0; i < N - 1; ++i) {
        ans_k[powed[i]] = i;
    }

    vector<ll> ans_diff(N - 1);
    rep(i, 0, N - 1) {
        ans_diff[i] = d[ans_k[i]];
    }
    vector<ll> ans(N);
    ans[0] = x[0];
    for (int i = 1; i < N; ++i) {
        ans[i] = ans[i - 1] + ans_diff[i - 1];
    }

    rep(i, 0, N) {
        cout << ans[i] << endl;
    }


    return 0;
}


Measured memory_bytes: 10468
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ciosup;
    int n;
    cin >> n;
    vector<pint> x(n);
    REP(i,n){
        cin >> x[i].FI >> x[i].SE;
    }
    multiset<pint> s;
    REP(i,n){
        REP(j,n){
            if (i != j) s.insert(make_pair(x[i].FI - x[j].FI,x[i].SE-x[j].SE));
        }
    }
    int ans=0;
    for (auto elem : s)
    {
        ans = max((int)s.count(elem),ans);
    }
    cout << n - ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;

int main()
{
    ll N, K;
    cin >> N >> K;
    ll ans = (N / K) * (N / K) * (N / K);
    for (ll i = 1; i < min(N + 1, K); i++)
    {
        if (2 * i % K == 0)
        {
            ll cnt1 = (N - i) / K + 1;
            ll cnt = (N - K + i) / K + 1;
            ll x = cnt1 * cnt * cnt;
            ans += x;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
  int M;
  cin >> M;
  int a,b;
  a = M/500;
  b = (M-a*500)/5;
  cout << 1000*a+b*5<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
m, d = map(int, input().split())

if d <= 21:
	print(0)
	sys.exit()

cnt = 0
for i in range(1,m+1):
	for j in range(22,d+1):
		d_1 = int(str(j)[1])
		d_10 = int(str(j)[0])

		if d_1 < 2 or d_10 < 2:
			continue

		if d_1 * d_10 == i:
			cnt += 1

print(cnt)
		

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;

public class Main {
	
	public void solve() throws IOException{
		int n;
		boolean flag = false;
		while( (n = nextInt()) != 0 ){
			if( flag ){
				writer.println();
			}
			flag = true;
			String[] name = new String[n];
			Map<Integer, Integer> temp = new HashMap<Integer, Integer>();
			
			for(int i = 0; i < n; i++){
				name[i] = nextToken();
				int x = nextInt(), y = nextInt(), z = nextInt();
				temp.put(i, 3*x + z);
			}
			SortedMap<Integer, Integer> map = new TreeMap<Integer, Integer>(new MyComparator(temp));
			map.putAll(temp);
			for(Integer x : map.keySet()){
				writer.println(name[x] + "," + map.get(x));
			}
			writer.flush();
		}
	}
			
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}
class MyComparator implements Comparator<Integer>{
	private Map<Integer, Integer> map;
	MyComparator(Map<Integer, Integer> map){
		this.map = map;
	}
	public int compare(Integer x, Integer y){
		int value1 = map.get(x);
		int value2 = map.get(y);
		if( value1 == value2 ){
			return x - y;
		}
		return value2 - value1;
	}
}

Measured memory_bytes: 10000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> nums;
    nums.push_back(0);
    vector<ll> ruisekiNums(N + 2);
    for (int i = 0; i < N; i++)
    {
        ll num;
        cin >> num;
        nums.push_back(num);
    }
    nums.push_back(0);
    for (int i = 0; i <= N; i++)
    {
        ruisekiNums.at(i + 1) = ruisekiNums.at(i) + abs(nums.at(i + 1) - nums.at(i));
    }
    for (int i = 1; i <= N; i++)
    {
        ll distance = ruisekiNums.at(i - 1) + ruisekiNums.at(N + 1) - ruisekiNums.at(i + 1) + abs(nums.at(i + 1) - nums.at(i - 1));
        cout << distance << "\n";
    }
    cout.flush();
    return 0;
}


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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;



  
int main() {
  int N;
  cin >> N;
  int x,y;
  x = N*800;
  y = N/15*200;
  cout << x-y << endl;
    
}

Measured memory_bytes: 3636
//AUTHOR - NIMISH UPADHYAY
//FROM IIIT ALLAHABAD
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define NIMISH ios_base::sync_with_stdio(false);cin.tie(NULL);
int main(){
    NIMISH
    ll i,n,k=0,m;
    cin>>n;
    for(i=1;i<n;i++){
        m=n/i;
        if(n%i==0)
        m--;
        k+=m;
    }
    cout<<k;
}

Measured memory_bytes: 3644
X = [int(e) for e in input().split()]
candies = [int(f) for f in input().split()]
i=1
ans=0
t = 0
while i<X[0]:
    if(candies[i-1]+candies[i]) > X[1] :
        t = (candies[i-1]+candies[i]) - X[1]
        ans += t
        if(t>=candies[i]):
            candies[i] = 0
        else:
            candies[i] -= t
    i+=1
print(ans)

Measured memory_bytes: 63984
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: Vec<char> = iterator.next().unwrap().chars().collect();

    let mut ans: usize = 700;
    for i in 0..3 {
        if s[i] == 'o' {
            ans += 100;
        }
    }
    return ans.to_string();
}


Measured memory_bytes: 2072
import bisect,collections,decimal,itertools,math,numpy,string
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
##################################################
def main(a,b,c):
    if c-a-b < 0:
        return 'No'
    if 4*a*b < (c-a-b)**2:
        return 'Yes'
    return'No'
    
a,b,c = LI()
print(main(a,b,c))

Measured memory_bytes: 22412
#include <stdio.h>

int  main(){
  int i, j, k, n, x, y;
  int ans[101][101];
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    for(j=0; j<n; j++)
      ans[i][j] = 0;
  }
  
  for(i=0; i<n; i++){
    scanf("%d %d", &x, &y);
    for(j=0; j<y; j++){
      scanf("%d", &k);
      ans[i][k-1] = 1;
    }
  }
  
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      if(j>0)
        printf(" ");
      printf("%d", ans[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}
      

Measured memory_bytes: 2768
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000
#define mod 1000000007
vector<vector<int> > dp;
vector<vector<vector<int> > > vvvi;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	ll N,W;
	cin>>N>>W;
	VI v(N);
	VI w(N);
	REP(i,N) cin>>v[i]>>w[i];
	dp = vector<vector<int> >(N+1, vector<int>(W+1, 0));
	REP(i,N){
		REP(j,W+1){
			if(j<w[i])
				dp[i+1][j]=dp[i][j];
			else
				dp[i+1][j]=max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
		}
	}
	cout<<dp[N][W]<<endl;
	
	return 0;
}


Measured memory_bytes: 10716
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
#define IOS ios::sync_with_stdio(0)
template <typename T>
inline T read(){T sum=0,fl=1;int ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')fl=-1;
for(;isdigit(ch);ch=getchar())sum=sum*10+ch-'0';
return sum*fl;}
template <typename T>
inline void write(T x) {static int sta[35];int top=0;
do{sta[top++]= x % 10, x /= 10;}while(x);
while (top) putchar(sta[--top] + 48);}
template<typename T>T gcd(T a, T b) {return b==0?a:gcd(b, a%b);}
template<typename T>T exgcd(T a,T b,T &g,T &x,T &y){if(!b){g = a,x = 1,y = 0;}
else {exgcd(b,a%b,g,y,x);y -= x*(a/b);}}
#ifndef ONLINE_JUDGE
#define debug(fmt, ...) {printf("debug ");printf(fmt,##__VA_ARGS__);puts("");}
#else
#define debug(fmt, ...)
#endif
typedef long long ll;
const ll mod = 1e9+7;

int main() {
	#ifndef ONLINE_JUDGE
		//freopen("in.txt", "r", stdin);
		//freopen("out.txt","w",stdout);
	#endif
	ll n,m;
	cin >> n >> m;
	n %= m;
	cout << min(abs(n-m),n) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
        public static void main(String[] args) {
// 標準入力からデータを読み込む準備
            Scanner sc = new Scanner(System.in);
// 最初の文字の固まりを整数値と想定して読み込む
            int x = sc.nextInt();
            int answer = x*x*x /* ここを変えて3乗しよう! */;
            System.out.println(answer);
        }
    }



Measured memory_bytes: 26208
s = input()

count = 0
counta = 0
for i in range(len(s)):
    if s[i] == "A":
        if s[i-1] != "B" or i == 0:
            counta += 1
        else:
            counta = 1
    elif s[i] == "B":
        if s[i-1] == "B":
            counta = 0
    else:
        if s[i-1] == "B":
            count += counta
        else:
            counta = 0
print(count)

Measured memory_bytes: 3500
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
char in[5];
int main(){
	scanf("%s",in);
	if(in[0]=='7'||in[1]=='7'||in[2]=='7')printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 1640
#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
    int A, B, H, M;
    std::cin >> A >> B >> H >> M;
    long double pi = 3.141592653589793238462643383L;
    long double h_angle = pi * (long double)H / 6.0L + pi * (long double)M / 360.0L;
    long double m_angle = pi * (long double)M / 30.0L;
    long double diff_angle = h_angle - m_angle;
    long double m_x = (long double)A;
    long double m_y = 0.0L;
    long double h_x = (long double)B * std::cos(diff_angle);
    long double h_y = (long double)B * std::sin(diff_angle);
    /*
    long double m_x = (long double)A * std::cos(m_angle);
    long double m_y = (long double)A * std::sin(m_angle);
    long double h_x = (long double)B * std::cos(h_angle);
    long double h_y = (long double)B * std::sin(h_angle); */
    long double result = std::sqrt((m_x - h_x) * (m_x - h_x) + (m_y - h_y) * (m_y - h_y));
    std::cout << std::fixed << std::setprecision(15) << result << std::endl;
}

Measured memory_bytes: 4124
#include <iostream>
#include <string>

using namespace std;



int main(void){
    string s;
    cin >> s;
    int wsum=0;
    long long ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='W'){
            ans+=i-wsum;
            wsum++;
        }
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
ll power(int x, unsigned int y) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp =(ll)power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
} 
int main()
{
  fastio;
 // fopen();
  string s;
  cin>>s;
  if(s[2]==s[3] && s[4]==s[5])
  {
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
const ld eps = 1e-7;
#define eq(x,y) (fabs((x)-(y)) < eps)
typedef pair<int,int>pii;
const int mod = 998244353;
long double PI = acosl(-1);
const ll infl = 1e18+100;
const int inf = 2e9+100;
const int nmax = 2e5+2;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;



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

//    freopen("bajeces.txt", "r", stdin);
//    freopen("mara.txt", "w", stdout);

    ll x;
    cin>>x;
    ll curnum = 101;
    int t = 1;
    while( curnum < x){
        t++;
        curnum = ( 1.01 * curnum + eps);
    }
    cout<<t<<endl;
}
/*

*/


Measured memory_bytes: 3620
N, K = map(int, input().split())
a = list(map(int, input().split()))
l = [1]
for i in range(N):
  l.append(a[l[i]-1])
p = l.index(l[N])
if K<=N:
  print(l[K])
else:
  x = (K-N+1)%(N-p)
  if x ==0:
    print(l[N-1])
  else:
    print(l[x+p-1])

Measured memory_bytes: 32252
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		Scanner scan = new Scanner(System.in);
		String word = "";		//???????????????string
		int[] shuffleBegin = new int[100]; //?????£?????????????§????
		String targetText = "";
		String temp = "";
		String kansei = "";
		while(true){
			temp = scan.next();
			if(temp.equals("-")){
				break;
			}
			targetText = temp;
			char[] targetChar = targetText.toCharArray();
			int targetLength = targetText.length();
			int shuffleTimes = scan.nextInt();
			
			for(int i=0; i<shuffleTimes; i++){
				shuffleBegin[i] = scan.nextInt();
				
			}
			for(int i =0;i<shuffleTimes; i++){
				for(int ii=0; ii<(targetLength - shuffleBegin[i]) ; ii++){
					word = word + targetChar[ii + shuffleBegin[i]];
//					System.out.println(word);
				}
				for(int ii=0; ii<shuffleBegin[i]; ii++){
					word = word + targetChar[ii];
//					System.out.println(word);
				}
			targetChar = word.toCharArray();
			kansei = word;
			word = "";
			}
			System.out.println(kansei);		
			
		}
	}
}

Measured memory_bytes: 45996
x,k,d = map(int, input().split())

if x>0:
    if x>k*d:
        ans=x-k*d
    else:
        X = x-round(x//d)*d
        if (k-round(x//d))%2==0:
            ans=abs(X)
        else:
            ans=abs(X-d)
else:
    if abs(x)>k*d:
        ans=abs(x+k*d)
    else:
        X=x+round(abs(x)//d)*d
        if (k-round(abs(x)//d))%2==0:
            ans=abs(X)
        else:
            ans=abs(X+d)

print(ans)

Measured memory_bytes: 9212
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= n; i+=2) {
            int tmp = 0;
            for (int j = 1; j <= i; j++) {
                if(i % j == 0) tmp++;
            }
            if(tmp == 8) ans++;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 22996
N = int(input())
F = [list(map(int, input().strip().split())) for i in range(N)]
P = [list(map(int, input().strip().split())) for i in range(N)]
maxProfit = -1000000000


for i in range(1,1024):
    openTime = list(map(int, list("{:0>10}".format(bin(i)[2:]))))
    thisProfit = 0
    for n in range(N):
        shopOpneTime = F[n]
        shopProfit = P[n]
        counter = 0
        for j in range(10):
            if((shopOpneTime[j])and(openTime[j])):
                 counter += 1
        thisProfit += shopProfit[counter]
    maxProfit = max(thisProfit, maxProfit)

print(maxProfit)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
#define NIL -1

int main() {
    LL h;
    LL w;
    cin >> h >> w;

    LL min_num1=h*w;
    LL min_num2=h*w;
    LL min_num3=h*w;
    LL min_num4=h*w;
    LL tmp1;
    LL tmp2;
    LL tmp3;
    LL tmp_diff;
    LL ans;
    if(h>=3){
        if(h%3==0){
            min_num1=0;
        }else{
            min_num1=w;
        }
    }

    for(int i=1; i<=w; i++){
        tmp1=i*h;
        if(h%2==0){
            tmp2=h/2*(w-i);
            tmp3=h/2*(w-i);
        }else{
            tmp2=(h/2+1)*(w-i);
            tmp3=h/2*(w-i);            
        }
        if(tmp1>tmp2){
            tmp_diff=tmp1-tmp3;
        }else{
            tmp_diff=tmp2-min(tmp1, tmp3);
        }
        if(min_num2>tmp_diff){
            min_num2=tmp_diff;
        }
    }

    if(w>=3){
        if(w%3==0){
            min_num3=0;
        }else{
            min_num3=h;
        }
    }

    for(int i=1; i<=h; i++){
        tmp1=i*w;
        if(w%2==0){
            tmp2=w/2*(h-i);
            tmp3=w/2*(h-i);
        }else{
            tmp2=(w/2+1)*(h-i);
            tmp3=w/2*(h-i);            
        }
        if(tmp1>tmp2){
            tmp_diff=tmp1-tmp3;
        }else{
            tmp_diff=tmp2-min(tmp1, tmp3);
        }
        if(min_num4>tmp_diff){
            min_num4=tmp_diff;
        }
    }

    ans = min(min(min_num1, min_num2), min(min_num3, min_num4));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
graph = {i:[] for i in range(1, n+1)}
for _ in range(m):
  a,b = map(int,input().split())
  graph[a].append(b)
  graph[b].append(a)
for i in range(1, n+1):
  print(len(graph[i]))


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll N , K ;
    cin >> N >> K ;
    vector<ll> V ;
    
    rep(i, N){
        ll inp;
        cin >> inp;
        V.pb(inp);
    }

    ll ans = 0 ;
    rep(l, N+1)rep(r, N+1){
        if((l+r) > min(N, K )) continue;
        ll d = K - l - r;
        
        vector<ll> jewl;

        rep(i, l){
            jewl.pb(V[i]);
        }
        rep(i, r){
            jewl.pb(V[N-1-i]);
        }
        
        sort(all(jewl));
        
        ll ret = 0;
        rep(i, jewl.size()){
            if(((i+1) <= d) && (jewl[i]<0))continue;
            ret += jewl[i];
        }
        ans = max(ans, ret);
    }
    
    cout << ans << endl;
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.string: replace, chomp;
import std.conv;
import std.array;
import std.algorithm;

void main(){
	string s;
	while (s = chomp(readln()), s) {
		int ans = solve(s);
		if (ans == -1) writeln("NA");
		else writeln(ans);
	}
}

int solve(string s){
	int p, e;
	string a, b, c;
	// parse
	for (int i = 0; i < s.length; i++) {
		if (s[i] == '+') p = i;
		else if (s[i] == '=') e = i;
	}
	// answer
	for (int i = 0; i < 10; i++) {
		a = replace(s[0..p], "X", to!string(i));
		b = replace(s[p+1..e], "X", to!string(i));
		c = replace(s[e+1..$], "X", to!string(i));
		if(i == 0 && !(zero(a) && zero(b) && zero(c))) continue;
		if (add(a, b) == c) return i;
	}
	return -1;
}

// able to put zero to X?
bool zero(string s){
	return (s[0] != '0') || (s[0] == '0' && s.length == 1);
}

string add(string a, string b){
	int x, y, z;
	int hi = 0;
	string c;
	int len = cast(int)max(a.length, b.length);
	for (int i = 1; i <= len+hi; i++) {
		x = (a.length < i) ? 0 : a[$-i] - '0';
		y = (b.length < i) ? 0 : b[$-i] - '0';
		z = x + y + hi;
		if (z > 9) {
			z -= 10;
			hi = 1;
		}else {
			hi = 0;
		}
		c =  cast(char)(z + '0') ~ c;
	}
	return c;
}

Measured memory_bytes: 1284
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifdef LOCALc
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a, p;
int main() {
	doin();
	cin >> a >> p;
	p += a*3;
	cout << p/2;
}


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

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

    int ans = 0;
    for(int i = 105; i <= n; i+=2) {
        int cnt = 0;
        for(int j = 2; j < i; j++) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 6) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628