akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        bool ok = s.Length == s.Distinct().Count();

        string answer = ok ? "yes" : "no";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

using namespace std;

int maxList(vector<int> vec) {
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    return vec.at(0);
}


int main() {
   int a, b;
   cin >> a >> b;
   cout << maxList({a + b, a - b, a * b}) << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Spyderエディタ

これは一時的なスクリプトファイルです
"""
n = int(input())

v = [0] * n
c = [0] * n

v = [int(s) for s in input().split()]
c = [int(s) for s in input().split()]

ans = []

for i in range(n):
    a = v[i] - c[i]
    if a > 0 :
      ans.append(a)
    
print(sum(ans))

    

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

count_max = -1
OK = True

for i in range(N):
    count = 0
    a = N - i
    while a % 2 == 0:
        a = a // 2
        count += 1
        if count_max < count:
            count_max = count
    else:
        continue
if 2 ** count_max == 0.5:
    print(1)
else:
    print(2 ** count_max)

Measured memory_bytes: 9184
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	nodes := make([]Node, n)

	for i := 0; i < n; i++ {
		nodes[i].list = make([]int, 0)
		nodes[i].d = -1
	}

	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		u--
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			v--
			nodes[u].list = append(nodes[u].list, v)
		}
	}

	queue := make([]int, n)
	queue[0] = 0
	nodes[0].d = 0
	d := 0
	i, j := 0, 1
	for i < j {
		d++
		prev := j
		for i < prev {
			for k, l := 0, len(nodes[queue[i]].list); k < l && i < n; k++ {
				if nodes[nodes[queue[i]].list[k]].d != -1 {
					continue
				}
				nodes[nodes[queue[i]].list[k]].d = d
				queue[j] = nodes[queue[i]].list[k]
				j++
			}
			i++
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i+1, nodes[i].d))
	}

	writer.Flush()
}

// Node ...
type Node struct {
	list []int
	d    int
}



Measured memory_bytes: 1148
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    Map<Integer, Integer> oMap = new HashMap<>();
    Map<Integer, Integer> eMap = new HashMap<>();

    for (int i = 0; i < N; i++) {
      int v = Integer.parseInt(sc.next());
      if (i % 2 == 0) {
        oMap.merge(v, 1, Integer::sum);
      } else {
        eMap.merge(v, 1, Integer::sum);
      }
    }

    List<Entry<Integer, Integer>> list_entries_o = new ArrayList<Entry<Integer, Integer>>(oMap.entrySet());
    Collections.sort(list_entries_o, new Comparator<Entry<Integer, Integer>>() {
      //compareを使用して値を比較する
      public int compare(Entry<Integer, Integer> obj1, Entry<Integer, Integer> obj2) {
        //降順
        return obj2.getValue().compareTo(obj1.getValue());
      }
    });

    List<Entry<Integer, Integer>> list_entries_e = new ArrayList<Entry<Integer, Integer>>(eMap.entrySet());
    Collections.sort(list_entries_e, new Comparator<Entry<Integer, Integer>>() {
      //compareを使用して値を比較する
      public int compare(Entry<Integer, Integer> obj1, Entry<Integer, Integer> obj2) {
        //降順
        return obj2.getValue().compareTo(obj1.getValue());
      }
    });

    int ans = 0;
    if (!list_entries_o.get(0).getKey().equals(list_entries_e.get(0).getKey())) {
      ans = N - list_entries_o.get(0).getValue() - list_entries_e.get(0).getValue();
    } else {
      int e = 0, o = 0;
      if (eMap.size() > 1) {
        e = list_entries_e.get(1).getValue();
      }
      if (oMap.size() > 1) {
        o = list_entries_o.get(1).getValue();
      }
      ans = Math.min(N - list_entries_o.get(0).getValue() - e, N - o - list_entries_e.get(0).getValue());
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 50140
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

bool reachable(int idx, int n, const vector<pair<char, char>>& magic,
               string s) {
    for (int i = 0; i < magic.size(); i++) {
        if (s[idx] == magic[i].first) {
            if (magic[i].second == 'L') idx--;
            if (magic[i].second == 'R') idx++;
        }
        if (idx == n) return true;
    }
    return false;
}

int main() {
    int n, q;
    string s;
    cin >> n >> q >> s;
    vector<pair<char, char>> magic(q);
    for (int i = 0; i < q; i++) {
        cin >> magic[i].first >> magic[i].second;
    }
    int dieLeft = -1;
    if (reachable(0, -1, magic, s)) {  // reach -1
        if (reachable(n - 1, -1, magic, s)) {
            dieLeft = n - 1;
        } else {
            int ok = 0;
            int ng = n - 1;
            while (abs(ng - ok) > 1) {
                int mid = (ok + ng) / 2;
                if (reachable(mid, -1, magic, s)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            dieLeft = ok;
        }
    }
    int dieRight = n;
    if (reachable(n - 1, n, magic, s)) {  // reach n
        if (reachable(0, n, magic, s)) {
            dieRight = 0;
        } else {
            int ok = n - 1;
            int ng = 0;
            while (abs(ng - ok) > 1) {
                int mid = (ok + ng) / 2;
                if (reachable(mid, n, magic, s)) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            dieRight = ok;
        }
    }
    cout << n - min(n, dieLeft + 1 + n - dieRight) << endl;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define fo(i,n) for(i=0;i<n;++i)
#define forr(i,n) for(i=n-1;i>=0;--i)
using namespace std;

ll gcd(ll a,ll b){while(a&&b)a>b?a%=b:b%=a;return a+b;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cerr<<"First never follows"<<endl;
	string s;
	cin>>s;
	int i, a[26]={0};
	fo(i,s.length())
		a[s[i]-'a']++;
	fo(i,26){
		if(a[i]&1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
    int n;
    cin >> n;
    cout << setprecision(10) << ( (n % 2 == 1) ? ((double)((n/2) + 1) / (double)n) : ((double)(n/2) / (double)n) ) << endl;
}








































//以下、ライブラリ
//ユークリッドの互除法

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
}



Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
num=1
start=0
while(start != -1):
    try:
        start=a.index(num,start)
        num+=1
    except ValueError:
        break
num-=1
#print(n,num)
if(num>0):
    print(n-num)
else:
    print(-1)

Measured memory_bytes: 26268
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include <iomanip>
using namespace std;

int main()
{
    long long n,ans=0;
    cin>>n;
    vector<long long>a(n+1),b(n);
    for(int i=0;i<n+1;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    
    for(int i=0;i<n;i++){
        if(b[i]>=a[i]){
            ans+=a[i];
            b[i]-=a[i];
            if(b[i]>0 and b[i]<=a[i+1]){
                ans+=b[i];
                a[i+1]-=b[i];
            }else if(b[i]>0 and b[i]>a[i+1]){
                ans+=a[i+1];
                a[i+1]=0;
            }
            
        }else{//if(b[i]<a[i])
            ans+=b[i];
            a[i]-=b[i];
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
    // Your code here!
    int H,W;
    char map[100][100];
    char map_2[200][100];
    
    scanf("%d%d",&H,&W);
    
    for(int i = 0; i < H; i++){
        for(int j = 0;j < W;j++){
            scanf(" %c ",&map[i][j]);
        }
    }
    
    for(int i = 0;i < 2*H;i++){
        for(int j = 0;j<W;j++){
            map_2[i][j] = map[i/2][j];
            printf("%c",map_2[i][j]);
        }
        printf("\n");
    }
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MOD (ll)998244353

int l[200001], r[200001];
set<int> se;
vector<int> v;
ll dp[200001];
ll dpsum[200001];

int main(void)
{
    int n, k;
    scanf("%d %d", &n, &k);

    for (int i = 1; i <= k; i++)
    {
        scanf("%d %d", &l[i], &r[i]);
    }

    dp[1] = 1LL, dpsum[1] = 1LL;

    for (int i = 1; i <= 200000; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            dp[i] = (dp[i] + dpsum[max(0, i - l[j])] - dpsum[max(0, i - r[j] - 1)]) % MOD;
        }
        dpsum[i] = (dpsum[i - 1] + dp[i]);
    }

    /*for (int i = 1; i <= n; i++)
        printf("%lld ", dp[i]);
    printf("\n");
    for (int i = 1; i <= n; i++)
        printf("%lld ", dpsum[i]);
    printf("\n");*/

    printf("%lld", dp[n]);
    return 0;
}

Measured memory_bytes: 6324
#include<bits/stdc++.h>
#include<set>
#include<map>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define itrep(at)	for(auto it=at.begin();it!=at.end();it++)
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
#define INF 1e18

#define MAX 100005

using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}

struct pll{
	lli x,y,z;
};
bool comp(pll a,pll b){
	if(a.x==b.x)	return a.y<b.y;
	else	return a.x<b.x;
}
void solve(lli the)
{
	char ch;
	db aa,bb,cc;
	string s1,s2,s3,str;
    lli i,j,k,a,b,c,d,n,m,l,r,x,y,low,high,mid,sum=0,ans=0,temp,t;
    cin >> x;
    for(i=0;i<=5400;i++){
    	a=i*i*i*i*i;
    	for(j=-5400;j<=5400;j++){
    		b=j*j*j*j*j;
    		if(a-b==x){
    			cout<<i<<" "<<j;return;
			}
		}
	}
    
    
}












int main()
{
	long long int t=1,c=1;
	//scanf("%lld",&t);
	while(t--){
		solve(c);
		c++;
	}
	return 0;
}
/* UJJWAL KESHRI */

Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int [] a = new int[3];

        for (int i = 0; i < 3; i++) {
            a[i] = input.nextInt();
        }

        Arrays.sort(a);

        System.out.println(Math.abs(a[0] - a[1]) + Math.abs(a[1] - a[2]));
    }
}


Measured memory_bytes: 23892
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll X, A;
    cin >> X >> A;
    if (X < A)
    {
        cout << 0;
    }
    else
    {
        cout << 10;
    }
    return 0;
}


Measured memory_bytes: 3144
N, W = map(int, input().split())
vw = [0] * N
for i in range(N):
  vw[i] = list(map(int, input().split()))
  
#vw = sorted(vw, key = lambda, x:x[1]) 
            
dp = [0] * (W + 1)
for i in range(W + 1):
  for j in range(N):
    if i >= vw[j][1]:
      dp[i] = max(dp[i], dp[i - vw[j][1]] + vw[j][0])
  
print(dp[-1])  





Measured memory_bytes: 5920
import java.util.Scanner;

public class Main {

  private static String[] results = new String[3];

  private static int[] input = new int[4];

  public static void main(String args[]) {
    Scanner scanner = new Scanner(System.in);
 
    String line = scanner.nextLine();
    

    for(int i = 0;i < line.length();i++){
      input[i] = Character.getNumericValue(line.charAt(i));
    }

    boolean flg = dfs(0,input[0]);

    String A = Integer.toString(input[0]);
    String B = Integer.toString(input[1]);
    String C = Integer.toString(input[2]);
    String D = Integer.toString(input[3]);

    // String answer = A+results[0]+B+results[1]+C+results[2]+D+"=7";

    System.out.print(A+results[0]+B+results[1]+C+results[2]+D+"=7");
    scanner.close();
  }

  public static boolean dfs(int index,int sum){

    if(index == 3 && sum == 7){
      return true;
    }else if(index <=2){

      results[index] = "+";

      if(dfs(index+1,sum+input[index+1])){
        return true;
      }
  
      results[index] = "-";

      if(dfs(index+1,sum-input[index+1])){
        return true;
      }
  
    }

    return false;
  }

}

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

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    vi A(n), B(n);
    rep(i, n)
        cin >> A[i] >> B[i];

    sort(begin(A),end(A));
    sort(begin(B),end(B));

    ll x,y;

    if(n%2) {
        x=A[n/2];
        y=B[n/2];
    } else {
        x=A[n/2-1] + A[n/2];
        y=B[n/2-1] + B[n/2];
    }

    cout<<y-x+1;

    return 0;
}


Measured memory_bytes: 4768
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Iterator;

public class Main {

	static BufferedReader reader;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		String[] HN = readLine();
		int H = Integer.parseInt(HN[0]);
		int N = Integer.parseInt(HN[1]);
		Map<Float,Attack> atks = new TreeMap<>();
		for(int i=0;i<N;i++) {
			String[] t = readLine();
			int a = Integer.parseInt(t[0]);
			int m = Integer.parseInt(t[1]);
			Attack att;
			if((att = atks.get((float)a/m))!=null) {
				if(att.m>m) {
					atks.put((float)a/m,new Attack(a,m));
				}
			}else {
				atks.put((float)a/m,new Attack(a,m));
			}
			
		}
		int Nn = atks.size();
		Attack[] atk = new Attack[Nn];
		Set<Float> ks = atks.keySet();
		Iterator<Float> ki = ks.iterator();
		for(int i=0;i<Nn;i++) {
			atk[Nn-i-1] = atks.get(ki.next());
		}
		
		int[] dpt = new int[H+1];
		Arrays.fill(dpt,Integer.MAX_VALUE);
		dpt[0] = 0;
		for(int i=0;i<Nn;i++) {
			Attack a = atk[i];
			for(int h=1;h<=H;h++) {
				int from = Math.max(0,h-a.a);
				if(dpt[from]+a.m<dpt[h]) {dpt[h]=dpt[from]+a.m;}
			}
		}
		print(dpt[H]);
		
		//String[] s = readLine();
		//print(num);
	}
	
	//functions here
	//note that all methods should be STATIC
	private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
}

class Attack{
	int a;
	int m;
	
	public Attack(int a, int m){
		// TODO 自動生成されたコンストラクター・スタブ
		this.a = a;
		this.m = m;
	}
	public String toString() {
		return a+"-"+m;
	}
}

class AttackNode{
	Attack atk;
	AttackNode parent;
	AttackNode[] child;
	int Hleft;
	int M;
	
	public AttackNode(Attack atk){
		// TODO 自動生成されたコンストラクター・スタブ
		this.atk = atk;
		this.child = null;
	}
	public void generateChilds(Attack[] atks) {
		float c = (float)atk.a/atk.m;
		child = new AttackNode[atks.length];
		for(int i=0;i<atks.length;i++) {
			if(c*atks[i].m<atks[i].a) {continue;}
			child[i] = new AttackNode(atks[i]);
			child[i].parent = this;
		}
	}
	public String toString() {
		if(parent==null) {return atk.toString();}
		else {return parent.toString()+"->"+atk.toString();}
	}
}


Measured memory_bytes: 22484
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        OneorTwo solver = new OneorTwo();
        solver.solve(1, in, out);
        out.close();
    }

    static class OneorTwo {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            UnionFind uf = new UnionFind(n);
            Set<Integer> set = new HashSet<>();
            for (int i = 0; i < m; i++) {
                int x = Integer.parseInt(in.next()) - 1;
                int y = Integer.parseInt(in.next()) - 1;
                int z = Integer.parseInt(in.next());
                uf.unite(x, y);
            }
            for (int i = 0; i < n; i++) {
                set.add(uf.findSet(i));
            }
            out.print(set.size());
        }

        public class UnionFind {
            private int[] ranks;
            private int[] parents;

            public UnionFind() {
            }

            public UnionFind(int size) {
                ranks = new int[size];
                parents = new int[size];
                for (int i = 0; i < size; i++) {
                    makeSet(i);
                }
            }

            public void makeSet(int x) {
                parents[x] = x;
                ranks[x] = 0;
            }

            public int findSet(int x) {
                if (x != parents[x]) {
                    parents[x] = findSet(parents[x]);
                }
                return parents[x];
            }

            public void unite(int x, int y) {
                if (same(x, y)) {
                    return;
                }
                link(findSet(x), findSet(y));
            }

            public boolean same(int x, int y) {
                return findSet(x) == findSet(y);
            }

            private void link(int x, int y) {
                if (ranks[x] > ranks[y]) {
                    parents[y] = parents[x];
                } else {
                    parents[x] = parents[y];
                    if (ranks[x] == ranks[y]) {
                        ranks[y]++;
                    }
                }
            }

        }

    }
}



Measured memory_bytes: 61032
import java.io.*
import java.util.*

const val YES = "YES"
const val NO = "NO"
fun solve(A: Long, B: Long, X: Long){
    if(A <= X && X <= A+B){
        println(YES)
    }else println(NO)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    val X = sc.next().toLong()
    solve(A, B, X)
}



Measured memory_bytes: 31524
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
using namespace std;
typedef long long ll;


int main(void) {
	int n, k; cin >> n >> k;
	int cnt = 0;
	while (n != 0) {
		n /= k;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const long long INF = 9223372000000000000/2145;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    int n;
    int ans=0,sm=0,mini=114514;
    scanf("%d",&n);
    REP(i,n){
        int tmp;
        scanf("%d",&tmp);
        sm += tmp;
        if(tmp%10) if(mini>tmp) mini = tmp;
    }
    
    if(sm%10) printf("%d\n",sm);
    else if(mini!=114514) printf("%d\n",sm-mini);
    else printf("0\n");

    return 0;
}

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

ll gcd(ll a, ll b) {
    while ( b != 0 ) {
        ll t = b;
        b = a % b;
        a = t;
    }
    return a;
}

ll solve() {
    ll A, B;
    cin >> A >> B;
    ll g = gcd(A,B);

    set<ll> d;
    for ( ll k = 2; k*k <= g; k++ ) {
        while ( g % k == 0 ) {
            g /= k;
            d.insert(k);
        }
    }
    if ( g > 1 ) d.insert(g);
    
    ll ans = d.size() + 1;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//
		int matches = 0;
		// 対戦者達
		String[] players = { "太郎", "花子" };
		//
		ArrayList<player2> players_beans = new ArrayList<player2>();;
		//プレイヤーのインスタンスを作る
		for (String val : players) {
			player2 obj = new player2();
			obj.setName(val);
			players_beans.add(obj);
		}

		// 標準入力
		Scanner sc = new Scanner(System.in);


		// 対戦回数
		while (sc.hasNext()) {

			matches = sc.nextInt();
			break;
		}

		// 対戦回数分まわす
		for (int m = 0; m < matches; m++) {

			// カードを入れるリスト
			ArrayList<String> battle = new ArrayList<String>();

			while (sc.hasNext()) {
				// 入力文字列をリストに追加
				String taro_card = sc.next();
				String hanako_card = sc.next();
				
				battle.add(taro_card);
				battle.add(hanako_card);

				// アルファベット順にソート
				Collections.sort(battle);

				// 引き分けの場合
				if (taro_card.equals(hanako_card)) {
					players_beans.get(0).setPoints(1);
					players_beans.get(1).setPoints(1);
				}

				// 太郎が勝つ場合
				else if (battle.get(0).equals(hanako_card)) {
					players_beans.get(0).setPoints(3);
				}

				// 花子が勝つ場合
				else if (battle.get(0).equals(taro_card)) {
					players_beans.get(1).setPoints(3);
				}

				break;
			}
		}

		// 出力
		System.out.println(players_beans.get(0).getPoints() + " " + players_beans.get(1).getPoints());
	}
}

// 各プレイヤーのプロパティ
class player2 {

	//
	private String name = "";
	private String card = "";
	private int points = 0;

	// セッター
	public void setName(String n) {
		name = n;
	}

	public void setCard(String c) {
		card = c;
	}

	// 合計値を持つようにする
	public void setPoints(int p) {
		points += p;
	}

	// ゲッター
	public String getName() {
		return name;
	}

	public String getCard() {
		return card;
	}

	public int getPoints() {
		return points;
	}

}

Measured memory_bytes: 23120
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
    int l[100002], r[100002];
    P p[100002];
    int lar = 0;
    int arglar = -1;
    for(int i = 0; i < n; i++){
        cin >> l[i] >> r[i];
        p[i] = P(r[i], l[i]);
        if(r[i] - l[i] + 1 > lar){
            lar = r[i] - l[i] + 1;
            arglar = i;
        }
    }
    int maxl = 0, minr = 1000000000;
    for(int i = 0; i < n; i++){
        if(i == arglar) continue;
        maxl = max(maxl, l[i]);
        minr = min(minr, r[i]);
    }
    int ans = lar + max(0, minr + 1 - maxl);
    sort(p, p + n);
    int lr = p[0].first;
    int ll = 0;
    int sl[100002];
    for(int i = 0; i < n - 1; i++){
        ll = max(ll, p[i].second);
        sl[i] = max(0, lr + 1 - ll);
    }
    int left[100002];
    left[n - 1] = p[n - 1].second;
    for(int i = n - 2; i >= 0; i--){
        left[i] = max(left[i + 1], p[i].second);
    }
    int sr[100002];
    for(int i = 0; i < n; i++){
        sr[i] = max(0, p[i].first + 1 - left[i]);
    }
    for(int i = 0; i < n - 1; i++){
        ans = max(ans, sl[i] + sr[i + 1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
P ans[100];
bool solve(LL a[50], int N, bool rev) {
	memset(ans, 0, sizeof(ans));
	LL Max = a[0];
	int pos = 0;
	for (int i = 1; i < N; i++) {
		if (Max < a[i]) {
			Max = a[i];
			pos = i;
		}
	}
	if (Max < 0) return 0;
	int cnt = 0;
	for (int i = 0; i + 1 < N; i++) {
		while (a[i] > a[i + 1]) {
			ans[cnt].first = pos;
			ans[cnt].second = i + 1;
			cnt++;
			if (cnt > 2 * N) return 0;
			a[i + 1] += Max;
			if (Max < a[i + 1]) {
				Max = a[i + 1];
				pos = i + 1;
			}
		}
	}
	cout << cnt << endl;
	for (int i = 0; i < cnt; i++) {
		if (rev) cout << (N - ans[i].first) << " " << (N - ans[i].second) << endl;
		else cout << (ans[i].first + 1) << " " << (ans[i].second + 1) << endl;
	}
	return 1;
}
int main() {
	int N;
	cin >> N;
	LL a[50], b[50];
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int i = 0; i < N; i++) b[i] = -a[N - 1 - i];
	if (solve(a, N, 0)) return 0;
	solve(b, N, 1);
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    string S;
    cin >> S;

    string T = "";
    string KIHBR = "KIHBR";
    bool unrelated = false;
    for (auto c: S) {
        for (int i = 0; i < 5; i++) {
            if (c == KIHBR[i]) {
                T += c;
            }
        }
        if (KIHBR.find(c) == string::npos && c != 'A') {
            unrelated = true;
        }
    }

    if (T != KIHBR || unrelated) {
        cout << "NO";
        return 0;
    }

    map<char, int> M;
    for (int i = 0; i < S.size(); i++) if (S[i] != 'A') M[S[i]] = i;

    bool good = true;
    if (M['K'] >= 2) good = false;
    if (M['I'] - M['K'] >= 2) good = false;
    if (M['H'] - M['I'] >= 2) good = false;
    if (M['B'] - M['H'] >= 3) good = false;
    if (M['R'] - M['B'] >= 3) good = false;
    if (S.size() - M['R'] >= 3) good = false;

    if(good) cout << "YES";
    else cout << "NO";

}






















































Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;


int main() {
	
	ll N;
	cin >> N;
	
	REP(h, 1, 3501){
		REP(n, h, 3501){
			if(4*h*n <= N * (h+n)) continue;
			if((N*h*n) % (4*h*n - N * (h+n)) != 0) continue;
			cout << h << " " << n << " " << (N*h*n) / (4*h*n - N * (h+n))  << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
while True:
    a, b = map(int, input().split())
    if a <= 0 or b <= 0:
        break
    elif a > 10 **9 or b > 10**9:
        break
    else:
        d = int(a/b)
        r = int(a%b)
        f = float(a/b)
        print(d, r, "{0:01.5f}".format(f))
        break

Measured memory_bytes: 7656
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	int n; cin >> n;
	if(n < 1000){
		cout << "ABC" << endl;
	}else{
		cout << "ABD" << endl;
	}
}

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

int main(){
  string S,T,U;
  int A,B;
  cin >> S >> T >> A >> B >> U;
  if(S==U){
    cout << A-1 << " " << B << endl;
  }
  else{
    cout << A << " " << B-1 << endl;
  }
}
  

Measured memory_bytes: 3620
import java.util.Scanner;


public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		//User Input
			int firstNum = sc.nextInt();

			int secondNum = sc.nextInt();

		//If statement
			if(firstNum <= 9 && firstNum >= 0 && secondNum >= 0 && secondNum <= 9)
			{
				int product = firstNum * secondNum;
				System.out.println(product);
			}
			else
				System.out.println("-1");
	}

}

Measured memory_bytes: 21972
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (true) {
			int chuu = sc.nextInt();
			int kima = sc.nextInt();
			int sai = sc.nextInt();
			if (chuu==-1 && kima==-1 && sai==-1) {break;}
			
			if (chuu==-1 || kima==-1) {System.out.println("F");}
			else if (chuu+kima >= 80) {System.out.println("A");}
			else if (chuu+kima >= 65 && chuu+kima <80) {System.out.println("B");}
			else if (chuu+kima >=50 && chuu+kima < 65) {System.out.println("C");}
			else if (chuu+kima >=30 && chuu+kima <50) {
				if (sai >= 50) {System.out.println("C");}
				else {System.out.println("D");}
			}
			else if (chuu+kima < 30) {System.out.println("F");}
		}
	}
}


Measured memory_bytes: 26204
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string s;
  int h,w;
  char x='A';
  cin>>h>>w;
  for(int i=1;i<=h;i++){
    for(int j=0;j<w;j++){
      cin>>s;
      if(s=="snuke"){
	cout<<char(x+j)<<i<<'\n';
      }
    }
  }
  return 0;
}


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

bool isPrime(int x) {
	bool flag = true;
	for(int i = 2; i <= sqrt(x); i++) {
		if(x % i == 0) {
			flag = false;
			break;
		}
	}
	return flag;
}

int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int x;
    cin>>x;
    while(1) {
    	if(isPrime(x)) {
    		cout<<x;
    		return 0;
    	}
    	x++;
    }
	return 0;		
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef pair<P,int> Pi;
typedef long long ll;

int w,h;
int board[31][31];
int c[4];

// dir : ??? 0,??? 1,??? 2,??? 3
P next(P p,int &dir,int cmd) {
    if(cmd==1) {
        dir++;
    }
    else if(cmd==2) {
        dir+=2;
    }
    else if(cmd==3) {
        dir--;
    }

    while(dir<0) dir+=4;
    dir%=4;
    p.fr+=dy[dir];
    p.sc+=dx[dir];

    return p;
}

int bfs() {
    map<Pi,int> d;
    queue<Pi> que;
    que.push(Pi(P(0,0),0));
    rep(y,h) rep(x,w) rep(k,4) d[Pi(P(y,x),k)]=INF;
    d[Pi(P(0,0),0)]=0;
    while(que.size()) {
        Pi p=que.front();
        que.pop();
        int y=p.fr.fr;
        int x=p.fr.sc;
        int dir=p.sc;
        int cmd=board[y][x];

        //printf("[debug] %d,%d,%d : %d\n",y,x,dir,d[p]);
        if(cmd!=4) {
            Pi next_p={next(p.fr,dir,cmd),0};
            next_p.sc=dir;

            if(0<=next_p.fr.fr<h && 0<=next_p.fr.sc<w && d[next_p]>d[p]) {
                d[next_p]=min(d[next_p],d[p]);
                que.push(next_p);
            }
        }
        rep(i,4) {
            dir=p.sc;
            Pi next_p={next(p.fr,dir,i),0};
            next_p.sc=dir;
            if(0<=next_p.fr.fr<h && 0<=next_p.fr.sc<w && d[next_p]>d[p]+c[i]) {
                d[next_p]=min(d[next_p],d[p]+c[i]);
                que.push(next_p);
            }
        }
    }
    int ret=INF;
    rep(i,4) if(d.count(Pi(P(h-1,w-1),i))) {
        //printf("%d %d\n",i,d[Pi(P(h-1,w-1),i)]);
        ret=min(ret,d[Pi(P(h-1,w-1),i)]);
    }

    return ret;
}
void solve() {
    rep(y,h) rep(x,w) cin>>board[y][x];
    rep(i,4) cin>>c[i];
    int ans=bfs();

    cout<<ans<<endl;
}
int main() {
    while(cin>>w>>h) {
        if(!w) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1484
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	
	int N, M;
	cin >> N >> M;
	int* X = new int[M];
	for (int i = 0; i < M; i++)
	{
		cin >> X[i];
	}
	sort(X, X + M);
	int* between = new int[M - 1];
	for (int i = 0; i < M - 1; i++)
	{
		between[i] = X[i + 1] - X[i];
	}
	sort(between, between + M - 1);
	int output = 0;
	for (int i = 0; i < M - N; i++)
	{
		output += between[i];
	}
	cout << output << endl;
	

	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,i,x1,x2,x3,z1,z2,z3,w1,w2,w3,y1,y2,y3;

	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++)	{
			scanf("%d %d %d %d %d %d %d %d",&x1,&y1,&z1,&w1,&x2,&y2,&z2,&w2);
			x3=x1*x2-y1*y2-z1*z2-w1*w2;
			y3=y1*x2+x1*y2-w1*z2+z1*w2;
			z3=x1*z2-y1*w2+z1*x2+w1*y2;
			w3=x1*w2+y1*z2-z1*y2+w1*x2;
			printf("%d %d %d %d\n",x3,y3,z3,w3);
		}
	}
	return 0;
}


Measured memory_bytes: 2684
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <cstring>
using namespace std;
#define LL long long
LL a[4];
int main(){
    for (int i = 0; i < 3; i++){
         scanf("%lld",&a[i]);
    }
    for (int i = 0; i < 3; i++){
         if (!(a[i] & 1)) {
            printf("0\n");
            return 0;
         }
    }
    LL ans = 2e18;
    for (int i = 0; i < 3; i++){
        ans = min(ans,a[i] * a[(i + 1) % 3]);
    }
    printf("%lld\n",ans);

}


Measured memory_bytes: 256
tmp = [int(i) for i in raw_input().split()]

N = tmp[0]
M = tmp[1]
C = tmp[2]

B = [int(i) for i in raw_input().split()]

count = 0
sum = 0

for i in range(N):
    tmp3 = [int(i) for i in raw_input().split()]
    
    for i in range(M):
        sum += tmp3[i]*B[i]
    if sum + C > 0:
        count += 1
    sum = 0
print(count)

Measured memory_bytes: 2568
sub f{my($u)=@_;
my$c=$c[$u-1]-1;
my$r=$v[$u]=1;
my$p=$h[$c];
my$s=1;
$v[$_]or($;=f($_),$t=$r+$;-$s-($h[$c]-$p),$a[$c]+=$t*$s,
$s+=$t,$r+=$;)for@$u;
$a[$c]+=($r-$h[$c]+$p)*($n-$p-$r)+1;
$h[$c]=$p+$r;
$r}
$n=@a=(0)x<>;
@c=glob<>;
map{($u,$v)=split;push@$u,$v;push@$v,$u}<>;
f 1;
print"@a"
##################################################
##################################################
##################################################
##################################################
##################################################
##################################################
##################################################
##################################################


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

int main() {
	int i, j, k;
	int	n, m, h, g, c, d, l, r;
	long long int f = 0;
	long long int w;
	long long int a;
	long long int b;

	scanf("%lld %lld", &a, &b);

	f = (a + b) / 2;
	w = a + b;
	if (f < 0) {
		f = f * -1;
		w = w * -1;
	}

	if (w % 2 == 1) {
		printf("IMPOSSIBLE");
		return 0;
	}

	printf("%lld", f);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll dp[19][10000][2][2];
bool ck(int c){
    if(c/1000==5&&c/100%10==1&&c%10==3) return true;
    return false;
}
int main(){
    string s;
    cin>>s;
    int n=s.size();
    dp[0][0][0][0]=1;
    rep(i,n)rep(j,10000)rep(k,2)rep(l,2){
        int ulim=l?9:s[i]-'0';
        rep(p,ulim+1){
            dp[i+1][(j*10+p)%10000][k||ck((j*10+p)%10000)][l||p<ulim]+=dp[i][j][k][l];
        }
    }
    ll ans=0;
    rep(i,10000)rep(k,2) ans+=dp[n][i][1][k];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8840
#include <iostream>
#include <assert.h>
using namespace std;

#define INFT 1000000007

void calc(int a, int b)
{
    assert(a >= b);
    if (a == b) {
        long product = 1;
        while (a) {
            product *= a;
            product %= INFT;
            a--;
        }
        cout << ((2 * product % INFT) * product) % INFT << endl;
    }
    if (a == b + 1) {
        long product = 1;
        while (b) {
            product *= b;
            product %= INFT;
            b--;
        }
        cout << ((a * product % INFT) * product) % INFT << endl;
    }
    return;
}

int main()
{
    int n, m;
    cin >> n >> m;
    if (n - m > 1 || n - m < -1) {
        cout << 0 << endl;
    }
    if (n - m >= 0) {
        calc(n, m);
    } else {
        calc(m, n);
    }
    return 0;
}

Measured memory_bytes: 256
int gcd(int a, int b) {
    int m = a>b?a:b, n = a<b?a:b;
    while (n) {
        m = m % n;
        m ^= n; n ^= m; m ^= n;
    }
    return m;
}
int main() {
    int N, X, x, r = 0;
    for (scanf("%d%d", &N, &X); N--;) {
        scanf("%d", &x);
        r = gcd(abs(x - X), r);
        if (r == 1) break;
    }
    printf("%d\n", r);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)
vector<int> DP, S;


int main() {
    int N;
    cin>>N;
    DP.resize(N+1, __INT_MAX__); S.resize(N+1);
    REP(i, 1, N+1){
        cin >> S[i];
    }
    DP[1] = 0;
    DP[2] = abs(S[2]- S[1]);
    REP(i, 3, N+1){
        DP[i] = min(DP[i-1]+abs(S[i]-S[i-1]), DP[i-2]+abs(S[i]-S[i-2]));
    }
    cout << DP[N] << endl;
}

Measured memory_bytes: 1024
n = int(input())
alis = list(map(int, input().split()))
blis = list(map(int, input().split()))
ans = 0
for i in range(n):
    if alis[i] + alis[i+1] > blis[i]:
        ans += blis[i]
        alis[i+1] = alis[i+1] - max(blis[i] - alis[i], 0)
    else:
        ans += alis[i] + alis[i+1]
        alis[i+1] = 0
print(ans)

Measured memory_bytes: 18476
/*
    Author: Aryan Yadav
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define f(i, a, b) for (long long i = a; i < b; i++)
#define rep(i, a, b) for (long long i = a; i <= b; i++)
#define fm(i, a, b) for (long long i = a; i > b; i--)
#define repm(i, a, b) for (long long i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define pqmaxi priority_queue<int>
#define pqmaxl priority_queue<ll>
#define pqmini priority_queue<int, vi, greater<int>>
#define pqminl priority_queue<ll, vl, greater<ll>>
#define t     \
    ll t;     \
    cin >> t; \
    while (t--)
#define pb(i) push_back(i)
#define mp(i, j) make_pair(i, j)
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL)
double pi = 3.1415926535897;
int main()
{
    string s;
    cin >> s;
    stack<char> st;
    ll cnt = 0;
    f(i, 0, s.length())
    {
        if (st.empty())
        {
            st.push(s[i]);
        }
        else
        {
            if ((st.top() == '1' && s[i] == '0') || (st.top() == '0' && s[i] == '1'))
            {
                st.pop();
                cnt += 2;
            }
            else
            {
                st.push(s[i]);
            }
        }
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 512
//dp[桁][mod 10000][prefixがNと一致しているか][ごちうさ数だと確定したか] = 個数すれば良い。
//一見、dp[桁][51?3のうち何文字とマッチしたか？][(同様なので略)]でできそうに見えるが、マッチしなかったときの遷移が、これだけでは一意に定まらないので
//できない。例えば、(N=999999で) 515153をチェックするとき「515」までマッチするが次の「1」でマッチしない。しかし、次は「51」までマッチした状態から始める必要がある。
//一方で、513153をチェックするとき「515」までマッチするが次の「5」でマッチしない。この場合は、次は「ノーマッチ」の状態から始める必要がある。(↑と状態を同一視できないことが分かる。）

#include <iostream>
#include <string>
#define rep(i, n) for (i = 0; i < n; i++)
#define int long long
using namespace std;

bool check(int x) { if (x / 1000 == 5 && (x % 1000) / 100 == 1 && x % 10 == 3) return true; return false; }
string s;
int dp[19][10000][2][2];

signed main() {
	int i, j, k, l, m;
	
	cin >> s;
	dp[0][0][1][0] = 1;
	
	rep(i, s.length()) {
		rep(j, 10000) {
			rep(k, 2) {
				rep(l, 2) {
					rep(m, 10) {
						if (k == 1 && m > s[i] - '0') break;
						dp[i + 1][(j * 10 + m) % 10000][k && (m == s[i] - '0')][l || check((j * 10 + m) % 10000)] += dp[i][j][k][l];
					}
				}
			}
		}
	}
	
	int ans = 0;
	rep(j, 10000) rep(k, 2) ans += dp[s.length()][j][k][1];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8820
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i%k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}

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

#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

signed main(){
    int n,m; cin >> n >> m;
    
    vector<int> a(m),b(m);
    rep(i,m) {cin >> a[i] >> b[i]; a[i]--; b[i]--;}

    int res=0;
    rep(i,m){
        UnionFind uf(n);
        rep(j,m){
            if(i==j) continue;
            uf.unite(a[j],b[j]);
        }
        int isBridge=0;
        rep(k,n){
            if(uf.root(k)==k){
                isBridge++;
            }
        }
        if(isBridge!=1) res++;
    }
    cout<<res<<endl;

}

Measured memory_bytes: 256