akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define ff first
#define ss second
#define MAXN  1000005
#define endl "\n"
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, v[100005], dp[100005];
    cin>>n;
    for(int i =  0; i < n; i++){
        cin>>v[i];
    }
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(int i = 2; i < n; i++){
        dp[i]=min(abs(v[i] - v[i-1]) + dp[i-1], abs(v[i] - v[i-2]) + dp[i-2]);
    }
    cout<<dp[n-1];

    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdint>

using namespace std;

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

	int64_t n;
	cin >> n;

	vector<int64_t> numbers(n);

	int64_t sum = 0;
	for (int64_t& x : numbers)
	{
		cin >> x;

		sum += x;
	}

	int64_t boxsum = n*(n+1)/2;
	int64_t boxcube = n*boxsum;

	bool ok = true;
	for (int64_t i=0 ; i<n ; i++)
	{
		int64_t chk = sum + boxsum * (numbers[i] - numbers[(i+1)%n]);
		if (chk<0 || (chk%boxcube))
		{
			ok = false;
		}
	}

	if (ok) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 1152
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N;
  cin >> N;
  vi A(N + 1);
  cin >> A;
  auto S = A;
  reverse(all(S));
  psum(S);
  reverse(all(S));

  int ans = 0;
  int cnt = 1;
  rep(i, 0, N + 1) {
    ans += cnt;
    cnt -= A[i];
    if (cnt < 0) {
      ans = -1;
      break;
    }
    if (i == N) break;
    if (cnt * 2 >= S[i + 1]) {
      cnt = S[i + 1];
    } else {
      cnt *= 2;
    }
  }
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



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

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

for i in range(k):
    if visited[now] != -1:#訪れたことがあるか
        loop = i - visited[now]   #ループの大きさ
        k = (k-(i-loop)) % loop
        
        for _ in range(k):
            now = a[now]
        
        break
        
    visited[now] = i
    now = a[now] 
        
print(now + 1)

Measured memory_bytes: 32352
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
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; }

const int INF=1e9;

int main(){
    int h,n;
    cin>>h>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;++i) cin>>a[i]>>b[i];
    vector<vector<long long>> dp(n+1,vector<long long>(h+1,INF));
    dp[0][0]=0;

    for(int i=0;i<n;++i){
        for(int j=0;j<=h;++j){
            chmin(dp[i+1][j],dp[i][j]);
            chmin(dp[i+1][min(j+a[i],h)],dp[i+1][j]+b[i]);
        }
    }

    cout<<dp[n][h]<<endl;
}

Measured memory_bytes: 81668
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int ans = 0;
    for(int i = 1;i<=k;i++){
      for(int ii = 1;ii<=k;ii++){
        for(int iii = 1;iii<=k;iii++){
          int a[] = new int[3];
          a[0] = i;
          a[1] = ii;
          a[2] = iii;
          Arrays.sort(a);
          int b = gcd(a[2],a[1]);
          int c = Math.max(b,a[0]);
          int d = Math.min(b,a[0]);
          ans += gcd(c,d);
        }
      }
    }
    System.out.println(ans);
  }
  public static int gcd(int a,int b){
    int temp = -1;
    while((temp = a%b)!=0){
      a = b;
      b = temp;
    }
    return b;
  }
}


Measured memory_bytes: 53124
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

lld gcd(lld a, lld b){
    lld c;
    if(a<b){
        c = a;
        a = b;
        b = c;
    }
    while(a%b!=0){
        c=a%b;
        a=b;
        b=c;
    }
    return b;
}

int main(){
    int n;
    scanf("%d", &n);
    lld u = 1LL, ans = 1LL;
    rep(i, 0, n){
        lld t;
        scanf("%lld", &t);
        u = gcd(ans, t);
        ans = ans / u * t;
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100010;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    int n, m; cin >> n >> m;
    priority_queue<ll> pq;
    rep(i, n){
        int a; cin >> a;
        pq.push(a);
    }
    ll x;
    while(m > 0){
        x = pq.top(); pq.pop();
        pq.push(x / 2);
        m--;
    }
    ll ans = 0;
    while(pq.size()){
        x = pq.top(); pq.pop();
        ans += x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
N = int(input())
A = list(map(int,input().split()))

cnt = [0] * max(A)

for i in range(len(A)):
    cnt[A[i]-1] += 1

ok = 0
ans = 0

for i in range(len(cnt)):
    if cnt[i] == 0:
        continue
    ans += 1
    if cnt[i] % 2 == 0:
        ok = 1 - ok

if ok == 1:
    ans -= 1

print(ans)

Measured memory_bytes: 20704
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#define ll long long
#define INF 1e+18
#define MOD 998244353
using namespace std;



int main(){
    int n,i;
    cin >> n >> i;
    cout<<n-i+1<<endl;
    
    return 0;
}


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

vector<int64_t> suffixSum(vector<int64_t> &vct){
	vector<int64_t> suffixSumVct(vct.size(), 0);
	for(int i=vct.size()-1;i>=0;i--){
		if(i==vct.size()-1)
			suffixSumVct[i] = 0;
		else{
			suffixSumVct[i] = vct[i+1] + suffixSumVct[i+1];
		}
	}
	return suffixSumVct;
}

int main(){
	int64_t N,tmp;
	vector<int64_t> vct;

	cin >> N;
	vct.resize(N, 0);
	for (int i=0;i<N;i++){
		cin >> tmp;
		vct[i] = tmp;
	}

	vector<int64_t> suffixSumVct = suffixSum(vct);
	int64_t res = 0;
	for (int i=0;i<vct.size();i++)
		res = ((res%1000000007) + ((vct[i]%1000000007) * (suffixSumVct[i]%1000000007)))%1000000007;

	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 6416
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
    int n, i;
	cin >> n;
	int count, tmp;
	int index = 1;
	count = 0;
	for (i = 0; i < n; i++) {
		cin >> tmp;
		if (tmp == index) 
			index++;
		else
			count++;
	}
	if (count == n)
		count = -1;

	cout << count << 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;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll X, Y; cin >> X >> Y;
    ll tx = X;
    ll ans = 0;
    while (tx <= Y) {
        ans += 1;
        tx = tx*2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  if ((a+b+c) == 17 ) {
    if ((a==b&&c==7)||(a==c&&b==7)||(c==b&&a==7)) {
      cout << "YES" << endl; 
    return 0;
    }
  }
  
  cout << "NO" << endl; 
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    order = [(i, a) for i, a in enumerate(A)]
    order = sorted(order, key=lambda x: x[1])
    ans = [o[0] + 1 for o in order]
    print(*ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == "__main__":
    main()


Measured memory_bytes: 30864
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    int h, w;
    cin >> h >> w;

    char s[1010][1010];
    vector<pair<int, int> > b;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
        for (int j = 0; j < w; j++) {
            if (s[i][j] == 'B') b.emplace_back(i, j);
        }
    }

    int ans = 0;
    for (int i = 0; i < b.size(); i++) {
        for (int j = 0; j < b.size(); j++) {
            ans = max(ans, abs(b[i].first - b[j].first)
            + abs(b[i].second - b[j].second));
        }
    }

    //cout << far_i << " " << far_j << endl;

    cout << ans << endl;

}


Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int main(){
  int n, k;
  while(cin >> n >> k && (n|k)){
    string card[10];
    string t;
    for(int i = 0 ; i < n ; i++)  cin >> card[i];
    
    sort(card, card+n);

    set<int> res;
    
    do{
      int a = 0;
      for(int i = 0 ; i < k ; i++){
        for(int j=0;j<card[i].size();j++){
          a *= 10;
          a += card[i][j] - '0';
        }
      }
      
      res.insert(a);
    }while(next_permutation(card, card+n));
      
    cout << res.size() << endl;
  }
}

Measured memory_bytes: 1336
#include <iostream>
#include <vector>

using namespace std;

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

    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) cout << "No\n";
    else if (a == b) cout << "Yes\n";
    else if (b == c) cout << "Yes\n";
    else if (a == c) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

bool mk[maxn];
int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);
	
	int n,m;
	cin >> n >> m;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		a[i]/=2;
	}
	int lcm = a[0];
	for(int i=1	;i<n;i++)
	{
		lcm = lcm*a[i]/__gcd(lcm,a[i]);
	}
	bool f = 0;
	for(int i=0;i<n;i++)
	{
		if((lcm-a[i])%(2*a[i])!=0)
		f=1;
	}
	//cout << lcm << endl;
	if(f)
	{
		cout << 0;
		return 0;
	}
	
	cout << (m/lcm)-(m/lcm/2);
	
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define LL long long
using namespace std;

const int N = 2e5;

LL a,b,c,k,d;

int main()
{
    //freopen("D:\\rush.txt","r",stdin);
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> a >> b >> c >> k;
    d = a-b;
    if (k%2==0){
        cout<<d<<endl;
    }else{
        cout<<-d<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;


int main() {
    ll n,k;
    cin >> n >> k;
    ll ans=n%k;
    if (k-ans<ans) ans=k-ans;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,A[200000],c[200000],i;
    scanf("%d",&N);
    for(i=0;i<N;i++)
        c[i]=0;
    for(i=0;i<(N-1);i++){
        scanf("%d",&A[i]);
        c[A[i]-1]++;
    }
    for(i=0;i<N;i++)
        printf("%d\n",c[i]);
    return 0;
}


Measured memory_bytes: 3292
#include <iostream>
#include <unordered_set>

using namespace std;

class C {
	int N;
	unordered_set<int> us;
public:
	void solve()
	{
		int A;
		for (int i{ 0 }; i < N; i++)
		{
			cin >> A;
			if (!(us.insert(A).second))
			{
				us.erase(A);
			}
		}

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

	C() { cin >> N; }
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 4388
n,m,l=gets.chomp.split(" ").map(&:to_i)

####n*mの行列の取得
require "matrix"
$mat=Array.new(n)
for i in 0..n-1 do
 $mat[i]=gets.chomp.split(" ").map(&:to_i)
end
a=Matrix[*$mat]

####m*lの行列の取得
$matb=Array.new(m)
for i in 0..m-1 do
 $matb[i]=gets.chomp.split(" ").map(&:to_i)
end
b=Matrix[*$matb]
c=(a*b).to_a

#2重リストの半角区切り出力
for i in 0..n-1 do
print"#{c[i].join(' ')}\n"
end 


Measured memory_bytes: 9156
import sys

class Node:
    def __init__(self, x, parent=None):
        self.key = x
        self.left = None
        self.right = None
        self.parent = parent

    def append_child(self, child):
        if self.key > child.key:
            self.left = child
            child.parent = self
        elif self.key < child.key:
            self.right = child
            child.parent = self
        else:
            pass

class BinaryTree:
    def __init__(self):
        self.root = None

    def insert(self, x):
        inserted = Node(x)
        if self.root is None:
            self.root = inserted
            return inserted

        node = self.root
        parent = None
        while node is not None:
            if x > node.key:
                parent = node
                node = node.right
            elif x < node.key:
                parent = node
                node = node.left
            else:
                return node

        parent.append_child(inserted)
        return inserted

    def delete(self, x):
        pass

    def find(self, x):
        node = self.root
        while node is not None:
            if x == node.key:
                return node
            elif x > node.key:
                node = node.right
            else:
                node = node.left
        return None

    def pre_order(self):
        keys = []
        self.do_pre_order(self.root, keys)
        print(' ' + ' '.join(map(str, keys)))

    def do_pre_order(self, node, keys):
        if node is None:
            return
        keys.append(node.key)
        self.do_pre_order(node.left, keys)
        self.do_pre_order(node.right, keys)

    def in_order(self):
        keys = []
        self.do_in_order(self.root, keys)
        print(' ' + ' '.join(map(str, keys)))

    def do_in_order(self, node, keys):
        if node is None:
            return
        self.do_in_order(node.left, keys)
        keys.append(node.key)
        self.do_in_order(node.right, keys)

# main
tree = BinaryTree()
lines = sys.stdin.readlines()

for line in lines[1:]:
    if len(line.rstrip()) == 0:
        continue

    command = line.rstrip().split(' ')

    if command[0] == 'insert':
        tree.insert(int(command[1]))
    elif command[0] == 'print':
        tree.in_order()
        tree.pre_order()
    elif command[0] == 'find':
        if (tree.find(int(command[1]))):
            print('yes')
        else:
            print('no')
    elif command[0] == 'delete':
        tree.remove(int(command[1]))
    else:
        raise 'unknown command: ' + command[0]

Measured memory_bytes: 232024
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
class Grid{
private:
  int h,w;
  vector<vector<int>> c;
  vector<int> dx={1,0,-1,1,-1,1,0,-1};
  vector<int> dy={1,1,1,0,0,-1,-1,-1};
public:
  //***************Constractor****************************
  Grid(int _h,int _w,vector<vector<int>> _c){
    w = _w;h = _h;c = _c;
  }

  //***********************************************
  
  void simple_dfs(int x,int y){
    c[x][y] = 0;
    rep(i,8){
      int nx = x + dx[i],ny = y + dy[i];
      if(nx>=0&&nx<h&&ny>=0&&ny<w) if(c[nx][ny]==1) simple_dfs(nx,ny);
    }
  }

  int run_dfs(){//check each node can reach goal
    int res=0;
    rep(x,h) rep(y,w){
      if(c[x][y]==1){
	res++ ;
	simple_dfs(x,y);
      }
    }
    return res;
  }

  void show(){
    rep(i,h){
      rep(j,w) cout << c[i][j] << " ";
      cout  << "\n";
    }
  }
  
};


int main()
{
  int w,h;
  vector<int> res;
  while(1){
    cin >> w >> h;
    if(w==0&&h==0) break;
    vector<vector<int>> c(h,vector<int>(w));
    rep(i,h) rep(j,w) cin >> c[i][j];
    Grid gr(h,w,c);
    res.push_back(gr.run_dfs());
  }
  rep(i,res.size()) cout << res[i] << "\n";
  return 0;
}



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

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

	ll n, a, b;
	cin >> n >> a >> b;

	ll c = a+b;
	ll r = n/c * a;
	n %= c;
	r += min(n, a);
	cout << r << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T = int > T in() {
  T x;
  cin >> x;
  return (x);
}
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  cout << max({A + B, A - B, A * B}) << "\n";
}

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

int main(){
  int a,b,c,d,e,k ; 
  cin >> a >> b >> c >> d >> e >> k ;
  
  if( e-a <= k ){
    cout << "Yay!" << endl ; 
  }
  else {
    cout << ":(" << endl ;     
  }
  
}

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

using namespace std;


int my_binary_search(vector<long long> & array, int left, int right, long long value){
    int med;
    while (left < right) {
        med = (left+right)/2;
        if (array[med] == value) return med;
        else if (array[med] > value) right = med;
        else left = med + 1;
    }
    return right;
}

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    const int inf = 1000000001;
    vector<long long> l(n, inf);
    l[0] = a[0];
    int length = 1;
    for(int i = 1; i < n; i++){
        //cout << "a[i]= " << a[i] << endl;
        //cout << "length= " << length << endl;
        if(l[length-1] < a[i]){
            l[length++] = a[i];
        }else{
            int j = my_binary_search(l, 0, length-1, a[i]);
            l[j] = a[i];
            //*lower_bound(l.begin(), l.end(), a[i]) = a[i];
        }
        //for(int k = 0; k < length; k++) cout << l[k] << " "; cout << endl;
        
    }
    cout << length << endl;
}

Measured memory_bytes: 4384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;

#define INF 1e+9
#define MAX_V 300

struct edge {
    int to;
    int cost;
};
using P = pair<ll, ll>;
int main(){
  string s;cin>>s;
  string l=s;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      l[i]='g';
    }else{
      l[i]='p';
    }
  }
  ll win=0;
  ll lose=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='g'&&l[i]=='p'){
      win++;
    }
    if(s[i]=='p'&&l[i]=='g'){
      lose++;
    }
  }
  cout<<win-lose<<endl;
}


Measured memory_bytes: 3344
#include <bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define sz(x) (x).size()
#define lowbit(x) (x)&(-x)
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
namespace FastIO {
#define BUF_SIZE 100000
#define OUT_SIZE 100000
	bool IOerror=0;
	inline char nc() {
		static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
		if(p1==pend) {
			p1=buf;
			pend=buf+fread(buf,1,BUF_SIZE,stdin);
			if(pend==p1) {
				IOerror=1;
				return -1;
			}
		}
		return *p1++;
	}
	inline bool blank(char ch) {
		return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
	}
	template<class T> inline bool read(T &x) {
		bool sign=0;
		char ch=nc();
		x=0;
		for(; blank(ch); ch=nc());
		if(IOerror)return false;
		if(ch=='-')sign=1,ch=nc();
		for(; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0';
		if(sign)x=-x;
		return true;
	}
	template<class T,class... U>bool read(T& h,U&... t) {
		return read(h)&&read(t...);
	}
#undef OUT_SIZE
#undef BUF_SIZE
};
using namespace std;
using namespace FastIO;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 0x3f3f3f3f;
const int N=1e6+10;

int cnt[N];

signed main() {
	
#ifdef xiaofan
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
#endif

	string s;
	int n,p,ans=0;
	cin>>n>>p>>s;
	if(p==2||p==5) {
		for(int i=0; i<n; i++)
			if((s[i]-'0')%p==0) ans+=i+1;
	} else {
		int t=1,sum=0;
		cnt[0]=1;
		for(int i=n-1; i>=0; i--) {
			sum=(sum+(s[i]-'0')*t)%p;
			ans+=cnt[sum];
			cnt[sum]++;
			t=t*10%p;
		}
	}
	cout<<ans<<endl;



	return 0;
}


Measured memory_bytes: 644
n=int(input())
v=list(map(int,input().split()))
v_odd={}
v_even={}
for i,x in enumerate(v):
  if i%2==1:
    if x in v_odd:#none [x] in v_??
      v_odd[x]+=1
    else:
      v_odd[x]=1
  else:
    if x in v_even:#none [x] in v_??
      v_even[x]+=1
    else:
      v_even[x]=1

v_odd_top = sorted(v_odd.items(), key=lambda x:x[1],reverse=True)[:2]
v_even_top = sorted(v_even.items(), key=lambda x:x[1],reverse=True)[:2]
 
if v_odd_top[0][0]!=v_even_top[0][0]:
  v_odd_ans=v_odd_top[0][1]
  v_even_ans=v_even_top[0][1]
else:
  if len(v_odd_top)>1 and len(v_even_top)>1:
    if v_odd_top[0][1]+v_even_top[1][1]>=v_odd_top[1][1]+v_even_top[0][1]:
      v_odd_ans=v_odd_top[0][1]
      v_even_ans=v_even_top[1][1]
    else:
      v_odd_ans=v_odd_top[1][1]
      v_even_ans=v_even_top[0][1]
  elif len(v_odd_top)==1 and len(v_even_top)>1:
    v_odd_ans=v_odd_top[0][1]
    v_even_ans=v_even_top[1][1]
  elif len(v_odd_top)>1 and len(v_even_top)==1:
    v_odd_ans=v_odd_top[1][1]
    v_even_ans=v_even_top[0][1]
  elif len(v_odd_top)==1 and len(v_even_top)==1:
    v_odd_ans=v_odd_top[0][1]
    v_even_ans=0
            
sum_freq = sum(v_odd.values())+sum(v_even.values())
ans = sum_freq - ( v_odd_ans + v_even_ans )
print(ans)

Measured memory_bytes: 19168
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int collatz(int a){
	if(a%2==0) return a/2;
	else return 3*a+1;
}
int main(){
  
  int s;
  cin >> s;
  int count = 1;
  while(s!=1 && s!=4 && s!= 2){
  	s = collatz(s);
  	count++;
  }
  cout << count + 3 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, k, Q;
llint x[200005];
llint pred[19][200005], succ[19][200005];
llint pred2[19][200005], succ2[19][200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> x[i];
	x[0] = -inf, x[n+1] = inf;
	
	for(int i = 1; i <= n; i++){
		llint p = lower_bound(x, x+n+2, x[i]+k) - x;
		succ[0][i] = p;
		p = upper_bound(x, x+n+2, x[i]-k) - x - 1;
		pred[0][i] = p;
	}
	succ[0][n+1] = n+1;
	
	for(int i = 1; i < 19; i++){
		for(int j = 1; j <= n+1; j++){
			pred[i][j] = pred[i-1][pred[i-1][j]];
			succ[i][j] = succ[i-1][succ[i-1][j]];
		}
	}
	
	for(int i = 1; i <= n; i++){
		succ2[0][i] = succ[0][i]-1;
		pred2[0][i] = pred[0][i];
	}
	for(int i = 1; i < 19; i++){
		for(int j = 1; j <= n; j++){
			pred2[i][j] = pred2[i-1][j] + pred2[i-1][pred[i-1][j]];
			succ2[i][j] = succ2[i-1][j] + succ2[i-1][succ[i-1][j]];
		}
	}
	
	/*for(int i = 1; i <= n; i++) cout << succ[0][i] << " "; cout << endl;
	for(int i = 1; i <= n; i++) cout << pred[0][i] << " "; cout << endl;
	
	for(int i = 1; i <= n; i++) cout << succ2[0][i] << " "; cout << endl;
	for(int i = 1; i <= n; i++) cout << pred2[0][i] << " "; cout << endl;*/
	
	cin >> Q;
	llint L, R;
	for(int q = 1; q <= Q; q++){
		cin >> L >> R;
		
		llint ans = R-L+1, v = L;
		for(int i = 18; i >= 0; i--){
			//cout << succ[i][v] << " " << R << endl;
			if(succ[i][v] <= R){
				ans -= succ2[i][v];
				v = succ[i][v];
			}
			///cout << v << " " << ans << endl;
		}
		v = R;
		for(int i = 18; i >= 0; i--){
			if(pred[i][v] >= L){
				ans += pred2[i][v];
				v = pred[i][v];
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

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

const int64_t MOD = 1000000007;
int64_t c[2002][2002];

void init(){
  c[0][0] = 1;
  for (int i=0; i<2001;++i ) {
    for (int j=0; j<2001;++j ) {
      c[i+1][j] = (c[i+1][j] + c[i][j]) % MOD;
      c[i+1][j+1] += (c[i+1][j+1] + c[i][j]) % MOD;
    }
  }
}

int64_t f2(int n, int k){
//  cout << "f2: " << n << " " << k << endl;
  return c[n][k];
}
int64_t f(int n, int k){
  return f2(n-k, k);
}

int main() {
  int N,K;
  cin >> N >> K;
  init();
 
  for (int i=1;i<=K;++i ) {
    /*
    // 青の場合の数
    int64_t b;
    b = f(K+i-1, i) % MOD;
    // 赤の場合の数
    int64_t r;
    r  = f(N-K+i-1, i-1) % MOD;
    r += f(N-K+i-1, i) % MOD;
    r += f(N-K+i-1, i) % MOD;
    r += f(N-K+i-1, i+1) % MOD;
    cout << b * r % MOD << endl;
*/
    int64_t b;
    b = (f2(N-K+1, i) % MOD) * (f2(K-1, i-1) % MOD) % MOD;
    cout << b << endl;
  }
}


Measured memory_bytes: 31488
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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


	int a, b;
	cin >> a >> b;

	if ((b - a) % 2) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << (a + b) / 2 << endl;
	}




	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int r_count,l_count;
string s;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		r_count++;
		if(s[i+1]=='L'){
			i++;
			while(i<s.size()&&s[i]=='L')l_count++,i++;
			//cout<<endl<<"test"<<l_count<<" "<<r_count<<endl;
			cout<<r_count-r_count/2+l_count/2<<" "<<r_count/2+l_count-l_count/2;
			l_count-=1;
			while(l_count--)cout<<" "<<0;

			if(i==s.size())return 0;
			else {
				r_count=0,l_count=0,i--;
				cout<<" ";
			}
		}
		else cout<<0<<" ";
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
const double EPS = 1e-10;
typedef complex<double> P;
typedef pair<P,P> L;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
  }
}
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
P crosspoint(const L &l, const L &m) {
  double A = cross(l.S - l.F, m.S - m.F);
  double B = cross(l.S - l.F, l.S - m.F);
  if (fabs(A) < EPS && fabs(B) < EPS) return m.F;
  return m.F + B / A * (m.S - m.F);
}
double area(vector<P> p) {
  double a=0;
  for(int i=0; i<(int)p.size(); i++) a+=cross(p[i],p[(i+1)%p.size()]);
  return fabs(a)/2;
}
int main() {
  int n;
  while(cin >> n && n) {
    L a[n+2],b[n+2];
    double c[n+2],d[n+2];
    for(int i=1; i<=n; i++) cin >> c[i];
    for(int i=1; i<=n; i++) cin >> d[i];
    c[0]=d[0]=0;
    c[n+1]=d[n+1]=1;
    for(int i=0; i<n+2; i++) a[i]=L(P(c[i],0),P(d[i],1));
    for(int i=1; i<=n; i++) cin >> c[i];
    for(int i=1; i<=n; i++) cin >> d[i];
    c[0]=d[0]=0;
    c[n+1]=d[n+1]=1;
    for(int i=0; i<n+2; i++) b[i]=L(P(0,c[i]),P(1,d[i]));
    P p[n+2][n+2];
    for(int i=0; i<n+2; i++) {
      for(int j=0; j<n+2; j++) p[i][j]=crosspoint(b[i],a[j]);
      sort(p[i],p[i]+n+2);
    }
    double ans=0;
    for(int i=0; i<n+1; i++) {
      for(int j=0; j<n+1; j++) {
        vector<P> v;
        v.push_back(p[i][j]);
        v.push_back(p[i][j+1]);
        v.push_back(p[i+1][j+1]);
        v.push_back(p[i+1][j]);
        ans=max(ans,area(v));
      }
    }
    printf("%.10f\n",ans);
  }
  return 0;
}


Measured memory_bytes: 3168
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

double round(double);

int main()
{
	double a, b, c, d, e, f;
	double x, y;
	
	while(scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) != EOF){

		x = (c*e - b*f)/(a*e - b*d);
		y = (a*f - c*d)/(a*e - b*d);

		x = x * 1000;
		y = y * 1000;

		round(x);
		round(y);

		x = x / 1000;
		y = y / 1000;

		if(fabs(x) < 1e-6)
			x = 0;
		if(fabs(y) < 1e-6)
			y = 0;

		printf("%5.3f %5.3f\n", x, y);
	}
	return 0;
}

double round(double x)
{
	if(x > 0.0){
		return floor(x + 0.5);
	}else{
		return -1.0 * floor(fabs(x) + 0.5);
	}
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
#define MN 200005
#define LL long long
#define mp make_pair
#define fir first
#define sec second
#define pii pair<int,int>
inline void chkmax(int &a,int b){if(a<b)a=b;}
inline void chkmin(int &a,int b){if(a>b)a=b;}
inline int read(){
	   int a=0,fh=1;char c=getchar();
	   while(c>'9'||c<'0'){if(c=='-')fh=-1;c=getchar();}
	   while('0'<=c&&c<='9'){
		   a=a*10+c-48;
		   c=getchar();
	   }
	   return a*fh;
}
char ch[MN];
int main(){
	int n=read();
	scanf("%s",ch+1);
	LL ans=0,cnt=0;
	for(int i=1;i<=n;++i)if(ch[i]=='B')cnt++; 
	for(int i=1;i<=n;++i){
		for(int j=i+1;j<=n;++j){
			if((ch[i]=='R'&&ch[j]=='G')||(ch[i]=='G'&&ch[j]=='R')){
				ans+=cnt;
			//	cerr<<"OK "<<endl;
	//			continue;
				int p=j-i;
				if(i-p>0&&ch[i-p]=='B')ans--;
				if(j+p<=n&&ch[j+p]=='B')ans--;
				if(j%2==i%2&&ch[(i+j)/2]=='B')ans--;
			}
		}
	}
	printf("%lld",ans);
	return 0;
}

















Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int a, b;

signed main() {
	cin >> a >> b;
	if (b%a == 0)cout << a + b << endl;
	else cout << b - a << endl;
	ggr
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>

using namespace std;

int main(){
    int  n;
    cin>>n;
    vector<bool>s(13,0);
    vector<bool>h(13,0);
    vector<bool>c(13,0);
    vector<bool>d(13,0);
    char q;
    int x;
    for(int i=0;i<n;i++){
    cin>>q>>x;
    if(q=='S')s.at(x-1)=1;
    else if(q=='H')h.at(x-1)=1;
    else if(q=='C')c.at(x-1)=1;
    else d.at(x-1)=1;
    }
    for(int j=0;j<13;j++)if(s.at(j)==0)cout<<"S "<<j+1<<endl;
     for(int j=0;j<13;j++)if(h.at(j)==0)cout<<"H "<<j+1<<endl;
      for(int j=0;j<13;j++)if(c.at(j)==0)cout<<"C "<<j+1<<endl;
       for(int j=0;j<13;j++)if(d.at(j)==0)cout<<"D "<<j+1<<endl;
       
}


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

int main()
{
	int n, a, b, a1, b1;
	cin >> n >> a >> b;
	a1=a*n;
	b1=b;
	if (a1>=b1)
		cout << b1 << endl;
	else
		cout << a1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef unsigned long long int ll;
#define fastio ios_base::sync_with_stdio(false);
#define rep(i,start,end) for(int i=start;i<end;i++)
using namespace std;


//debugger template
#define error(args...) { string _s = #args; replace(_s.begin() , _s.end() , ',',' ') ; stringstream _ss(_s) ; istream_iterator<string> _it(_ss) ; err(_it , args) ; }

void err(istream_iterator<string> it) {}
template<typename T , typename... Args>
void err(istream_iterator<string> it , T a , Args... args){
	cerr << *it << " = " << a << endl;
	err(++it , args...);
}

void show(int *arr , int size){
	rep(i,0,size){
		cout << arr[i] << " ";
	}
	cout << endl;
}

int main(){
	fastio
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	bool flag=0;
	switch(a){
		case 1:
			if(b == 31){
				flag=1;
			}break;

		case 2:
		if(b == 28){
				flag=1;flag=1;
			}break;
		case 3:
		if(b == 31){
				flag=1;
			}break;
		case 4:
			if(b == 30){
				flag=1;
			}break;
		case 5:
			if(b == 31){
				flag=1;
			}break;
		case 6:
		if(b == 30){
				flag=1;
			}break;
		case 7:
			if(b == 31){
				flag=1;
			}break;
		case 8:
				if(b == 31){
				flag=1;
			}break;
		case 9:
			if(b == 30){
				flag=1;
			}break;
		case 10:
			if(b == 31){
				flag=1;
			}break;
		case 11:
			if(b == 30){
				flag=1;
			}break;
		case 12:
			if(b == 31){
				flag=1;
			}break;
	}
	if(flag)cout << 1 << endl;
	else{
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=100010;
char s[N];
int k,t[N],a,b;
int main(){
	scanf("%s%d",s+1,&k);
	int n=strlen(s+1);
	bool all=1;
	for(int i=1;i<=n;i++)if(s[i]!=s[1])all=0;
	if(all){
		LL ans=(LL)n*k/2;
		cout<<ans<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(s[i]!=s[1]){
			a=i-1;break;
		}
	}
	for(int i=n;i>=1;i--){
		if(s[i]!=s[n]){
			b=n-i;break;
		}
	}
	int tot=0;
	
	for(int i=a+1;i<=n-b;i++){
		if(s[i]!=s[i-1]){
			t[i]=1;
		}
		else{
			t[i]=t[i-1]+1;
			if(t[i]%2==0)tot++;
		}
	}
	LL ans=0;
	if(s[1]==s[n]){
		ans=(LL)tot*k+a/2+b/2+(LL)(a+b)/2*(k-1);
	}
	else{
		ans=(LL)tot*k+(LL)a/2*k+(LL)b/2*k;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);

    int n, k;
    cin >> n >> k;
    int m = (n - 2) * (n - 1) / 2;
    if(m<k){
        cout << -1 << endl;
        return 0;
    }
    k = m - k;
    int ans = n - 1 + k;
    cout << ans << endl;
    for (int i = 2; i <= n;i++){
        cout << 1 << " " << i << endl;
    }
    int cnt = 0;
    for (int i = 2; i <= n;i++){
        for (int j = i + 1; j <= n;j++){
            if(cnt<k){
                cnt++;
                cout << i << " " << j << endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
	//------------入力------------
	//要素数N,Mを定義
	int N, M;
	//N,Mの入力
	cin >> N >> M;

	//座標a,b,c,dを宣言
	int* a = new int[N];
	int* b = new int[N];
	int* c = new int[M];
	int* d = new int[M];
	//カウンタi,jを定義
	int i = 0, j = 0;

	//a,bの入力
	for (i = 0; i < N; i++) cin >> a[i] >> b[i];
	//c,dの入力
	for (j = 0; j < M; j++) cin >> c[j] >> d[j];

	//------------出力------------
	//X,Y,Z,MIN,NUMを定義
	int* X = new int[M] {};
	int* Y = new int[M] {};
	int* Z = new int[M] {};
	int* MIN = new int[N] {};
	int* NUM = new int[N] {};
	//導出
	for (i = 0; i < N; i++) {
		for (j = 0; j < M; j++) {
			//マンハッタン距離を求める
			X[j] = abs(a[i] - c[j]);
			Y[j] = abs(b[i] - d[j]);
			Z[j] = X[j] + Y[j];
			//最も近いチェックポイントを求める
			if (j == 0) {
				MIN[i] = Z[0];
				NUM[i] = 0;
			}
			else if ((Z[j] < Z[j - 1]) && (Z[j] < MIN[i])) {
				MIN[i] = Z[j];
				NUM[i] = j;
			}
		}
		//最も近いチェックポイントを出力
		cout << NUM[i] + 1 << endl;
	}
	return 0;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;

int d[5];

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

	ll n,m;cin>>n>>m;

	ll ans =n*m-2*(n+m-2);

	writeln(abs(ans));



}


Measured memory_bytes: 256
//ACL Beginners Contest C

#include<iostream>
#include<vector>
using namespace std;

class UnionFind {
private:
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
public:
    UnionFind(int n = 1) {
        init(n);
    }

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

    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 (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    int res=n-1;
    for(int i=0;i<m;++i){
        int a,b;
        cin>>a>>b;
        --a,--b;
        if(uf.merge(a,b)) --res;
    }

    cout<<res<<endl;
}

Measured memory_bytes: 4032
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fi first
#define se second
#define PI acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int, int>
#define lowbit(x) x & (-x)
using namespace std;
const int maxx = 1e6 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int n, m, T;


int main(){
	int i, j, k;
	string s;
	cin >> s; int flag = 0;
	for(i = 0; i < s.size(); i++){
		if( (i & 1) == 0 && s[i] == 'L'){ flag = 1; break; }
		else if(i & 1 && s[i] == 'R'){ flag = 1; break; }
	}
	if(flag) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 256
//問題URL
//

//解き方メモ
//
    
#include<iostream>
using namespace std;

int main(){
  int n;
  int a;
  int all_or;
  int cnt;

  cin >> n;

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

  cnt = 0;
  while((all_or&1) != 1){
    all_or = all_or >> 1;
    cnt++;
  }

  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
struct SegmentTree {
  int n;
  vi node;
  SegmentTree(int sz) {
    int n_ = 1;
    while(n_ < sz) {
      n_ *= 2;
    }
    n = n_;
    node.resize(2*n, 0);
  }
  void build(vi v) {
    for(int i=0;i<((int)(v.size()));++i) {
      node[i+n-1] = v[i];
    }
    for(int i=n-2;i>=0;--i) {
      node[i] = node[2*i+1] + node[2*i+2];
    }
  }
  void update(int idx, int val) {
    idx += n-1;
    node[idx] += val;
    if(idx == 0) return;
    idx = (idx - 1) / 2;
    while(1) {
      node[idx] = node[2*idx+1] + node[2*idx+2];
      if(idx == 0) break;
      idx = (idx-1)/2;
    }
  }
  int query(int a, int b) {
    return query(a, b, 0, n, 0);
  }
private:
  int query(int a, int b, int l, int r, int k) {
    if(a <= l && r <= b) return node[k];
    if(r <= a || b <= l) return 0;
    int v1 = query(a, b, l, (l+r)/2, 2*k+1);
    int v2 = query(a, b, (l+r)/2, r, 2*k+2);
    return v1 + v2;
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, q; cin >> n >> q;
  SegmentTree st(n);
  for(int i=0;i<(q);++i) {
    int c, x, y; cin >> c >> x >> y;
    x--;
    if(c == 0) {
      st.update(x, y);
    } else {
      cout << st.query(x, y) << endl;
    }
  }
}



Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr,0,sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int a, b;
        cin >> a >> b;
        if(a == 1|| b == 1){
            cout << 1 << '\n';
            continue;
        }
        int ans = (a * b + 1LL) / 2LL;
        cout << ans << '\n';
    } 
}

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

int main()
{
	string s;
	cin >> s;
	stack<int> s1;
	stack<pair<int, int> > s2;
	int sum = 0;
	for (int i = 0; i < s.length(); ++i)
	{
		if (s[i] == '\\')s1.push(i);
		else if (s[i] == '/' && s1.size() > 0){
			int j = s1.top();
			s1.pop();
			sum += i - j;
			int a = i - j;
			while (s2.size() > 0 && s2.top().first > j){
				a += s2.top().second;
				s2.pop();
			}
			s2.push(make_pair(j, a));
		}
	}

	vector<int> ans;
	while (s2.size() > 0){
		ans.push_back(s2.top().second);
		s2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); ++i)
	{
		putchar(' ');
		cout << ans[i];
	}
	putchar('\n');
	return 0;
}


Measured memory_bytes: 3284
import sys
sys.setrecursionlimit(10 ** 7)
class Tree:
  C, RL = {}, {}
  R, N, D, S, P, T = None, None, None, None, None, None
  TL = None
  def __init__(s, num):
    s.N = num
  def set(s, a, b):
    if a in s.C: s.C[a].append(b)
    else: s.C[a] = [b]
    if b in s.C: s.C[b].append(a)
    else: s.C[b] = [a]
  def makeRank(s, root):
    s.R = [0] * s.N #各ノードのランク
    s.R[root] = 1
    s.RL[1] = [root] #各ランクのノード
    s.S = {} #各ノードの子ノード
    s.P = [-1] * s.N #各ノードの親ノード
    s.D = 1
    while s.RL[s.D] != []:
      s.D += 1
      s.RL[s.D] = []
      for i in s.RL[s.D - 1]:
        for j in s.C[i]:
          if s.R[j] == 0:
            s.R[j] = s.D
            s.RL[s.D].append(j)
            if i not in s.S: s.S[i] = [j]
            else: s.S[i].append(j)
            s.P[j] = i      
  def bottomUpDP(s):
    for i in range(s.D - 2, 0, -1):
      T = s.RL[i]
      for j in T:
        if j not in s.S: continue
        for k in s.S[j]:
          s.dp_sub_exe(j, k)
  def topDownDP(s):
    for i in range(2, s.D):
      T = s.RL[i]
      for j in T:
        s.dp_sub_exe_inv(j, s.P[j])
  def allDP(s):
    s.dp_init()
    s.bottomUpDP()
    s.topDownDP()
    return s.DP
  def dp_init(s): #単位元で初期化
    s.DP = [1] * N
    s.sDP = [1] * N
  def dp_sub_exe(s, x, y): #ボトムアップの処理
    s.sDP[x] += s.sDP[y]
    s.DP[x] = s.DP[x] * s.DP[y] * com.com(s.sDP[x] - 1, s.sDP[y]) % MOD
  def dp_sub_exe_inv(s, x, y): #トップダウンの処理
    t = com.com(s.sDP[y] - 1, s.sDP[x]) * s.DP[x] % MOD
    t = s.DP[y] * s.inv(t, MOD)
    k = s.sDP[y] - s.sDP[x]
    k = com.com(s.sDP[y] - 1, k) % MOD
    s.sDP[x] = s.sDP[y]
    s.DP[x] = s.DP[x] * t * k % MOD
  def inv(s, a, mod): #逆元
    return pow(a, mod - 2, mod)
  
class comb():
  F = [1, 1]
  Fi = [1, 1]
  I = [0, 1]
  def __init__(self, num, mod):
    self.MOD = mod
    for i in range(2, num + 1):
      self.F.append((self.F[-1] * i) % mod)
      self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
      self.Fi.append(self.Fi[-1] * self.I[i] % mod)
  def com(self, n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]

MOD = 10 ** 9 + 7
com = comb(N, MOD)

T = Tree(N)
for a, b in ab:
  a -= 1
  b -= 1
  T.set(a, b)

T.makeRank(0)
DP = T.allDP()

for i in DP:
  print(i)

Measured memory_bytes: 151132
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,r;
  cin >> h >> r;
  if(h == -r) {cout << 0 << endl;
  } else if(h<0 && r>h){ cout << -1 << endl;
  } else {cout << 1 << endl;}

  return 0;
}



Measured memory_bytes: 3100