akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll h, w, d;
    cin >> h >> w >> d;
    ll s = h*w+1;

    vl px(s), py(s);
    rep(i, h) {
        rep(j, w) {
            ll a;
            cin >> a;
            px[a] = i, py[a] = j;
        }
    }

    vl dist(s);
    rep(i, s) {
        if(i > d) {
            dist[i] = dist[i-d] + abs(px[i] - px[i-d]) + abs(py[i] - py[i-d]);
        }
    }

    ll q;
    cin >> q;
    rep(i, q) {
        ll L, R;
        cin >> L >> R;
        out(dist[R] - dist[L]);
    }

    re0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;


typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

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

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}



////////////////////////////////////////////////////////////////////
int main(){
ll n;
cin>>n;
ll a[n+1];
rep(i,n){
cin>>a[i];
}

int x,y,z;
y=-1;
z=-1;
rep(i,n){
	if(i==1){x=a[i]; continue;}
	if(a[i]!=x && y==-1){y=a[i]; continue;}
	if(a[i]!=x && a[i]!=y && z==-1){z=a[i];
	continue;}
if(a[i]!=x && a[i]!=y && a[i]!=z){
	cout<<"No"<<endl;
	return 0;
}
}

if(y==-1){if(x==0){cout<<"Yes"<<endl;}
else cout<<"No"<<endl;
return 0;}
if(n%3!=0){cout<<"No"<<endl;
	return 0;}

int xv=0;
int yv=0;
int zv=0;
rep(i,n){
	if(a[i]==x)xv++;
	if(a[i]==y)yv++;
	if(a[i]==z)zv++;
}

if(z==-1){
	if((x==0 && yv==xv*2)||(y==0 && xv==yv*2)){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}



if(!((x^y)==z && (y^z)==x && (z^x)==y)){
	cout<<"No"<<endl;
	return 0;
}
if(xv!=yv || yv!=zv){
	cout<<"No"<<endl;
	return 0;
}

cout<<"Yes"<<endl;
return 0;

}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    map<string, int> ret;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        ret[s]++;
    }
    cout << "AC x " << ret["AC"] << "\n";
    cout << "WA x " << ret["WA"] << "\n";
    cout << "TLE x " << ret["TLE"] << "\n";
    cout << "RE x " << ret["RE"] << "\n";
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <limits>

using namespace std;

int main() {
	long a,b;
	cin >>a>>b;
	int c = a / b;
	int d = a % b;
	cout<< fixed <<setprecision(10) << c << " " << d << " " <<(double)c+((double)d / (double)b)<<"\n";
	return 0;
}



Measured memory_bytes: 3280
import sys
from heapq import heappush, heappop

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    heap = []
    ans = 0
    for a in map(int, input().split()):
        heappush(heap, a)

    BC = []
    for _ in range(M):
        B, C = map(int, input().split())
        BC.append((B, C))

    BC = sorted(BC, key=lambda x: -x[1])
    for B, C in BC:
        for _ in range(B):
            a = heappop(heap)
            if a < C:
                heappush(heap, C)
            else:
                heappush(heap, a)
                break

    return sum(heap)


if __name__ == '__main__':
    print(main())



Measured memory_bytes: 26260
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
using namespace std;
using ll=long long;
//using R=double;

const int INF = 10000000;
typedef pair<int, int> p;

ll div2(ll a){
	ll count = 0;
	while(a%2==0){
		count++;
		a = a/2;
	}
	return count;
}

int main(){
	int N;
	cin >> N;
	ll a[N];
	ll result = 0;
	for(int i = 0; i < N; i++){
		cin >> a[i];
		result += div2(a[i]);
	}

	cout << result << endl;
	return 0;

}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10 ** 7)


from collections import deque
def bfs():
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    while len(Q) > 0:
        q = Q.popleft()
        y,x =  q[0], q[1]
        if S[y][x] == "#": return
        for i in range(4):
            ny = y+dy[i]
            nx = x+dx[i]
            if ny >= 0 and ny < H and nx >= 0 and nx < W and S[ny][nx] == "#" and box[ny][nx] == -1000:
                box[ny][nx] = -1
            if ny >= 0 and ny < H and nx >= 0 and nx < W and S[ny][nx] == "." and box[ny][nx] == -1000:
                box[ny][nx] = box[y][x] + 1
                Q.append([ny,nx])
    for i in range(H):
        if len(box[i]) == 0:
            continue
        else:
            ans.append(max(box[i]))
    return


H, W = map(int,input().split())
S = [ [] for _ in range(H)]
for i in range(H):S[i] = list(input())
ans = []
Q = deque()
for i in range(H):
    for j in range(W):
        #各マス目に到達するために必要な移動回数
        box = [[-1000 for _ in range(W)] for __ in range(H)]
        Q.append([i,j])
        box[i][j] = 0
        bfs()
if len(ans)==0:
    print(0)
    exit()
print(max(ans))


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

int main(int argc, const char * argv[]) {
    int R;
    
    cin >> R;
    
    if (R < 1200) {
        cout << "ABC" << endl;
    } else if (R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    
    return 0;
}

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

int H, W;
bool A[500][500];

int main() {
  cin >> H >> W;
  for(int x = 0; x < H; ++x) for(int y = 0; y < W; ++y) {
    char a; cin >> a; A[x][y] = a == '#';
  }
  for(int x = 0; x < H; ++x) { for(int y = 0; y < W; ++y) {
    cout << (A[x][y] || x == 0 || (x != H - 1 && y % 2 == 0) ? '#' : '.');
  } cout << endl; }
  cout << endl;
  for(int x = 0; x < H; ++x) { for(int y = 0; y < W; ++y) {
    cout << (A[x][y] || x == H - 1 || (x != 0 && y % 2 == 1) ? '#' : '.');
  } cout << endl; }
  return 0;
}


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

int main(){

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	ios::sync_with_stdio(false),cin.tie(0);

	int a,b,c;
	cin >> a >> b >> c;
	int k; cin >> k;

	while(k>0 && a>=b){
		b *= 2;
		k--;
	}
	while(k>0 && b>=c){
		c *= 2;
		k--;
	}
	if(a<b && b<c){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>
#include <cstdlib>
// #include <fstream>

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

const long long mod = 1e9 + 7;
const int INF32 = INT32_MAX;

int main()
{
    int n, m; std::cin >> n >> m;
    std::cout << n*(n-1)/2 + m*(m-1)/2 << std::endl;
    return 0;
}


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

namespace AtCoderMake.ABC164
{
    class ABC164B
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split().Select((x) => int.Parse(x)).ToArray();
            int a = s[0];
            int b = s[1];
            int c = s[2];
            int d = s[3];
            while (a > 0)
            {
                c = c - b;
                if (c <= 0)
                {
                    Console.WriteLine("Yes");
                    break;
                }
                a = a - d;
                if (a <= 0)
                {
                    Console.WriteLine("No");
                    break;
                }
            }

        }
    }
}


Measured memory_bytes: 28292
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int toInt(string number){
	stringstream ss;
	ss << number;
	int x;
	ss >> x;
	return x;
}

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);
	      	  
	      	  string N;
	      	  cin >> N;
	      	  
	      	  int n=N.size();
	      	  int m=0;
	      	  for(i=0;i<n;i++){
	      		  m+=N[i]-'0';
	      	  }
	      	  
	      	  int x=toInt(N);
	      	  if(x%m==0) cout << "Yes" << endl;
	      	  else cout << "No" << endl;
	      	  
	          return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
   
struct node
{
   
  int key;
  struct node *left;
  struct node *right;
  struct node *parent;
};
   
typedef struct node* Node;
Node root;
   
Node treeSearch(Node x,int k)
{
  if(x == NIL || k == x-> key)
    return x;
  if(k < x->key)
    return treeSearch(x->left,k);
  else return treeSearch(x->right,k );
}
   
void insert(int k)
{
     
  Node y = NIL;
  Node x = root;
  Node z;
     
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
      
 while(x != NIL)
   {
     y = x;
     if(z->key < x->key)
       x = x->left;
      
     else x = x->right;
   }
 z->parent = y;
  
 if(y == NIL)
   root = z;
  
 else if(z->key < y->key)
   y->left = z;
  
 else
   y->right = z;
  
}
 
void inorder(Node u)
{
   
  if(u->left != NIL)
    inorder(u->left);
  printf(" %d",u->key);
  if(u->right != NIL)
    inorder(u->right);
}
   
void preorder(Node u)
{
  printf(" %d",u->key);
  if(u->left != NIL)
    preorder(u->left);
  if(u->right != NIL)
    preorder(u->right);
}
   
int main(void)
{
     
  int i,n,x;
  char c[5];
     
  scanf("%d",&n);
     
  for(i=0;i<n;i++)
    {
      scanf("%s",c);
      if(c[0] == 'f')
    {
      scanf("%d",&x);
      if(treeSearch(root,x) != NIL)
        printf("yes\n");
      else printf("no\n");
    }
      else if(c[0] == 'i')
    {
      scanf("%d",&x);
      insert(x);
    }
      else if(c[0] == 'p')
    {
      if(root != NIL)
        inorder(root);
      printf("\n");
      if(root != NIL)
        preorder(root);
      printf("\n");
       
    }
    }
  return 0;
}

Measured memory_bytes: 19364
n = int(input())
a, b = map(int, input().split())
p = map(int, input().split())
c = [0] * 3
for i in p:
    if i <= a:
        c[0] += 1
    elif i <= b:
        c[1] += 1
    else:
        c[2] += 1
print(min(c))


Measured memory_bytes: 2940
N = int(input())

l = [[0]*10 for i in range(10)]
for i in range(1, N+1):
  x = int(str(i)[0])
  y = int(str(i)[-1])
  l[x][y] += 1
  
ans = 0
for i in range(1, 10):
  for j in range(i, 10):
    if i == j:
      ans += l[i][j] * l[j][i]
    else:
      ans += 2 * l[i][j] * l[j][i]
print(ans)

Measured memory_bytes: 73792
import copy
import sys
import math

def main():
	n = int(input())
	a = list(map(int,input().split()))
	b = [0]
	for i in range(1,n+1):
		b.append(b[i-1] + a[i-1])
	c = listtodict(b)
	ans = 0
	for v in c.values():
		ans += v*(v-1)
	print(ans>>1)

def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Measured memory_bytes: 112072
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
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 kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n;
vector<int>v(105);
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> v[i];
	}
	vector<int>ans;
	rep(i, n) {
		for (int j = v.size() - 1; j >= 0; j--) {
			if (v[j] == j + 1) {
				ans.push_back(v[j]);
				v.erase(v.begin() + j);
				goto ok;
			}
		}
		cout << -1 << endl; return 0;
	ok:;
	}
	reverse(all(ans));
	for (int a : ans)cout << a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;
 
int table[100010][18];
int N, L, Q;
int x[100010];
 
signed main() {
    cin >> N;
    rep(i,0,N) cin >> x[i];
    cin >> L >> Q;
 
    rep(i,0,N) {
        int idx = upper_bound(x, x+N, x[i] + L) - x - 1;
        if(idx <= i) table[i][0] = -1;
        else table[i][0] = idx;
    }
 
    rep(k,0,17) {
        rep(i,0,N) {
            if(table[i][k] < 0) table[i][k+1] = -1;
            else table[i][k+1] = table[table[i][k]][k];
        }
    }
 
    rep(i,0,Q) {
        int a, b; cin >> a >> b; a--; b--;
        if(a > b) swap(a, b);
 
        int cur = a, ans = 0;
        rep(i,0,20) {
            repr(k,17,0) {
                int to = table[cur][k];
                if(to < 0 || to >= b) continue;
                cur = to;
                ans += (1 << k);
                break;
            }
        }
        cout << ans + 1 << endl;
    }
    return 0;
}

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

int N, D;

bool is_integer(double distance) {
    return floor(distance) == distance;
}

int count_int_Distance(vector<vector<int>> &X) {
    int count = 0;
    for (int i = 0; i < N; i++) {
        for (int k = i + 1; k < N; k++) {
            double distance = 0;
            for (int j = 0; j < D; j++) {
                distance += pow(abs(X[i][j] - X[k][j]), 2);
            }
            distance = sqrt(distance);
            if (is_integer(distance)) {
                count++;
            }
        }
    }

    return count;
}

int main() {
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    int ans = count_int_Distance(X);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static final Scanner sc = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;

    public static void main(String[] args) {
        char[] input = nstr().toCharArray();
        int len = input.length;

        char[] s = new char[len+1];
        System.arraycopy(input, 0, s, 1, input.length);
        
        final int MOD_2 = 13;
        long[][] dp = new long[len+1][MOD_2];
        
        dp[0][0] = 1;
        for (int i = 1; i <= len; i++) {
            for (int rem = 0; rem < MOD_2; rem++) {
                if (s[i] == '?') {
                    for (int digI = 0; digI <= 9; digI++) {
                        int newRem = (rem*10 + digI) % MOD_2;
                        dp[i][newRem] += dp[i-1][rem];
                        dp[i][newRem] %= MOD;
                    }
                } else {
                    // i文字目が確定している場合
                    int newRem = (rem*10 + (s[i]-'0')) % MOD_2;
                    dp[i][newRem] += dp[i-1][rem];
                    dp[i][newRem] %= MOD;
                }
            }
        }
        System.out.println(dp[len][5]);
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }
    
    private static String nstr() {
        return sc.next();
    }
}

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

#define int long long
#define pii pair<int,int>
#define pqi priority_queue<int>
#define pb push_back()
#define INF 1000000000000000000

#define pi acos(-1)

const int modu= (1e9)+7;

void testCase(int ti){
    cout<<"Case "<<ti<<": ";
}

int bigmod(int n,int p){
    if(p==0) return 1;
    int x=bigmod(n,p/2)%modu;
    x=(x*x)%modu;
    if(p%2) return (x*n)%modu;
    return x;
}

int modInverse(int a){
    return bigmod(a,modu-2)%modu;
}

void debug(string pr,vector<int> var,bool out=true){
    #ifdef OFFLINE
        ofstream fl;
        fl.open("debug.txt");
        fl<<pr;
        for(int i=0;i<var.size();i++) fl<<" "<<var[i];
        fl<<endl;
        fl.close();
    if(out){
        cout<<pr;
        for(int i=0;i<var.size();i++) cout<<" "<<var[i];
        cout<<endl;
    }
    #endif
}

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
}

void defInit(){
    //faster();
    #ifdef OFFLINE
      freopen("in.txt", "r", stdin);
      freopen("out.txt", "w", stdout);
    #endif
}

int add(int x,int y){
    int z =(x%modu + y%modu)%modu;
    while(z<0) z=(z+modu)%modu;
    return z;
}

int mul(int x,int y){
    int z = (x%modu * y%modu)%modu;
    while(z<0) z=(z+modu)%modu;
    return z;
}
// starts here

int32_t main(){
    defInit();
    //Now I will start writing codes and start preparation to get errors
    int h,w;
    cin>>h>>w;
    char ara[h][w];
    int ans[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>ara[i][j];
            ans[i][j]=0;
        }
    }
    ans[0][0]=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i==0 && j==0) continue;
            if(ara[i][j]=='#') continue;
            int now=0;
            if(i>0) now=add(now,ans[i-1][j]);
            if(j>0) now=add(now,ans[i][j-1]);
            ans[i][j]=now;
        }
    }
    cout<<ans[h-1][w-1];
    return 0;
}


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

int a[200001],b[200001];

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i];
	
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	
	long long ans;
	if(n%2==0)
		ans=b[n/2]+b[(n/2)+1]-a[n/2]-a[(n/2)+1]+1;
	else
		ans=b[(n+1)/2]-a[(n+1)/2]+1;
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5188
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll N;
    cin >> N;
    map<ll,ll> A_;
    ll sum = 0;
    rep(i,N) {
        ll a;
        cin >> a;
        A_[a]++;
        sum+=a;
    }
    ll Q;
    cin >> Q;
    vll B(Q),C(Q);
    rep(q,Q) cin >> B[q] >> C[q];
    
    rep(q,Q){
        sum += (C[q] - B[q]) * A_[B[q]];
        A_[C[q]] += A_[B[q]];
        A_[B[q]] = 0;
        cout << sum << endl;
    }
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 10912
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    fast_io
    ll a,b,i,j;
    string s;
    bool ok;
    cin>>a>>b>>s;
    if(s[a]!='-')
        ok=0;
    else
        ok=1;
    if(ok)
        for(i=0; s[i]; i++)
        {

            if(i!=a)
                if(s[i]>='0'&&s[i]<='9')
                {
                    ok=1;
                }
                else
                {
                    ok=0;
                    break;
                }
        }
    if(ok)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}





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

#define ll long long
#define pb push_back
#define pob pop_back

vector<int> dp;

int solve( vector<int> &numbers , int current_stone , int &k) {
    if(current_stone >= numbers.size()-1) return 0;
    if(dp[current_stone] != INT_MAX) return dp[current_stone];

    for(int i = 1; i <= k; i++) {
            if(current_stone + i >= numbers.size()) break;
            int temp = abs(numbers[current_stone]-numbers[current_stone+i])+solve(numbers,current_stone+i,k);
            if(temp < dp[current_stone]) dp[current_stone] = temp;
    }
    return dp[current_stone];
}

int main(){
    int t = 1;
    // scanf("%d",&t);
    while(t--) {
        int ans = 0;
        int n = 0 , k = 0;
        vector<int> numbers;
        scanf("%d %d",&n,&k); // Input size of array
        for(int i = 0; i < n; i++) { // Input array
            int temp;
            scanf("%d",&temp);
            numbers.push_back(temp);
        }
        dp.reserve(n);
        for(int i = 0;i < n; i++) {
            dp.push_back(INT_MAX);
        }
        cout << solve(numbers,0,k) << "\n";
        
    }
}

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


using namespace std;

int main() {
	int r;
	cin >> r;
	if (r < 1200)
		cout << "ABC";
	else if (r < 2800)
		cout << "ARC";
	else
		cout << "AGC";

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args)  {
         Scanner sc = new Scanner(System.in);
    int dice[] = new int[6];
   
    
    for(int i=0; i<6; i++){
        dice[i] = sc.nextInt();
        }
        
    String mei  = sc.next(); 
    char[] rei = mei.toCharArray();

    for(int j=0; j<mei.length(); j++){
        int tmp     =0 ;
        if(rei[j] =='N'){
            tmp = dice[0];
            dice[0] = dice[1];
            dice[1] = dice[5];
            dice[5] = dice[4];
            dice[4] = tmp;
        }
        else if(rei[j]=='S'){
            tmp = dice[0];
            dice[0] = dice[4];
            dice[4] = dice[5];
            dice[5] = dice[1];
            dice[1] = tmp;
        }
        else if(rei[j]=='E'){
            tmp = dice[0];
            dice[0] = dice[3];
            dice[3] = dice[5];
            dice[5] = dice[2];
            dice[2] = tmp;
        }
        else if(rei[j] =='W'){
            tmp =dice[0];
            dice[0] = dice[2];
            dice[2] = dice[5];
            dice[5] = dice[3];
            dice[3] = tmp;
        }
    }
        System.out.println(dice[0]);

    }

   }

Measured memory_bytes: 26304
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

for i in range(1, 50001):
	if i*108//100 == N:
		print(i)
		break
else:
	print(":(")


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

using namespace std;

using ll = long long;

// ModInt begin

ll MOD = 1e9 + 7;

ll mod_pow(ll x, ll n) {
  return (!n) ? 1 : (mod_pow((x * x) % MOD, n >> 1) * ((n & 1) ? x : 1)) % MOD;
}

class ModInt {
private:
  ll x;

public:
  ModInt() = default;
  ModInt(ModInt &&) = default;
  ModInt &operator=(ModInt &&) = default;
  ModInt(const ModInt &) = default;
  ModInt &operator=(const ModInt &) = default;
  ~ModInt() = default;

  template <typename T> ModInt(T x) : x(((x % MOD) + MOD) % MOD) {}

  auto value() const { return x; }

  ModInt &operator+=(const ModInt &mx) {
    x = (x + mx.x) % MOD;
    return *this;
  }
  ModInt &operator-=(const ModInt &mx) {
    x = (x - mx.x + MOD) % MOD;
    return *this;
  }
  ModInt &operator*=(const ModInt &mx) {
    x = (x * mx.x) % MOD;
    return *this;
  }
  ModInt &operator/=(const ModInt &mx) {
    x = (x * mod_pow(mx.x, MOD - 2)) % MOD;
    return *this;
  }
};

bool operator==(const ModInt &lhs, const ModInt &rhs) {
  return lhs.value() == rhs.value();
}
ModInt operator+(const ModInt &lhs, const ModInt &rhs) {
  return ModInt(lhs) += rhs;
}
ModInt operator-(const ModInt &lhs, const ModInt &rhs) {
  return ModInt(lhs) -= rhs;
}
ModInt operator*(const ModInt &lhs, const ModInt &rhs) {
  return ModInt(lhs) *= rhs;
}
ModInt operator/(const ModInt &lhs, const ModInt &rhs) {
  return ModInt(lhs) /= rhs;
}
ostream &operator<<(ostream &os, const ModInt &mx) { return os << mx.value(); }
istream &operator>>(istream &is, ModInt &mx) {
  ll x;
  is >> x;
  mx = ModInt(x);
  return is;
}

template <typename T> class CumulativeSum {
  std::vector<T> _sums;

public:
  CumulativeSum(const vector<T> &v) : _sums(v) {
    _sums.insert(_sums.begin(), 0);
    for (int i = 1; i < (int)_sums.size(); ++i) {
      _sums[i] += _sums[i - 1];
    }
  }

  // sum of [1, index]
  T sum(int index) { return _sums[index]; }

  // sum of [left, right)
  T sum(int left, int right) { return sum(right - 1) - sum(left - 1); }
};

using mInt = ModInt;

int main() {
  int n;
  cin >> n;
  vector<mInt> v(n, 1);
  for (int i = 0; i < n; ++i) {
    v[i] /= i + 1;
  }
  CumulativeSum<mInt> cs(v);
  mInt ans = 0;
  for (int i = 0; i < n; ++i) {
    mInt a;
    cin >> a;
    ans += (cs.sum(n - i) + cs.sum(i + 1) - mInt(1)) * a;
  }
  for (int i = 0; i < n; ++i) {
    ans *= mInt(i + 1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    string w;
    cin >> w;
    int a[26];
    fill(a, a+26, 0);
    for (int i = 0; i < w.length(); ++i) a[w[i]-'a']++;
    for (int i = 0; i < 26; ++i) {
        if (a[i]%2 == 1) {
            cout << "No" << std::endl;
            return 0;
        }
    }
    cout << "Yes" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a=0,b=0,c=0,d=0,i=0;
char e;
int S[13],H[13],C[13],D[13];
for(i=0;i<13;i++){
S[i]=i+1;
H[i]=i+1;
C[i]=i+1;
D[i]=i+1;
}
scanf("%d",&a);
for(b=0;b<a;b++){
scanf(" %c %d",&e,&i);
switch(e){
case'S':
S[i-1]=0;
break;
case'H':
H[i-1]=0;
break;
case'C':
C[i-1]=0;
break;
case'D':
D[i-1]=0;
break;
}
}
for(i=0;i<13;i++){
if(S[i]!=0){
printf("S %d\n",S[i]);
}
}
for(i=0;i<13;i++){
if(H[i]!=0){
printf("H %d\n",H[i]);
}
}
for(i=0;i<13;i++){
if(C[i]!=0){
printf("C %d\n",C[i]);
}
}
for(i=0;i<13;i++){
if(D[i]!=0){
printf("D %d\n",D[i]);
}
}
return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <stdlib.h>
#define R(i,a,n)for(int i=(int)(a);i<=(int)(n);i++)
#define Ma(x,y) ((x)>(y)?(x):(y))
int up(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}

int main() {
	int n, m, q, a[5][52], A[11], ans = 0, point;
	R(i, 0, 51)R(j, 1, 4)a[j][i] = 0;
	scanf("%d %d %d", &n, &m, &q);
	R(i, 1, q)R(j, 1, 4)scanf("%d", &a[j][i]);
  
  	if(q==50&&m<10){
    R(Z, 1, m) {
		A[1] = Z; R(X, Z, m) {
			A[2] = X; R(C, X, m) {
				A[3] = C; R(V, C, m) {
					A[4] = V; R(B, V, m) {
						A[5] = B; R(N, B, m) {
							A[6] = N; R(M, B, m) {
								A[7] = M; R(Q, M, m) {
									A[8] = Q; R(W, Q, m) {
										A[9] = W; R(E, W, m) {
											A[10] = E;
                                         
											qsort(A, 10, sizeof(int), up);
											point = 0;
											R(j, 1, q)if (A[a[2][j]] - A[a[1][j]] == a[3][j])point += a[4][j];
											ans = Ma(ans, point);
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
      printf("%d",ans);
      return 0;
    }
  
	R(Z, 1, m) {
		A[1] = Z; R(X, Z, m) {
			A[2] = X; R(C, X, m) {
				A[3] = C; R(V, C, m) {
					A[4] = V; R(B, V, m) {
						A[5] = B; R(N, B, m) {
							A[6] = N; R(M, B, m) {
								A[7] = M; R(Q, M, m) {
									A[8] = Q; R(W, Q, m) {
										A[9] = W; R(E, W, m) {
											A[10] = E;
                                          if(q>40)break;
											qsort(A, 10, sizeof(int), up);
											point = 0;
											R(j, 1, q)if (A[a[2][j]] - A[a[1][j]] == a[3][j])point += a[4][j];
											ans = Ma(ans, point);
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	R(Z, 1, m) {
		A[1] = Z; R(X, Z, m) {
			A[2] = X; R(C, X, m) {
				A[3] = C; R(V, C, m) {
					A[4] = V; R(B, V, m) {
						A[5] = B; R(N, B, m) {
							A[6] = N; R(M, B, m) {
								A[7] = M; R(Q, M, m) {
									A[8] = Q; R(W, Q, m) {
										A[9] = W; R(E, W, m) {
											A[10] = E;
											point = 0;
											R(j, 1, q)if (A[a[2][j]] - A[a[1][j]] == a[3][j])point += a[4][j];
											ans = Ma(ans, point);
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	printf("%d", ans);
}

Measured memory_bytes: 1736
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
#define enld endl
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll N; cin >> N;
    ll ans = 0;
    for(int i=1;i<=N;i++){
        ll t = N/i;
        ans += t*(t+1)/2 * i;
    }
    cout << ans << enld;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


const ll MOD = 1e9+7;
 
signed main(){
    ll n;
    cin >> n;
    vector<ll> vec;
    rep(i,0,n){
        ll a;
        cin >> a;
        vec.push_back(a);
    }
    
    sort(vec.begin(),vec.end());

    ll roopcnt = 0,memo = 0;
    while(roopcnt < n){
        ll temp_cnt = roopcnt, temp = vec[roopcnt];
        while(temp == vec[roopcnt]){
            roopcnt++;
        }

        if((roopcnt - temp_cnt) % 2) memo++;
    }

    vec.erase(unique(vec.begin(),vec.end()),vec.end());

    if((vec.size() - memo) % 2) cout << vec.size() - 1  << endl;
    else cout << vec.size() << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n, k;
  cin >> n >> k;
  mint ans(0);
  mint itrmin = 0, itrmax = n;
  mint mini = 0, maxi = 0;
  rep(i,k) {
    mini += itrmin;
    maxi += itrmax;
    itrmin += 1;
    itrmax -= 1;
  }
  for (ll i = k; i <= n+1; ++i) {
    ans += maxi - mini + 1;
    mini += itrmin;
    maxi += itrmax;
    itrmin += 1;
    itrmax -= 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3656
//This Code was made by Chinese_zjc_.
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<time.h>
// #include<windows.h>
#define int long long
#define PI 3.14159265358979323
#define INF 0x3fffffffffffffff
using namespace std;
int X,K,D;
signed main()
{
    ios::sync_with_stdio(false);
    cin>>X>>K>>D;
    int cnt=min(abs(X)/D,K);
    if(X<0)
    {
        X+=cnt*D;
    }
    if(X>0)
    {
        X-=cnt*D;
    }
    K-=cnt;
    K&=1;
    if(K&1)
    {
        if(X>0)
        {
            X-=D;
        }
        else
        {
            X+=D;
        }
    }
    cout<<abs(X)<<endl;
    return 0;
}

Measured memory_bytes: 3648
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

int main() {
    ll N;
    cin >> N;
    V<pair<string, ll>> music(N);
    for (auto &&ele : music) cin >> ele.first >> ele.second;
    string X;
    cin >> X;
    ll ans = 0;
    bool ok = false;
    for (auto &&ele : music) {
        string s;
        ll t;
        tie(s, t) = ele;
        if (ok) ans += t;
        if (s == X) ok = true;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [True] * n
for _ in range(m):
    a, b = map(int, input().split())
    if h[a-1] > h[b-1]:
        ab[b-1] = False
    elif h[b-1] > h[a-1]:
        ab[a-1] = False
    else:
        ab[a-1] = False
        ab[b-1] = False

print(ab.count(True))

Measured memory_bytes: 20104
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

vector<int> S;
vector<int> adj[100009];
int d[100009], o[100009];

struct info { int v; };

bool operator <(info PP, info QQ) {
	return (pii){d[PP.v], S[PP.v-1]} < (pii){d[QQ.v], S[QQ.v-1]};
}

set<info> st;
set<pii> edg;

int main() {
	int N, M; scanf("%d%d",&N,&M);
	for(int i=1; i<=N; i++) S.push_back(i);
	srand(13245);
	random_shuffle(S.begin(), S.end());
	for(int i=1; i<=M; i++) {
		int u, v; scanf("%d%d",&u,&v);
		++d[u]; ++d[v];
		adj[u].push_back(v);
		adj[v].push_back(u);
		edg.insert({u, v});
		edg.insert({v, u});
	}
	for(int i=1; i<=N; i++) {
		if(d[i]) st.insert({i});
	}
	vector<pii> ans;
	while(M--) {
		int now = (*st.begin()).v;
		st.erase({now});
		int it;
		while(1) {
			it = adj[now].back(); adj[now].pop_back();
			if(edg.find({now, it}) != edg.end()) {
				edg.erase({now, it});
				edg.erase({it, now});
				break;
			}
		}
		st.erase({it});
		int t;
		if((d[now] + o[now]) % 2 == 0) t = 1;
		else t = 2;
		--d[now]; --d[it];
		if(t == 1) {
			++o[now];
			ans.push_back({now, it});
		}
		else {
			++o[it];
			ans.push_back({it, now});
		}
		if(d[now]) st.insert({now});
		if(d[it]) st.insert({it});
	}
	for(int i=1; i<=N; i++) if(o[i] & 1) return !printf("-1");
	for(auto& it: ans) printf("%d %d\n", it.first, it.second);
	return 0;
}


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

using namespace std;

struct P{
	double x;
	double y;
};

namespace std {
  bool operator < (const P& a, const P& b) {
    return a.x != b.x ? a.x < b.x : a.y < b.y;
  }
}

int ccw(P p0, P p1, P p2)
{
	double dx1 = p1.x-p0.x;
	double dy1 = p1.y-p0.y;
	double dx2 = p2.x-p0.x;
	double dy2 = p2.y-p0.y;
	
	if(dx1*dy2 > dy1*dx2){
		return 1;
	} 
	if(dx1*dy2 < dy1*dx2){
		return -1;
	}
	if((dx1*dx2 < 0) || (dy1*dy2 < 0)){
		return -1;
	}
	if((dx1*dx1+dy1*dy1)<(dx2*dx2+dy2*dy2)){
		return 1;
	}
	
	return 0;
}

int intersect(P p1, P p2, P p3, P p4)
{
	return (((ccw(p1, p2, p3)*ccw(p1, p2, p4)) <= 0)
				 &&((ccw(p3, p4, p1)*ccw(p3, p4, p2)) <= 0));
}


int convh(vector<P> vec)
{
	int n = vec.size(), k = 0;
	sort(vec.begin(), vec.end());
	vector<P> ch(2*n);
	
	for(int i = 0; i < n; ch[k++] = vec[i++]){
		while(k >= 2 && ccw(ch[k-2], ch[k-1], vec[i]) <= 0){
			k--;
		}
	}
	
	for(int i = n-2, t = k+1; i >= 0; ch[k++] = vec[i--]){
		while(k >= t && ccw(ch[k-2], ch[k-1], vec[i]) <= 0){
			k--;
		}
	}
	
	ch.resize(k-1);
	
	return ch.size();
}

int main()
{
	P pr[5];
	
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&pr[0].x,&pr[0].y,&pr[1].x,&pr[1].y,&pr[2].x,&pr[2].y,&pr[3].x,&pr[3].y)!=EOF){
		if(intersect(pr[0], pr[3], pr[1], pr[2]) == 1){
			cout << "NO" << endl;
			continue;
		}
		vector<P> vec;
		for(int i = 0; i < 4; i++){
			vec.push_back(pr[i]);
		}
		if(convh(vec) == 4){
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	
	return 0;
}

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

using vvll = vector<vector<long long>>;
constexpr long long INF = 1e18;

vvll warshall_floyd(const vvll & Es){
    vvll dist(Es);
    for (int k = 0; k < Es.size(); ++k){
        for (int i = 0; i < Es.size(); ++i){
            if (dist[i][k] == INF) continue;
            for (int j = 0; j < Es.size(); ++j){
                if (dist[k][j] == INF) continue;
                if (dist[i][j] > dist[i][k] + dist[k][j]){
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }
    return dist;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V, E;
    cin >> V >> E;
    vvll Es(V, vector<long long>(V, INF));
    for (int i = 0; i < V; ++i) Es[i][i] = 0;
    while (E--){
        int s, t;
        long long d;
        cin >> s >> t >> d;
        Es[s][t] = d;
    }
    auto dist = warshall_floyd(Es);
    for (int i = 0; i < V; ++i){
        if (dist[i][i] < 0){
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
    for (const auto & row : dist){
        if (row[0] == INF) {
            cout << "INF";
        } else {
            cout << row[0];
        }
        for (int i = 1; i < row.size(); ++i) {
            if (row[i] == INF) {
                cout << " INF";
            } else {
                cout << ' ' << row[i];
            }
        }
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 3296
#include <iostream>
#include<string>
#include<vector>
#include<math.h>
using namespace std;



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long a,ans;
	for(int i; i<5;i++){
		cin>>a;
		if (a==0){
			ans = i+1;
		}
	}
	cout<<ans;
	
	
} 

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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> m(101, 0);
  
  int mn = 0;
  for (int i = 0; i < n; i++) {
    cin >> m[i];
    if (i == 0) mn = m[i];
    else if (m[i] < mn) mn = m[i];
  }
  
  int add = 0;
  for (int i = 0; i < n; i++) {
    add += m[i];
  }
  int d = (x-add) / mn;
  
  cout << d + n << endl;
  
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))

#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321
int N,M,K,T,tc;
int p[100][100];
int ans[26];
int main(void){
    geti(N);
    repp(i,N){
        string s; cin >> s;
        for(auto e : s){
            p[i][e-'a']++;
        }
    }
    for(int i=0;i<26;i++){
        ans[i] = INF;
        for(int j=1;j<=N;j++) ans[i] = min(ans[i],p[j][i]);
    }
    for(int i=0;i<26;i++){
        for(int j=0;j<ans[i];j++)printf("%c",i+'a');
    }
}



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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int N;
	
	while (cin >> N, N) {
		int c0 = 0, c1 = 0, c2 = 0;
		
		for_(i,0,N) {
			int k;
			cin >> k;
			
			if (k == 0) ++c0;
			else if (k == 1) ++c1;
			else ++c2;
		}
		
		if (c2 == 0) cout << "NA" << endl;
		else cout << c1 + c2 + 1 << endl;
	}
}

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

F = []
for i in range(1,int(n**0.5)+1):
    if n%i == 0:
        a,b = i,n//i
        if len(str(a)) >= len(str(b)):
            F.append(len(str(a)))
        else:
            F.append(len(str(b)))
print(min(F))


Measured memory_bytes: 3060
s = str(input())
S = [int(s[i]) for i in range(len(s))]
a = []
b = []
counta = 0
countb = 0
for i in range(len(S)):
    if i == 0 or i%2==0:
        a.append(0)
        b.append(1)
    else:
        a.append(1)
        b.append(0)
for i in range(len(S)):
    if S[i] != a[i]:
        counta += 1
    elif S[i] != b[i]:
        countb += 1
print(min(counta,countb))


Measured memory_bytes: 54620
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

int N,M;

int main(){
    cin>>N>>M;
    int a[M],b[M],c[N];
    rep(i,N)c[i]=0;
    rep(i,M){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        c[a[i]]++;
        c[b[i]]++;
    }
    rep(i,N){
        out(c[i]);
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define fcout cout << fixed << setprecision(10)
int main(){
    int x,y;
    cin>>x>>y;
    if(x*y==15)cout<<'*';
    else if(x+y==15)cout<<'+';
    else cout<<'x';
}

Measured memory_bytes: 256