akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;

class Main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1};
    public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1};
    public static int INF = 0x3f3f3f3f;
    public static long LINF = 0x3f3f3f3f3f3f3f3fL;
    public static int MOD = 1000000007;

    public static void main(String[] args) throws Exception{
        st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int T = Integer.parseInt(st.nextToken());
        long total = 0;
        int[] A = new int[N];
        st = new StringTokenizer(br.readLine());
        for(int i = 0; i < N; i++){
            A[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i < N-1; i++){
            total += Math.min(A[i+1] - A[i], T);
        }
        total += T;
        pw.print(total + "\n");
        
        pw.close(); 
        br.close();
    }
}

class Point {
    public int r, c;

    Point(int r, int c){
        this.r = r;
        this.c = c;
    }

    // public int compareTo(Point p){
    //     if(x != p.x) return x < p.x ? -1 : 1;
    //     else if(y != p.y) return y < p.y ? -1 : 1;
    //     return 0;
    // }
}

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

const int N=1000010;
long long f[N][4];
const long long mod=1000000007;

int main(){
	int n;
	scanf("%d",&n);
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		f[i][0]=f[i-1][0]*8;f[i][0]%=mod;
		f[i][1]=f[i-1][1]*9+f[i-1][0];f[i][1]%=mod;
		f[i][2]=f[i-1][2]*9+f[i-1][0];f[i][2]%=mod;
		f[i][3]=f[i-1][1]+f[i-1][2]+f[i-1][3]*10;f[i][3]%=mod;
	}
	printf("%lld\n",f[n][3]);
}

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

public class Main{
	public static void main(String[] args){
		Scanner stdIn = null;
		int[] num = {1,4,1,4,1,2,1,2,1,4,1,4,1,2,1};
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				int[] data = new int[8];
				for(int i = 0; i < 8; i++){
					data[i] = stdIn.nextInt();
				}
				int min = -1;
				String key = new String();
				for(int i = 0; i < 8; i++){
					int sum = 0;
					for(int j = 0; j < 8; j++){
						sum += (data[j] > num[i+j]) ? (data[j]-num[i+j]) : 0;
					}
					if( min < 0 || sum <= min ){
						StringBuilder key2 = new StringBuilder();
						for(int j = 0; j < 8; j++){
							key2.append(Integer.toString(num[i+j]));
						}
						if( sum < min ){
							key = new String(key2.toString());
						} else if( key.equals("") || Integer.parseInt(key2.toString()) < Integer.parseInt(key) ){
								key = new String(key2.toString());
						}
						min = sum;							
					}
				}
				for(int i = 0; i < 7; i++){
					System.out.print(key.charAt(i) + " ");
				}
				System.out.println(key.charAt(7));				
			}			
		} finally {
			if( stdIn != null){
				stdIn.close();
			}
		}
	}
}

Measured memory_bytes: 12000
import bisect
N=int(input())
d=list(map(int,input().split()))
d=sorted(d)
num=len(d)
ans=0
val=max(d)
for i in range(val+1):
  tmp=bisect.bisect_left(d,i)
  if tmp==num-tmp:
    ans+=1
print(ans)
  


Measured memory_bytes: 14396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final char[] s = scanner.nextLine().toCharArray();

        for (int i = 0; i < s.length; i++) {
            if (i % 2 == 1){
                if(s[i] == 'R'){
                    System.out.println("No");
                    return;
                }
            }else{
                if(s[i] =='L'){
                    System.out.println("No");
                    return;
                }
            }
        }

        System.out.println("Yes");
    }

    static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 21460
#include<iostream>

using namespace std;
int main() {
	int N;
	char S;
	int y = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S;
	
		if (S == 'Y') {
			y++;
			
		}
	}
	if (y != 0) {
		cout << "Four" << endl;
	}
	else {
		cout << "Three" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  char A; cin >> A;
  if(A>='a') cout << "a" << endl;
  else cout << "A" << endl;

  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &x : a) cin >> x;
    int ht = 0;
    for (int i = 1; i < n; ++i) {
        if (a[i] < a[i - 1]) {
            ht += abs(a[i] - a[i - 1]);
            a[i] = a[i - 1];
        }
    }
    cout << ht << endl;
}

int32_t main() {
    solve();
}

Measured memory_bytes: 4732
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;
import java.util.Map.Entry;

public class Main {

	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = in.nextInt();
		if (n == 1) {
			out.println("Hello World");
		} else if (n == 2) {
			out.println(in.nextInt() + in.nextInt());
		}
		out.flush();
		out.close();

	}

	static class FastReader {
		StringTokenizer st;
		BufferedReader br;

		public FastReader(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastReader(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

Measured memory_bytes: 24532
#include <algorithm>
#include <iostream>
#include <numeric>

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

bool canAllocate(int *w, int n, int k, int p) {
  int i = 0;
  int x = 0;

  while (x < k) {
    int sum = 0;
    while (i < n && sum + w[i] <= p) {
      sum += w[i];
      i++;
    }
    // std::cout << "x: " << x << "i: " << i << "p: " << p << '\n';
    x++;
    if (i == n)
      return true;
  }
  return false;
}

int main() {
  int n, k;
  std::cin >> n >> k;
  int w[n];
  rep(i, n) std::cin >> w[i];

  int left = *std::max_element(w, w + n) - 1;
  int right = std::accumulate(w, w + n, 0);
  int m = (left + right) / 2;

  while (right - left > 1) {
    m = (left + right) / 2;
    if (canAllocate(w, n, k, m))
      right = m;
    else
      left = m;
  }

  std::cout << right << '\n';
  return 0;
}



Measured memory_bytes: 3488
#include <bits/stdc++.h>
#define len(x) int(x.size())
#define all(x) x.begin(), x.end()
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    int a, b, c;
    cin >> a >> b >> c;
    int ans = a+b;
    ans = min(ans, b+c);
    ans = min(ans, a+c);
    cout << ans << endl;
}

Measured memory_bytes: 256
# 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__) << "] "
 
# define forn(i, n) for (ll i = 0; i < int(n); i++)
# define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
# define all(V) V.begin(), V.end()
# define rall(V) V.rbegin(), V.rend()
# define len(V) (int)V.size()
# define ll long long
# define ld long double
# define ff first
# define ss second
# define pb push_back
# define mp make_pair
# define endl '\n'
# define M_PI 3.14159265358979323846

const int MAX_N = 100;
vector<int> xy(MAX_N);
 
void solve()
{
        ll l, n; cin >> l >> n;
        vector<ll> a(n);
        forn(i, n) cin >> a[i];
        ll res = INT_MAX;
        sort(all(a));
        res = a[n - 1] - a[0];
        for(int i = 1; i < n; ++i)
        {
                res = min(res, l - a[i] + (a[i - 1]));
        }
        cout << res;
}
 
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        solve();
}

Measured memory_bytes: 1792
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>

using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define ull unsigned long long
#define ll long long
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}



int dp[3][105];
int A[3][105];
int N;
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin >> N;
	rep(i,1,N+1) cin >> A[1][i];
	rep(i,1,N+1) cin >> A[2][i];
	dp[1][1] = A[1][1];
	for(int i=2;i<=N;++i) dp[1][i] = dp[1][i-1] + A[1][i];
	for(int i=1;i<=N;++i) dp[2][i] = max(dp[2][i-1],dp[1][i]) + A[2][i];
	cout << dp[2][N] << endl;
	
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF=1001001001;
int main() {
    int n;cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<int> s=a;
    sort(s.rbegin(),s.rend());
    for(int i=0;i<n;i++){
        int ans=s[0];
        if(s[0]==a[i])ans=s[1];
        cout<<ans<<endl;
    }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll s; cin >> s;
    ll cnt = 1;
    ll prev = s;
    set<ll> x; x.insert(prev);
    while (true){
        if (prev % 2 == 0){
            prev = prev / 2;
        } else {
            prev = 3 * prev + 1;
        }
        cnt++;
        if (x.find(prev) != x.end()){break;}
        x.insert(prev);
    }
    cout << cnt << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3664
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
  }
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += d[i];
  }
  int ans = sum * sum;
  for (int i = 0; i < n; ++i) {
    ans -= d[i] * d[i];
  }
  ans /= 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
from random import *
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(365)]
for i in range(365):
    cand=0
    for j in range(26):
        if s[i][cand]<s[i][j]:
            cand=j
    #print(cand+1)
    #print(randrange(1,26))
for i in range(365):
    print(26-i%26)

Measured memory_bytes: 83644
from collections import deque
INF=1001001001
dy=[0,1,0,-1]
dx=[1,0,-1,0]
my=[-2,-2,-2,-2,-2,-1,-1,-1,-1,0,0,1,1,1,1,2,2,2,2,2]
mx=[2,1,0,-1,-2,2,1,-1,-2,2,-2,2,1,-1,-2,2,1,0,-1,-2]
h,w=map(int,input().split())
ch,cw=map(int,input().split())
ch-=1
cw-=1
dh,dw=map(int,input().split())
dh-=1
dw-=1
s=[list(input()) for i in range(h)]
dist=[[INF for i in range(w)] for j in range(h)]
dist[ch][cw]=0
d=deque([])
d.append([ch,cw])

while d:
  nowh,noww=d.popleft()
  for i in range(4):
    th=nowh+dy[i]
    tw=noww+dx[i]
    if 0<=th<=h-1 and 0<=tw<=w-1 and dist[th][tw]>dist[nowh][noww] and s[th][tw]==".":
      d.appendleft([th,tw])
      dist[th][tw]=dist[nowh][noww]
  for i in range(20):
    th=nowh+my[i]
    tw=noww+mx[i]
    if 0<=th<=h-1 and 0<=tw<=w-1 and dist[th][tw]>dist[nowh][noww]+1 and s[th][tw]==".":
      d.append([th,tw])
      dist[th][tw]=dist[nowh][noww]+1

ans=dist[dh][dw]
if ans==INF:
  ans=-1
print(ans)

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

int main(void) {
	int n, alice = 0, bob = 0;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end(),greater<int>());
	// sort(&a[0],&a[n]);	// 昇順ソート
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0)alice += a[i];
		else bob += a[i];
	}
	cout << alice - bob << endl;
	return 0;
}

Measured memory_bytes: 256
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;


public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] ar = new int[m];
        for (int i = 0; i < m; i++) {
            ar[i] = sc.nextInt();
        }
        Arrays.sort(ar);
        int[] dis = new int[m-1];
        for (int i = 0; i < dis.length; i++) {
            dis[i] = ar[i+1] - ar[i];
        }
        Arrays.sort(dis);
        int sum = 0;
        if (n >= m) {
            System.out.println(0);
        } else {
            for (int i = 0; i < m-n; i++) {
                sum += dis[i];
            }
            System.out.println(sum);
        }
        sc.close();
    }
}

Measured memory_bytes: 52236
import java.io.*
import java.util.InputMismatchException
import java.io.IOException
import kotlin.system.measureTimeMillis
var out = PrintWriter(System.out)
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

var line = intArrayOf(1, 400, 800, 1200, 1600, 2000, 2400, 2800, 5050)
fun solve() {
    var N = ni()
    var A = na(N)
    A.sort()

    var color:MutableSet<Int> = mutableSetOf()
    var non = 0
    for(a in A) {
        if(3200 <= a) {
            non++
            continue
        }

        for(j in 0..7) {
            if(a in line[j] until line[j + 1]) color.add(j)
        }
    }

    var max = color.size + non
    var min = Math.max(color.size, 1)
    out.println("$min $max")
}









//---------------------------------------------------------------------------------------------------
fun main(args: Array<String>) {
    var time = measureTimeMillis {
        solve()
        out.flush()
    }
    //println("$time ms")
}
//---------------------------------------------------------------------------------------------------
private var inbuf = ByteArray(1024)
private var lenbuf = 0
var ptrbuf = 0

var `is` = System.`in`

fun readByte(): Byte {
    if (lenbuf === -1) throw InputMismatchException()
    if (ptrbuf >= lenbuf) {
        ptrbuf = 0
        try {
            lenbuf = `is`.read(inbuf)
        } catch (e: IOException) {
            throw InputMismatchException()
        }

        if (lenbuf <= 0) return -1
    }
    return inbuf[ptrbuf++]
}


private fun isSpaceChar(c: Byte): Boolean {
    return !(c >= 33 && c <= 126)
}

private fun skip(): Byte {
    var b: Byte
    while (true) {
        b = readByte()
        if(b < 0 && isSpaceChar(b)) break
    }
    return b
}

private fun ns(): String {
    var b = skip()
    val sb = StringBuilder()
    while (!isSpaceChar(b)) {
        sb.appendCodePoint(b.toInt())
        b = readByte()
    }
    return sb.toString()
}

fun na(n: Int) = IntArray(n, {ni()})

fun ni(): Int {
    var num = 0
    var b: Byte
    var minus = false
    while (true) {
        b = readByte()
        if(b < 0) break
        if(b >= '0'.toByte() && b <= '9'.toByte() || b == '-'.toByte()) break

        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
    }

    while (true) {
        if (b >= '0'.toByte() && b <= '9'.toByte()) {
            num = num * 10 + (b - '0'.toByte())
        } else {
            return if (minus) -num else num
        }
        b = readByte()
    }
}

Measured memory_bytes: 31692
#!/usr/bin/python
# -*- coding: utf-8 -*-

N = int(input())
AB = []
for _ in range(N):
    AB.append(list(map(int,input().split())))

A = []
B = []

for i in range(N):
    A.append(AB[i][0])
    B.append(AB[i][1])

A.sort()
B.sort()

if N%2 == 1:
    print(B[N//2]-A[N//2]+1)
else:
    print((B[N//2-1]+B[N//2]) - (A[N//2-1]+A[N//2])+1)


Measured memory_bytes: 49196
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long ll;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
//
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = (c + b - 1) / b;
    int y = (a + d - 1) / d;
    if(x <= y) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 3636
class UnionFind:

    def __init__(self, dimension):
        self.root = [i for i in range(dimension)]
        self.height = [1 for i in range(dimension)]

    def parent(self, i):
        p = self.root[i]
        if i == p:
            return p
        else:
            pp = self.parent(p)
            self.root[i] = pp
            return pp

    def unite(self, i1, i2):
        p1 = self.parent(i1)
        p2 = self.parent(i2)
        if self.height[p1] < self.height[p2]:
            self.root[p1] = p2
        else:
            self.root[p2] = p1
            if self.height[p1] == self.height[p2]:
                self.height[p1] += 1

    def same(self, i1, i2):
        return self.parent(i1) == self.parent(i2)


n, q = map(int, input().strip().split())
uf = UnionFind(n)

for i in range(q):
    com, x, y = map(int, input().strip().split())
    if com == 0:
        uf.unite(x, y)
    else:
        print(1 if uf.same(x, y) else 0)



Measured memory_bytes: 6036
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        System.out.println(findXOR(a-1) ^ findXOR(b));
    }

    static long findXOR(long n) {
        long mod = n % 4;
        if (mod == 0) return n;
        else if (mod == 1) return 1;
        else if (mod == 2) return n + 1;
        else if (mod == 3)
            return 0;
        return 0;
    }
}

Measured memory_bytes: 21716
from itertools import count, takewhile
N = int(input())

def dfs(n, d={}):
  if(n < 6):
    return n
  if(n in d):
    return d[n]
  mn = max(takewhile(lambda x: x<=n, (9**i for i in count())))
  ms = max(takewhile(lambda x: x<=n, (6**i for i in count())))
  d[n] = min(dfs(n-mn), dfs(n-ms))+1
  return d[n]

print(dfs(N))

Measured memory_bytes: 3064
import sys
from math import gcd
from collections import Counter
MOD = 10**9 + 7
def main():
    input = sys.stdin.readline
    N = int(input())
    V = []
    z = 0
    for _ in range(N):
        A, B = map(int, input().split())
        g = gcd(A, B)
        if g == 0:
            z += 1
            continue
        A, B = A // g, B // g
        if A == 0: V.append((0, 1))
        elif A < 0: V.append((-A, -B))
        else: V.append((A, B))
    C = Counter(V)
    ans = Mint(1)
    used = set()
    for k, V in C.items():
        if k in used: continue
        a, b = k
        v = (0, 1) if b == 0 else (b, -a) if b > 0 else (-b, a)
        t = Mint(1)
        t += pow(2, V, MOD) - 1
        t += pow(2, C[v], MOD) - 1
        ans *= t
        used.add(v)
    print(ans - 1 + z)

class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self

    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self

    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj

    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self

    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self

    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj

    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj


if __name__ == '__main__':
    main()


Measured memory_bytes: 134420
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    S = input()
    if S[0] != S[1] and S[1] != S[2] and S[2] != S[3]:
        print("Good")
    else:
        print("Bad")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
//============================================================================
// Name        : 2408.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n, k, r, m[50], b[50][50], ans = 0;
	bool ul[50][50], uh[50];

	cin >> n >> k;
	fill(uh,uh + n,false);
	for(int i = 0;i < n;i++){ // 初期化
		fill(ul[i],ul[i] + n,false);
	}

	for(int i = 0;i < k;i++){
		cin >> m[i];
		for(int j = 0;j < m[i];j++){
			cin >> b[i][j];
			b[i][j]--;
		}
	}
	cin >> r;
	for(int i = 0;i < r;i++){
		int p, q;
		cin >> p >> q;
		p--; q--;
		ul[p][q] = ul[q][p] = true;
	}
	for(int i = 0;i < k;i++){
		for(int j = 0;j < m[i];j++){
			for(int l = 0;l < m[i];l++){
				if(ul[b[i][j]][b[i][l]]){
					if(!uh[b[i][j]]){
						uh[b[i][j]] = true;
						ans++;
					}
					if(!uh[b[i][l]]){
						uh[b[i][l]] = true;
						ans++;
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1172
#include <stdio.h>

int main()
{

        int H, W;

        while(1) {
                scanf("%d %d", &H, &W);

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

                for (int w = 0; w < W; w++) {
                        printf("#");
                }
                printf("\n");

                for (int i = 0; i < H - 2; i++) {
                        printf("#");
                        for (int j = 0; j < W - 2; j++) {
                                printf(".");
                        }
                        printf("#\n");
                }


                for (int w = 0; w < W; w++) {
                        printf("#");
                }
                printf("\n\n");
        }
        return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

// ナップサック

// 品物がN個しかなかったら、価値の最大は V_MXAX * N だと思ってたので
// jのループを1000*Nまでにしてたがなぜか通らなかった

ll N, W;
ll w[101], v[101];
ll dp[101][100001]; // dp[i][j] : i番目までの商品で価値j持って帰る際の最小の重さ

void input() {
	cin >> N >> W;
	for (int i = 1; i <= N; i++) cin >> w[i] >> v[i];
	for (int j = 0; j <= 1000*N; j++) dp[0][j] = LLINF;
}

void solve() {
	dp[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= 1000*N; j++) {
			if (j >= v[i]) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
			else dp[i][j] = dp[i - 1][j];
		}
	}

	int ans = 0;
	for (int j = 0; j <= 1000*N; j++) {
		if (dp[N][j] <= W) {
			// 持って帰れる
			ans = j;
		}
	}
	cout << ans << endl;
}

int main() {
	input();
	solve();

	return 0;
}

Measured memory_bytes: 79104
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

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

  ll n;
  std::cin>>n;

  std::map<ll,ll> cnt;

  rep(i,0,n){
    ll a;
    std::cin>>a;
    cnt[a]++;
  }

  ll ans=0;

  for(P e:cnt){
    if(e.second%2)ans++;
  }

  std::cout<<ans<<"\n";

  return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Card[] a = new Card[n];
        Card[] a2 = new Card[n];
        for (int i = 0; i < n; i++) {
            Card c = new Card(scanner.next(), scanner.nextInt());
            a[i] = c;
            a2[i] = c;
        }
        sort(a, 0, a.length - 1);
        mergeSort(a2);
        boolean isStable = true;
        for (int i = 0; i < n; i++) {
            if (a[i] != a2[i]) {
                isStable = false;
                break;
            }
        }
        System.out.println(isStable ? "Stable" : "Not stable");
        for (Card c : a) {
            System.out.println(c.toString());
        }
    }

    private static int partition(Card[] a, int p, int r) {
        Card x = a[r];
        int i = p - 1;
        for (int j = p; j < r; j++) {
            if (a[j].i <= x.i) {
                i++;
                Card t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
        }
        i++;
        Card t = a[i];
        a[i] = a[r];
        a[r] = t;
        return i;
    }

    private static void sort(Card[] a, int p, int r) {
        if (p < r) {
            int q = partition(a, p, r);
            sort(a, p, q - 1);
            sort(a, q + 1, r);
        }
    }

    private static void merge(Card[] a1, Card[] a2, Card[] a) {
        int i1 = 0;
        int i2 = 0;
        while (i1 < a1.length || i2 < a2.length) {
            if (i1 < a1.length && (i2 >= a2.length || a1[i1].i <= a2[i2].i)) {
                a[i1 + i2] = a1[i1++];
            } else {
                a[i1 + i2] = a2[i2++];
            }
        }
    }

    private static void mergeSort(Card[] a) {
        if (a.length < 2) {
            return;
        }
        int n1 = a.length / 2;
        int n2 = a.length - n1;
        Card[] a1 = new Card[n1];
        Card[] a2 = new Card[n2];
        for (int i = 0; i < n1; i++) {
            a1[i] = a[i];
        }
        for (int i = 0; i < n2; i++) {
            a2[i] = a[n1 + i];
        }
        mergeSort(a1);
        mergeSort(a2);
        merge(a1, a2, a);
    }

    private static class Card {
        String s;
        int i;

        private Card(String s, int i) {
            this.s = s;
            this.i = i;
        }

        public String toString() {
            return s + " " + String.valueOf(i);
        }
    }
}

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

int main(void)
{
	using namespace std;
	string word, text;
	int count = 0;
	cin >> word;
	transform(word.begin(), word.end(), word.begin(), ::tolower);
	while(true)
	{
		cin >> text;
		if(text == "END_OF_TEXT")
			break;
		transform(text.begin(), text.end(), text.begin(), ::tolower);
		if(text == word)
			count++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3200
n, c = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]

A.sort(key = lambda x:x[0])
A.sort(key = lambda x:x[2])

for i in range(n-1) :
    if A[i][2] == A[i+1][2] and A[i+1][0] - A[i][1] <= 1 :
        A[i+1][0] = A[i][0]
        A[i] = [-10, 0, 0]
for i in range(n) :
    A[i][0] -= 1

#A.sort(key = lambda x:x[0])

T = [0 for i in range(10**5+10)]
ans = 0
for i in range(n) :
    if A[i][0] != -11 :
        T[A[i][0]] += 1
        T[A[i][1]] -= 1

for i in range(len(T)-1) :
    T[i+1] += T[i]

print(max(T))


Measured memory_bytes: 29060
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i = int(a) ; i < int(b) ; i++)
using namespace std ;

int getString(const string  &s )
{
	vector<int> A , Z ;
	int sz = s.size();
	REP(i,0,sz)
	{
		if (s[i] == 'A') A.push_back(i) ;
		if (s[i] == 'Z') Z.push_back(i) ;
	}
	if (A.empty() || Z.empty()) return 0 ;
		return Z[Z.size() - 1 ] -  A[0] + 1 ;
}

int main()
{
		string s  ;
		getline(cin,s) ;
		cout << getString(s);
		return  0 ;
}


Measured memory_bytes: 1364
N = int(input())
A = list(map(int, input().split()))

def bubbleSort(A, N):
    counter = 0
    i = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                counter += 1
        i += 1
    print(" ".join(map(str, A)), counter, sep="\n")
bubbleSort(A, N)


Measured memory_bytes: 5604
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	
		public static void main(String[] args) {
			int a=scan.nextInt()*100+scan.nextInt()*10+scan.nextInt();
			System.out.println(a%4==0?"YES":"NO");
		}
}


Measured memory_bytes: 20560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=2e5+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m,k,t,a[maxn],b[maxn];
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
ll ans;
set<int>p;
set<int>::iterator l,r;
int main()
{
    int i,j;
    scanf("%d",&n);
    p.insert(0),p.insert(n+1);
    rep(i,1,n)scanf("%d",&a[i]),b[a[i]]=i;
    rep(i,1,n)
    {
        int pos=b[i];
        p.insert(pos);
        l=p.lower_bound(pos);
        --l;
        r=p.upper_bound(pos);
        ans+=((ll)pos-(*l))*((*r)-pos)*i;
    }
    printf("%lld\n",ans);
    //system("Pause");
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using ll=long long; //using lll=__int128;
using pii=pair<int,int>;
#define repeat(i,a,b) for(int i=(a),iE=(b);i<iE;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,iE=(a);i>=iE;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define N 100010
#define inf 1e9
#define qwq {cout<<"qwq"<<endl;}
#define int ll
const int mod=1000000007;
int t1,t2,a1,a2,b1,b2,a,b;
int sgn(int n){return n>0?1:n<0?-1:0;}
#define abs(n) (n<0?-n:n)
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>t1>>t2>>a1>>a2>>b1>>b2;
	a=(a1-b1)*t1;
	b=a+(a2-b2)*t2;
	if(b==0){
		cout<<"infinity"<<endl;
		exit(0);
	}
	if(sgn(a)==sgn(b)){
		cout<<0<<endl;
		exit(0);
	}
	a=abs(a),b=abs(b);
	if(a%b==0)cout<<(a/b)*2<<endl;
	else cout<<(a/b)*2+1<<endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

struct Main {
    n: usize,
    x: usize,
    y: usize,
    g: Vec<Vec<usize>>,
    d: Vec<Option<usize>>,
    res_d: Vec<Vec<Vec<usize>>>,
    contained: Vec<Vec<bool>>,
}
impl Main {
    fn bfs(&mut self, start: usize) {
        let mut q: VecDeque<usize> = VecDeque::new();
        q.push_back(start);
        let mut d: Vec<Option<usize>> = vec![None; self.n];
        d[start] = Some(0);
        while !q.is_empty() {
            let v = q.pop_front().unwrap();
            for &next_v in self.g[v].iter() {
                match d[next_v] {
                    None => {
                        q.push_back(next_v);
                        let new_d = d[v].unwrap() + 1;
                        d[next_v] = Some(new_d);
                        let new_res_d = if start < next_v {
                            vec![start, next_v]
                        } else {
                            vec![next_v, start]
                        };
                        if !self.contained[new_res_d[0]][new_res_d[1]] {
                            self.res_d[new_d].push(vec![start, next_v]);
                        }
                        self.contained[new_res_d[0]][new_res_d[1]] = true;
                        ()
                    }
                    Some(_) => (),
                }
            }
        }
//        println!("d: {:?}", d);
    }
    fn invoke(&mut self) {
        for i in 0..self.n {
            if i as i32 - 1 >= 0 {
                self.g[i].push(i - 1);
            }
            if i + 1 < self.n {
                self.g[i].push(i + 1);
            }
        }
        self.g[self.x-1].push(self.y-1);
        self.g[self.y-1].push(self.x-1);

        for i in 0..self.n {
            self.bfs(i);
        }

//        println!("{:?}", self.g);
//        println!("{:?}", self.res_d);

        for (i, res_d_one) in self.res_d.iter().enumerate() {
            if i == 0 {
                continue;
            }
            println!("{}", self.res_d[i].len());
        }
    }
}



fn main() {
    let n: usize = read();
    let x: usize = read();
    let y: usize = read();
    Main {
        n: n,
        x: x,
        y: y,
        g: vec![vec![]; n],
        d: vec![None; n],
        res_d: vec![vec![]; n],
        contained: vec![vec![false; n]; n],
    }.invoke()
}


Measured memory_bytes: 127228
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n,k; cin >> n >> k;
    map<int,int>mod;
    int ans = 0;
    rep(i,n)mod[(i+1)%k]++;
    for(int m = 0; m < k;m++){
        int sub = k - m;
        int temp = 0,a,b,c;
        if((m + m) % k != 0)continue;
        if(m == sub or m == 0){
            a = mod[m] * (mod[m] - 1) * (mod[m] - 2);
            b = mod[m]*(mod[m] - 1)*3LL;
            c = mod[m];
            ans += max(0LL,a) + max(0LL,b) + c;
        } else {
            a = mod[m] * mod[sub] * (mod[m] - 1);
            b = mod[m]*(mod[sub])*3;
            ans += b+a;
        }
    }
    cout << ans << endl;
}





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

using namespace std;

int main(){
  int N; cin >> N;
  vector<int> p(N);
  for(int i = 0; i < N; i++){ cin >> p[i];}
  
  bool flag = true;
  
  for(int i = 0; i < N - 1; i++){
    if(p[i] > p[i+1] ){ flag = false;}}
  
  if(flag){ cout << "YES" << endl; return 0;}
  
  
  for(int i = 0; i < N - 1; i++){
    for(int j = i + 1; j < N; j++){
      int s,t;  flag = true;
     s = p[i]; t = p[j];
      p[j] = s; p[i] = t;
      for(int k = 0; k < N - 1; k++){
        if( p[k] > p[k+1]){ flag = false;}}
      if( flag){ cout << "YES" << endl; return 0;}
      p[i] = s; p[j] = t;
    }}
  
  cout << "NO" << endl; return 0;}
     
  
  
  
  


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;

int N, M;
bool used[101][101];

class Node {
public:
    int dist, number;
    Node(int d, int n) {
        dist = d;
        number = n;
    }
};

bool operator < (const Node &l, const Node &r) {
    return l.dist < r.dist
    || (!(r.dist < l.dist) && l.number < r.number);
};

bool operator > (const Node &l, const Node &r) {
    return r < l;
};

class Edge {
public:
    int to, cost;
    Edge(int t, int c) {
        to = t;
        cost = c;
    }
};

int node_n;
vector<vector<Edge>> edges;
vector<int> d;

void edge_initializer(int n) {
    edges = vector<vector<Edge>>(n, vector<Edge>());
}

void dijkstra(int start_p) {
    d = vector<int>(node_n, INT_MAX); d[start_p] = 0;
    vector<int> prev = vector<int>(node_n, -1);

    priority_queue<Node,vector<Node>,greater<Node>> Q;

    for(int i=1; i<node_n; i++) {
        Q.push(Node(d[i],i));
    }

    while(!Q.empty()) {
        Node u = Q.top(); Q.pop();
        if(u.dist > d[u.number]) continue;
        for(Edge edge:edges[u.number]) {
            int alt = d[u.number] + edge.cost;
            int v = edge.to;
            if(d[v] > alt) {
                d[v] = alt;
                prev[v] = u.number;
                Q.push(Node(d[v],v));
            }
        }
    }

    REP(i,1,node_n) {
        int cur = i;
        while(prev[cur] != -1) {
            // if(cur==-1 || cur==0 || prev[cur]==-1 || prev[cur]==0) break;
            // cout << cur << " " << prev[cur] << endl;
            used[cur][prev[cur]] = used[prev[cur]][cur] = true;
            cur = prev[cur];
        }
    }
}

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

    cin >> N >> M; node_n = N+1;
    edge_initializer(node_n);
    rep(i,M) {
        int a, b, c; cin >> a >> b >> c;
        edges[a].pb(Edge(b,c));
        edges[b].pb(Edge(a,c));
    }

    REP(i,1,N+1) dijkstra(i);

    int cnt = 0;
    REP(i,edges.begin(),edges.end()) {
        REP(j,(*i).begin(),(*i).end()) {
            int n = i - edges.begin();
            if(!used[n][(*j).to]) cnt++;
        }
    }
    cout << cnt / 2 << endl;

    // REP(i,1,N+1) {
    //     REP(j,1,N+1) cout << used[i][j] << " ";
    //     cout << endl;
    // }
    return 0;
}


Measured memory_bytes: 256