akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
 
const long long   INF       = 1000000007ll*1000000007ll;
const long long   N         = 1000002;
 
long long l, r, d;
long long n, m;
long long ans[N];
bool mark[N];
vector < pair < long long , long long > > g[N];
 
void dfs(int v) 
{
    mark[v] = true;
    for (int i = 0; i < g[v].size(); ++i) 
    {
        long long to = g[v][i].first, len = g[v][i].second;
        if (ans[to] == INF) ans[to] = ans[v] + len;
        if (ans[to] != ans[v] + len) 
	    {
            printf("No\n");
            exit(0);
        }
        if (!mark[to]) dfs(to);
    }
}
 
void solve() 
{
    fill(ans, ans+N, INF);
    scanf("%d%d", &n , &m);
    for (int i = 0; i < m; ++i) 
    {
        scanf("%d%d%d", &l , &r ,&d);
        g[l].push_back({r, d});
        g[r].push_back({l, -d});
    }
    for (int i = 1; i <= n; ++i) 
    {
        if (!mark[i]) 
	    {
            ans[i] = 0;
            dfs(i);
        }
    }
    printf("Yes\n");
}
 
int main() 
{
    long long t = 1;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 45568
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.TreeSet;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main{
	static Scanner s=new Scanner(System.in);

	void solve(){
		int n=gInt();
		TreeSet<Integer>t=new TreeSet<>();
		INTS(n).sorted().forEach(t::add);

		int max=t.pollLast();
		Integer left=t.floor(max/2);
		Integer right=t.ceiling(max/2+1);
		if(left==null)
			left=t.first();
		if(right==null)
			right=t.last();
		System.out.println(
				Math.abs(max/2.0-left)<Math.abs(max/2.0-right)
				?(max+" "+left):(max+" "+right)
				);
	}

	public static void main(String[] $){
		new Main().solve();
	}

	static int gInt(){
		return Integer.parseInt(s.next());
	}
	static long gLong(){
		return Long.parseLong(s.next());
	}
	static double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,Main::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,Main::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,Main::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(Main::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}
class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}

	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}

}


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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
	int a = ri();
	int b = ri();
	int c = ri();
	int x = ri();
	int y = ri();
	
	s64 res = 0;
	int mi = min(x,y);
	res += mi*min(c*2,a+b);
	int left = max(x,y) - mi;
	if (x>y) res += left * min(2*c,a);
	if (y>x) res += left * min(2*c,b);
	cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import math
n, k = map(int, input().split())

if k <= n:
  prob = 1 - (k-1)/n
else:
  prob = 0

p = 1 - prob
for i in range(1, min(k, n+1)):
  prob += 0.5 ** math.ceil(math.log2(k/i)) / n

print(prob)

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

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

  int n,W;
  cin >> n >> W;

  int w[n],v[n];

  REP(i,n)cin >> w[i] >> v[i];

  vector<vector<ll>> dp(2,vector<ll>(W+1,0));


  REP(i,n){
    int from = i&1;
    int to = (i+1)&1;
    REP(j,W+1){
      if(j-w[i] >= 0){
        dp[to][j] = max(dp[from][j] , dp[from][j-w[i]] + v[i]);
      }else{
        dp[to][j] = dp[from][j];
      }
    }
  }

  cout << dp[n&1][W] << endl;
  

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int frag;
  if(n%2) frag = n;
  else frag = n+1;
  int ans = n *(n -1) /2;
  ans -= n/2;
  cout << ans << endl;
  for(int i=1; i<=n; ++i) for(int j=i+1; j<=n; ++j){
    if(i+j == frag) continue;
    printf("%d %d\n",i,j);
  }
}

Measured memory_bytes: 3764
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		long result = 0;
		if(n == 1 && m == 1){
		    result = 1; 
		}else if(n == 1 || m == 1){
		    result = max(n, m) - 2;
		}else{
		    result = (long)max(0, (n-2))*max(0, (m-2));
		}
		
		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 21588
//vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
//includeとusing
#include <bits/stdc++.h>
using namespace std;
//型名省略
using ll = long long;
using st = string;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using pcc = pair<char, char>;
//定数
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define REP(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define RREP(i,x,n) for(ll i = (ll) n - 1; i >= x; i--)
#define each(i,A) for(ll i: (vl) A)
#define all(A) A.begin(), A.end()
#define Size(A) ll(A.size())
//入力
template<typename T> T input() {T x; cin >> x; return x;}
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
//余り切り上げ
ll ceil(ll a,ll b) {return (a + b - 1) / b;}
//最大値・最小値
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b) {a = b; return true;} return false;}
//最大公約数
ll gcd(ll a,ll b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
//最小公倍数
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//n乗の余り
ll modpow(ll x,ll n,ll mod){ll res=1;for(ll i=0;i<n;i++){res=res*x%mod;}return res;}
ll MODpow(ll x,ll n){ll res=1;for(ll i=0;i<n;i++){res=res*x%MOD;}return res;}


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

//main関数
int main() {
    ll n; cin >> n;
    cout << n * (n + 1) / 2 << endl;
}



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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	ll a = 1;
	int ans = 0;
	while (a < n) {
		a *= 3;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
string s;
bool check(int a,int b){
  int ok=1;
  if(a==0){
    if(b==0)s="NA";
    else if(b<=12)s="YYMM";
    else s="NA";
  }
  else if(a<=12){
    if(b==0)s="MMYY";
    else if(b<=12)s="AMBIGUOUS";
    else s="MMYY";
  }
  else{
    if(b==0)s="NA";
    else if(b<=12)s="YYMM";
    else s="NA";
  }
}
int main(){
  string s1;
  cin>>s1;
  int a,b;
  a=0;
  b=0;
  for(int i=0;i<2;i++){
    a=a*10+(s1[i]-'0');
    b=b*10+(s1[i+2]-'0');
  }
  check(a,b);
  cout<<s;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    new Main().solve();
  }

  public void solve() {

    Scanner input = new Scanner(System.in);
    int a = input.nextInt();
    int b = input.nextInt();
    int c = input.nextInt();

    int add1 = a * 10 + b + c;
    int add2 = a * 10 + c + b;
    int add3 = b * 10 + c + a;
    int add4 = b * 10 + a + c;
    int add5 = c * 10 + a + b;
    int add6 = c * 10 + b + a;

    System.out.println(
        Math.max(Math.max(Math.max(Math.max(Math.max(add1, add2), add3), add4), add5), add6));
  }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using graph=vector<vi>;
int main(){
  graph bingo(3,vi(3,0));
  graph checked(3,vi(3,0));
  bool ans=false;
  vi a;
  int n;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>bingo[i][j];
    }
  }
  cin>>n;
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    a.push_back(k);
  }
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      for(int l=0;l<n;l++){
        if(a[l]==bingo[i][j]) checked[i][j]++;
      }
    }
  }for(int i=0;i<3;i++){
    if(checked[0][i]==1&&checked[1][i]==1&&checked[2][i]==1){
      ans=true;//縦
    }else if(checked[i][0]==1&&checked[i][1]==1&&checked[i][2]==1){
      ans=true;//横
    }
  }if(checked[0][0]==1&&checked[1][1]==1&&checked[2][2]==1){
    ans=true;
  }else if(checked[0][2]==1&&checked[1][1]==1&&checked[2][0]==1){
    ans=true;
  }
  if(ans){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int qTem, qNece, qQuer, cont=0;
		Scanner scanner = new Scanner (System.in);
		qTem = scanner.nextInt();
		qNece = scanner.nextInt();
		qQuer = scanner.nextInt();
		
		while(qNece >= qTem) {
			qNece -= qTem;
			cont++;
		}
		if(cont < qQuer) {
			System.out.println(cont);
		}else if (cont == qQuer){
			System.out.println(qQuer);
		}else if(cont == 0){
			System.out.println("0\n");
		}else if(cont > qQuer) {
			System.out.println(qQuer);
		}
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int k; cin >> k;
    string s; cin >> s;
    if (s.size() <= k) {
        cout << s << endl;
    } else {
        rep(i, k) cout << s[i];
        cout << "..." << endl;
    }
}


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

int main(){
	int n;
	int i;
	int min;
	int max;
	long int sum = 0;
	int a;

	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d",&a);

		if (i == 0){
			min = a;
			max = a;
		}else{
			if (a < min) min = a;
			if (a > max) max = a;
		}

		sum += a;
	}


	printf("%d %d %ld\n",min,max,sum);

	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef unsigned long long Long;


int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif


  int n;
  cin >> n;

  bool odd = false;
  while (n--) {
    int x;
    cin >> x;
    odd |= (x & 1);
  }

  cout << (odd ? "first" : "second") << endl;

}



Measured memory_bytes: 256
using System;

namespace ITP1_11_A
{
    class Dice
    {
        private readonly int[,] adj = new int[6, 4] { { 1, 2, 4, 3 }, { 0, 3, 5, 2 }, { 0, 1, 5, 4 }, { 0, 4, 5, 1 }, { 0, 2, 5, 3 }, { 1, 3, 4, 2 } };
        private int top, front;
        private int[] vals = new int[6];
        public int Top { get { return vals[top]; } }
        public Dice(int[] values)
        {
            Array.Copy(values, vals, 6);
            top = 0;
            front = 1;
        }

        public void N()
        {
            int index = GetIndex(front, top);
            top = front;
            front = adj[front, (index + 2) % 4];
        }

        public void W()
        {
            int index = GetIndex(top, front);
            top = adj[top, (index + 1) % 4];
        }
        public void S()
        {
            int index = GetIndex(top, front);
            front = top;
            top = adj[top, (index + 2) % 4];
        }
        public void E()
        {
            int index = GetIndex(top, front);
            top = adj[top, (index + 3) % 4];
        }

        private int GetIndex(int top, int val)
        {
            for (int i = 0; i < 4; i++) if (adj[top, i] == val) return i;
            throw new Exception();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Dice dice = new Dice(Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse));
            string cmd = Console.ReadLine();
            foreach (var c in cmd)
            {
                switch (c)
                {
                    case 'N': dice.N(); break;
                    case 'W': dice.W(); break;
                    case 'S': dice.S(); break;
                    case 'E': dice.E(); break;
                    default: break;
                }
            }
            Console.WriteLine(dice.Top);
        }
    }
}

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
     int n; cin>>n;
     vector <int> data(100010);
     for(int i=0;i<n;i++){
        int a; cin>>a;
        data[i+1] = a;
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        int ag = data[i];
        if(data[ag]==i) ans++;
    }
    cout<<ans/2<<endl;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int h,w,n; cin >> h >> w >> n;
    int cnt = 0, i = 0;
    while(cnt < n) {
        i++;
        cnt += max(h,w);
    }
    cout << i << '\n';
}

Measured memory_bytes: 256
import copy

N, M, Q = map(int, input().split())

def dfs(count, pre, ls):
    if count == N:
        temp = copy.copy(ls)
        num.append(temp)
        return

    for n in range(pre, M+1):
        ls[count] = n
        dfs(count+1, n, ls)
        ls[count] = 0

num = []
ls = [0] * N
dfs(0, 1, ls)

q = [[int(i) for i in input().split()] for j in range(Q)]
ans = 0
for i in range(len(num)):
    n = num[i]
    score = 0
    for j in range(Q):
        a, b, c, d = q[j]
        if n[b-1] - n[a-1] != c:
            continue
        score += d
    else:
        ans = max(ans, score)

print(ans)

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

int main()
{
	int i,x;
	cin>>i;
	int a[10000],b[10000],c[10000];
	for(x=0;x<i;x++){
		cin>>a[x]>>b[x]>>c[x];
	}
	for(x=0;x<i;x++){
		if(((a[x]*a[x])+(b[x]*b[x]))==(c[x]*c[x]) || ((a[x]*a[x])+(c[x]*c[x]))==(b[x]*b[x]) || ((c[x]*c[x])+(b[x]*b[x]))==(a[x]*a[x])){
			cout<<"YES"<<endl;
		}else{ cout<<"NO"<<endl;}
	}
}

Measured memory_bytes: 1176
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

x, a = map(int,input().split())
if x < a:
    print(0)
else:
    print(10)

Measured memory_bytes: 5588
#include <bits/stdc++.h>
//#include "stdc++.h"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = max(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

void	solve()
{
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i, n) cin >> v[i];
	int k = 0, i = 1;
	bool ok = false;
	for (int x : v)
	{
		if (x == i)
		{
			ok = true;
			i++;
		}
		else
		{
			k++;
		}
	}
	if (ok) cout << k << endl;
	else cout << -1 << endl;
}

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	solve();
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int n;
int a[500005];
int lf[500005/2];
int rt[500005/2];
int count = 0;

void merge(int l, int mid, int r) {
    int n1 = mid - l;
    int n2 = r - mid;
    for (int i = 0; i < n1; i++) {
        lf[i] = a[l + i];
    }
    for (int i = 0; i < n2; i++) {
        rt[i] = a[mid + i];
    }
    int i = 0;
    int j = 0;
    for (int k = l; k < r; k++) {
        count++;
        if ((lf[i] <= rt[j] && i != n1) || (j == n2)) {
            a[k] = lf[i];
            i++;
        } else {
            a[k] = rt[j];
            j++;
        }
    }
}

void mergeSort(int l, int r) {
    if (l + 1 < r) {
        int mid = (l + r) / 2;
        mergeSort(l, mid);
        mergeSort(mid, r);
        merge(l, mid, r);
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    mergeSort(0, n);
    for (int i = 0; i < n; i++) {
        if (i) {
            cout << " ";
        }
        cout << a[i];
    }
    cout << endl;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 6908
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { Integer.parseInt(it) }.toTypedArray()
    val b = readLine()!!.split(" ").map { Integer.parseInt(it) }.toTypedArray()

    var ans = 0
    for (k in 29 downTo 0) {
        var count = 0L
        val powk = 1.shl(k)
//        for (i in 0 until n) {
//            val ai = a[i]
//            val t1 = b.lowerbound(powk - ai)
//            val t2 = b.lowerbound(powk*2 - ai)
//            count += t2 - t1
//            val t3 = b.lowerbound(powk*3 - ai)
//            val t4 = b.size
//            count += t4 - t3
//        }
        var r1 = 0
        var r2 = 0
        var r3 = 0
        for (i in n - 1 downTo 0) {
            val ai = a[i]
            while (r1 < n && (ai + b[r1]) < powk) r1 += 1
            while (r2 < n && (ai + b[r2]) < 2 * powk) r2 += 1
            while (r3 < n && (ai + b[r3] < 3 * powk)) r3 += 1
            count += r2 - r1 + n - r3
        }
        for (index in 0 until n) {
            a[index] %= powk
            b[index] %= powk
        }
        a.sort()
        b.sort()

        ans += (count % 2).toInt().shl(k)
    }
    println(ans)
}

fun Array<Int>.lowerbound(key: Int): Int {
    return this.binarySearch(key, Comparator { o1: Int, o2: Int -> if (o1 >= o2) 1 else -1 }).inv()
}

Measured memory_bytes: 152460
#include <bits/stdc++.h>
#define N 100005
#define ll long long
#define For(i,x,y) for(int i=(x);i<=(y);++i)
#define Rof(i,x,y) for(int i=(x);i>=(y);--i)
#define p_b push_back
#define pii pair<int,int>
#define mp make_pair
#define fr first
#define sd second
#define mod 1000000007
using namespace std;

ll _2[N],_2_[N],fac[N],invf[N];
int nxt[N],id[N],len[N],deg[N],a[N],tot[N],cir[N],d[N],pos;
bool vis[N],inq[N];
vector<pii > v[N];

void dfs(int x,int dep){
	if(inq[x] || cir[x]){
		if(!cir[x]){
			len[x]=dep-d[x],pos=x,cir[x]=x,id[x]=1;
			if(d[x]-1) v[x].push_back(mp(1,d[x]-1));
		} else if(dep-1) v[cir[x]].push_back(mp(id[x],dep-1));
		return; 
	}
	d[x]=dep,inq[x]=1,vis[x]=1;
	dfs(nxt[x],dep+1),inq[x]=0;
	if(pos && dep>d[pos]) cir[x]=pos,id[x]=id[nxt[x]]+1;
}
int ___(int x,int y){ if(x>y) return 2; if(x<y) return 0;return 1; }
ll qpow(ll x,int y){
	ll tmp=1;
	for(;y;y>>=1,(x*=x)%=mod) if(y&1) (tmp*=x)%=mod;
	return tmp;
}
int main(){
	int n;ll ans=1,ans2=1;
	scanf("%d",&n);
	_2[0]=_2_[0]=1;ll fuck=qpow(2ll,mod-2);
	fac[0]=fac[1]=invf[0]=invf[1]=1,_2[1]=2,_2_[1]=fuck;
	For(i,1,n) scanf("%d",&a[i]),nxt[i]=a[i],deg[nxt[i]]++;
	For(i,2,n){
		_2[i]=(_2[i-1]+_2[i-1])%mod;
		_2_[i]=_2_[i-1]*fuck%mod;
		fac[i]=1ll*fac[i-1]*i%mod;
		invf[i]=1ll*(mod-mod/i)*invf[mod%i]%mod; 
	}
	For(i,1,n) (invf[i]*=invf[i-1])%=mod;
	For(i,1,n)
		if(!deg[i]) pos=0,dfs(i,1);
	For(i,1,n) if(!vis[i]) pos=0,dfs(i,1);
	For(i,1,n){
		if(deg[i]>2) return puts("0"),0;
		else if(!cir[i] && deg[i]>=2) return puts("0"),0;
	}
	For(i,1,n) sort(v[i].begin(),v[i].end());
	For(i,1,n){
		if(!v[i].size()){ if(len[i]) tot[len[i]]++;continue; }
		if(v[i].size()==1){
			if(len[i]<v[i][0].sd) return puts("0"),0;
			else if(len[i]>v[i][0].sd)(ans*=2ll)%=mod; 
		} else{
			For(j,0,(int)v[i].size()-2){
				ll p=1ll*___(v[i][j+1].fr-v[i][j].fr,v[i][j].sd);
				if(!p) return puts("0"),0;
				else (ans*=p)%=mod;
			}
			int p=v[i].size()-1;
			if(len[i]-v[i][p].fr+v[i][0].fr<v[i][p].sd) return puts("0"),0;
			else if(len[i]-v[i][p].fr+v[i][0].fr>v[i][p].sd) (ans*=2ll)%=mod;
		}
	}
	For(i,1,n){
		if(!tot[i]) continue;
		ll qwq=0;
		For(j,0,tot[i]/2){
			int x=j*2;
			ll tmp=qpow(1ll*i,j)*fac[tot[i]]%mod*invf[tot[i]-x]%mod*_2_[j]%mod*invf[j]%mod;
			(tmp*=_2[((i%2) && i!=1)*(tot[i]-x)])%=mod;
			(qwq+=tmp)%=mod;
		}
		(ans2*=qwq)%=mod;
	}
	printf("%lld\n",ans*ans2%mod);
}

Measured memory_bytes: 13696
import numpy as np
str = input()
lst = str.split()
a = int(lst[0])
b = int(lst[1])
c = int(lst[2])
if b > c:
    print(int(a*c/b)-int(c/b)*a)
else:
    d = int(c/b)
    if d > 100:
      d = 100
    lst = np.zeros(d)
    for i in range(d):
        k = b*(i+1)-1
        lst[i] = int(a*k/b)-int(k/b)*a
    print(int(np.max(lst)))

Measured memory_bytes: 26988
N = int(input())
H_list = list(map(int,input().split()))
if N==1:
    print("Yes")
    exit()
for i in range(N-1):
    if H_list[i] < H_list[i+1]:
        H_list[i+1] = H_list[i+1] - 1
if H_list == sorted(H_list):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define frpn(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout);
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define fornd(i, n) for(int i=(int)(n-1); i>=0; --i)

//const int NAX = (int)3e5+5;
const int MOD = (int)1e9+7;

template <class T>
inline void rem(T &n){
   n = (-MOD <= n && n <= MOD) ? n : n%MOD ;
  if(n < 0) n += MOD; 
}
//modular inverse
//inv(a,m) - inverse of a mod m
template <class T>
inline T inv(T a, T m){
 return 1<a ? m - inv(m%a, a)*m/a : 1;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, p;
    cin >> s >> p;
    int res = 0;
    forn(i, 3)
      if(s[i] == p[i]) ++res;
    cout<< res << "\n";
    return 0;
}


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

int main(void)
{
    char s[200001], t[200001];
    scanf("%s", s);
    scanf("%s", t);

    int n = strlen(s);
    int ans = 0;

    for(int i=0; i<n; i++){
        if(s[i] != t[i]){
            ans++;
        }
    }
    printf("%d", ans);
}

Measured memory_bytes: 2112
def resolve():
    n = int(input())
    a = [0]
    a.extend( list(map(int,input().split())) )
    tmp = [0]*(n+1)
    ans = []
    for i in range(n,0,-1):
        sum = 0
        for j in range(i+i,n+1,i):
            sum = sum^tmp[j]
        tmp[i] = sum^a[i]
    for i in range(1,n+1):
        if(tmp[i]>0):
            ans.append(i)
    
    print(len(ans))
    s = ' '.join([str(n) for n in ans])
    print(s)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 20528
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int main(){
	int alpha[51][26]={};
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		char S[51];
		cin>>S;
		for(int j=0;j<strlen(S);j++){
			alpha[i][S[j]-'a']++;
		}
	}
	for(int i=0;i<26;i++){
		int mini=INF;
		for(int j=0;j<n;j++){
			mini=min(mini,alpha[j][i]);
		}
		for(int j=0;j<mini;j++){
			printf("%c",('a'+i));
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) //cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}


typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

ll INF = 1e11;

int n;

void warshall_floyd(vvll &cost) {
  rep (k, n) {
    rep (i, n) {
      rep (j, n) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
    }
  }
}

vvll cost;

int main() {
  int m, num_c, s, g;
  while (true) {
    cin >> n >> m >> num_c >> s >> g;
    s -= 1; g -= 1;
    if (n == 0) {
      break;
    }
    vvll initial(n, vll(n, INF));
    rep (i, n) {
      initial[i][i] = 0;
    }
    vector<vvll> rosen(num_c, vvll(initial));
    //vector<vvll> rosen(num_c, vvll(n, vll(n, INF)));
    rep (i, m) {
      int x, y, d, c_;
      cin >> x >> y >> d >> c_;
      x -= 1; y -= 1; c_ -= 1;
      rosen[c_][x][y] = min(rosen[c_][x][y], (ll)d);
      rosen[c_][y][x] = min(rosen[c_][y][x], (ll)d);
    }
    //cost.assign(n, vll(n, INF));
    cost = vvll(initial);
    vi p(num_c);
    rep (i, num_c) {
      cin >> p[i];
    }
    debug(num_c);
    rep (i, num_c) {
      debug(i);
      int num_sect = p[i];
      debug(rosen[i]);
      warshall_floyd(rosen[i]);
      debug(rosen[i]);
      vll q(num_sect, 0), r(num_sect);
      FOR (j, 1, num_sect) {
        cin >> q[j];
      }
      rep (j, num_sect) {
        cin >> r[j];
      }
      vll val(num_sect, 0);
      FOR (j, 1, num_sect) {
        val[j] = val[j-1] + (q[j] - q[j-1]) * r[j-1];
      }
      debug(val);
      rep (j, n) {
        rep (k, n) {
          if (rosen[i][j][k] == INF) { continue; }
          int ind = upper_bound(begin(q), end(q), rosen[i][j][k]) - begin(q) - 1;
          ll new_cost = val[ind] + (rosen[i][j][k] - q[ind]) * r[ind];
          cost[j][k] = min(cost[j][k], new_cost);
        }
      }
    }
    debug(cost);
    warshall_floyd(cost);
    debug(cost);
    ll ans;
    if (cost[s][g] == INF) {
      ans = -1;
    } else {
      ans = cost[s][g];
    }

    cout << ans << "\n";
  }

  return 0;
}

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

#define cant -1e18

struct interval {
  int l, r, num;
};

interval lr[505];
long long w[505][505];
long long dp[505];

int main() {
  long long n, s;
  cin >> n >> s;
  s--;

  for (int i = 0; i < n; i++) {
    cin >> lr[i].l >> lr[i].r;
    lr[i].num = i;
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> w[i][j];
    }
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        w[i][j] = min(w[i][j], w[i][k] + w[k][j]);
      }
    }
  }

  //ここまでWF

  sort(lr, lr+n, [&](const interval &a, const interval &b){
    return a.r < b.r;
  });

  for (int i = 0; i < n; i++) if (s == lr[i].num) {
    s = i;
    break;
  }

  int sn = lr[s].num;

  for (int i = 0; i < n; i++) {
    int in = lr[i].num;
    long long tmp = lr[i].r - max<long long>(lr[i].l, w[sn][in]);
    if(tmp >= 0) dp[i] = tmp;
    else dp[i] = cant;

    for (int j = 0; j < i; j++) {
      int jn = lr[j].num;
      if (lr[j].r + w[jn][in] < lr[i].r) {
        long long nv = dp[j] + lr[i].r - max<long long>(lr[i].l, lr[j].r + w[jn][in]);
        dp[i] = max<long long>(dp[i], nv);
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, dp[i]);
  }

  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 5136
#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 ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

struct UnionFind {
	vector<int> par, rank;
	
	UnionFind(int n) {
		par.resize(n);
		rank.resize(n);
		REP(i, n) {
		 par[i] = i;
		 rank[i] = 0;
		}
	}
	
	int operator[] (int x) {
		return find(x);
	}
	
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		
		if (rank[x] < rank[y]) swap(x, y);
		
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
	
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> p(N);
	REP(i, N) scanf("%d", &p[i]), --p[i];
	UnionFind uf(N);
	REP(i, M) {
		int x, y;
		scanf("%d %d", &x, &y);
		--x; --y;
		uf.unite(x, y);
	}
	
	REP(i, N) {
		if (p[i] == i) continue;
		while (p[i] != i && uf.same(p[i], i)) {
			swap(p[p[i]], p[i]);
		}
	}
	
	int ans = 0;
	REP(i, N) ans += p[i] == i;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1408
from collections import deque

s = input()
t = s[::-1]
ss = deque(s)
tt = deque(t)
isS = True
n = int(input())
query = []

# print(q1, q2)

for i in range(n):
    query.append(list(input().split()))

# print(query)

for i in range(n):
    # Reverse
    if query[i][0] == '1':
        # s = s[::-1]
        isS = not isS
    # Add
    else:
        # To Head
        if query[i][1] == '1':
            if isS:
                ss.appendleft(query[i][2])
                tt.append(query[i][2])
            else:
                ss.append(query[i][2])
                tt.appendleft(query[i][2])
        # To Tail
        else:
            if isS:
                ss.append(query[i][2])
                tt.appendleft(query[i][2])
            else:
                ss.appendleft(query[i][2])
                tt.append(query[i][2])

if isS:
    temp = list(ss)
    ans = ''.join(temp)
    print(ans)
else:
    temp = list(tt)
    ans = ''.join(temp)
    print(ans)


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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
   int k, n;
   cin>>k>>n;
   vector<int> a(n);
   rep(i, n) cin>>a[i];

   int mx=0;
   rep(i, n){
      if(i==n-1) mx=max(mx, k+a[0]-a[n-1]);
      else mx=max(mx, a[i+1]-a[i]);
   }

   cout << k-mx << endl;
   return 0;
}


Measured memory_bytes: 4032
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#pragma warning( disable:4996 )
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))

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

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

int main(void) {
	/*int s;
	scanf("%d", &s);
	if (s % 10 == s % 100 / 10 || s % 100 / 10 == s % 1000 / 100 || s / 1000 == s % 1000 / 100) {
		printf("Bad\n");
	}
	else {
		printf("Good\n");
	}*/

	/*int n, l;
	scanf("%d %d", &n, &l);
	int absmin = 99999999;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += l + i;
		if (abs(absmin) > abs(l + i)) {
			absmin = l + i;
		}
	}
	sum -= absmin;
	printf("%d\n", sum);*/

	long long a, b, c, d;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
	long long start = a + ((a%c==0)?0:(c - a % c));
	//if (a%c == 0)start -= c;
	long long end = b - ((b%c==0)?0:(b%c));
	//if (b%c == 0)end += c;
	long long ccount = (end - start >= 0) ? (end - start) / c + 1 : 0;
	start = a + ((a%d == 0) ? 0 : (d - a % d));
	//if (a%d == 0)start -= d;
	end = b - ((b%d == 0) ? 0 : (b%d));
	//if (b%d == 0)end += d;
	long long dcount = (end - start >= 0) ? (end - start) / d + 1 : 0;
	long long gcdcd = lcm(c, d);
	start = a + ((a%gcdcd == 0) ? 0 : (gcdcd - a % gcdcd));
	//if (a%(d*c) == 0)start -= (d*c);
	end = b - ((b%gcdcd == 0) ? 0 : (b%gcdcd));
	//if (b% (d*c) == 0)end += (d*c);
	long long ecount = (end - start >= 0) ? (end - start) / gcdcd + 1 : 0;
	printf("%lld\n", (b-a + 1) - ccount - dcount + ecount);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

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


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int ans = 0;
    rep(i, k) {
        ans += a.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string, string> ss;
typedef map<int,int> mii;
#define ff first
#define ss second
#define pset(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define mp make_pair
#define setint set<int>
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vi,greater<int> >
#define size 2000005
#define mod 1000000007
#define rep(i,s,e) for(int i=s;i<e;i++)
#define tc int tc; cin>>tc; while(tc--)

// string change(string num){
//     int n= num.size()-1;
//     bool forw = true;
//     for(int i=0;i<n;i++){
//        int eve = (int) num[i];
//        if((int)num[i]%2==0) {
//           if(eve<(int)num[n]) {
//             swap(num[i],num[n]); 
//             return num;
//           }
//        }
//     }
  
//     for(int i=num.size()-2;i>=0;i--){
//        if((int)num[i]%2==0) {
//           swap(num[i],num[n]); 
//           return num;
//        }
//     }
//     return num;
//   } 

// int pony(int arr[],int n){
//     int flag = 0;
//     int count = 0;
//     int start;
//     for(int i=0;i<n;i++){
//       if(arr[i]>arr[(i+1)%n]){
//         flag++;
//         start = i;
//       }
//     }
//     if(flag == 0){
//       return 0;
//     } else if(flag == 1){
//       return n-start-1;
//     } else {
//       return -1;
//     }
    
// }

ll fib(ll a,ll b, ll n){
  ll arr[6];
  arr[1] = a;
  arr[2] = b;
  arr[3] = b - a;
  arr[4] = -a;
  arr[5] = -b;
  arr[0] = a - b;
  return (arr[n%6] + 2*mod)%mod;
}

int main(){
    string a,b;
    cin>>a;
    cin>>b;
    int count = 0;
    for(int i=0;i<3;i++){
      if(a[i]==b[i]){
        count++;
      }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
def get_input_row():
  return [int(i) for i in input().split(" ")]

inp = input()
index = [int(a) for a in inp.split(" ")]
N = index[0]
M = index[1]
C = index[2]
B = [int(b) for b in input().split(" ")]
collect = 0
for i in range(N):
  row_data = get_input_row()
  val = sum([a * b for a, b in zip(row_data, B)]) + C
  collect += 1 if val > 0 else 0
print(collect)

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)(n); i++)
#define reps(i,s,e) for(int i=s; i<(int)(e); i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;


// #include <iostream>

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr operator int() const noexcept {
        return (int)val;
    }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr std::ostream& operator << (std::ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    Fp<MOD> sum(0);
    Fp<MOD> sqsum(0);
    rep(i, N) {
        int x;
        cin >> x;
        sum += x;
        sqsum += Fp<MOD>(x)*Fp<MOD>(x);
    }
    sum *= sum;
    sum -= sqsum;
    sum /= 2;
    cout << sum << endl;
}

Measured memory_bytes: 3632
import sys

N = int(input())
*B, = map(int, input().split())

ok = 1
for i in range(N):
    if B[i] > i+1:
        ok = 0
if not ok:
    print(-1)
    exit(0)

ans = []
S = [0]*N
for i in range(N):
    rest = i
    for j in range(N-1, -1, -1):
        if S[j] == 1:
            rest -= 1
            continue
        if rest+1 == B[j]:
            ans.append("%d\n" % B[j])
            S[j] = 1
            break
sys.stdout.writelines(ans)

Measured memory_bytes: 40560
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD (int)1e9+(int)7
#define INF 2147483647
typedef long long ll;
typedef unsigned long long ull;

//dark power
//#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
/*
vector<int> d(100000);
vector<int> b(100000);
class UnionFind{
	public:
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	signed find(signed x){
		if(d[x]==x){
			return x;
		}else{
			return d[x]=find(d[x]);
		}
	}
	UnionFind(signed n){rep(i,n){d[i]=i;b[i]=0;}}
	void unite(signed x,signed y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(b[x]<b[y]){
			d[x]=y;
		}else{
			d[y]=x;
			if(b[x]==b[y])b[x]++;
		}
	}
	bool same(signed x,signed y){return (find(x)==find(y));}
};
*/
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	if(b%a==0){cout<<a+b<<endl;}
	else{cout<<b-a<<endl;}




//	int m,n;
//	cin>>n>>m;
//	vector<string> a(n);
//	vector<string> b(m);
//
//	rep(i,n)cin>>a[i];
//	rep(i,m)cin>>b[i];
//
//	rep(i,n-m+1)rep(j,n-m+1){
//		rep(k,m)rep(l,m)if(a[i+k][j+l]!=b[k][l])goto BB;
//		cout<<"Yes"<<endl;
//		return 0;
//BB:
//		continue;
//	}
//	cout<<"No"<<endl;
//
//
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main(){
	int num;
	cin>>num;
	for(int i=0;i<num;i++){
		double a,b,c,d,e,f;
		double x1,y1,x2,y2,x3,y3;
		cin>>x1>>y1>>x2>>y2>>x3>>y3;
	
		a=x1-x2;
		b=y1-y2;
		c=x2-x3;
		d=y2-y3;
		e=(x2*x2+y2*y2)-(x1*x1+y1*y1);
		f=(x3*x3+y3*y3)-(x2*x2+y2*y2);
		double l=(e*d-f*b)/(a*d-c*b);
		double m=(c*e-a*f)/(c*b-a*d);
		double n=-1*x1*x1-(y1*y1)-l*x1-m*y1;
	
		double x=-1*l/2.0;
		double y=-1*m/2.0;
		double r=sqrt(l*l+m*m-4*n)/2.0;
		printf("%.3f %.3f %.3f\n",x,y,r);
	}
}

Measured memory_bytes: 1244