akhauriyash/Code-Regression huggingface dataset:
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs.shift());
const adj = inputs.map((s) => s.split(' ').map(Number));

class Node {
  constructor(id) {
    this.id = id;
    this.children = [];
  }
  add(node) {
    node.parent = this;
    this.children.push(node);
  }
  hasParent() {
    return !!this.parent;
  }
  hasChild() {
    return !!this.children.length;
  }
  getType() {
    return !this.hasParent() ? 'root' : (this.hasChild() ? 'internal node' : 'leaf');
  }
  calc(depth) {
    this.depth = depth++;
    this.children.forEach(child => child.calc(depth));
  }
  toString() {
    return 'node ' + this.id + ': ' + [
      'parent = ' + (this.hasParent() ? this.parent.id : -1),
      'depth = ' + this.depth,
      this.getType(),
      '[' + this.children.map(child => child.id).join(', ') + ']',
    ].join(', ');
  }
}

class Tree {
  constructor() {
    this.map = new Map();
  }
  getNode(id) {
    this.map.has(id) || this.map.set(id, new Node(id));
    return this.map.get(id);
  }
  getRoot() {
    return Array.from(this.map.values()).find(node => !node.hasParent());
  }
  calc() {
    const root = this.getRoot();
    root.calc(0);
  }
  print() {
    for (let i = 0; i < this.map.size; i++) {
      const node = this.map.get(i);
      console.log(node.toString());
    }
  }
}

const tree = new Tree();
adj.forEach(([u, k, ...vk]) => {
  const parent = tree.getNode(u);
  vk.forEach(v => {
    const node = tree.getNode(v);
    parent.add(node);
  });
});

tree.calc();
tree.print();



Measured memory_bytes: 115520
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w,k;
    cin>>h>>w>>k;
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    --sx,--sy,--tx,--ty;
    auto c=vector(h,vector(w,' '));
    for(auto&i:c) for(auto&j:i) cin>>j;
    constexpr int inf=1e7;
    auto a=vector(h,vector(w,vector(4,make_pair(inf,0))));
    fr(i,4) a[sx][sy][i]=make_pair(0,0);
    struct gr{
        int x,y,i,d,t;
        bool operator<(const gr&a)const{
            return d==a.d?t>a.t:d>a.d;
        }
    };
    priority_queue<gr> pq;
    fr(i,4) pq.push(gr{sx,sy,i,0,0});
    int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
    auto ok=[&](int x,int y){
        return 0<=x and x<h and 0<=y and y<w and c[x][y]=='.' ;
    };
    while(!pq.empty()){
        auto[x,y,i,d,t]=pq.top();pq.pop();
        t=-t;
        if(x==tx and y==ty){
            cout<<d<<'\n';
            return 0;
        }
        fr(f,4){
            if(f==i and t){
                if(ok(x+dx[f],y+dy[f]) and a[x+dx[f]][y+dy[f]][f]>make_pair(d,1-t)){
                    a[x+dx[f]][y+dy[f]][f]=make_pair(d,1-t);
                    pq.push(gr{x+dx[f],y+dy[f],f,d,1-t});
                }
            }
            else{
                if(ok(x+dx[f],y+dy[f]) and a[x+dx[f]][y+dy[f]][f]>make_pair(d+1,1-k)){
                    a[x+dx[f]][y+dy[f]][f]=make_pair(d+1,1-k);
                    pq.push(gr{x+dx[f],y+dy[f],f,d+1,1-k});
                }
            }
        }
    }
    puts("-1");
}

Measured memory_bytes: 144796
n=int(input())

for i in range(n):
    a,b,c=map(int,input().split())
    if c**2 == a**2+b**2 or b**2 == a**2+c**2 or a**2 == c**2+b**2 :
       print("YES") 
    else :
        print("NO")


Measured memory_bytes: 5596
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vector<vector<ll>> a(n,vector<ll>(m));
	REP(i,n) {
		REP(j,m) cin>>a[i][j];
	}
	ll res=INF;
	vector<bool> used(m,true);
	REP(i,m) {
		vector<ll> c(m,0);
		REP(j,n) {
			REP(k,m) {
				if(used[a[j][k]-1]) {
					c[a[j][k]-1]++;
					break;
				}
			}
		}
		ll buf=0;
		ll roc=-1;
		REP(j,m) {
			if(c[j]>buf) {
				buf=c[j];
				roc=j;
			}
		}
		res=min(res,buf);
		used[roc]=false;
	}
	cout<<res<<endl;
}


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

int main()
{
	string s; 
    cin >> s;
    int ans = 2147483647; 
    for(int i = 1;i < s.size();i++) 
        if(s[i] != s[i-1]) 
            ans = min(ans,max(i,int(s.length())-i));
    cout << min(ans , int(s.size())) <<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

lint app() {
  int rm,cm,k;
  cin>>rm>>cm>>k;

  vector<vector<int>> item(rm,vector<int>(cm,0));
  rep(i,k){
    int r,c,v;
    cin>>r>>c>>v;
    r--;c--;
    item[r][c]=v;
  }

  vector<vector<lint>> dp(cm,vector<lint>(4,0));
  vector<lint> ldp(cm,0);
  rep(r,rm){
    dp[0][0]=ldp[0];
    rep_range(t,1,4) dp[0][t]=0;
    rep_rev(t,4,1){
      if(item[r][0]>0) chmax(dp[0][t],dp[0][t-1]+item[r][0]);
    }
    rep_range(c,1,cm){
      dp[c][0]=dp[c-1][0];
      chmax(dp[c][0],ldp[c]);
      rep_range(t,1,4) dp[c][t]=dp[c-1][t];
      rep_rev(t,4,1){
        if(item[r][c]>0) chmax(dp[c][t],dp[c][t-1]+item[r][c]);
      }
    }
    rep(c,cm){
      ldp[c]=0;
      rep(t,4){
        chmax(ldp[c],dp[c][t]);
      }
    }
  }

  return ldp[cm-1];
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 38904
//JSD
#include<iostream>
using namespace std;
int ans(int Num){
	int count=0;
	while(Num>0){
		Num/=10;
		count++;
	}
	return count%2;
}
int main(){
	int n;
	cin>>n;
	int an=0;
	for(int i=1;i<=n;i++) an+=ans(i);
	cout<<an;
	return 0;
}

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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define tc ll t; cin >> t; while (t--)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define sz(c) (ll) c.size()
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define trav(x,c) for(auto &x : c)
#define _for(i,a,n) for(ll i = a ; i < n ; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);

int main() {
    godspeed;
    ll n; cin >> n;
    cout << n/2 + n%2;
}

Measured memory_bytes: 3648
def main():
    s = input()
    for i in range(len(s)):
        a = s[:-(i+1)]
        if len(a) % 2 == 1:
            continue
        half_len_a = len(a) // 2
        if a[:half_len_a] == a[half_len_a:]:
            print(len(a))
            exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10e+6
#define DEKA 1000000007

using namespace std;

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



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

signed main()
{
  int n;
  ll t=1, a;
  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> a;

    if(t == 0 || a == 0){
      t = 0;
    }
    else if ( t > 0 && t <= 1000000000000000000 / a) {
      t *= a;
    }
    else{
      t = -1;
    }
  }

  cout << t << endl;
}

Measured memory_bytes: 3600
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int count = 0;
            for (int i = 1; i <= N; i++)
            {
                if (i.ToString().ToCharArray().Count() % 2 == 1) count++;
            }
            Console.WriteLine(count.ToString());
//            Console.Read();
        }
    }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	auto x1=in(),y1=in(),x2=in(),y2=in();
	double dx = x2-x1,dy = y2-y1;
	double norm = hypot(dx,dy);
	dx/=norm,dy/=norm;
	auto Q=in();
	REP(i,Q){
		int x3=in(),y3=in();
		double proj = dx*(x3-x1)+dy*(y3-y1);
		printf("%.10lf %.10lf\n",proj*dx+x1,proj*dy+y1);
	}

	return 0;
}



Measured memory_bytes: 3252
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <bitset>

#define rep(i, a, b) for ( ll i = (a); i < (b); i++ )
#define per(i, a, b) for ( ll i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

const int MAX_ROW = 100005;
const int MAX_COL = 100;

struct BitMatrix {
  int H, W;
  bitset<MAX_COL> val[MAX_ROW];
  BitMatrix(int h = 1, int w = 1) : H(h), W(w) {}
  inline bitset<MAX_COL>& operator [] (int i) { return val[i]; }
};

int xor_elimination(BitMatrix &A) {
  //rep(i, 0, A.H) cout << A[i] << endl;
  //cout << "\n";
  int COL = A.W, ROW = A.H;
  int rank = 0;
  for (int col = COL; col>=0; col--) {
    int pivot = -1;
    for (int row = rank; row<=ROW; row++) {
      if (A[row][col]) {
        pivot = row;
        break;
      }
    }
    
    if (pivot == -1) continue;
    swap(A[pivot], A[rank]);
    
    for (int row = 0; row<=ROW; row++) {
      if (row != rank && A[row][col]) A[row] ^= A[rank];
    }
    
    rank++;
  }
  //rep(i, 0, A.H) cout << A[i] << endl;
  return rank;
}

int n;
ll a[100005], ans;

int main(void) {
  cin >> n;
  
  BitMatrix M(n, MAX_COL);
  rep (i, 0, n) {
    cin >> a[i];
    M[i] = a[i];
  }
  
  for (int d=61; d>=0; d--) {
    int num = 0;
    for (int i=0; i<n; i++) num += M[i][d];
    
    if (num%2) {
      ans += (1LL<<d);
      for (int i=0; i<n; i++) M[i][d] = 0;
    }
  }
 
  int rank = xor_elimination(M);
  
  bitset<MAX_COL> b;
  rep(i, 0, rank) b ^= M[i];
  
  rep(i, 0, 62) ans += (1LL<<(i+1))*b[i];
  
  cout << ans << endl;
   
    return 0;
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    rep(i,9)
    {
        rep(j,9)
        {
            if( (i+1)*(j+1) == N )
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;

}


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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long
#define pii pair<int, int>
#define ld long double

const int INF = 2e9 + 1;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    vector<vector<int>> dp(n + 1, vector<int>(13));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 13; j++) {
            if (s[i] != '?') {
                dp[i + 1][(10 * j + s[i] - '0') % 13] += dp[i][j];
                if (dp[i + 1][(10 * j + s[i] - '0') % 13] >= mod) dp[i + 1][(10 * j + s[i] - '0') % 13] -= mod;
            } else {
                for (int l = 0; l < 10; l++) {
                    dp[i + 1][(10 * j + l) % 13] += dp[i][j];
                    if (dp[i + 1][(10 * j + l) % 13] >= mod) dp[i + 1][(10 * j + l) % 13] -= mod;
                }
            }
        }
    }
    cout << dp[n][5];
    return 0;
}


Measured memory_bytes: 11828
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n,m;
    cin >> n >> m;
    int h,w;
    cin >> h >> w;
    cout << (n-h)*(m-w) << endl;
}


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

using namespace std;

long long dp[51][2501],ans;

int main()
{
	int n,a,x;
	cin >> n >> a;
	dp[n][0]=1;
	for (int i=0; i<n; i++)
	{
		cin >> x;
		transform(&dp[0][x],&dp[n-1][n*50]+1,&dp[1][0],&dp[0][x],plus<>());
	}
	for (int k=1; k<=n; k++)
		ans+=dp[n-k][a*k];
	cout << ans;
	return 0;
}

Measured memory_bytes: 1280
h, w = gets.chomp.split(" ").map(&:to_i)
arr = Array.new(h).map{Array.new(w,0)}
kara = Array.new(w+2," ")
arr = []
arr << kara
h.times do |i|

    s = gets.chomp.split("")
    s.unshift(" ")
    s << " "
    arr << s
end
arr << kara

y = 1
x = 1
ka = []
#p arr
until y == h + 1 && x == w + 1
    x = 1
    kazu = []
    until x == w + 1
        count = 0
        if arr[y][x] == "."
            # p "Y"
            # p y
            # p x
            # puts "x"

            if arr[y-1][x-1] == "#"
                count += 1
            end
            if arr[y-1][x] == "#"
                count += 1
            end
            if arr[y-1][x+1] == "#"
                count += 1
            end
            if arr[y][x-1] == "#"
                count += 1
            end
            if arr[y][x+1] == "#"
                count += 1
            end
            if arr[y+1][x-1] == "#"
                count += 1
            end
            if arr[y+1][x] == "#"
                count += 1
            end
            if arr[y+1][x+1] == "#"
                count += 1
            end
            kazu << count
        elsif arr[y][x] == "#"
            kazu << "#"
            
        end
        x += 1
    end
    ka << kazu
    y += 1
end

# ka.shift
# ka.pop
# p ka
ka.each do |i|
    # i.shift
    # i.pop
    puts i.join("")
end

Measured memory_bytes: 14432
<?php
list($n) = ints();
$d = ints();
list($m) = ints();
$t = ints();
for ($i = 0; $i < $n; ++$i) {
    if (isset($cnt[$d[$i]])) ++$cnt[$d[$i]];
    else $cnt[$d[$i]] = 1;
}
for ($i = 0; $i < $m; ++$i) {
    if (isset($cnt[$t[$i]])) --$cnt[$t[$i]];
    else exit('NO');
}
echo min($cnt) >= 0 ? 'YES' : 'NO';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

int main(){
    int N,K,total;
    cin >> N >> K;
    for (int i = 0; i < N; i++){
        int x;
        cin >> x;
        if(2*x > 2*(K-x)){
            total = total + 2*(K-x) ;
        }
        else{
            total = total + 2*x;
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << ":" << x << endl

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;


}

using namespace atcoder;


int main() {
	int a;
	cin >> a;
	string e;
	for (int i = 0; i < 25 - a; i++) {
		e += " Eve";
	}
	cout << "Christmas" << e << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        int count = 0;
        for (int i = a;i <= b; i++) {
            if ((c % i) == 0) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 26264
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ cin >> p.first >> p.second; return s;}
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007


int dw[4] = { 0, 0,-1, 1 };
int dh[4] = {-1, 1, 0, 0 };

int H, W;
vector<string> S;

int solve(int h1,int w1,int h2,int w2)
{
    vector<vector<int>> d(H, vector<int>(W, -1));
    queue<pair<int, int>> q;

    d[h1][w1] = 0;
    q.push(make_pair(h1, w1));
    
    while (!q.empty()) {
        pair<int, int> hw = q.front(); q.pop();
        rep(j, 4) {
            int h = hw.first + dh[j];
            int w = hw.second + dw[j];
            if (0 <= h && h < H && 0 <= w && w < W && S[h][w] != '#' && d[h][w] == -1) {
                d[h][w] = d[hw.first][hw.second]+1;
                if (h == h2 && w == w2) {
                    return d[h][w];
                }
                q.push(make_pair(h, w));
            }
        }
    }

    return -1;
}

int main()
{
    cin >>H>>W;
    S.resize(H); cin >> S;

    int ans = 0;

    for (int i = 0; i < H*W-1; i++) {
        for (int j = i+1; j < H*W; j++) {
            int h1 = i / W;
            int w1 = i % W;
            int h2 = j / W;
            int w2 = j % W;
            if (S[h1][w1] == '.' && S[h2][w2] == '.') {
                // D4(h1,w1,h2,w2);
                int d = solve(h1,w1,h2,w2);
                // D1(d);
                if (ans < d) ans = d;
                // ans = chmax(ans, d);
                // D1(ans);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define Max 10000

int main(){
  int *a,*b;

  int c[Max+1];
  int n,i,j;
  scanf("%d",&n);

  a=malloc(sizeof(int)*n+1);
  b=malloc(sizeof(int)*n+1);

  for(i=0;i<=Max;i++)c[i]=0;
  for(i=0;i<n;i++){
    scanf("%d",&a[i+1]);
    c[a[i+1]]++;
  }
  for(i=1;i<=Max;i++)c[i]=c[i]+c[i-1];
  for(j=1;j<=n;j++){
    b[c[a[j]]]=a[j];
    c[a[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",b[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 17440
n=int(input())
a=list(map(int,input().split()))
s=sum(a)//2
x=s-sum(a[1::2])
table=[x]
for i in range(n-1):
    table.append(a[i]-x)
    x=a[i]-x
ans=list(map(lambda x:2*x,table))
print(*ans)

Measured memory_bytes: 21456
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int x, c = 1;
  while (cin >> x) {
    if (!x)
      break;
    cout << "Case " << c << ": " << x << endl;
    c++;
  }
}



Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int n, k, sel[4];
string s[10];
bool used[10];
map<string, bool> mp;

void dfs(int d) {
	if (d == k) {
		string t;
		for (int i = 0; i < k; ++i) {
			t += s[sel[i]];
		}
		mp[t] = true;
		return;
	}

	for (int i = 0; i < n; ++i) {
		if (used[i])
			continue;
		sel[d] = i;
		used[i] = true;
		dfs(d + 1);
		used[i] = false;
	}
}

int main() {
	while (cin >> n >> k && n != 0) {
		for (int i = 0; i < n; ++i) {
			cin >> s[i];
		}

		fill(used, used + n, false);
		mp.clear();
		dfs(0);

		cout << mp.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 3440
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#define REP(i,n) for(lint i{}, i##_len=(n); i<i##_len; ++i)
#define DREP(i, h, j, w) for(lint i{}; i < (lint)(h); ++i)for(lint j{}; j < (lint)(w); ++j)
#define DREP2(i, j, n) for(lint i{}; i < (lint)(n - 1); ++i)for(lint j{i + 1}; j < (lint)(n); ++j)
#define SZ(x) ((lint)(x).size())
using lint = long long; lint N, M, H, W;
using namespace std;
const long long INF{ 1LL << 60 };
const long double PI{ 3.1415926535897932 };
const long long NUM97{ 1000000007 };
//動的計画法
template<class T> inline bool chmax(T& x, T y) { if (x < y) { x = y; return 1; } return 0; }
template<class T> inline bool chmin(T& x, T y) { if (x > y) { x = y; return 1; } return 0; }
std::vector<std::string> field;
std::vector<std::vector<bool>> seen(H, std::vector<bool>(W));
//マス上の操作ハンドル(0 < i < 4)でループ回して用いる。
const std::vector<int> dx{ 1, 0, -1, 0 };
const std::vector<int> dy{ 0, 1, 0, -1 };
//pair型vectorの整列。sortの第三因数に指定して用いる。
bool first_larger(std::pair<lint, lint>& a, std::pair<lint, lint>& b) {
    if (a.first != b.first) return{ a.first > b.first };
    else return { a.second > b.second };
}
bool second_smaller(std::pair<lint, lint>& a, std::pair<lint, lint>& b) {
    if (a.second != b.second) return{ a.second < b.second };
    else return { a.first < b.first };
}
bool second_larger(std::pair<lint, lint>& a, std::pair<lint, lint>& b) {
    if (a.second != b.second) return{ a.second > b.second };
    else return { a.first > b.first };
}
//桁数取得
lint get_digit(lint& n) {
    return log10(n) + 1;
}
//素数判定
bool is_prime(lint N) {
    if (N == 1) return false;
    for (lint i = 2; i * i <= N; ++i) { if (N % i == 0) return false; }
    return true;
}
//約数列挙
std::vector<lint> divisors(lint N) { std::vector<lint> divisor;
    for (lint i = 1; i * i <= N; ++i) {
        if (N % i == 0) { divisor.push_back(i);
            if (N / i != i) divisor.push_back(N / i); }
    } std::sort(divisor.begin(), divisor.end());
    divisor.erase(std::unique(divisor.begin(), divisor.end()), divisor.end());
    return divisor;
}
//素因数列挙
std::vector<lint> prime_divisors(lint N) { std::vector<lint> p_divisor;
    for (lint i = 1; i * i <= N; ++i) {
        if (N % i == 0) { if (is_prime(i)) { p_divisor.push_back(i); }
            if (N / i != i) { if (is_prime(N / i)) { p_divisor.push_back(N / i); } } }
    } std::sort(p_divisor.begin(), p_divisor.end());
        p_divisor.erase(std::unique(p_divisor.begin(), p_divisor.end()), p_divisor.end());
    return p_divisor;
}

int main() {
    lint N; std::cin >> N;
    vector<lint> A = divisors(N);
    std::cout << get_digit(A[SZ(A) / 2]);
}

Measured memory_bytes: 3896
a = list(input())
a = a[-1]
a = int(a)

if a == 0:
    print("pon")

elif a == 1:
    print("pon")

elif a == 2:
    print("hon")

elif a == 3:
    print("bon")

elif a == 4:
    print("hon")

elif a == 5:
    print("hon")

elif a == 6:
    print("pon")

elif a == 7:
    print("hon")

elif a == 8:
    print("pon")
    
elif a == 9:
    print("hon")

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

int main(){
  int ax, ay, bx, by;
  cin >> ax >> ay >> bx >> by;
  
  int p = bx - ax, q = ay - by;
  cout << bx+q << ' ' << by+p << ' ' << ax+q << ' ' << ay+p << endl;
}

Measured memory_bytes: 256
fun main(args : Array<String>) { 
  val (K, S) = readLine()!!.split(" ").map { x -> x.toInt() } 
  var t = (0..K).map{x->
    (0..K).map{y ->
        var z = S -x -y
        if(z >= 0 && z <= K) 1
        else 0
        }
    }.flatMap{x->x}.sum()
  println(t)
}


Measured memory_bytes: 177716
#include<bits/stdc++.h>
#define ft(i,l,r) for(register int i=l;i<=r;i++)
#define fd(i,r,l) for(register int i=r;i>=l;i--)
using namespace std;
int n,m,ans;
double a[15][15],s;
int main()
{
	cin>>n>>m;
	ft(i,1,n)
	  ft(j,1,m)
	    cin>>a[i][j];
	ft(i,1,n)
	  ft(j,i+1,n)
	  {
	  	  s=0.0;
	  	  ft(k,1,m) s+=(double)(1.0*(1.0*a[i][k]-a[j][k])*(1.0*a[i][k]-a[j][k]));
	  	  s=sqrt(s);
	  	  if(int(s)==s) ans++;
	  }
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

#define debug(x) cerr<<#x<<'='<<x<<'\n'
#define Int const int &

bool map[55][55];
bool b[55][55];
bool vis[55];
int n, m;
int tot;
void dfs(int k) {
//	debug(k);
	if (vis[k]) return;
	vis[k]=true; tot++;
	for (int i=1; i<=n; i++) {
		if (i==k || !map[i][k] || b[i][k]) continue;
		dfs(i);
	}
}
bool judge(void) {
	tot=0;
	memset(vis, 0, sizeof vis);
	dfs(1);
	//for (int i=1; i<=n; i++) {
	//	debug(vis[i]);
//	}
	return tot==n;
}
int ans;
int main(void) {
	cin>>n>>m;
	for (int i=1; i<=m; i++) {
		int a, b;
		cin>>a>>b;
		map[a][b]=map[b][a]=true;
	}
//	b[1][3]=true;
//	debug(judge());
//	debug("===");
	for (int i=1; i<=n; i++) {
		for (int j=i+1; j<=n; j++) {
			if (!map[i][j]) continue;
			b[i][j]=b[j][i]=true;
			if (!judge()) ans++;
			b[i][j]=b[j][i]=false;
		}
	}
	cout<<ans<<'\n';
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 1100000

ll dp[MAXN][4];

int main(){
  int n;cin>>n;
  ll result = 1, eight=1, nine=1;

  rep(i, n){
    result = result * 10 % MOD;
    nine = nine * 9 % MOD;
    eight = eight * 8 % MOD;
  }
  result = (result - nine + MOD - nine + MOD + eight)%MOD;
 
  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
  ll n,m;
  cin>>n>>m;
  vector<pair<ll,ll>> ab(n);
  rep(i,n) {
    ll a,b;
    cin>>a>>b;
    ab[i].first=a;
    ab[i].second=b;
  }
  //////////////
  sort(all(ab));
  //cout<<ab[0].first;
  ll sum=0;//買った本数
  ll ans=0;
  rep(i,n){
    if((sum+ab[i].second)<m){
      sum+=ab[i].second;
      ans+=ab[i].first*ab[i].second;
    }
    else{
      ll c=m-sum;
      ans+=c*ab[i].first;
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][] A = new int[M][2];
		for(int i = 0; i < M; i++) {
			A[i][0] = sc.nextInt();
			A[i][1] = sc.nextInt();
		}
		Arrays.sort(A, (x,y) -> x[1]-y[1]);
		int ans = 1, temp = A[0][1];
		for(int i = 0; i < M; i++) {
			if(A[i][0] >= temp) {
				ans++;
				temp = A[i][1];
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 92700
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD = 1000000007;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i=0;i<N;i++){
        cin >> S[i];
        sort(S[i].begin(),S[i].end());
    }
    vector<map<char,int>> mpl(N);
    for(int i=0;i<N;i++){
        for(auto x : S[i]){
            mpl[i][x]++;
        }
    }
    int ans = 0;
    for(int i=0;i<26;i++){
        char k = char('a'+i);        
        int s = 51;
        for(int j=0;j<N;j++){
            s = min(s,mpl[j][k]);
        }
        for(int i=0;i<s;i++) cout << k;
    }
    cout << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    vector<char> taka(N, '-');
    long long int score = 0;
    for(int i = 0; i < N; i++) {
        if(T.at(i) == 'r') {
            if(i < K) {
                score += P;
                taka.at(i) = 'p';
            } else {
                if(taka.at(i - K) != 'p') {
                    score += P;
                    taka.at(i) = 'p';
                }
            }
        } else if(T.at(i) == 'p') {
            if(i < K) {
                score += S;
                taka.at(i) = 's';
            } else {
                if(taka.at(i - K) != 's') {
                    score += S;
                    taka.at(i) = 's';
                }
            }
        } else if(T.at(i) == 's') {
            if(i < K) {
                score += R;
                taka.at(i) = 'r';
            } else {
                if(taka.at(i - K) != 'r') {
                    score += R;
                    taka.at(i) = 'r';
                }
            }
        }
    }
    cout << score << endl;
}

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

using namespace std;
using ll = long long;

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    long long ans = 0;
    for (int i = 0; i <= N / R; ++i)
        for (int j = 0; j <= N / G; ++j) {
            int x = N - R * i - G * j;
            if (x >= 0 && x % B == 0)
                ++ans;
        }
    cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    h, w, k = map(int, input().split())

    bf = [0] * (w + 2)
    nx = [0] * (w + 2)
    bf[1] = 1

    c = [1, 1, 2, 3, 5, 8, 13, 21]

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            nx[j] = c[j - 1] * c[w - j] * bf[j] + c[j - 1] * c[w - j - 1] * bf[j + 1] + c[j - 2] * c[w - j] * bf[j - 1]

        bf = nx
        nx = [0] * (w + 2)

    print(bf[k] % (10 ** 9 + 7))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	string s ; cin >> s ;
	ll n = s.size() ;
	ll k ; cin >> k ;
	if(k==1){
		cout << s.at(0)-'0'+9*(n-1) << endl ;
	}else{
		vvll dp0(n,vll(k+1,0)),dp1(n,vll(k+1,0)) ;
		dp0.at(0).at(0) = 1 ;
		dp0.at(0).at(1) = s.at(0)-'0'-1 ;
		dp1.at(0).at(1) = 1 ;
		for(int i=1;i<n;i++){
			for(int j=0;j<=k;j++){
				if(j==0){
					dp0.at(i).at(0) = dp0.at(i-1).at(0)+dp1.at(i-1).at(0)*(s.at(i)!='0') ;
					dp1.at(i).at(0) = dp1.at(i-1).at(0) ;
				}else{
					dp0.at(i).at(j) = dp0.at(i-1).at(j)+dp0.at(i-1).at(j-1)*9+dp1.at(i-1).at(j-1)*(s.at(i)-'0'-(s.at(i)!='0'))+dp1.at(i-1).at(j)*(s.at(i)!='0') ;
					dp1.at(i).at(j) = (s.at(i)=='0'?dp1.at(i-1).at(j):dp1.at(i-1).at(j-1)) ;
				}
			}
		}
		/*for(int j=0;j<=k;j++){
			for(int i=0;i<n;i++){
				cout << dp0.at(i).at(j) << (i==n-1?'\n':' ') ;
			}
		}
		for(int j=0;j<=k;j++){
			for(int i=0;i<n;i++){
				cout << dp1.at(i).at(j) << (i==n-1?'\n':' ') ;
			}
		}*/
		cout << dp0.at(n-1).at(k)+dp1.at(n-1).at(k) << endl ;
	}
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define scan(x) scanf("%lld",&x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok, flag;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111



int main(void) {
  ll a, b, c;
  cin >> a >> b >> c;
  vll x;
  x.pb(abs(a - b));
  x.pb(abs(a - c));
  x.pb(abs(b - c));
  sort(all(x));
  cout << x[0] + x[1] << endl;

  return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
grid = [input() for _ in range(h)]
MOD = 10**9+7
dp = [[0]*(w+1) for _ in range(h+1)]
dp[0][1] = 1
for i in range(h):
	for j in range(w):
		if grid[i][j] == "#":
			dp[i+1][j+1] = 0
		else:
			dp[i+1][j+1] = dp[i+1][j]+dp[i][j+1]
print(dp[-1][-1]%MOD)

Measured memory_bytes: 157416
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#define ll long long int
#define skip cin>>ws;
#define vll vector<ll> 
#define vb vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define vs vector<string>
#define vvpll vector<vector<pair<ll, ll>>>
#define pb push_back
#define pob pop_back()
#define MOD (ll)(1e9 + 7)
#define test ll t; cin>>t; while(t--)

using namespace std;

void enter(vll &ar)
{
    ll n = ar.size();

    for(ll i=0;i<n;i++)
    {
        cin>>ar[i];
    }
}

void show(vll &a)
{
    ll n = a.size();

    for(ll i=0;i<n;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void SieveOfErat1sthenes(int n, vll &pri) 
{ 
    vb prime(n+1, true); 
   
    for (int p=2; p*p<=n; p++) 
    { 
        
        if (prime[p] == true) 
        { 
            pri.pb(p);
            
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll mo(ll a)
{
    return a%MOD;
}

bool compare(pll a, pll b)
{
    return a.first>b.first;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, W;
    cin>>n>>W;

    vll w(n), v(n);

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

    vvll mat(W+1, vll(n+1));

    for(ll i=1;i<=W;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            if(w[j-1]>i) mat[i][j] = mat[i][j-1];
            else
            {
                mat[i][j] = max(mat[i][j-1], v[j-1] + mat[i-w[j-1]][j-1]);
            }
        }
    }

    cout<<mat[W][n]<<"\n";

    return 0;
}


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

int main(){
 
  int p, q, r;
  cin >> p >> q >> r;
  
  if(p + q < q + r && p + q < r + p)
    cout << p + q;
  else if(q + r < r + p)
    cout << q + r;
  else
    cout << r + p;
  
  return 0;
}

Measured memory_bytes: 256
N = int(input())  #頂点数
tree = [[] for _ in range(N)]
dic = {}
for i in range(N-1):
    u, v, w = map(int, input().split())
    if u > v:
        u, v = v, u
    tree[u-1].append(v-1)
    tree[v-1].append(u-1)
    dic[(u-1, v-1)] = w

import sys
sys.setrecursionlimit(10 ** 8)

#black:1, white:0, none:-1
ans = [-1]*N
ans[0] = 0
flag = [False]*N

def dfs(i):
    flag[i] = True
    for j in tree[i]:
        if flag[j]:
            continue
        x = min(i, j)
        y = max(i, j)
        if dic[(x, y)] % 2 == 0:
            ans[j] = ans[i]
        else:
            if ans[i] == 0:
                ans[j] = 1
            else:
                ans[j] = 0
        if not(flag[j]):
            dfs(j)
            
dfs(0)

for answer in ans:
    print(answer)

Measured memory_bytes: 86188
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
s = LS()
print(s[0][0].upper()+s[1][0].upper()+s[2][0].upper())
#B

#C
"""
n = I()
a = LI()
b = [a[i] for i in range(n)]
ans = 0
k = a[0]
if a[0] == 0:
    a[0] = 1
    ans = 1
    k = 1
for i in range(1,n):
    if k*(k+a[i]) >= 0:
        if k < 0:
            ans += abs(1-k-a[i])
            a[i] = 1-k
            k = 1
        else:
            ans += abs(-1-k-a[i])
            a[i] = -1-k
            k = -1
    else:
        k += a[i]
if b[0] >= 0:
    ans2 = b[0]+1
    k = -1
    b[0] = -1
else:
    ans2 = 1-b[0]
    k = 1
    b[0] = 1
for i in range(1,n):
    if k*(k+b[i]) >= 0:
        if k < 0:
            ans2 += abs(1-k-b[i])
            b[i] = 1-k
            k = 1
        else:
            ans2 += abs(-1-k-b[i])
            b[i] = -1-k
            k = -1
    else:
        k += b[i]
print(min(ans,ans2))
"""
#D
"""
x,y = LI()
if abs(x-y) <= 1:
    print("Brown")
else:
    print("Alice")
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x=sc.nextInt()*2,y=sc.nextInt();
        int count=0;
        for(int i=2;i<x;i+=2) {
            if(y*i%x==0) {
                count++;
            }
        }
        System.out.println(x/2+y-count);
    }
}


Measured memory_bytes: 26344
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;

ll n, a, p;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  ll ans = 0;
  FOR(i, 0, n){
    cin >> a;
    if(a*p > 0){
      ans++;
      a--;
    }
    ans += a / 2;
    a %= 2;
    p = a;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
  int A,B,C,D ;
  cin>>A>>B>>C>>D ;
  int left=A+B ;
  int right=C+D ;
  if(right>left) cout<<"Right"<<endl ;
  else if(right<left) cout<<"Left"<<endl ;
  else cout<<"Balanced"<<endl ;
  
  return 0 ;
}

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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 50;

int n, m;

char g[maxn + 5][maxn + 5];

int dp[maxn + 5][maxn + 5][maxn + 5][maxn + 5];

int sum[maxn + 5][maxn + 5];

inline int get_sum(int xl, int yl, int xr, int yr)
{
	return sum[xr][yr] - sum[xl][yr] - sum[xr][yl] + sum[xl][yl];
}

int px, py;

int ans = oo;

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%d", &n, &m);
	REP(i, 0, n) scanf("%s", g[i]);
	px = py = -1;
	REP(i, 0, n) REP(j, 0, m) if (g[i][j] == 'P') px = i, py = j;
	REP(i, 0, n) REP(j, 0, m)
		sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + (g[i][j] == '#');
	memset(dp, oo, sizeof dp);
	dp[0][0][n][m] = 0;
	REP(xl, 0, n) REP(yl, 0, m) for (int xr = n; xr > xl; --xr) for (int yr = m; yr > yl; --yr) if (dp[xl][yl][xr][yr] < oo)
	{
		REP(xmid, xl, xr + 1) REP(ymid, yl, yr + 1)
		{
			chkmin(dp[xl][yl][xmid][ymid], dp[xl][yl][xr][yr] + get_sum(xl, ymid, xmid, yr) + get_sum(xmid, yl, xr, ymid));
			chkmin(dp[xmid][ymid][xr][yr], dp[xl][yl][xr][yr] + get_sum(xl, ymid, xmid, yr) + get_sum(xmid, yl, xr, ymid));
			chkmin(dp[xl][ymid][xmid][yr], dp[xl][yl][xr][yr] + get_sum(xl, yl, xmid, ymid) + get_sum(xmid, ymid, xr, yr));
			chkmin(dp[xmid][yl][xr][ymid], dp[xl][yl][xr][yr] + get_sum(xl, yl, xmid, ymid) + get_sum(xmid, ymid, xr, yr));
		}
	}
	ans = oo;
	REP(xl, 0, px + 1) REP(yl, 0, py + 1) REP(xr, px + 1, n + 1) REP(yr, py + 1, m + 1)
		if (dp[xl][yl][xr][yr] < oo) 
		{
			chkmin(ans, dp[xl][yl][xr][yr] + min({get_sum(xl, yl, px + 1, py + 1), get_sum(xl, py, px + 1, yr), get_sum(px, yl, xr, py + 1), get_sum(px, py, xr, yr)}));
		}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 35968
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>; using vvi = vector<vector<int>>;
using vl = vector<ll>; using vvl = vector<vector<ll>>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
struct edge{
  int to,wt,from;
  bool operator<(edge right){
    return wt < right.wt;
  }
};
using ve = vector<edge>;
using vve = vector<ve>;
struct union_find{//rank,経路圧縮で高速化
  vector<long long> data;//そのノードがrootであれば-（集合のサイズ）を表し、そうでなければ親ノードidを示す。
  union_find(long long size):data(size,-1){}//コンストラクタ,size個のノードを作成し、-1で初期化
  long long root(long long a){//根を探す,経路圧縮
    return data[a] < 0 ? a : data[a]=root(data[a]);
  }
  bool find(long long a,long long b){//a,bが同じ集合に属するか調べる
    return root(a) == root(b);
  }
  bool unite(long long a,long long b){//小さい方の木の根に大きい方の根を上書きする
    a = root(a),b = root(b);
    if(a==b) return false;//根が同じなら終了,uniteが失敗したことを出力
    if(data[a]<data[b]) swap(a,b); //集合サイズの大きい方の根に低い方の根をつける
    data[a] += data[b];//集合サイズを統合
    data[a] = b;//yの親にxをつける
    return true;//unite成功を出力
  }
  long long size(long long a){//aが属する集合のサイズを出力
    return -data[root(a)];
  }
};
int kruskal(int sz,ve &edges){
  sort(rALL(edges));
  union_find uf(sz);
  int res = 0;
  while(!edges.empty()){
    edge &e = edges.back();
    edges.pop_back();
    if(!uf.unite(e.to,e.from)) continue;
    res += e.wt;
  }
  return res;
}
signed main(){
  int v,e;
  cin >> v >> e;
  // vve gr(v);
  ve edges(e);
  REP(i,e){
    int nd1,nd2,wt;
    cin >> nd1 >> nd2 >> wt;
    // gr[nd1].emplace_back(edge{nd2,wt,nd1});
    // gr[nd2].emplace_back(edge{nd1,wt,nd2});
    edges[i]=(edge){nd1,wt,nd2};
  }
  cout << kruskal(v,edges) << endl;
}


Measured memory_bytes: 4124