akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100005;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r;
    cin >> r;
    printf("%.10f\n",2*r*M_PI);
}


Measured memory_bytes: 3768
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
 long long int i,j,h,w,mod=1000000007;
 cin>>h>>w;
 char a[h][w];
 long long int d[h][w];
 for (i=0;i<h;i++){
  for (j=0;j<w;j++){
   cin>>a[i][j];
   d[i][j]=0;
  }
 }
 for (i=1;i<h;i++){
  if (a[i][0]=='#'){
   break;
  }
  else {
   d[i][0]=1;
  }
 }
 for (i=0;i<w;i++){
  if (a[0][i]=='#'){
   break;
  }
  else {
   d[0][i]=1;
  }
 }
 for (i=1;i<h;i++){
  for (j=1;j<w;j++){
   if (a[i][j]!='#'){
    if (a[i-1][j]=='.'&&a[i][j-1]=='.'){
     d[i][j]=(d[i][j]+d[i-1][j]+d[i][j-1])%mod;
    }
    else if (a[i-1][j]=='.'&&a[i][j-1]=='#'){
     d[i][j]=(d[i][j]+d[i-1][j])%mod;
    }
    else {
     d[i][j]=(d[i][j]+d[i][j-1])%mod;
    }
   }
  }
 }
 cout<<d[h-1][w-1];
 return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

int a[100100];

int main(){
    int n;
    cin>>n;
    for(int i=0 ; i<n ;i ++){
        scanf("%d",&a[i]);
    }
    int j=0;
    int st;
    int r =0;
    while(j < n-1){
        while(j < n-1 && a[j] == a[j+1])
            j++;
        if(j < n-1){
            if(a[j] < a[j+1])
            {
                while(j < n-1 && a[j] <= a[j+1])
                j++;
            }
            else{
            while(j < n-1 && a[j] >= a[j+1])
                j++;
            }
        }
        j++;
        r++;
    }
    if(j == n-1)
        r++;
    cout<<r<<endl;
    return 0;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<vector<vector<int>>> F(n, vector<vector<int>>(5, vector<int>(2)));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){
            for(int k = 0; k < 2; k++){
                cin >> F[i][j][k];
            }
        }
    }
    vector<vector<int>> P(n, vector<int>(11, 0));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 11; j++){
            cin >> P[i][j];
        }
    }

    long long maxProfit = -1000000000000000;

    // i個目のbit : i / 2曜日のi % 2時間に営業するかどうか
    for(int bit = 1; bit < (1 << 10); bit++){
        vector<int> c(n, 0);
        for(int i = 0; i < 10; i++){
            if(bit & (1 << i)){
                int yobi = i / 2;
                int zikan = i % 2;
                for(int k = 0; k < n; k++){
                    if(F[k][yobi][zikan] == 1){
                        c[k]++;
                    }
                }
            }
        }
        // 利益計算
        long long profit = 0;
        for(int k = 0; k < n; k++){
            profit += P[k][c[k]];
        }
        maxProfit = max(profit, maxProfit);
    }

    cout << maxProfit << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, D;
	cin >> N >> D;
	vector<vector<long double>>A(N, vector<long double>(D));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) {
			cin >> A.at(i).at(j);
		}
	}
	vector<long double>B;
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			long double num = 0;
			for (int k = 0; k < D; k++) {
				num += pow(abs(A.at(i).at(k) - A.at(j).at(k)), 2);
			}
			B.push_back(num);
		}
	}
	int ans = 0;
	for (int i = 0; i < B.size(); i++) {
		int sum = sqrt(B.at(i));
		if (sum == sqrt(B.at(i))) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int ichigo_pos_in_row(int row, const vector<string>& s)
{
    auto pos = s[row].find('#');
    if (pos == string::npos) {
        return -1;
    }

    return pos;
}

int main()
{
    int H, W, K;
    cin >> H >> W >> K;

    vector<string> s(H);

    for (int i = 0; i < H; ++i) {
        cin >> s[i];
    }

    vector<vector<int>> a(H, vector<int>(W, 0));

    // とりあえずいちごのある場所を番号で埋める
    int k = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (s[i][j] == '#') {
                a[i][j] = k;
                ++k;
            }
        }
    }

    // 左右を埋める
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W-1; ++j) {
            if (a[i][j+1] == 0) {
                a[i][j+1] = a[i][j];
            }
        }

        for (int j = W-1; j >= 1; --j) {
            if (a[i][j-1] == 0) {
                a[i][j-1] = a[i][j];
            }
        }
    }

    // 上下を埋める
    for (int j = 0; j < W; ++j) {
        for (int i = 0; i < H-1; ++i) {
            if (a[i+1][j] == 0) {
                a[i+1][j] = a[i][j];
            }
        }

        for (int i = H-1; i >= 1; --i) {
            if (a[i-1][j] == 0) {
                a[i-1][j] = a[i][j];
            }
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cout << a[i][j] << ' ';
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
package main

import (
	"fmt"
)

func divide(n int)int {
	sum := 0
	for n > 0 {
		sum += n % 10
		n = n / 10
	}
	return sum
}

func main() {
	var n int
	fmt.Scan(&n)
	
  	s := divide(n)
  	
    if n % s == 0 {
      fmt.Println("Yes")
    } else {
      fmt.Println("No")
    }
}

Measured memory_bytes: 512
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
		int c=sc.nextInt();
		int max=Math.max(Math.max(a,b),c);
  		int sa=max*3-a-b-c;
  		if(sa%2!=0){
        sa=sa+3;
        }
          
  		
    	System.out.println(sa/2);
    }
}


Measured memory_bytes: 35800
#include "stdio.h"

#define MAX(a, b)  (((a)>(b))?(a):(b))
#define MIN(a, b)  (((a)<(b))?(a):(b))

#define INF 300002

struct segtree {
    int l;
    int r;
    int max;
} tree[300010 * 4];

int dp[300010];
int seq[300010];

int modify(int i, int dis, int val) {
    if (tree[i].l == tree[i].r) {
        tree[i].max = val;
        return 0;
    }    
    int mid = (tree[i].l + tree[i].r) >> 1;
    if (dis > mid) modify(2 * i + 1, dis, val);
    else modify(2 * i, dis, val);
    if (tree[i].max < val) tree[i].max = val;
    return 0;    
}

int search(int i, int l, int r) {
    if (tree[i].l >= l && tree[i].r <= r)
        return tree[i].max;
    int m = (tree[i].l + tree[i].r) >> 1;
    int x = 0, y = 0;
    if (m >= l) x = search(i * 2, l, r);
    if (m < r) y = search(i * 2 + 1, l, r);
    return MAX(x, y);      
}

int build(int i, int l, int r) {
    tree[i].l = l;
    tree[i].r = r;
    tree[i].max = 0;
    if (l == r) return 0;
    int mid = (l + r) >> 1;
    build(2 * i, l , mid);
    build(2 * i + 1, mid + 1, r);
    return 0;
}

int main() {
        int N, K;
        scanf("%d", &N);
        scanf("%d", &K);
        int max = 0, min = INF;
        for (int i = 0; i < N; i++) {
            scanf("%d", &seq[i]);
            max = MAX(seq[i], max);
            min = MIN(seq[i], min); 
        }    
        build(1, 0, max);    
        dp[0] = 1;
        modify(1, seq[0], dp[0]);
        int res = 0;
        for (int i = 1; i < N; i++) {
             dp[i] = search(1, seq[i] - K, seq[i] + K) + 1;
             modify(1, seq[i], dp[i]);
             if (dp[i] > res) res = dp[i];  
        }
        printf("%d", res);       
}

Measured memory_bytes: 16364
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>

#define INF 1 << 30
#define MOD 1000000007;
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

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

int main() { 
  int n;
  cin >> n;
  vi a(2 * n);
  rep (i, 2 * n) {
    cin >> a[i];
  }

  sort(all(a));

  int sum = 0;

  rep(i, 2 * n) {
    sum += a[i];
    ++ i;
  }
  
  D(sum);
  return 0;
}



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

using namespace std;

typedef long long ll;

#define MOD 1000000007

// x^n
ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

// x^{-1}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }

vector<ll> fact;
vector<ll> fact_inv;

void init_fact(int n) {
  fact.resize(n + 1);
  fact_inv.resize(n + 1);
  fact[0] = fact_inv[0] = 1;
  for (int i = 0; i < n; ++i) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
    fact_inv[i + 1] = fact_inv[i] * mod_inv(i + 1) % MOD;
  }
}

ll nCr(ll n, ll r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

ll nPr(ll n, ll r) { return nCr(n, r) * fact[r] % MOD; }

int main() {
  ll n, k;
  cin >> n >> k;
  init_fact(n);
  ll ans = 0;
  for (int i = 0; i <= min(n - 1, k); ++i) {
    ll res = (nCr(n, i) * nCr(n - 1, n - 1 - i)) % MOD;
    ans = (ans + res) % MOD;
  }
  cout << ans << endl;
  return 0;
}

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

ll nC2(ll n){
    return n*(n-1)/2;
}

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    map<ll,ll> cnt;
    rep(i,n) cnt[a[i]]++;
    ll allC = 0;
    for (auto itr : cnt){
        allC += nC2(itr.second);
    }
    rep(i,n){
        cout << allC - nC2(cnt[a[i]]) + nC2(cnt[a[i]]-1) << endl;
    }
    return 0;
}


Measured memory_bytes: 11008
#include<cstdio>

int main(){
  int a, b, d, r;
  double f;

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

  d = a / b;
  r = a % b;
  f = (double) a / (double)b;

  printf("%d %d %f\n", d, r, f);

  return 0;
}

Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
//using ll = long long;
//using P = pair<int,int>;

void selectionSort(vector<int>& A, int N, int& change_cnt){ // N個の要素を含む0-オリジンの配列A
    for (int i=0;i<N;i++){
        int minj = i;
        for (int j=i;j<N;j++){
            if (A[j] < A[minj]){
                minj = j;
            }
        }
        if (A[i]!=A[minj]){ 
            int tmp_Ai = A[i];
            A[i] = A[minj];
            A[minj] = tmp_Ai;
            change_cnt++;
        }
    }
}

int main(){
    int N, change_cnt=0;
    cin >> N;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin >> A.at(i);
    selectionSort(A, N, change_cnt);
    for (int i=0;i<N;i++) {
        cout << A.at(i);
        if (i == N-1) break;
        cout << ' ';
    } 
    cout << endl;
    cout << change_cnt << endl;
}


Measured memory_bytes: 3116
using System;
using System.Collections.Generic;



public class Test
{
	public static void Main()
	{
//		while(true){
		  string[] str1 = Console.ReadLine().Split(' ');
		  int n = int.Parse(str1[0]); 
//		  int m = int.Parse(str1[1]); 

//		  if(n == 0) break;
		
		  int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
//		  string ss = Console.ReadLine();
//		  int[] b = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
//		  int[] c = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
		  //Console.WriteLine("改行あり N = {0} P = {1} Ai = {2}", n, p, a);
		  
		  int max = 0;
		  int sum = 0;
		  for(int i=0; i<a.Length; i++){
		  	if(max<a[i]) max = a[i];
		  	sum+=a[i];
		  
		}
		  
		  Console.WriteLine((max<(sum-max))?"Yes":"No");
//	    }


	}

  public static int calc(int n,int m,int[] a,int[] b,int[] c) {



	  return 0;
  }
  
  


}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n=4,a=4,b=6; cin >> n >> a >> b;--n;
    ll ans = (b*n+a) - (a*n+b) + 1;
    cout << (ans<0 ? 0 : ans) << endl;
    return 0;
}

Measured memory_bytes: 256
from math import ceil
k = int(input())
A = list(map(int,input().split()))[::-1]
if A[0]!=2:
    print(-1)
    exit()
flg = True
ans = [2,3]
for i in range(1, k):
    a = A[i]
    m = a*ceil(ans[0]/a)
    if m>ans[1]:
        flg = False
        break
    else:
        ans = [m,a*(ans[1]//a+1)-1]
if flg:
    print(*ans)
else:
    print(-1)

Measured memory_bytes: 63984
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	ll n,m;
	scanf("%lld%lld",&n,&m);
	if(m%n==0){
		printf("%lld",n+m);
	}	
	else{
		printf("%lld",m-n);
	}
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> v) {os << "(" << v.first << ", " << v.second << ")"; return os;}


void solve() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(all(A));
  int ii, jj;
  for (int i = 1; i < N; i++) {
    int j = lower_bound(all(A), A[i] / 2) - A.begin();
    double mi = 1e9 + 10;
    if (i != j + 1 && j + 1 < N) {
      if (mi > fabs(A[i] / 2.0 - A[j + 1])) {
        mi = fabs(A[i] / 2.0 - A[j + 1]);
        ii = i;
        jj = j + 1;
      }
    }
    if (i != j - 1 && j - 1 >= 0) {
      if (mi > fabs(A[i] / 2.0 - A[j - 1])) {
        mi = fabs(A[i] / 2.0 - A[j - 1]);
        ii = i;
        jj = j - 1;
      }
    }
    if (i != j && mi > fabs(A[i] / 2.0 - A[j])) {
      mi = fabs(A[i] / 2.0 - A[j]);
      ii = i;
      jj = j;
    }
  }
  cout << A[ii] << " " << A[jj] << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){
	int n,a[10001],temp,low=10001;
	for(int i=0;i<10001;i++){
		a[i]=0;
	}
	scanf("%d",&n);
	for(int i=0;i<n;i++){
	scanf("%d",&temp);
if(temp<low)low=temp;
	a[temp]++;
	}
printf("%d",low);
a[low]--;
	for(int i=0;i<10001;i++){
		while(a[i]>0){
			a[i]--;
			printf(" %d",i);
		}
	}
	printf("\n");
}

Measured memory_bytes: 2796
#include<iostream>
using namespace std;
int main(){
  int count,max,i,j,k,l;
   int sum,data_set[5000];
  while(cin>>count){
    if(!count)break;
    cin>>data_set[0];
    max=data_set[0];
    for( i=1;i<count;i++){
      cin>>data_set[i];
    }
    //  for(l=1;l<=count;l++){
      for( j=0;j<count;j++){
	sum=0;
	for( k=j;k<count;k++){
	  sum+=data_set[k];
	if(max<sum)max=sum;
	}
    }
    cout<<max<<endl;
  }
}

Measured memory_bytes: 1176
N = gets.to_i
A = []
B = []
N.times{
    a, b = gets.split.map(&:to_i)
    if N.even?
        a *= 2
        b *= 2
    end
    A << a
    B << b
}
A.sort!
B.sort!
#warn A.inspect
#warn B.inspect
if N.odd?
    min = A[N / 2]
    max = B[N / 2]
    puts(max - min + 1)
else
    min = (A[N / 2] + A[N / 2 - 1]) / 2
    max = (B[N / 2] + B[N / 2 - 1]) / 2
    puts(max - min + 1)
end


Measured memory_bytes: 20484
// 2011/12/01 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int a1, a2, a3, a4;
	cin >> a1 >> a2 >> a3 >> a4;
	int b1, b2, b3, b4;
	cin >> b1 >> b2 >> b3 >> b4;

	int S = a1+a2+a3+a4;
	int T = b1+b2+b3+b4;

	if(S>=T)
		cout << S << endl;
	else
		cout << T << endl;

	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

const int MAX = 2020;

int N;
int A[MAX];

ll dp[MAX][MAX];

ll solve() {
    vii a;
    REP (i, N) a.push_back(ii(A[i], i));
    sort(a.rbegin(), a.rend());

    REP (i, N) {
        dp[i+1][0] = dp[i][0] + a[i].first * (a[i].second - i);
        dp[0][i+1] = dp[0][i] + a[i].first * (N - 1 - i - a[i].second);
    }

    FOR (k, 2, N+1) {
        FOR (i, 1, k) {
            CHMAX(dp[i][k-i], dp[i-1][k-i] + a[k-1].first * (a[k-1].second - i + 1));
            CHMAX(dp[i][k-i], dp[i][k-i-1] + a[k-1].first * (N - k + i - a[k-1].second));
        }
    }

    ll ret = 0;
    REP (i, N+1) CHMAX(ret, dp[i][N-i]);
    return ret;
}

int main() {
    cin >> N;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b == c + d) cout << "Balanced" << endl;
  if (a + b > c + d) cout << "Left" << endl;
  if (a + b < c + d) cout << "Right" << endl;
}

Measured memory_bytes: 384
# 参考URL https://note.nkmk.me/python-union-find/
class UnionFind():
    # 各要素の親要素の番号を格納するリスト
    # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 要素xが属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 要素x, yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

def main():
    from sys import stdin
    input = stdin.buffer.readline

    n, q = map(int, input().split())

    uf = UnionFind(n)

    ans = []
    for _ in range(q):
        t, u, v = map(int, input().split())
        if t == 0:
            uf.union(u, v)
        else:
            if uf.same(u, v):
                ans.append(1)
            else:
                ans.append(0)
    
    for i in ans:
        print(i)

main()

Measured memory_bytes: 12292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> t(n), x(n), y(n);
    rep(i,n) cin >> t[i] >> x[i] >> y[i];
    int preX = 0, preY = 0, preT= 0;
    rep(i,n){
        int diffX, diffY, diffT;
        diffX = abs(x[i] - preX);
        diffY = abs(y[i] - preY);
        diffT = abs(t[i] - preT);
        if (diffT < (diffX + diffY)){
            cout << "No" << endl;
            return 0;
        }
        if (((diffX + diffY) % 2) != (diffT % 2)){
            cout << "No" << endl;
            return 0;
        }
        preX = x[i];
        preY = y[i];
        preT = t[i];
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 4160
N,A,B,C = map(int,input().split())

L = [int(input()) for i in range(N)]
INF = 10 ** 18

def bamboo_search(l,a,b,c):
    if l==N:
        return abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c)>0 else INF
    else:
        bcan = bamboo_search(l+1,a,b,c)
        ba = bamboo_search(l+1,a+L[l],b,c)+10
        bb = bamboo_search(l+1,a,b+L[l],c)+10
        bc = bamboo_search(l+1,a,b,c+L[l])+10
        return min(bcan,ba,bb,bc)
    
print(bamboo_search(0,0,0,0))

Measured memory_bytes: 3064
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, M, X := sc.nextInt(), sc.nextInt(), sc.nextInt()
	A := make(map[int]bool)
	for i := 0; i < M; i++ {
		A[sc.nextInt()] = true
	}
	cost := 0
	for i := 1; i < X; i++ {
		if A[i] {
			cost++
		}
	}
	cost2 := 0
	for i := X + 1; i < N; i++ {
		if A[i] {
			cost2++
		}
	}

	fmt.Fprintln(wtr, min(cost, cost2))
	wtr.Flush()
}


Measured memory_bytes: 640
//???????!w

#include <stdio.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
typedef long long ll;
const ll N = 1 << 20;

void init(int n_, ll dat);

void update(int k, ll dat);

ll gcd(ll m, ll n);

ll n, tree[2 * N - 1];
ll nn;
ll a[100005];
ll ans = 0;

int main()
{
	scanf("%lld", &nn);
	for (int i = 0; i < nn; i++) {
		scanf("%lld", &a[i]);
	}

	init(nn, a[nn - 1]);
	for (int i = 0; i < nn; i++) {
		update(i, a[i]);
	}
	ans = tree[0];
	for (int i = 0; i < nn; i++) {
		if (i & 1) {
			update(i, a[i - 1]);
		} else {
			update(i, a[i + 1]);
		}

		ans = max(ans, tree[0]);
		update(i, a[i]);
	}

	init(nn, a[nn - 2]);
	for (int i = 0; i < nn; i++) {
		update(i, a[i]);
	}
	for (int i = 0; i < nn; i++) {
		if (i & 1) {
			update(i, a[i - 1]);
		} else {
			update(i, a[i + 1]);
		}

		ans = max(ans, tree[0]);
		update(i, a[i]);
	}

	printf("%lld\n", ans);

	return 0;
}

void init(int n_, ll dat)
{
	n = 1;
	while (n < n_) {
		n *= 2;
	}

	for (int i = 0; i <= 2 * n; i++) {
		tree[i] = dat;
	}
}

void update(int k, ll dat)
{
	k += n - 1;
	tree[k] = dat;

	while (k > 0) {
		k = (k - 1) / 2;

		tree[k] = gcd(tree[2 * k + 1], tree[2 * k + 2]);
	}
}

ll gcd(ll m, ll n)
{
	if (m < n) {
		ll tmp = m;
		m = n;
		n = tmp;
	}

	while (n) {
		ll tmp = n;
		n = m % n;
		m = tmp;
	}

	return m;
}


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

int main()
{
	string S, T;
	cin >> S >> T;
	
	int ans = 0;
	for(int i = 0; i < (int)(S.length()); i++)
	{
		if(S[i] != T[i])
			ans++;
	}
	
	printf("%d", ans);
}


Measured memory_bytes: 3924
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define endl "\n"
#define int long long
#define F first
#define S second
#define B begin
#define E end
#define RB rbegin
#define RE rend
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const int Q = 47;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}


signed main()
{
    hello();
    
    int n;
    cin >> n;
    int res = 0;
    for (int i = 1; i <= n; ++i)
    {
        int x;
        cin >> x;
        if (i % 2 && x % 2)
            ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 3648
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (a, b, x) = scan!(i64, i64, i64);

    let mut n = b / x + 1;
    if a > 0 {
        n -= (a - 1) / x + 1
    }

    println!("{}", n);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

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

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

signed main(void)
{
    ll n;
    cin >> n;
    
    if (n == 10 || n == 100 || n == 1000 || n == 10000 || n == 100000) {
        mes(10);
        re0;
    }
    
    ll num = n-1, sum = 0, dig = 0;
    
    while(num){
        dig = num % 10;
        sum = sum + dig;
        num = num / 10;
    }
    

    mes(sum+1);
    
    
    
    
    
    
    
    
    
}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  string check = "TRUE";
  int ans = 0;
  
  while(check == "TRUE"){
   for(int j=0; j<N; j++){
    if(vec.at(j) %2 != 0){
      check = "FALSE";
      break;
    }
    vec.at(j) = vec.at(j) / 2;
   }
   ans++;
  }
    
  cout << ans - 1 << endl;

}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 3003
using namespace std;

int n, Mod, S2[N][N], pw[N][N], C[N][N];

inline int fsp(int x, int k, int p = Mod) {
    int res = 1;
    while (k) {
        if (k & 1) res = 1ll * res * x % p;
        x = 1ll * x * x % p, k >>= 1;
    } return res;
}

inline int get(int x) {
    long long res = 0, tmp = fsp(2, fsp(2, n - x, Mod - 1));
    for (int i = 0; i <= x; ++i)
        res = (res + 1ll * S2[x + 1][i + 1] * pw[x][i] % Mod * tmp % Mod) % Mod;
    return res;
}

int main() {
#ifdef isLOCAL
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n >> Mod;
    long long ans = 0;
    S2[0][0] = 1;
    for (int i = 0; i <= n + 1; ++i)
        for (int j = C[i][0] = 1; j <= i; ++j)
            S2[i][j] = (S2[i - 1][j - 1] + 1ll * S2[i - 1][j] * j) % Mod,
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % Mod;
    for (int i = 0; i <= n; ++i) {
        int tmp = fsp(2, n - i);
        for (int j = pw[i][0] = 1; j <= i; ++j)
            pw[i][j] = 1ll * tmp * pw[i][j - 1] % Mod;
    }
    for (int i = 0; i <= n; ++i)
        ans = (ans + ((i & 1) ? -1ll : 1ll) * get(i)\
        * C[n][i] % Mod) % Mod;
    if (ans < 0) ans += Mod;
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 104576
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n;
ll a[100005];
int main()
{
        cin >> n;
        for(ll i = 1 ; i <= n ; i++) cin >> a[i];
        ll L = 2;
        ll R = 2;
        if(a[n] != 2){
                cout << "-1\n"; return 0;
        }
        for(ll i = n ; i >= 2 ; i--) {
                ll lb = L;
                ll rb = R + a[i] - 1;
                ll el = (rb / a[i - 1]);
                el = el * a[i-1];
                ll ell = (lb + a[i-1] - 1) / a[i-1];
                ell = ell * a[i-1];
                if(ell >= lb && ell <= rb && el <= rb && el >= lb){
                        L = min(el , ell);
                        R = max(el , ell);
                }else if(ell >= lb && ell <= rb) {
                        L = ell;
                        R = ell;
                }else if(el >= lb && el <= rb) {
                        L = el;
                        R = el;
                }else {
                        cout << "-1\n"; return 0;
                }
        }
        R = R + a[1] - 1;
        cout << L << " " << R << endl;
        return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(auto& i : v){
        cin >> i;
    }
    sort(all(v));
    cout << accumulate(v.end()-k, v.end(), 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,b,c,n;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        n = a;
        a = b;
        b = n;
    }
    if(b>c){
        n = b;
        b = c;
        c = n;
    }
    if(a>b){
        n = a;
        a = b;
        b = n;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int>t(n+1),x(n+1),y(n+1);
  t[0]=x[0]=y[0]=0;
  for(int i=1;i<=n;i++){
    cin>>t[i]>>x[i]>>y[i];
  }
  bool at=true;
  for(int i=0;i<n;i++){
    int dist=abs(x[i]-x[i+1])+abs(y[i]-y[i+1]);
    int d=t[i+1]-t[i];
    if(d<dist) at=false;
    if(dist%2!=d%2) at=false;
  }
  if(at) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
    
  


Measured memory_bytes: 1408
package main

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

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n_bricks := scanInt(sc)

	bricks := make([]int, n_bricks)
	for i := 0; i < n_bricks; i++ {
		bricks[i] = scanInt(sc)
	}

	next := 1
	n_broken := 0
	for _, brick := range bricks {
		if brick == next {
			next += 1
		} else {
			n_broken += 1
		}
	}

	if n_broken == n_bricks {
		fmt.Println(-1)
	} else {
		fmt.Println(n_broken)
	}
}


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

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

	long long dp[100001] = {0};
	for (int i = 1; i <= N; ++i) {
		int w, v;
		cin >> w >> v;
		for (int j = W; j >= 1; --j) {
			if (j >= w) dp[j] = max(dp[j], dp[j-w] + v);
		}
	}
	long long ans = dp[W];

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

Measured memory_bytes: 1024
s = input()
l = len(s)
if l%2 == 1:
    b = s[:l//2]
    a = s[l//2+1:][::-1]
else:
    b = s[:l//2]
    a = s[l//2:][::-1]
count = 0
for x,y in zip(b, a):
    if x != y:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    int H, W, A, B; cin >> H >> W >> A >> B;

    vector<vector<int>> matrix(H, vector<int>(W, -1));

    vector<pair<int,int>> col(H, pair<int,int>(0,0));
    vector<pair<int,int>> row(W, pair<int,int>(0,0));

    bool flag = true;

    rep(i,H) rep(j,W)
    {
        bool a_0 = col[i].first == W-A, a_1 = col[i].second == W-A,
             b_0 = row[j].first == H-B, b_1 = row[j].second == H-B;
        
        if (a_0 && b_1 || a_1 && b_0) flag = false;
        
        else if (a_0 || b_0)
        {
            matrix[i][j] = 1;
            col[i].second++;
            row[j].second++;
        }
        else if (a_1 || b_1)
        {
            matrix[i][j] = 0;
            col[i].first++;
            row[j].first++;
        }

        else
        {
            matrix[i][j] = 0;
            col[i].first++;
            row[j].first++;
        }
    }

    if (flag)
    {
        rep(i,H)
        {
            rep(j,W)
            {
                cout << matrix[i][j];
            }
            cout << endl;
        }
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	set<string> s;
	char before;
	REP(i,0,n){
		string tmp;
		cin>>tmp;
		if(i!=0){
			if(before!=tmp[0]){
				cout<<"No"<<endl;
				return 0;
			}
			if(s.find(tmp)!=s.end()){
				cout<<"No"<<endl;
				return 0;
			}
		}
		s.insert(tmp);
		before = tmp[tmp.size()-1];
	}
	cout<<"Yes"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main(){
  long long A, B, C, K;
  cin >> A >> B >> C >> K;

   if(K <= A){
  cout << K << endl;
    }
  
   if(A < K && K <= A + B){
  cout << A << endl;
    }
  
 if(K > A + B){
     cout << max(A-C, A-(K-A-B)) << endl;
   }

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    int a,b,c,x;
    cin >> a >>b >> c>>x;
    int res = 0;
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <=b ; ++j) {
            for (int k = 0; k <=c ; ++k) {
                if(500 * i + 100 * j + 50 *k == x) res++;
            }

        }

    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int a,b;
    cin >> a >> b;
    if(a>9||b>9)cout << -1 << endl;
    else cout << a*b << endl;
}

Measured memory_bytes: 256
def check(animals, s)
  result = false
  case animals[1]
  when 'S'
    case s
    when 'o'
      result = true if animals[0] == animals[2]
    when 'x'
      result = true if animals[0] != animals[2]
    end
  when 'W'
    case s
    when 'o'
      result = true if animals[0] != animals[2]
    when 'x'
      result = true if animals[0] == animals[2]
    end
  end
  result
end

def make_result(result, s, n)
  result
  (n-2).times do |i|
    case result[i + 1]
    when 'S'
      case s[i + 1]
      when 'o'
        result << 'S' if result[i] == 'S'
        result << 'W' if result[i] == 'W'
      when 'x'
        result << 'W' if result[i] == 'S'
        result << 'S' if result[i] == 'W'
      end
    when 'W'
      case s[i + 1]
      when 'o'
        result << 'W' if result[i] == 'S'
        result << 'S' if result[i] == 'W'
      when 'x'
        result << 'S' if result[i] == 'S'
        result << 'W' if result[i] == 'W'
      end
    end
  end

  return result if check(result[n - 2] + result[n - 1] + result[0], s[n - 1]) && check(result[n - 1] + result[0] + result[1], s[0])
  nil
end

N = gets.chomp.split(' ').map(&:to_i)[0]
s = gets.chomp

['SS', 'SW', 'WS', 'WW'].each do |first|
  result = make_result(first, s, N)
  unless result.nil?
    puts result
    exit
  end
end
puts -1

Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;



int main() {
   ll h,w;
   int n;
   cin >> h >> w >> n;
  set<pair<ll,ll>> s;
  vector<ll> a(10);
  rep(i,10) a.at(i)=0;
  a.at(0)=(h-2)*(w-2);
  ll x,y;
  rep(i,n){
    cin >> y >> x;
    s.insert(make_pair(x,y));
    vector<vector<int>> b(5,vector<int>(5));
    rep(j,5){
      rep(k,5){
        b.at(k).at(j)=0;
        if (x-2+k>w || x-2+k<1 || y-2+j>h || y-2+j<1) continue;
        auto it=s.find(make_pair(x-2+k,y-2+j));
        if (it!=s.end()) b.at(k).at(j)=1;
      }
    }  
     
    rep(j,3){
      rep(k,3){
        int u=0;
        if (x+k>w || x-2+k<1 || y+j>h || y+j-2<1) continue;
        rep(jj,3){
          rep(kk,3){
            u+=b.at(k+kk).at(j+jj);
          }
        }
        //cout << "kkkkkkk" << u << " " << i << " " << j << k << endl;
        a.at(u-1)--;
        a.at(u)++;
      }
    }
  }
  rep(i,10){
    cout << a.at(i) << endl;
  }
}


Measured memory_bytes: 6528
#include <iostream>
using namespace std;
int main() {
	int n, m;
	char a[51][51], b[51][51];
	cin >> n >> m;
	for (int y = 0; y < n; y++) {
		for (int x = 0; x < n; x++) {
			cin>>a[y][x];
		}
	}
	for (int y = 0; y < m; y++) {
		for (int x = 0; x < m; x++) {
			cin>> b[y][x];
		}
	}
	bool exist = false;
	for (int ly = 0; ly < n; ly++) {
		for (int lx = 0; lx < n; lx++) {
			if (ly + m - 1 >= n or lx + m - 1 >= n) continue;
			bool match = true;
			for (int y = 0; y < m; y++) {
				for (int x = 0; x < m; x++) {
					if (b[y][x] != a[ly + y][lx + x]) match = false;
				}
			}
			if (match) exist = true;
		}
	}
	if (exist) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class D
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = Scanner.Scan<long>();
            var prime = new Prime(N);
            var answer = 0;
            foreach (var count in prime.Factors.Values)
            {
                var i = 1;
                while (count >= i * (i + 1) / 2)
                {
                    i++;
                    answer++;
                }
            }
            Console.WriteLine(answer);
        }

        public class Prime
        {
            public Dictionary<long, int> Factors => new Dictionary<long, int>(_factors);
            private Dictionary<long, int> _factors;
            public Prime(long n)
            {
                _factors = new Dictionary<long, int>();
                var tmp = n;
                var max = (long)Math.Sqrt(n);
                var p = 2;
                while (p <= max)
                {
                    if (tmp % p == 0)
                    {
                        _factors[p] = 0;
                        while (tmp % p == 0)
                        {
                            tmp /= p;
                            _factors[p]++;
                        }
                    }
                    p++;
                }
                if (tmp > 1) _factors[tmp] = 1;
            }
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 28336