akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using llong = long long;
#define rep(i,N) for(llong i = 0; i < N; i++)
#define im(index) (index+mod)%mod

const llong MOD = 1e9+7;
const llong mod = 13;

string s;
llong dp[100010][mod];

//二分累乗
llong modpow(llong base, llong ex, llong m) {
    llong res = 1;
    llong temp = base%m;
    while(ex) {
        if (ex&1) res *= temp;
        temp *= temp;
        temp %= m; res %= m;
        ex /= 2;
    }
    return res;
}

int main() {
    cin >> s;
    reverse(s.begin(), s.end());
    //初期化
    if (s[0] == '?') {
        rep(i,10) dp[0][i] = 1;
    }else{
        dp[0][s[0]-'0'] = 1;
    }

    rep(i,s.size()-1) {
        if (s[i+1] == '?') {
           rep(j,10) {
                llong num = j*modpow((llong)10, (llong)(i+1), mod);
                rep(k,mod) {
                    dp[i+1][im(k+num)] += dp[i][k];
                    dp[i+1][im(k+num)] %= MOD;
                }
           }
        }else{
            llong num = (llong)(s[i+1] -'0')*modpow((llong)10, (llong)(i+1), mod);
            rep(j,mod) {
                dp[i+1][im(j+num)] += dp[i][j];
                dp[i+1][im(j+num)] %= MOD;
            }
        }
    }

    cout << dp[s.size()-1][5] << endl;
    return 0;
}

Measured memory_bytes: 10624
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
  string S;
  cin >> S;
  int ans = 1000;
  for (int i = 0; i < S.length() - 2; i++)
  {
    int sub = stoi(S.substr(i, 3));
    int tmp = abs(sub - 753);
    if (tmp < ans)
    {
      ans = tmp;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        if (n == 0)
        {
            return;
        }
        string[] data = Console.ReadLine().Split(' ');
        int min,max;
        long sum;
        min = max = int.Parse(data[0]);
        sum = int.Parse(data[0]);
        for (int i = 1; i < n; i++)
        {
            int num = int.Parse(data[i]);
            if (num < min)
            {
                min = num;
            }

            if (num > max)
            {
                max = num;
            }

            sum += num;
        }
        Console.WriteLine("{0} {1} {2}", min, max, sum);
    }
}

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

long long N,M;
vector<long long> A,B;
vector<long long> uf(100010);
vector<long long> g(100010,1);

long long root(long long a){
	if(uf[a]==a)return a;
	else return uf[a]=root(uf[a]);
}

void unite(long long a,long long b){
	a=root(a);
	b=root(b);
	if(a==b)return;
	
	uf[a]=b;
}

bool query(long long a,long long b){
	return root(a)==root(b);
}

int main(){
	cin >> N >> M;
	for(long long i=0;i<M;i++){
		long long a,b;
		cin >> a >> b;
		A.push_back(a);
		B.push_back(b);
	}
	
	vector<long long> ans(M);
	ans[0]=N*(N-1)/2;
	
	for(long long i=0;i<=N;i++)uf[i]=i;
	
	reverse(A.begin(),A.end());
	reverse(B.begin(),B.end());
	
	for(long long i=0;i<M-1;i++){
		if(!query(A[i],B[i])){
			long long connect=g[root(A[i])]*g[root(B[i])];
			ans[i+1]=ans[i]-connect;
			long long r=g[root(A[i])]+g[root(B[i])];
			unite(A[i],B[i]);
			g[root(A[i])]=r;
		}
		else ans[i+1]=ans[i];
	}
	
	reverse(ans.begin(),ans.end());
	for(long long i=0;i<M;i++)cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 5484
package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	fmt.Scan(&x)

	total := 100.0
	count := 0

	for total < x {
		total = total + math.Trunc(total/100)
		count++
	}
	fmt.Println(count)

}


Measured memory_bytes: 1756
#include<iostream>
#include<stdlib.h>
#include<string.h>

using namespace std;

typedef struct BiTNode{
public:
  int key;
  struct BiTNode *parent;
  struct BiTNode *left;
  struct BiTNode *right;

  BiTNode(int key){
    this->key = key;
    this->parent = NULL;
    this->left = NULL;
    this->right = NULL;
  }
} BiTNode;

typedef struct BiT{
public:
  struct BiTNode *root;
  BiT(){
    this->root = NULL;
  }
}BiT;

void insert(BiT *T,int key){

  BiTNode *y;
  BiTNode *x;
  BiTNode *z;

  y = NULL;
  x = T->root;
  z = new BiTNode(key);

  while(1){
    if(x == NULL){
      break;
    }
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  z->parent = y;

  if(y == NULL){
    T->root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else {
    y->right = z;
  }
}

BiTNode* find(BiTNode *node,int key){

  if(node == NULL || key == node->key){
    return node;
  }
  if(key < node->key){
    return find(node->left,key);
  }
  return find(node->right,key);
}

void inorderTreeWalk(BiTNode *node){

  if(node != NULL){
    inorderTreeWalk(node->left);
    cout << " " << node->key;
    inorderTreeWalk(node->right);
  }
}

void preorderTreeWalk(BiTNode *node){

  if(node != NULL){
    cout << " " << node->key;
    preorderTreeWalk(node->left);
    preorderTreeWalk(node->right);
  }
}

void print(BiT T){

  inorderTreeWalk(T.root);
  cout << endl;
  preorderTreeWalk(T.root);
  cout << endl;
}

int main(){

  int i;
  int n;
  int k;
  BiT T;
  char order[10];
  char dummy;

  cin >> n;

  for(i = 0;i < n;i++){
    cin >> order;
    if(strcmp(order,"insert") == 0){
      cin >> k;
      insert(&T,k);
    }
    else if(strcmp(order,"find") == 0){
      cin >> k;
      if(find(T.root,k) != NULL){
	cout << "yes" << endl;
      }
      else {
	cout << "no" << endl;
      }
    }
    else if(strcmp(order,"print") == 0){
      print(T);
    }
  }

  return 0;
}

Measured memory_bytes: 19948
#include <stdio.h>
#include <string.h>

int main()
{
    char s[200000];
    
    scanf("%s",s);

    int len = strlen(s);
    int i,j;

    int T[200001] = {0};
    T[len] = 0;
    int count2019[2019] = {0};
    count2019[0] = 1;
    int dig = 1;
    for (i = len - 1; i >= 0; i--)
    {   
        T[i] = (T[i + 1] + dig * (s[i] - '0')) % 2019;
        count2019[T[i]]++;
        dig *= 10;
        dig %= 2019;
    }

    long long ans = 0;
    for (i = 0; i < 2019; i++)
    {
        ans += count2019[i] * (count2019[i] - 1) / 2;
    }
    
    printf("%lld",ans);
}


Measured memory_bytes: 2676
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int H, W;
	cin >> H >> W;

	auto base = make_vec(H, W, 0LL);//与えられるグラフ

	char temp;
	Int white = 0;//白マスの個数
	for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			cin >> temp;
			if (temp == '.') {
				white++;
				continue;
			}
			else base[i][j] = 1;
		}
	}

	vector<Int> diri{ -1,0,1,0 };
	vector<Int> dirj{ 0,1,0,-1 };

	Int ni, nj;
	vector<vector<Int>> Graph(H * W);
	for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			if (base[i][j] == 1)continue;

			for (Int k = 0; k < 4; k++) {
				ni = i + diri[k];
				nj = j + dirj[k];

				if (ni < 0 || ni >= H || nj < 0 || nj >= W)continue;
				if (base[ni][nj] == 0) {
					Graph[i * W + j].push_back(ni * W + nj);
					Graph[ni * W + nj].push_back(i * W + j);
				}
			}
		}
	}

	//bfs
	vector<Int> dist(H*W, -1); // 全頂点を「未訪問」に初期化
	queue<Int> que;

	// 初期条件 (頂点 0 を初期ノードとする)
	dist[0] = 0;
	que.push(0); // 0 を橙色頂点にする

	// BFS 開始 (キューが空になるまで探索を行う)
	while (!que.empty()) {
		Int v = que.front(); // キューから先頭頂点を取り出す
		que.pop();

		// v から辿れる頂点をすべて調べる
		for (Int nv : Graph[v]) {
			if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

			// 新たな白色頂点 nv について距離情報を更新してキューに追加する
			dist[nv] = dist[v] + 1;
			que.push(nv);
		}
	}

	if (dist[W * H - 1] == -1) {
		cout << -1 << "\n";
	}
	else {
		cout << white - dist[W * H - 1]-1 << "\n";
	}


}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
    
int main() {
    int N,M,C;
    cin>>N>>M>>C;
    vector<int> B(M);
    for (int i=0;i<M;i++) cin>>B.at(i);
    vector<vector<int>> A(N, vector<int>(M));
    for (int i=0;i<N;i++){
        for (int j=0;j<M;j++){
            cin>>A.at(i).at(j);
        }
    }

    int counter = 0;
    for (int i=0;i<N;i++){
        int sum = 0;
        for (int j=0;j<M;j++){
            sum += A.at(i).at(j)*B.at(j);
        }
        if (sum+C>0) counter++;
    }
        
    cout<<counter<<endl;
}

Measured memory_bytes: 256
N,M,C=map(int,input().split())
b_list = list(map(int, input().split())) # "1 2 3"と入力
a = []
for i in range(N):
    a.append(list(map(int, input().split())))

import numpy as np
b_list=np.array(b_list)
a=np.array(a)

ans=0
for i in range(N):
    if (sum(b_list*a[i])+C)>0:
        ans+=1
print(ans)

Measured memory_bytes: 12424
#include <bits/stdc++.h>
#define int long long int
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
#define output(x) for (auto a:x) cout<<a<<" ";cout<<endl;
#define output2(x) for (auto a:x) cout<<a.fi<<" "<<a.se<<endl;
#define PI 3.14159265

// DEBUG TEMPLATE
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
  *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  
// DEBUG TEMPLATE ENDS

#define MOD 1000000007
int power(int x,int y,int mod = MOD) 
{ 
  int ret = 1;
  x = x % mod;
  while (y){
    if(y&1) ret = (ret*x)%mod;
    y = y>>1;
    x = (x*x)%mod;
    } 
    return ret%mod; 
}

void solve()
{ 
  int x,n;
  cin>>x>>n;
  vector<int> inp(n);
  vector<int> occ(105);
  for (int i=0;i<n;i++) {
    cin>>inp[i];
    occ[inp[i]] = 1;
  }
  int l ,r;
  for (l=x; l > 0 ; l--){
    if (occ[l] == 0 ) break;
  }
  for (r=x; r < 102 ; r++){
    if (occ[r] == 0 ) break;
  }
  if ((abs(r-x)<abs(l-x))){
    cout<<r;
  } else cout << l;
}


/*
  
*/
signed main(){
  // int t;
  // cin>>t;
  // while (t--)
  solve();
}
// Check MOD values plox :(


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

using namespace std;


void solve(){
    int n;
    cin>>n;
    vector<int> v;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        v.push_back(a);
    }

    int breakCount = 0;
    int index =1;
   for(int i=0;i<n;){
       if(v[i]!=index){ breakCount++;i++;}
       if(v[i]==index){index++;i++;}
   }
    if(breakCount==n) cout << -1 << endl;
    else cout << breakCount;

    

}


int main(){
    solve();
}

Measured memory_bytes: 1400
from bisect import bisect_left

N, M = map(int, input().split())
S = [i for i, s in enumerate(input()) if s == '0']

ans = []
now = N
while now > 0:
    nxI = bisect_left(S, now - M)
    nx = S[nxI]

    if nx == now:
        print(-1)
        exit()

    ans.append(now - nx)
    now = nx

print(*ans[::-1])


Measured memory_bytes: 10120
#include <bits/stdc++.h>
using namespace std;
#define v(type) vector<type>

int main() {
    string s;
    cin >> s;
    bool c = true, f = true;
    for (int i = 0; i < s.size(); i++) {
        if (c && s[i]=='C') c = false;
        if (!c && f && s[i]=='F') f = false;
    }
    if (!c && !f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3568
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define MOD 1000000007
#define add(x,y) x=(x+y)%MOD
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}

ll dp[50][1<<17];
//dp[i][j]=i文字目まで見て、XYZがなく、状態jである場合の数
//状態j=「jのx bit目が1⇔末尾から先頭に向けて見た連続部分列で和がxになるものがある」
int main(){
	int n,a,b,c;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	ll hit=((1<<a|1)<<b|1)<<c;
	ll M=a+b+c;
	
	dp[0][1]=1;
	rep(i,0,n)repp(j,1,1<<M,2)rep(k,1,11)if(((j<<k)&hit)!=hit)add(dp[i+1][(j<<k|1)&((1<<M)-1)],dp[i][j]);
	ll ans=0;
	repp(j,1,1<<M,2)add(ans,dp[n][j]);
	printf("%lld\n",(pom(10,n,MOD)-ans+MOD)%MOD);
	return 0;
}

Measured memory_bytes: 42112
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	int N;
	cin >> N;
    vector<int> A(N), B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    vector<P> v(N);
    stack<int> s;
    int ans = 500, tmp, p, q;
    rep(i,1<<N) {  // bit探索
        tmp = 0;
        rep(j,N) {
            if ((i>>j)&1) v[j] = P(B[j], j);
            else          v[j] = P(A[j], j);
        }
        rep(j,N) {
            p = j;
            while (p && v[p].first < v[p-1].first) {
                swap(v[p], v[p-1]);
                tmp++;
                p--;
            }
        }
        rep(j,N) {
            int idx = v[j].second;
            if (((i>>idx)+idx-j)&1) s.push(v[j].first*500+j);
        }
        if (s.size()&1) {
            tmp = 500;
            s.pop();
        }
        while (s.size()) {
            p = s.top(); s.pop();
            q = s.top(); s.pop();
            if ((p-q)&1) tmp += p-q;
            else         tmp += 500;
        }
        ans = min(ans, tmp);
    }
    if (ans < 500) cout << ans << endl;
    else       	   cout << -1  << endl;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var (a,b,k) = readLine()!!.split(" ").map(String::toInt)
    var list:MutableList<Int> = mutableListOf()
    var c= 1
    while(a>=c || b>=c){
        if(a%c==0 && b%c == 0) list.add(c)
        c++
    }
    
    println(list[list.size - k])
}


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

const int N = 2500 + 10;
const int INF = (1 << 30) - 1;

std::vector<std::pair<int, int>> neighbors[N];
bool in_queue[N];
int dist[N], times[N];
int n, m, p;

int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 0; i < m; ++ i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    neighbors[u].push_back(std::make_pair(v, w - p));
  }

  for (int i = 1; i <= n; ++ i) {
    dist[i] = -INF;
  }
  dist[1] = 0;

  std::queue<int> queue;
  queue.push(1);
  while (!queue.empty()) {
    int u = queue.front();
    queue.pop();
    in_queue[u] = false;
    for (auto x : neighbors[u]) {
      int v = x.first;
      int w = x.second;
      if (dist[u] + w > dist[v]) {
        dist[v] = dist[u] + w;
        if (!in_queue[v] && times[v] <= n) {
          queue.push(v);
          in_queue[v] = true;
          times[v] ++;
          if (times[v] > n) {
            dist[v] = INF;
          }
        }
      }
    }
  }
  if (dist[n] >= INF) {
    puts("-1");
  } else {
    printf("%d\n", std::max(0, dist[n]));
  }
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
set <int> a;
int main(){
	int n,x;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>x;
		a.insert(x);
	}
	cout<<a.size()<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d,f,g,h,i,j;
	scanf("%d %d %d",&a,&s,&d);
	if(s<d){
		if(d-s<=a) printf("safe\n");
		else printf("dangerous\n");
	}
	else printf("delicious\n");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private CommonInput cin;

        private void Process()
        {
            this.cin = new CommonInput();

            int money, n;

            money = 100000;

            n = this.cin.GetNextToInt();

            Console.WriteLine("{0}", this.Calc(money, n));

            Console.ReadKey();
        }

        private int Calc(int x, int n)
        {
            int y = (int)(x * 1.05);

            if (n == 0)
                return x;
            else
                return this.Calc(y / 1000 * 1000 + (y % 1000 == 0 ? 0 : 1000), n - 1);
        }
    }

    public class CommonInput
    {
        public CommonInput()
        {
            this._s = new string[0];
            this._i = 0;
        }

        public string Line { get; set; }
        private string[] _s;
        private int _i;
        private char[] _sep = { ' ' };

        public void GetLine()
        {
            this._i = 0;
            do
            {
                this.Line = Console.ReadLine();
            } while (this.Line == "");

            if (this.Line != null)
                this._s = this.Line.Split(this._sep, StringSplitOptions.RemoveEmptyEntries);
        }

        public string GetNext()
        {
            if (this._i < this._s.Length)
                return this._s[this._i++];

            this.GetLine();

            return this._s[this._i++];
        }

        public int GetNextToInt()
        {
            return int.Parse(this.GetNext());
        }

        public long GetNextToLong()
        {
            return long.Parse(this.GetNext());
        }

        public double GetNextToDouble()
        {
            return double.Parse(this.GetNext());
        }
    }
}

Measured memory_bytes: 5640
import numpy as np
N = int(input())
A = np.array(["0"] + input().split() + ["0"], dtype=np.int64)
B = np.abs(A[1:] - A[:-1])
C = np.abs(A[2:] - A[:-2])
D = B[1:] + B[:-1]
total = B.sum()
for i in range(N):
    print(total - D[i] + C[i])

Measured memory_bytes: 22552
#include<bits/stdc++.h>
#include<numeric>
#define int long long
const int inf=1e9+5;
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int h[n];for(int i=0;i<n;i++)cin>>h[i];
    vector<int> dp(n,inf);
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+2;j++){
            if(j<n){
                dp[j]=min(dp[i]+abs(h[j]-h[i]),dp[j]);
                //cout<<dp[j]<<"-";
        }
        }
        
        //cout<<dp[i]<<" ";
    }
    cout<<dp[n-1]<<endl;
            
        
    }
    


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

int main(){
  ll N;
  cin>>N;
  ll ans=0;
  ll W=(ll)sqrt(N);
  for(int i=1;i<W+1;i++){
    if(N%i==0){
      if(N/i-W<2)
        continue;
      ans+=N/i-1;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = 1e9;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}ll n,sum = 0,m,a,b;
struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
    cin >> n >> m; UnionFind tree(2*n);
    rep(i, m) {
        cin >> a >> b;
        a--; b--;
        tree.unite(a, b + n);
        tree.unite(a + n, b);
    }ll cnt = 0;
    if (tree.same(0, n)) {
        cout << n * (n - 1) / 2 - m << endl;
    }
    else {
        rep(i, n) {
            if (tree.same(0, i)) cnt++;
        }cout << cnt * (n - cnt) - m << endl;
    }
}

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

int main() {
  string S;
  cin >> S;
  string K = "keyence";
  int N = S.size();
  bool flag = false;
  if(S == K) cout << "YES" <<endl;
  else{

  for(int i = 0;i<N;i++){
      for(int j = i;j<N;j++){
          string newS;//取り除く部分文字列以外を繋げた文字列
          for(int k = 0;k<N;k++){
            if(i<=k && k<=j) continue;
            newS.push_back(S[k]);
          }
          if(newS == K){
              flag = true;
              cout << "YES" <<endl;
              return 0;
          } 
      }
  }
   if(!flag) cout << "NO" <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
const int maxn = 1e5 + 5;
int a[maxn];
int f[maxn];
int getf (int x)
{
    return f[x] == x ? x : f[x] = getf(f[x]);
}
void mer (int a , int b)
{
    int fa = getf(a) , fb = getf(b);
    if (fa == fb) return ;
    f[fb] = fa;
}
int main()
{
    ios::sync_with_stdio(false);
    int n , m; cin >> n >> m;
    for (int i = 1 ; i <= n ; i++) f[i] = i;
    for (int i = 1 ; i <= m ; i++) {
        int x , y; cin >> x >> y;
        mer(x , y);
    }
    int ans = 0 ;
    for (int i = 1 ; i <= n ; i++) if (getf(i) == i) ans++;
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 4044
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define INF 1000000009
#define LINF 1000000000000000009
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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 (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }
ll mod = 1000000007;

ll fac[2000010];

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

void modfac() {
	fac[0] = 1;
	for (ll i = 1; i < 2000010; i++) {
		fac[i] = (fac[i - 1] * i) % mod;
	}
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	else return (fac[n] * modinv(fac[n - k])) % mod;
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	else return ((fac[n] * modinv(fac[k])) % mod*modinv(fac[n - k])) % mod;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]++;
	}
	int ans = 0;
	int cnt = 0;
	for (int i = 0; i < k; i++) cnt += a[i];
	for (int i = 0; i < n - k; i++) {
		chmax(ans, cnt);
		cnt -= a[i];
		cnt += a[i + k];
		//cout << cnt << endl;
	}
	chmax(ans, cnt);
	cout << fixed << setprecision(15) << (double)ans / 2.0 << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int fun(int [],int ,int );
int fun(int a[],int N,int k)
{
    int i,t,j,flag=1,p=0;
    for(i=N;;i++)
    {
        t=i;
        while(t)
        {
            for(j=0;j<k;j++)
            {
                if(a[j]==t%10)
                {
                    flag=0;
                    break;
                }
            }
            if(flag==0)
            {
                flag=1;
                break;
            }
            t=t/10;
            if(t==0&&flag==1)
            {
                p=1;
                break;
            }
        }
        if(p==1)
        {
            break;
        }
    }
    return i;
}
int main()
{
    int a[10005];
    int N,k,i;
    scanf("%d%d",&N,&k);
    for(i=0;i<k;i++)
    {
        scanf("%d",&a[i]);
    }
    printf("%d\n",fun(a,N,k));
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>

using namespace std;

void t(int a[],int b[],int c[]) {
	for (int i = 0; i < 7; i++) {
		if (a[i] != c[i]) {
			a[i] = c[i];
			b[i] = 1;
		} else {
			b[i] = 0;
		}
	}
	return;
}

int main() {
	int k,n;

	while (1) {
		int a[7] = {0};
		int b[7];
		cin >> n;
		if (n == -1) {
			break;
		} else {
			for (int j = 0; j < n; j++) {
				cin >> k;
					if (k == 0) {
						int c[] = {1,1,1,1,1,1,0};
						t(a,b,c);
					} else if (k == 1) {
						int c[] = {0,1,1,0,0,0,0};
						t(a,b,c);
					} else if (k == 2) {
						int c[] = {1,1,0,1,1,0,1};
						t(a,b,c);
					} else if (k == 3) {
						int c[] = {1,1,1,1,0,0,1};
						t(a,b,c);
					} else if (k == 4) {
						int c[] = {0,1,1,0,0,1,1};
						t(a,b,c);
					} else if (k == 5) {
						int c[] = {1,0,1,1,0,1,1};
						t(a,b,c);
					} else if (k == 6) {
						int c[] = {1,0,1,1,1,1,1};
						t(a,b,c);
					} else if (k == 7) {
						int c[] = {1,1,1,0,0,1,0};
						t(a,b,c);
					} else if (k == 8) {
						int c[] = {1,1,1,1,1,1,1};
						t(a,b,c);
					} else {
						int c[] = {1,1,1,1,0,1,1};
						t(a,b,c);
					}
				
					for (int i = 6; i >= 0; i--) {
						cout << b[i];
					}
					cout << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>

#include <iomanip>      // std::setprecision

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,a,b) for(int i=(a);i>=(b);i--)

using namespace std;
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;



const ll mod = 1e9 + 7;

ll dp[2*1000+10][2*1000+10];

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

  int N, M;
  cin >> N >> M;

  vi S(N+1);
  vi T(M+1);

  rep(i, 1, N) cin >> S[i];
  rep(i, 1, M) cin >> T[i];

  dp[0][0] = 1;
  rep(i, 1, N) { dp[i][0] = 1; }
  rep(i, 1, M) { dp[0][i] = 1; }

  rep(i, 1, N) {
    rep(j, 1, M) {
      dp[i][j] = 0;
      dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod;
      dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
      dp[i][j] = (dp[i][j] - dp[i-1][j-1] + mod) % mod;

      if (S[i] == T[j]) dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % mod;
    }
  }

  cout << dp[N][M] << endl;



  return 0;
}


Measured memory_bytes: 31744
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;


 	
 	
int main() {
	
int A,B;
cin>>A>>B;
if(A==2||B==2){
	ce("No");
}else{
	ce("Yes");
}

}

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

int main() {
  char a;
  cin >> a;
  if(a=='a'||a=='i'||a=='u'||a=='e'||a=='o')
    cout << "vowel" <<endl;
  else
    cout << "consonant" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, s, a[5000], dp[5000];

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> s;
	zep(i, 0, n){
		cin >> a[i];
	}
	
	ll ans = 0;
	memset(dp, 0, sizeof(dp));
	dp[0] = 1;
	zep(i, 0, n){
		rrep(j, s, 0){
			if(a[i]+j <= s){
				dp[a[i]+j] += dp[j];
				dp[a[i]+j] %= MOD;
			}
		}
		dp[0]++;
		dp[0] %= MOD;
		
		ans += dp[s];
		ans %= MOD;
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>

using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main() {

    int N;
    cin >> N;

    vector<ll> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];

    bool flag = true;
    for(int i = 0; i < N; i++){
        if(v[i] % 2 == 1) flag = false;
    }

    if(flag){
        cout << "second" << endl;
    }
    else{
        cout << "first"  << endl;
    }


}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
typedef pair<int,int> P;

int main(){
  int n,s; cin >> n >> s;
  int a[n];rep(i,n) cin >> a[i];
  bool frag = false;
  //smallest window length
  int ans = n;
  int r = 0;
  int sum = 0;
  rep(l,n){
    while(sum < s){
      if(r == n) break;
      else {
        sum += a[r];
        r++;
      }
    }
    if(sum < s) break; // r == n でもsに達しない場合
    // cout << l << " " << r << "\n";
    frag = true;
    ans = min(ans, r-l);
    sum -= a[l];
    if(r == l) r++;
  }
  if(frag) cout << ans << "\n";
  else cout << 0 << "\n";
}


Measured memory_bytes: 3504
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << (a * 3 + b) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val line = io.StdIn.readLine()
    val target = io.StdIn.readLine()
    val twice = line + line
    val answer =
      if (twice.contains(target)) {
        "Yes"
      } else {
        "No"
      }
    println(answer)
  }
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>


using namespace std;
const ll maxn=2e5+100,inf=1e18,LOG=23,mod=1e9+7;
int block = 300, timer = 0;
const ld EPS = 1e-7;

#define bt(i) (1 << (i))
#define int ll

int n, ans;

void solve(int n)
{
	forn(2, i, n)
	{
		if(i*i > n) break;
		if(n % i == 0)
		{
			int m = n;
			while(m % i == 0)
			{
				m /= i;
			}
			if(m % i == 1) ans++;
			if(i != n / i)
			{
				m = n;
				while(m % (n / i) == 0)
				{
					m /= (n / i);
				}
				if(m % (n / i) == 1) ans++;
			}
		}
	}
	ans++;
}

main()
{
	int t;
	cin >> t;
	if(t == 2)
	{
		cout << 1;
		return 0;
	}
	solve(t);
	t--;
	forn(2, i, t)
	{
		if(i*i > t) break;
		if(t % i == 0)
		{
			ans++;
			if(i != t / i) ans++;
		}
	}
	ans++;
	cout << ans;
}

Measured memory_bytes: 256
S = input()
ac = 1
if S[0] != 'A':
    ac = 0
c = 0
for i in range(1,len(S)):
    if 2 <= i <= (len(S) - 2) and S[i] == 'C':
        c += 1
        continue
    if S[i].isupper():
        ac = 0
if c == 1 and ac:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
#define ls int len=s.size()
#define ls1 int len1=s1.size()
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%I64d",&x)
#define reps(i,n) for(int i=1;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=n-1;i>=0;i--)
typedef long long int LL;
typedef long long int ll;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include<stack>
#include<ctime>
void g(int t){if(t){g((t-1)/26);putchar(65+(t-1)%26);}}

string s;

bool judge(){
    ls;
    for(int i=2;i<len;i++){
        if(s[i]!=s[i-1]) return false;
    }
    return true;
}

int main()
{
#ifdef LOCAL
    freopen("data.h", "r", stdin);
    //freopen("1.h","w",stdout);
#endif
    cin>>s;
    if(judge()){
        printf("Second\n");
        return 0;
    }
    ls;
    if(s[0]==s[len-1]) len-=3;
    else len-=2;
    if(len%2) printf("First\n");
    else printf("Second\n");
}


Measured memory_bytes: 512
n,y=map(int,input().split())
for a in range(n+1):
    for b in range(n+1):
        c=n-a-b
        if c<0:
            continue 
        if a*10000+b*5000+c*1000==y:
            print(a,b,c)
            exit()
print('-1 -1 -1')

Measured memory_bytes: 2940
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    std::cin >> N>>M;
    std::vector<int>a(N) ;
    for(int i=0;i<M;i++){
        int x,y;
        std::cin >> x>>y;
        a[x-1]++;a[y-1]++;
    }
    for(int i=0;i<N;i++){
        std::cout << a[i] << std::endl;
    }
}    

Measured memory_bytes: 256
n,m = map(int,input().split())
from collections import defaultdict,deque
l = defaultdict(list)

for i in range(m):
    ta,tb = map(int,input().split())
    ta-=1
    tb -=1
    l[ta].append(tb)
    l[tb].append(ta)
Q = deque()
Q.append([0,0])
dp = [-1]*n
dp[0] = 0
while Q:
    q,p = Q.popleft()
    # print(q,p)
    # print(l[q])
    for i in l[q]:
        # print(i,dp)
        # print(dp[i])
        if dp[i]==-1:
            dp[i] = q
            Q.append([i,p+1])
if -1 in dp:
    print('No')
else:
    print('Yes')
    for i in dp[1:]:
        print(i+1)

Measured memory_bytes: 44056
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//--<for debugging>
#define whatis(x) cout << #x << " is " << x<<" ";
#define whatisl(x) cout << #x << " is " << x<<"\n";
#define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
#define lline cout<<"\n";
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"___";}
    
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a <<" , ";
    err(++it, args...);
}
//--</for debugging> 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define testcase ll tt; cin >> tt; while(tt--)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define vars ll h,i,j,k,d,l,p,q,r,x,y,a,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;
#define vll vector<ll>
#define pll pair<ll,ll>
#define sll set<ll>
#define pint pair<int,int>
const ll INF=1e9+7;
const ll MOD=1e9+7;
int main()
{
    boost vars
    cin>>a>>b>>x;
    v=b/x-a/x;
    if(a%x==0)v++;
    cout<<v;
}

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

int main(){
	int n,k;
	int cost = 0;
	vector<int>v;
	cin >> n >> k;
	for(int i=0;i<n;i++){
		int t;
		cin >> t;
		v.push_back(t);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<k;i++){
		cost+=v[i];
	}
	cout << cost;
}

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

int main(void){
   char a,b;
   cin>>a>>b;
   char ans='D';
   if(a=='H'&&b=='H') ans='H';
   if(a=='D'&&b=='D') ans='H';
   cout<<ans<<endl;
   return 0;
}



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

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

  int L[N];
  int MAX = 0;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> L[i];
    MAX = max(MAX, L[i]);
    sum += L[i];
  }
  int tmp = sum - MAX;
  if (MAX < tmp) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 888
#include<cstdio>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=20;
int n,a[N];
inline long long DFS(CI l,CI r,CI cl,CI cr)
{
	if (r-l+1<=2) return 0; long long ret=1e18;
	for (RI i=l+1;i<r;++i) ret=min(ret,DFS(l,i,cl,cl+cr)+DFS(i,r,cl+cr,cr)+1LL*(cl+cr)*a[i]);
	return ret;
}
signed main()
{
	RI i; for (scanf("%d",&n),i=1;i<=n;++i)
	scanf("%d",&a[i]); return printf("%lld",DFS(1,n,1,1)+a[1]+a[n]),0;
}

Measured memory_bytes: 384
import sys
n = int(input())
l = [int(i)//400 if int(i)//400 <= 7 else 8 for i in input().split()]
multi = l.count(8)
if multi == 0:
    num_cols = len(set(l))
    print(num_cols, num_cols)
    sys.exit()
    
num_cols = len(set(l)) - 1
min_cols = max(1,num_cols)
max_cols = num_cols+multi
print(min_cols, max_cols)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cassert>
#include <vector>
#include <algorithm>
#include <complex>
#include <string>
#include <map>
#include <set>
using namespace std;

int H, W, s, fusoku;
int u[40][40];
int sum[40][40];
const int INF = 100*100*100;
pair<int, int> memo[33][33][33][33];

inline int region_sum(int y, int x, int h, int w) {
  return sum[y+h][x+w] + sum[y][x] - sum[y+h][x] - sum[y][x+w];
}

pair<int, int> calc(int y, int x, int h, int w) {
  if (memo[y][x][h][w].first != -1) { return memo[y][x][h][w]; }
  int rs = region_sum(y, x, h, w);
  if (rs < fusoku) {
    return memo[y][x][h][w] = make_pair(-INF, -INF);
  }
  pair<int, int> ret = make_pair(1, rs);
  for (int i = 1; i < h; ++i) {
    pair<int, int> ret1 = calc(y, x, i, w);
    pair<int, int> ret2 = calc(y+i, x, h-i, w);
    ret = max(ret, make_pair(ret1.first + ret2.first, min(ret1.second, ret2.second)));
  }
  for (int i = 1; i < w; ++i) {
    pair<int, int> ret1 = calc(y, x, h, i);
    pair<int, int> ret2 = calc(y, x+i, h, w-i);
    ret = max(ret, make_pair(ret1.first + ret2.first, min(ret1.second, ret2.second)));
  }
  return memo[y][x][h][w] = ret;
}

int main() {
  while (scanf("%d%d%d", &H, &W, &s), H|W|s) {
    memset(memo, -1, sizeof(memo));
    for (int y = 0; y < H; ++y) {
      for (int x = 0; x < W; ++x) {
        scanf("%d", &u[y][x]);
      }
    }
    memset(sum, 0, sizeof(sum));
    for (int y = 1; y <= H; ++y) {
      for (int x = 1; x <= W; ++x) {
        sum[y][x] = sum[y-1][x] + sum[y][x-1] - sum[y-1][x-1] + u[y-1][x-1];
      }
    }
    fusoku = sum[H][W] - s;
    pair<int, int> ret = calc(0, 0, H, W);
    printf("%d %d\n", ret.first, s - (sum[H][W] - ret.second));
  }
}

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

int main(){
    int x, y;
    while(cin>>x >>y){
        if(x==0 && y==0)break;
        if(x<y){
            cout<<x<<" "<<y<<endl;
        }else{
            cout<<y<<" "<<x<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

LL A, B;
int main() {
	scanf("%lld%lld", &A, &B);
	for (int i = 60; i >= 0; i--) {
		int a = A >> i & 1, b = B >> i & 1;
		if (a ^ b) break;
		if (a && b) A ^= 1ll << i, B ^= 1ll << i;
	}
	LL ans = A == 0;
	for (int i = 60; i >= 0; i--) {
		if (1ll << i > B) continue;
		if (2ll << i <= A) continue;
		if (1ll << i <= A) {
			ans += (2ll << i) - A;
			continue;
		}
		if (2ll << i <= B) {
			ans += 1ll << i;
			continue;
		}
		++ans;
		for (int j = 0; j < i; j++) {
			if ((1ll << i | 1ll << j) <= B) {
				ans += 1ll << j;
				continue;
			}
			if (2ll << j <= A) continue;
			if (1ll << j > A) {
				ans += 1ll << j;
				continue;
			}
			ans += (2ll << j) - A;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
H , N = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
dp = [float('inf')]*(H+1)
dp[0] = 0
#dp[i]:モンスターにiダメージ与えるための最小コスト
for h in range(H):
    for i in range(N):
        #dmgはHを超えてもHとして扱う
        dmg = min(h+ab[i][0],H)
        #costを更新
        dp[dmg] = min(dp[dmg],dp[h]+ab[i][1])
print(dp[H])

Measured memory_bytes: 43612
// वाह मोदी जी वाह!

#include<iostream>
#include<algorithm>
#include<bitset>

#include<cmath>
#include<cstring>
#include<climits>

#include<deque>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>

#include<fstream>
#include<chrono>
using namespace std;

typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second;
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{
    // DANGER;
    ofstream out("output.txt");

    auto start = chrono::high_resolution_clock::now();
    
    string s, t;
    cin>>s>>t;

    LL c = 0;
    rep(i,0,2)
    {
        if( s[i]==t[i] ) c++;
    }
    cout<<c<<endl;
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll a, b, c;
    cin >> a >> b >> c;
    ll odp;
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
        odp = 0;
    else
        odp = min(a * b, min(b * c, c * a));
    cout << odp;
    return 0;
}


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


def solve(X: str):
    stack = deque(X[0])
    for i in range(1, len(X)):
        if not stack:
            stack.append(X[i])
            continue
        if stack[-1] == "T":
            stack.append(X[i])
            continue
        if X[i] == "T":
            stack.pop()
            continue
        stack.append(X[i])

    print(len(stack))


# 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()
    X = next(tokens)  # type: str
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5288
//コンパイラ最適化用
#pragma GCC optimize("O3")
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

signed main(){
    //入力の高速化用のコード
    int X;
    int q = 8;
    int temp = 0;
    cin >> X;
    for(int i = 400; i < 2000; i+=200){
      if((X < i+200) && (X >= i))
        temp = q;
      else 
        q--;
    }

    cout << temp;
}



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

A= list(map(int, input().split()))
B= list(map(int, input().split()))


ans = 0
u = 0
for i in range(N):
    if A[i]>=B[i]:
        ans += B[i]
    else:
        ans += A[i]
        u = A[i+1]
        A[i+1]-=B[i]-A[i]
        if A[i+1]<0:
            A[i+1]=0
        ans += u - A[i+1]

print(ans)


Measured memory_bytes: 81892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
   int k,a,b;
   cin >> k >> a >> b;
   for(int i=1;i<=1000;i++){
        if(a<=i*k&&i*k<=b){
            cout << "OK" << endl;
            return 0;
        } 
   }
   cout << "NG" << endl;
}

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

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

#define pb push_back

const int INF = 100100100;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

int main(){

  set<ll> st1,st2;
  ll n,a;
  ll c,max;

  max = 0;
  cin >> n;
  REP( i, n){
    cin >> a;
    if( max == a){
      ++c;
    }else if( a > max){
      max = a;
      c = 1;
    }
    auto t = st1.insert(a);
    if( !t.second ){
      st2.insert(a);
    }
  }

  if( c >= 4){
    cout << max*max << endl;
    return 0;
  }
  
  if( st2.size() >= 2){
    auto itr = st2.end();
    --itr;
    ll x = *itr;
    --itr;
    ll y = *itr;
    cout << x*y << endl;
  }else{
    cout << 0 << endl;
  }

}




Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main()
{
    int n,i,s=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
	{
        scanf("%d",&a[i]);
        s+=abs(a[i]-a[i-1]);
    }
    s+=abs(a[n]-a[n-1]);
    for(i=0;i<n;i++)
	{
        printf("%d\n",s-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]));
    }
    return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		while (true) {

			int num = sc.nextInt();
			int sum = sc.nextInt();

			if (num == 0 && sum == 0)
				break;

			// ??????????????????????????°??¨????????¶????????????????????????????????°??????????????????????????°
			int cnt = 0;

			for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			}
			System.out.println(cnt);
		}
		sc.close();
	}

}

Measured memory_bytes: 26428