akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#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++)
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; }

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1330

int main(){
    int n, m, a, b, d;
    char c;
    while(cin >> n >> m){
        if(n == 0) break;
        UnionFind<int> uf(n);
        rep(i, m){
            cin >> c;
            if(c == '!'){
                cin >> a >> b >> d;
                --a;
                --b;
                uf.merge(a, b, d);
            }
            else if(c == '?'){
                cin >> a >> b;
                a--;
                b--;
                if(uf.issame(a, b)){
                    cout << uf.diff(a, b) << endl;
                }
                else {
                    puts("UNKNOWN");
                }
            }
        }
    }
}


Measured memory_bytes: 3980
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n;
		int[][] M;
		int[] visit;
		int sum=0, min,v,number=1;
		final int inf = Integer.MAX_VALUE;
		
		n = sc.nextInt();
		M = new int[n][n];
		for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { M[i][j] = sc.nextInt(); } }
		
		//その頂点が訪問済みかどうかを示す配列、初期値は0, 訪問すると1になる
		visit = new int[n];
		//一番最初の頂点は訪問済みにしておく
		visit[0] = 1;
		//頂点の数だけ繰り返す（n回）
		while( true ) {
			min = inf;
			v = -1;
			
			//木の探索を行う
			for(int i=0; i<n; i++) {
				if(visit[i] == 1) {
					for(int j=0; j<n; j++) {
						if(visit[j]==0 && M[i][j]>=0 && M[i][j]<min) {
							min = M[i][j];
							v = j;
						}
					}	
				}
			}//木の探	索終了
			//訪問済みにする
			visit[v] = 1	;
			sum += min;
			number++;
			if(number == n) break;
		}//n個の頂点に対し	処理が終了
		
		System.out.println( sum );
	}
}



Measured memory_bytes: 40896
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

int N;
vector<int> X, Y;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  X.resize(N);
  Y.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
  }

  int mod = abs(X[0] + Y[0]) % 2;
  for (int i = 1; i < N; i++) {
    if (abs(X[i] + Y[i]) % 2 != mod) {
      cout << -1 << endl;
      return 0;
    }
  }

  int m = 0;
  vector<int> d;
  if (mod == 1) {
    m = 31;
    for (int i = m - 1; i >= 0; i--) {
      d.push_back(pow(2, i));
    }
  } else {
    m = 32;
    for (int i = m - 2; i >= 0; i--) {
      d.push_back(pow(2, i));
    }
    d.push_back(1);
  }

  vector<vector<char>> w(N);
  for (int i = 0; i < N; i++) {
    int xt = X[i], yt = Y[i];
    int x = 0, y = 0;
    vector<char> s(m);
    for (int j = 0; j < m; j++) {
      if (abs(x - xt) >= abs(y - yt)) {
        if (x >= xt) {
          x -= d[j];
          s[j] = 'L';
        } else {
          x += d[j];
          s[j] = 'R';
        }
      } else {
        if (y >= yt) {
          y -= d[j];
          s[j] = 'D';
        } else {
          y += d[j];
          s[j] = 'U';
        }
      }
    }
    w[i] = s;
  }

  // output
  cout << m << endl;
  for (int i = 0; i < d.size(); i++) {
    if (i != 0) {
      cout << " ";
    }
    cout << d[i];
  }
  cout << endl;
  for (auto &e : w) {
    for (auto &c : e) {
      cout << c;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 512
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    std::string S;
    std::cin >> S;

    std::cout << S.size()/2 - std::count(std::begin(S), std::end(S), 'p') << std::endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
}

Measured memory_bytes: 384
import fractions
A, B, C, D = map(int, input().split())

def lcm(a,b):
    return a*b//fractions.gcd(a,b)

b_n = B//C + B//D - B//lcm(C,D)
a_n = (A-1)//C + (A-1)//D - (A-1)//lcm(C,D)
ans_n = b_n - a_n
print(int(B-A+1-ans_n))

Measured memory_bytes: 5048
#include <iostream>

using namespace std;

int main(void){
  char c;
  for (int i=0; i<3; i++){
    cin >> c;
    if (c=='1') cout << '9';
    else if (c=='9') cout << '1';
    else cout << c;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
    p[i]-=i+1;
  }

  sort(all(p));

  ll x=p[n/2];

  ll ans=0;
  rep(i,n){
    ans+=abs(x-p[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 1920
#include <stdio.h>
#define MAX 100
#define INF 1000000
#define DISCONNECT -1
#define BLACK -2
void initializeSingleSource(int);
void dijkstra(int G[MAX][MAX], int);

int d[MAX], pi[MAX];

int main(){
  int G[MAX][MAX], n, u, v, k, i, j;

  for(i = 0; i < MAX; i++){
    for(j = 0; j < MAX; j++) G[i][j] = DISCONNECT;
  }
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d %d",&u,&k);
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      scanf("%d",&G[u][v]);
    }
  }
  dijkstra( G, n );

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

void initializeSingleSource(int n){
  int i;
  for(i = 0; i < n; i++){
    d[i] = INF;
    pi[i] = DISCONNECT;
  }
  d[0] = 0;
}

void dijkstra(int G[MAX][MAX], int n){
  int mincost, color[MAX], u, v, i, j;
  initializeSingleSource(n);
  while( 1 ){
    mincost = INF;
    for(i = 0; i < n; i++){
      if( color[i] != BLACK && d[i] < mincost ){
	mincost = d[i];
	u = i;
      }
    }
    if( mincost == INF ) break;
    color[u] = BLACK;
    for(j = 0; j < n; j++){
      if( G[u][j] != DISCONNECT ){
	v = j;
	if( color[v] != BLACK && d[u] + G[u][v] < d[v] ){
	  pi[v] = u;
	  d[v] = d[u] + G[u][v];
	}
      }
    }
  }
}




Measured memory_bytes: 2052
//#include <cmath>

#include <iostream>
#include <vector>
#include <string>




using namespace std;

string S;



int main()
{

	cin >> S;

	bool ans = S[2] == S[3] && S[4] == S[5];


	cout << (ans?"Yes":"No") <<endl;

	return 0;
}



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

using namespace std;

const int RANKS = 13;
const int SUITS = 4;
const char suits[SUITS] = {'S', 'H', 'C', 'D'};

int deck[SUITS][RANKS];

int suit_to_int(char suit) {
	if (suit == 'S') return 0;
	if (suit == 'H') return 1;
	if (suit == 'C') return 2;
	return 3;
}

int main() {
	int n;
	cin >> n;
	while (n--) {
		char suit;
		int rank;
		cin >> suit >> rank;
		deck[suit_to_int(suit)][rank-1]++;
	}
	for (int i = 0; i < SUITS; ++i) {
		for (int j = 0; j < RANKS; ++j) {
			if (!deck[i][j]) {
				cout << suits[i] << ' ' << j+1 << '\n';
			}
		}
	}
}


Measured memory_bytes: 3040
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;

int main(){
    int A, B;
    cin >> A;
    cin >> B;
    int ans = max( max(A+B,A-B),A*B );
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
s=[input() for i in range(N)]
M=int(input())
l=[input() for i in range(M)]
list_str=list(dict.fromkeys(s+l))
s_l=[]
for i in range(len(list_str)):
  s_l.append(s.count(list_str[i])-l.count(list_str[i]))
#print(all([i < 0 for i in s_l]))
if(all([i < 0 for i in s_l])):
  print(0)
else:print(max(s_l))

Measured memory_bytes: 3064
n = int(input())
d=list(map(int, input().split()))

a = 0
for i in range(n):
    a += d[i]**2
    
b = 0
for j in range(n):
    for k in range(n):
        b += d[j]*d[k]
        
ans = int((b-a)/2) 
print(ans)

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

int n;
struct node{
	int a,b;
}v[maxn];

bool cmp(node x,node y){
	return x.b<y.b;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d %d",&v[i].a,&v[i].b);
	sort(v+1,v+n+1,cmp);
	ll time=0,flag=0;
	for(int i=1;i<=n;i++){
		time+=v[i].a;
		if(time>v[i].b){
			flag=1;
			break;
		}
	}
	if(flag==0)printf("Yes");
	else printf("No");
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define log(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int a,b;cin>>a>>b;
  int h,m;cin>>h>>m;

  long double th = h*30+ m*0.5 - m*6;
  th = abs(th);
  
  long double ans = a*a + b*b -  2*a*b*cosl(th*3.1415926535897932384626433832795028841/(long double)180);
  cout<<fixed<<setprecision(30)<<(sqrtl(ans))<<endl;

  return 0;
}


Measured memory_bytes: 4160
n,a,b=map(int,input().split())
def modpow(x,y,p):
  if y==1:
    return x%p
  if y%2==1:
    return x*modpow(x,y-1,p)
  t=modpow(x,y/2,p)
  return (t*t)%p
def modfc(x,y,p):
  f=1
  for i in range(x,y+1):
    f=f%p*i%p
  return f%p
A=modfc(n-a+1,n,10**9+7)*modpow(modfc(1,a,10**9+7),10**9+5,10**9+7)
B=modfc(n-b+1,n,10**9+7)*modpow(modfc(1,b,10**9+7),10**9+5,10**9+7)
print((modpow(2,n,10**9+7)-1-A-B)%(10**9+7))

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;



signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> a(M,0);
    vector<ll> b(M,0);
    for(ll i=0;i<M;++i){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
    }
    um Ma;
    for(ll i=0;i<M;++i){
        Ma[a[i]]++;
        Ma[b[i]]++;
    }
    for(auto p: Ma){
        if(p.second%2!=0){
            prt("NO");return 0;
        }
    }
    prt("YES");

    return 0;
}



Measured memory_bytes: 8356
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
using Point = complex<double>;

#define X real()
#define Y imag()
double dot(Point a, Point b) {
    return (a.X*b.X + a.Y*b.Y);
}
using Line = pair<Point, Point>;
Point Projection(Line s, Point p) {
    Point vase = s.second - s.first;
    p -= s.first;
    return s.first + dot(p, vase) / norm(vase)*vase;
}
Point Reflection(Line s, Point p) {
    return p + (Projection(s, p) - p) * 2.0;
}
double cross(Point a, Point b) {
    return a.X*b.Y - a.Y*b.X;
}
int ccw(Point a, Point b, Point c) {
    if (cross(b - a, c - a) > EPS)return 1;
    if (cross(b - a, c - a) < -EPS)return -1;
    if (dot(b - a, c - a) < -EPS)return 2;
    if (abs(b-a)+EPS <abs(c-a))return -2;
    return 0;
}
bool isOrthogonal(Line a, Line b) {
    return dot(a.second - a.first, b.second - b.first)? 0 : 1;
}
bool isParallel(Line a, Line b) {
    return cross(a.second - a.first, b.second - b.first)? 0 : 1;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Point p1, p2,p3,p4;
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        double x1, x2, y1, y2,x3,x4,y3,y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        p1 = Point(x1, y1);
        p2 = Point(x2, y2);
        p3 = Point(x3, y3);
        p4 = Point(x4, y4);
        Line l1 = Line(p1, p2),l2=Line(p3,p4);
        if (isOrthogonal(l1,l2)&&!isParallel(l1, l2)) {
            cout << 1 << endl;
        }
        else if (!isOrthogonal(l1, l2) && isParallel(l1, l2)) {
            cout << 2 << endl;
        }
        else {
            cout << 0 << endl;
        }
    }
    return 0;

}



Measured memory_bytes: 3300
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

int n, a[112345];

int main() {

	scanf("%d", &n);
	int biggest = 0, bn = 0;
	rep(i, n) {
		scanf("%d", &a[i]);
		biggest = max(a[i], biggest);
		if (biggest == a[i]) bn = i;
	}

	int nearest = bn ? a[0] : a[1], delta = bn ? abs(a[0] - biggest / 2) : abs(a[1] - biggest / 2);

	rep(i, n) {
		if (bn != i && delta > abs(a[i] - biggest / 2)) {
			delta = abs(a[i] - biggest / 2);
			nearest = a[i];
		}
	}

	printf("%d %d\n", biggest, nearest);


	return 0;
}


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

int main() {
  int n;string s;cin>>n>>s;
  int ans=0;
  for(int i=1;i<n-1;i++){
    vector<int> a(26),b(26);
    for(int j=0;j<i;j++)a[s[j]-'a']++;
    for(int j=i;j<n;j++)b[s[j]-'a']++;
    int cnt=0;
    rep(j,26){
      if(a[j]>0&&b[j]>0)cnt++;
    }
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


int main(int argc, char const* argv[])
{
    int n,m;
    cin >> n >> m;
    cout << (n-1) * (m-1) << endl;
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector


// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }


Measured memory_bytes: 256
use proconio::*;
use proconio::marker::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        s: Bytes,
    }
    let s = s.into_iter().map(|s| (s - b'0') as i32).collect::<Vec<_>>();
    let cnt = s.iter().sum::<i32>();
    let mut rem = vec![];
    for div in (cnt - 1)..=(cnt + 1) {
        if div <= 0 {
            rem.push((0, vec![]));
            continue;
        }
        let mut val = vec![0; n];
        let mut p = 1;
        let mut sum = 0;
        for (val, c) in val.iter_mut().zip(s.iter()).rev() {
            *val = p;
            sum = (c * p + sum) % div;
            p = 2 * p % div;
        }
        rem.push((sum, val));
    }
    for i in 0..n {
        let mut c = cnt;
        if s[i] == 1 {
            c -= 1;
        } else {
            c += 1;
        }
        if c == 0 {
            println!("0");
            continue;
        }
        let mut ans = 1;
        let mut val = if s[i] == 1 {
            (rem[0].0 + c - rem[0].1[i]) % c
        } else {
            (rem[2].0 + c + rem[2].1[i]) % c
        };
        while val > 0 {
            val = val % val.count_ones() as i32;
            ans += 1;
        }
        println!("{}", ans);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 5272
#include<bits/stdc++.h>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e5+5;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(x) memset(x,0,sizeof(x))
#define sca(x) scanf("%d",&x)
#define scall(x) scanf("%lld",&x)
#define eps 1e-6
int main()
{
	int n,x,t;
	sca(n);sca(x);sca(t);
	if(n%x==0)
	cout<<n/x*t<<endl;
	else
	cout<<(n/x+1)*t<<endl;
}

Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <vector>

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

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

int main()
{
  string S;
  cin >> S;
  switch (S[S.size() - 1])
  {
  case 's':
    cout << S + "es" << endl;
    break;
  default:
    cout << S + "s" << endl;
    break;
  }

  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int x,count=0;
    cin>>x;
    int y[x];
    for(int i=0;i<x;i++){
        cin>>y[i];
    }
    for(int i=1;i<x-1;i++){
        if( (y[i]<y[i-1] && y[i]>y[i+1]) || (y[i]>y[i-1] && y[i]<y[i+1]) ){
            count++;
        }
    }
    cout<<count<<endl;

}



Measured memory_bytes: 3600
#include<stdio.h>
#include<stdlib.h>

int main(void){
  int N,key;
  int *data;
  int i,j;

  scanf("%d",&N);

  data=(int *)malloc(N*sizeof(int));

  for(i=0;i<N;i++) scanf("%d",&data[i]);

  printf("%d",data[0]);
  for(i=1;i<N;i++){
    printf(" %d",data[i]);
  }
  printf("\n");

  for(i=1;i<N;i++){
    key=data[i];
    j=i-1;
    while(j>=0 && data[j]>key){
      data[j+1]=data[j];
      j--;
    }
    data[j+1]=key;
    
    printf("%d",data[0]);
    for(j=1;j<N;j++){
      printf(" %d",data[j]);
    }
    printf("\n");
  }

  free(data);

  return 0;
}

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

int main() {
  int A;
  int B;
  int C;
  cin >> A >> B >> C;
  int flug = 0;
  if (A < 1 || A > 100 || B < 1 || B > 100 || C < 1 || C > 100 ) {
    flug = 1;
  }
  if (flug != 1) {
  vector<int> cost = { A, B, C };
  sort(cost.begin(), cost.end());
  cout << cost.at(2) - cost.at(0) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1000000000
typedef long long  ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a /g* b ;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
int  GetDigit(T num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};


int main()
{
    ll Q, H, S, D;

    ll N;
    cin >> Q >> H >> S >> D >> N;
    ll tm = min(min(8 * Q, 4 * H), min(2 * S, D));
    ll om = min(min(4* Q, 2 * H),S);
    
    if (N % 2 == 0)
    {
        cout << tm * (N / 2) << endl;
    }
    else{
        cout << tm * (N / 2 )+om<< endl;
    }

}

Measured memory_bytes: 256
from math import sqrt

n = int(input())
# 平方数はパス
sq = [i*i for i in range(15)]

ans = 0
for num in range(2,n+1):
    cnt = 0
    if num in sq:
        pass
    else:
        for div in range(1,int(sqrt(num))+1):
            if num % div == 0:
                cnt += 1
                
        if cnt == 4 and num%2 == 1:
            ans += 1
            
print(ans)

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

using namespace std;

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const ll INF = 1e11;
int n;
int a[100000],b[100000];
ll da[100001],db[100001];
int add[100000],rev[100000];
// [4 1] 5 9 // +8 +1
// 3 1 [4 1] // +3 -2
// 合計でN個以下いれる
// 1 1 0 0 -1 -1

ll suma, sumb;

// N log N
int main() {
	cin>>n;
	priority_queue<int, vector<int>, greater<int> > a;
	priority_queue<int> b;
	REP(i,n*3){
		int d;
		cin >> d;
		if(i<n){
			suma+=d;
			a.push(d);
		}
		if(n*2<=i){
			sumb+=d;
			b.push(d);
		}
		if(n<=i && i <n*2){
			add[i-n]=d;
		}
	}
	FOR(k,1,n+1){
		a.push(add[k-1]);
		da[k]=da[k-1] - a.top() + add[k-1];
		a.pop();
	}
	FOR(k,1,n+1){
		b.push(add[n-k]);
		db[k]=db[k-1] - b.top() + add[n-k];
		b.pop();
	}
	ll ans = -1e16;
	REP(i,n+1){
		ans = max(ans, suma + da[i] - sumb - db[n-i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3064
#include<stdio.h>

int main(void) {
        int nums[3000][2];
        int i, count = 1;

        while(1) {
                scanf("%d %d",&nums[count][0], &nums[count][1]);
                if(nums[count][0] == 0 && nums[count][1] == 0) break;
                else if(nums[count][0] < 0 || nums[count][0] > 10000 && nums[count][1] < 0 || nums[count][1] > 10000 ) return 1;
                count++;
        }

        for(i = 1; i < count; i++) {
                nums[i][0] < nums[i][1] ? printf("%d %d\n", nums[i][0], nums[i][1]) : printf("%d %d\n", nums[i][1], nums[i][0]);
        }

        return 0;
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

vector<int> edge[100000];
int board[100000];

int dfs1(int cur, int prev, int target, int dist) {
  if (cur == target) return dist;

  int res = -1;

  rep (i, edge[cur].size()) {
    int next = edge[cur][i];
    if (next == prev) continue;
    res = max(res, dfs1(next, cur, target, dist + 1));
  }

  return res;
}

void dfs2(int cur, int prev, int color, int dist, int limit) {
  if (dist >= limit) return;

  rep (i, edge[cur].size()) {
    int next = edge[cur][i];
    if (next == prev) continue;
    if (board[next] != 0 && board[next] != color) continue;
    board[next] = color;
    dfs2(next, cur, color, dist + 1, limit);
  }
}

int main() {
  int N;
  cin >> N;
  rep (i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    edge[a].eb(b);
    edge[b].eb(a);
  }

  int dist = dfs1(0, 0, N - 1, 0);

  board[0] = 1;
  board[N - 1] = 2;
  dfs2(    0,     0, 1, 0, dist / 2);
  dfs2(N - 1, N - 1, 2, 0, dist / 2);
  dfs2(    0,     0, 1, 0, INF);
  dfs2(N - 1, N - 1, 2, 0, INF);

  int cnt1 = 0, cnt2 = 0;
  rep (i, N) {
    if (board[i] == 1) cnt1++;
    if (board[i] == 2) cnt2++;
  }

  cout << (cnt1 > cnt2 ? "Fennec" : "Snuke") << endl;
}


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

using namespace std;

int main(void) {
    string S;
    cin >> S;
    string s = S.substr(5, 2);
    int month = stoi(s);
    if(month <= 4) {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // AGC033A - Darker and Darker
  // BFS
  int H, W; cin >> H >> W;
  vector<string> A(H);
  REP(i, H){
    cin >> A[i];
  }

  vector<vector<int> > dist(H, vector<int>(W, -1)); // 距離情報を保持して、訪問済みか判定する
  queue<pair<int, int> > q;
  REP(i, H){
    REP(j, W){
      if(A[i][j] == '#'){
        dist[i][j] = 0;
        q.push({i, j});
      }
    }
  }

  vector<int> X = {1, 0, -1, 0}; // 縦方向
  vector<int> Y = {0, 1, 0, -1}; // 横方向
  while(!q.empty()){
    auto cur = q.front();
    q.pop();
    REP(i, 4){
      int x = cur.first + X[i], y = cur.second + Y[i];
      if(x < 0 || x > H-1 || y < 0 || y > W-1) continue;
      if(dist[x][y] == -1){
        dist[x][y] = dist[cur.first][cur.second] + 1;
        q.push({x, y});
      }
    }
  }

  int ans = 0;
  REP(i, H){
    REP(j, W){
      ans = max(ans, dist[i][j]);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 13456
n=int(input())
a=list(map(int,input().split()))

ans=[0 for i in range(n)]
for i in range(n-1,-1,-1):
  if i+1>n//2:
    ans[i]=a[i]
    continue

  t_sum=sum(ans[i::i+1])
  if t_sum%2==a[i]:
    ans[i]=0
  else:
    ans[i]=1

cnt=ans.count(1)
print(cnt)
if cnt!=0:
  print(*[i+1 for i in range(n) if ans[i]==1])

Measured memory_bytes: 13112
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    int cnt=0;
    cin >> s;
    for (int i = 0; i < s.size(); ++i){
        if(s[i]=='x'){
            cnt++;
        }
    }
    if(cnt>7){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e5+50;
int n,m;
int f[maxn];
int s[maxn];
char S[maxn];
inline int add(int x)
{
	return x>=mod?x-mod:x;
}
inline int dec(int x)
{
	return x<0?x+mod:x;
}
void dp(int L)
{
	f[1]=s[1]=1;
	for(int i=2;i<=n;++i)
	{
		f[i]=dec(s[i-1]-s[max(0,i-L-2)]);
		s[i]=add(s[i-1]+f[i]);
	} 
}
int solve()
{
	if(S[1]=='B')
	{
		for(int i=1;i<=m;++i)
		{
			S[i]=S[i]=='R'?'B':'R'; 
		}
	}
	int an=0,k=1,L=n;
	while(k<m&&S[k+1]=='R')
	{
		++k;
	}
	if(k==m)
	{
		static int f[maxn][2];
		memset(f,0,sizeof(f)); 
		f[1][0]=1;
		for(int i=1;i<n;++i)
		{
			f[i+1][0]=add(f[i][0]+f[i][1]);
			f[i+1][1]=add(f[i][0]);
		}
		an=add(an+f[n][0]);
		an=add(an+f[n][1]);
		memset(f,0,sizeof(f));
		f[1][1]=1;
		for(int i=1;i<n;++i)
		{
			f[i+1][0]=add(f[i][0]+f[i][1]);
			f[i+1][1]=add(f[i][0]);
		}
		an=add(an+f[n][0]);
		return an;
	}
	if(n&1) return 0;
	L=k&1?k:k+1;
	for(int i=k+1,j;i<=m;i=j+1)
	{
		j=i;
		while(j<=m&&S[j]!='B')
		{
			++j;
		}
		if(j==m+1) continue;
		int _k=j-i;
		if(_k&1) L=min(L,_k);
	}
	n>>=1,L>>=1;
	dp(L);
	for(int i=n;i>=1;--i)
	{
		if(n-i>L) break;
		an=(an+(ll)(n-i+1)*f[i])%mod;
	}
	an=add(an<<1);
	return an;
}
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",S+1);
	printf("%d\n",solve());
	return 0;
} 

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e6+1;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
  int a, b, c;
  cin >> a >> b >> c;
  if ((a == b && a != c) || (a == c && a != b) || (b == c && a != b))
    cout << "Yes";
  else
    cout << "No";
  	return 0;
}


Measured memory_bytes: 256
n, q = (int(_) for _ in input().split())
res = [0] * n
l = [[] for i in range(n-1)]
for i in range(n-1):
    a, b = (int(_) for _ in input().split())
    l[a-1].append(b)
p = [list(map(int, input().split())) for i in range(q)]

for i in p:
    res[i[0]-1] += i[1]
for i in range(n-1):
    for ii in l[i]:
        res[ii-1] += res[i]

[print(i,end=" ") for i in res]
print()

Measured memory_bytes: 93316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

ll lcm(ll x, ll y){
    return x*y/__gcd(x,y);
}

int main(){
    ll n,m;
    string s,t;
    cin >>n >>m >>s >>t;

    ll L = lcm(n,m);

    map<int,char> ch;
    rep(i,n){
        ch[L/n * i] = s[i];
    }

    ll ans = L;
    rep(i,m){
        ll pos = L/m * i;
        if(ch.count(pos)){
            if(ch[pos] != t[i]) ans = -1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;
 
int A,B;

int f(int N){
    if(N%4==0)return N;
    if(N%4==1)return 1;
    if(N%4==2)return N+1;
    if(N%4==3)return 0;
    return 0;
}

signed main() {
    IOS();
    cin>>B>>A;
    cout<<(f(B-1)^f(A))<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var (
		N int
		S string
	)
	fmt.Scanf("%d", &N)
	fmt.Scanf("%s", &S)

	ans := 1
	for i := 1; i < N; i++ {
		if S[i-1] != S[i] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1280
/*  CREATED BY
    Stream_Cipher
    13-sep-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define debug2(a,b) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<"\n"
#define debug3(a,b,c) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<","<<#c<<"="<<(c)<<"\n"
#define fix_precision(n) cout<<fixed<<setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int mx=5*1000000;//5*64M bit ->5*8M byte ->40MB size for long long int (64 bit)
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
        int n;
        cin>>n;
        vector<int>a(n);
        for(auto &i:a)
        	cin>>i;
        // sort(all(a));
        int ans=0;
        for(int i=0;i<n;i++)
        {
        	for(int j=i+1;j<n;j++)
        	{
        		for(int k=j+1;k<n;k++)
        		{
        			if(a[i]+a[j]>a[k]&&a[k]+a[j]>a[i]&&a[k]+a[i]>a[j]&&a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i])
        			{
        				// cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<endl;
        				ans++;
        			}
        		}
        	}
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] v = new int[N+1];
        int[] w = new int[N+1];
        for (int i = 1; i <= N; i++) {
            v[i] = sc.nextInt(); w[i] = sc.nextInt();
        }
        int[][] dp = new int[N+1][W+1];
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= W; j++) {
                if(j < w[i] || dp[i-1][j-w[i]] + v[i] < dp[i-1][j]) dp[i][j] = dp[i-1][j];
                else dp[i][j] = dp[i-1][j-w[i]] + v[i];
            }
        }
        System.out.println(dp[N][W]);
        sc.close();

    }

}



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

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

bool palin(string &S, int x, int y) {
	x--; y--;
	while(x<y) {
		if(S[x]!=S[y])
			return false;
		x++; y--;
	}
	return true;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string S; cin>>S;
	int N=S.size();
	int w=1,x=(N-1)/2,y=(N+3)/2,z=N;
	cout<< ((palin(S,w,z)&&palin(S,w,x)&&palin(S,y,z))?"Yes":"No")<<"\n";
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
r, c = map(int, input().split())
arr = []
for i in range(r):
    arr.append(list(map(int, input().split())))
 
for line in arr:
    line.append(sum(line))
     
arr.append([sum([line[i] for line in arr]) for i in range(c  + 1)])

for line in arr:
    print(*line)


Measured memory_bytes: 6240
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        List<Integer> list = new ArrayList<>();
        int sum = 0;
        for(int i = 0 ; i < m ; i++){
            list.add(sc.nextInt());
        }

        for(int i = 0 ; i < m ; i++){
            sum += list.get(i);
        }

        if(n < sum){
            System.out.println(-1);
        }else{
            System.out.println(n - sum);
        }

        

            
                


    }
}

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

int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    
    int num;
    int g,h;
    cin >> num;
    for(int i=0; i<num; i++){
        cin >> g >> h;
        for(int i=0; !(a==g && b==h); i++){
            if(d==h || c==h){
                int tmp = a;
                a = d;
                d = f;
                f = c;
                c = tmp;
            }
            for(int i=0; b!=h; i++){
                int tmp=a;
                a = b;
                b = f;
                f = e;
                e = tmp;
            }
            for(int i=0; a!=g; i++){
                int tmp=a;
                a = d;
                d = f;
                f = c;
                c = tmp;
            }
        }
        cout << c << endl;
    }
}


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

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

int sum = 0;

int main() {
    int k;
    cin >> k;
    for(int i = 1;i <=k;i++){
        for(int j = 1;j <=k;j++){
            for(int m = 1;m <= k;m++){
                sum += gcd(gcd(m,j),i);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3636
//別の

#include<stdio.h>

int main (void){

    long long int n,count;
    long long int a,b,c;

    scanf("%lld",&n);

    count=0;

    for(a=1;a<n;a++){
        for(b=1;b<n;b++){
            if(n<=a*b){
                break;
            }else{
                count++;
            }

        }
    }


    printf("%lld",count);







    return 0;
}

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

int main()
{
    int people;
    int train;
    int taxi;
    int total;
cin >> people >> train >> taxi;
int totalTrain = people * train;
if( totalTrain >= taxi){
    cout << taxi << endl;
}else {
    cout << totalTrain << endl;
}
}



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

int N, M;
int A[100010];
int B[100010];
int res;
map<int, bool> ver;


struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};


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

    res = N-1;
    UnionFind uf(N+1);
    for(int i = 0; i < M; i++){
        cin >> A[i] >> B[i];
        if(uf.merge(A[i], B[i])) --res;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4576
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
#include <functional>

//#include "All.h"

using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    REP(i, b) tmp *= a;
    return tmp;
}

ll N, M, Q;
ll a[110], b[110], c[110], d[110];
ll A[110] = {};

ll ans = 0;

void Amaker(int n, int i) {
    //nはn+1番目のループであることを表す
    //iはA[n]の初期値
    for (A[n] = i; A[n] < M; A[n]++) {
        if (n == N - 1) {
            //処理
            //ここでAの数列確定
            ll tmp = 0;
            /*
            cout << "A[]:";
            REP(j, N) {
                cout << A[j] + 1 << " ";
            }
            cout << endl;
            */
            REP(j, Q) {
                //そのAに対してQ回確かめる
                if (A[b[j] - 1] - A[a[j] - 1] == c[j]) {
                    tmp += d[j];
                    //cout << a[j] << " " << b[j] << " " << c[j] << " " << d[j] << endl;
                }
            }
            ans = max(ans, tmp);
        }
        else {
            Amaker(n + 1, A[n]);
        }
    }
}

int main() {
    cin >> N >> M >> Q;
    REP(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    Amaker(0, 0);
    /*
    for (A[0] = 0; A[0] < M; A[0]++) {
        for (A[1] = A[0]; A[1] < M; A[1]++) {
            for (A[2] = A[1]; A[2] < M; A[2]++) {
                for (A[3] = A[2]; A[3] < M; A[3]++) {
                    for (A[4] = A[3]; A[4] < M; A[4]++) {
                        for (A[5] = A[4]; A[5] < M; A[5]++) {
                            for (A[6] = A[5]; A[6] < M; A[6]++) {
                                for (A[7] = A[6]; A[7] < M; A[7]++) {
                                    for (A[8] = A[7]; A[8] < M; A[8]++) {
                                        for (A[9] = A[8]; A[9] < M; A[9]++) {
                                            
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    */
    cout << ans << endl;
}

/*
10 10 2
1 10 9 1
2 10 9 2
*/


Measured memory_bytes: 3688
using System;
using System.Linq;

class D
{
	static void Main() => Console.WriteLine(Dfs(new int[int.Parse(Console.ReadLine())].Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray()));

	static long Dfs(long[][] dc)
	{
		var s = dc.Sum(x => x[0] * x[1]);
		return dc.Sum(x => x[1]) - 1 + (s < 10 ? 0 : Dfs(new[] { new[] { 1, s / 10 }, new[] { s % 10, 1 } }));
	}
}


Measured memory_bytes: 32784
from functools import reduce
import sys
n=list(map(int,input().split()))
a=list(map(int,input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd_list(numbers):
    return reduce(gcd, numbers)

for i in range(n[0]):
  a[i] -= n[1]

print(abs(gcd_list(a)))

Measured memory_bytes: 14596