akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>


void print_array(int A[], int N)
{
    int i;

    for(i = 0; i < N - 1; i++)
        printf("%d ", A[i]);

    printf("%d", A[N - 1]);
    printf("\n");

}


void insertionSort(int A[], int N)
{
    int i;

    for(i = 1; i < N; i++){
        int v = A[i];
        int j = i - 1;

        print_array(A, N);

        while(j >= 0 && A[j] > v){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
    }
    print_array(A, N);
}

int main(void)
{
    int N, i;
    int A[1001];

    scanf("%d", &N);


    for(i = 0; i < N; i++){
        scanf("%d", A + i);
    }

    insertionSort(A, N);

    return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;
int main(){
    lli k,n;
    cin>>k>>n;
    lli A[n];
    for(lli i = 0; i<n; i++){
        cin>>A[i];
    }
    lli max_dist = k - A[n-1] + A[0];
    for(lli i = 0; i<n-1; i++){
        max_dist = max(max_dist, A[i+1]-A[i]);
    }
    cout<<k-max_dist;
    return 0;
}

Measured memory_bytes: 1792
def main():
    l,r = map(int,input().split())
    if r-l+1 >= 2*2019:
        print(0)
        return
    min_val = float('inf')
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            min_val = min(min_val,(i*j)%2019)

    print(min_val)


main()


Measured memory_bytes: 2940
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = [LIST() for i in range(N-1)]
graph = defaultdict(list)

for u, v, w in L:
    graph[u-1].append((v-1, w))
    graph[v-1].append((u-1, w))

color = [0] * N
visited = [False] * N

q = deque([0])
visited[0] = True
color[0] = 1

while q:
    a = q.pop()
    for node, w in graph[a]:
        if visited[node] == True:
            continue
        if w % 2 == 0:
            color[node] = color[a]
        else:
            color[node] = -1 * color[a]
        visited[node] = True
        q.append(node)
print(*[0 if c == 1 else 1 for c in color])



Measured memory_bytes: 70184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const int INF = 1000000000; // 10^9
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int S,W;
    cin >> S >> W;
    if(S <= W){
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }

}


Measured memory_bytes: 3636
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] x = new int[4];
    int[] y = new int[4];
    for(int j = 0; j < 2; j++){
      x[j] = sc.nextInt();
      y[j] = sc.nextInt();
    }
    for(int j = 2; j < 4; j++){
      x[j] = x[j -1] - (y[j -1] - y[j -2]);
      y[j] = y[j -1] + (x[j -1] - x[j -2]);
    }
    System.out.print(x[2] + " ");
    System.out.print(y[2] + " ");
    System.out.print(x[3] + " ");
    System.out.println(y[3]);
  }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <utility>

typedef long long ll;
typedef unsigned long long ull;

#define vi std::vector<int>
#define vl std::vector<ll>
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;

int main()
{
    double D, T, S;
    std::cin >> D >> T >> S;

    if(D/S <= T)
    {
        print("Yes");
    }

    else
    {
        print("No");
    }

    return 0;
}

Measured memory_bytes: 3724
#n=int(input())
k,n=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

difl=[]

for i in range(n-1):
    difl.append(al[i+1]-al[i])
difl.append(al[0]+k-al[n-1])

print(k-max(difl))

Measured memory_bytes: 26444
#include<stdio.h>

int main(void){
	long long n,a[131072],r,i,c,d,s;
	scanf("%lld",&n);
	for(i = 1;i <= n;i++){scanf("%lld",&a[i]);}
	s=0;c=0;
	for(i = 1;i <= n;i++){
		s+=a[i];
		if(i%2 == 1 && s <= 0){c+=(1-s);s=1;}
		if(i%2 == 0 && s >= 0){c+=(s-(-1));s=-1;}
	}
	s=0;d=0;
	for(i = 1;i <= n;i++){
		s+=a[i];
		if(i%2 == 1 && s >= 0){d+=(s-(-1));s=-1;}
		if(i%2 == 0 && s <= 0){d+=(1-s);s=1;}
	}
	if(c<d){printf("%lld\n",c);}else{printf("%lld\n",d);}
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) a = b;
  return a > b;
}
template<class T> inline bool chmax(T&a, T b) {
  if (a < b) a = b;
  return a < b;
}
// まともなにんげんなこのようなこーどをかいてはいけない
signed main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) cin >> p[i];
  vector<int> p1 = p, p2 = p;
  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < N; i++) {
    if (i == 0 && p1[i] > p1[i+1]) {
      ans1 += p1[i+1]*2;
      p1[i] -= p1[i+1];
      p1[i+1] = 0;
      ans1 += p1[i];
    } else if (i == N-1) {
      ans1 += p1[i];
    } else {
      ans1 += p1[i]*2;
      p1[i+1] = max(0LL, p1[i+1]-p1[i]);
    } 
    p1[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      ans2 += p2[i];
    } else if (i == N-1) {
      ans2 += p2[i];
    } else {
      ans2 += p2[i]*2;
      p2[i+1] = max(0LL, p2[i+1]-p2[i]);
    } 
    p2[i] = 0;
  }
  cout << min(ans1,ans2) << endl; 
}



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

using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a))
#define mp make_pair
#define All(a) (a).begin(), (a).end()
template <typename T=long long>
inline T IN(){T x; cin>>x; return(x);}
inline void CIN(){}
template <class Head,class... Tail>
inline void CIN(Head&& head,Tail&&... tail){
    cin>>head;
    CIN(move(tail)...);
}
#define CINT(...) int __VA_ARGS__;CIN(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CIN(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CIN(__VA_ARGS__)
 
typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int,V,greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int N,Q,K;
const int NMAX=1e5;
struct edge{int to; ll cost;};
vector<vector<edge>> G(NMAX);
vector<ll> d(NMAX); 

int main(){
    cin>>N;
    REP(i,N-1){
        CINT(a,b,c);
        G[--a].push_back({--b,c});
        G[b].push_back({a,c});
    }
    cin>>Q>>K;
    d.assign(N+1,LINF);
    d[--K]=0;
    priority_queue<PL, vector<PL>, greater<PL>>gq;
    gq.push({d[K],K});
    while(!gq.empty()){
        PL target=gq.top(); gq.pop();
        ll dt=target.first, t=target.second;
        if(d[t]<dt) continue;
        REP(i,G[t].size()){
            edge e=G[t][i];
            if(d[e.to]>d[t]+e.cost){
                d[e.to]=d[t]+e.cost;
                gq.push({d[e.to],e.to});
            }
        }
    }
    REP(i,Q){
        CINT(x,y);
        cout<<(d[--x]+d[--y])<<"\n";
    }
    return 0;
}

Measured memory_bytes: 11104
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>

using namespace std;

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node*)malloc(sizeof(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 == NIL) {
		return;
	}
	inOrder(u->left);
	printf(" %d", u->key);
	inOrder(u->right);
}

void preOrder(Node* u)
{
	if (u == NIL) {
		return;
	}
	printf(" %d", u->key);
	preOrder(u->left);
	preOrder(u->right);
}

bool find(Node* root, int k)
{
	while (root != NIL) {
		if (root->key == k) {
			return true;
		}else if (k < root->key) {
			root = root->left;
		}else {
			root = root->right;
		}
	}
	return false;
}


int main(int argc, char *argv[]) {
	int n, i, x;
	string com;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++) {
		cin >> com;
		if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}else if (com == "print") {
			inOrder(root);
			printf("\n");
			preOrder(root);
			printf("\n");
		}else if (com == "find") {
			scanf("%d", &x);
			if (find(root, x)) {
				printf("yes\n");
			}else {
				printf("no\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 22048
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
long long M  = 1e9+7;
 
 
signed main(){
    fast;
    int n,m; cin >> n >> m;
    int ans = n*(n-1)/2 + m*(m-1)/2;
    cout << ans << endl;
}


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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N, K, ans=0, tmp1=0, tmp2=0, sum1=0, sum2=0;
vector<ll> A, S, L, R, SS;

signed main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    S.resize(N, 0);
    SS.resize(N, 0);
    L.resize(N, 0);
    R.resize(N, 0);
    S[0] = A[0];
    for(int i=1;i<N;i++) {
        S[i] = S[i-1]+A[i];
    }
    SS[0] = S[K-1];
    for(int i=1;i<=N-K;i++) {
        SS[i] = S[i+K-1]-S[i-1];
    }
    for(int i=1;i<N;i++) {
        L[i] = L[i-1]+max(0LL, A[i-1]);
        //cout << L[i] << endl;
    }
    //cout << endl;
    for(int i=1;i<N;i++) {
        R[N-i-1] = R[N-i]+max(0LL, A[N-i]);
        //cout << R[N-i-1] << endl;
    }
    //cout << endl;
    for(int i=0;i<=N-K;i++) {
        ans = max(ans, L[i]+R[i+K-1]+max(0LL, SS[i]));
        //cout << SS[i] << endl;
        //cout << L[i] << " " << R[i+K-1] << " " << max(0LL, SS[i]) << " " << ans << endl;
    }
    //cout << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7192
from itertools import * 
n = int(input())
L = list(map(int,input().split()))
p = list(combinations(L, 3))

ans = 0
for i,j,k in p:
    if i != j and j != k and k != i:
        if i + j > k  and j + k > i and k + i > j:
            ans += 1
print(ans)

Measured memory_bytes: 20628
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
  
 char s[10];
 scanf("%s", s);
 sort(s, s + 4);
 printf((s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) ? "Yes\n" : "No\n");
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

const ll MOD = (ll)(1e9 + 7);

const int MAX_N = 105;
ll dp[MAX_N][4][4][4];

bool check1(int a, int b, int c) {
  bool ok = true;
  if (a == 0 && b == 1 && c == 2) ok = false;
  if (a == 1 && b == 0 && c == 2) ok = false;
  if (a == 0 && b == 2 && c == 1) ok = false;
  return ok;
}

int main2() {
  int N; cin >> N;

  CLR(dp, 0);

  REP(a, 4) REP(b, 4) REP(c, 4) {
    if (check1(a, b, c))
      dp[3][a][b][c] = 1;
  }

  for (int i = 3; i <= N; i++) {
    REP(a, 4) REP(b, 4) REP(c, 4) REP(d, 4) {
      bool ok = check1(b, c, d);
      if (a == 0 && c == 1 && d == 2) ok = false;
      if (a == 0 && b == 1 && d == 2) ok = false;
      if (ok)
        (dp[i+1][b][c][d] += dp[i][a][b][c]) %= MOD;
    }
  }

  ll ans = 0;
  REP(a, 4) REP(b, 4) REP(c, 4) {
    ans += dp[N][a][b][c];
  }
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include  <stdio.h>
#include  <algorithm>
#include  <math.h>
#include  <vector>
#include  <string>
#include  <sstream>
#include  <numeric>
#include  <set>
#include <map>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long

using namespace std;

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

	int num = 0;
	while (cin >> num && num != 0)
	{
		vector<vector<int>> gem(22, vector<int>(22, 0));
		rep(i, num)
		{
			int tmp[2] = { 0 };
			cin >> tmp[0] >> tmp[1];
			gem[tmp[0]][tmp[1]] = 1;
		}
		int num2 = 0;  cin >> num2;
		int x = 10, y = 10, ans = 0;
		rep(i, num2)
		{
			char dir = 0; int m = 0;
			cin >> dir >> m;
			rep(j, m)
			{
				switch (dir)
				{
				case 'N': y++; break;
				case 'E': x++;  break;
				case 'S': y--;  break;
				case 'W': x--;  break;
				}
				num -= gem[x][y];
				gem[x][y] = 0;
			}
		}
		if (num == 0) { printf("Yes\n"); }
		else { printf("No\n"); }
	}
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> vec(H, vector<char>(W));
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> vec.at(i).at(j);
    }
  }
  for(int j=0; j<W; j++){
    for(int i=0; i<H; i++){
      if(vec.at(i).at(j)=='.'){
        if(i==H-1){
          for(int i=0; i<H; i++){
            vec.at(i).at(j)='+';
          }
        }
      }
      else{
        break;
      }
    }
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(vec.at(i).at(j)=='.'||vec.at(i).at(j)=='+'){
        if(j==W-1){
          for(int j=0; j<W; j++){
            vec.at(i).at(j)='-';
          }
        }
      }
      else{
        break;
      }
    }
  }

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(vec.at(i).at(j)=='-'){
        if(j==W-1){
          
        }
      }
      else{
        if(vec.at(i).at(j)!='+'){
          cout << vec.at(i).at(j);
        }
        if(j==W-1){
          cout << endl;
        }
      }
    }
  }
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(a,b,c) for(int i=a;i<b;i+=c)  
typedef pair<ll , pair<ll, ll> > pi;
int pow(int x,int y){
    int res=1;
    while(y){
        if(y&1) res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}   
struct Compare {
    constexpr bool operator()(pi const & a,
                              pi const & b) const noexcept
    { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }
 
};
void prefix_function( string s,ll arr[] )
{
     long long border=0; arr[0]=0;
    for(long long i=1;i<s.size();i++)
    {
      while(border>0 && s[i]!=s[border])
        border=arr[border-1];
     
     if(s[i]==s[border])
         border++;
      else
       border=0;
      
      arr[i]=border;
    }
}
ll mod=998244353;
ll add( ll a , ll b)
{
    return (((a%mod)+(b%mod))%mod);
}
ll mul(ll a,ll b)
{
  return (((a%mod)*(b%mod))%mod);
}
//send mod-2 for a^-1 if mod is a prime number
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}
ll dsu_arr[100000];
ll dsu_sz[100000];
void dsu(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        dsu_arr[i]=i;
        dsu_sz[i]=1;
    }
}
ll find(ll x)
{
     ll root=x;
    while (root!=dsu_arr[root])
    {
        root=dsu_arr[root];
    }
    while(x!=dsu_arr[x])
    {
        dsu_arr[x]=root;
        x=dsu_arr[x];
    }
    return root;
}
ll merge(ll x,ll y)
{
    ll root1=find(x);
    ll root2=find(y);
    
    if(root1==root2)
    return 0ll;
 
    if(dsu_sz[x]>dsu_sz[y]){
    dsu_arr[root2]=root1;
    dsu_sz[x]+=dsu_sz[y];
    }
    else
    {
         dsu_sz[y]+=dsu_sz[x];
        dsu_arr[root1]=root2;
    }
    return 1ll;
}


int main()
{
string s;
cin>>s;
ll ans=0;
for(ll i=0;i<s.size();i++)
{
    ll cou=1;
    if(s[i]=='R')
    {
        while(s[i]==s[i+1] && i+1<s.size())
        {
            cou++;
            i++;
        }
        ans=max(ans,cou);
    }
}
cout<<ans<<endl;

}



   
      
    
        



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

bool is_uruu(int x){
    return x%400==0||(x%4==0&&x%100!=0);
}
int main(){
    int a,b;
    bool flag=false;
    while(cin>>a>>b,a||b){
        if(flag)cout<<endl;
        else flag=true;

        bool latte=false;
        for(int i=a;i<=b;i++){
            if(is_uruu(i)){
                latte=true;
                cout<<i<<endl;
            }
        }
        if(!latte)cout<<"NA"<<endl;

    }
    return 0;
}

Measured memory_bytes: 1160
#define M 99999
T[M],t[M];main(i,j,m,a,b,p,q){
for(i=2;i<M;i++)if(!T[i])for(j=i*2;j<M;j+=i)T[j]=1;
for(i=2,j=1;i<M;i++)if(!T[i])t[j++]=i;
for(;scanf("%d%d%d",&m,&a,&b),m;printf("%d %d\n",p,q))for(i=1;;i++)if(t[i]*t[i]>m)i=0,m--;else if(!T[q=m/t[i]]&&(p=t[i])*q==m&&a*q<=b*p)break;
exit(0);}

Measured memory_bytes: 1028
#include <stdio.h>

int main(){
  int N;
  int T[110] = {};
  int M;
  int P[110] = {};
  int X[110] = {};

  scanf("%d", &N);
  for(int i = 1; i <= N; i++){
    scanf("%d", &T[i]);
  }

  scanf("%d", &M);
  for(int i = 1; i <= M; i++){
    scanf("%d %d", &P[i], &X[i]);
  }

  for(int i = 1; i <= M; i++){

    int T_tot = 0;
    for(int j = 1; j <= N; j++){
      if(j == P[i]){
        T_tot += X[i];
      }else{
        T_tot += T[j];
      }
    }

    printf("%d\n", T_tot);
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    int A[N];
    rep(i,N) {
        cin >> A[i];
    }
    int ans=A[0];
    rep(i,N){
        ans=__gcd(ans,A[i]);
    }

    cout << ans << endl;



}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>//"geometry.cpp"
#include<iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
#include<queue>
#include<string>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<algorithm>//"lower_bound(it,it,v)", "next_permutation(a,a+n)"
#include<functional>//"greater<T>" Ex. sort(a,a+n,greater<int>());
#include<cmath>//"abs", "sqrt"
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
#define is insert
typedef pair<int,int> pii;//Add other types in the same way.

int main(){
	int n;
	long long dt,t[200000];
	cin>>n>>dt;
	for(int i=0;i<n;++i){
		cin>>t[i];
	}
	if(n==1){
		cout<<dt<<endl;
	}else{
		long long ans=dt;
		for(int i=0;i<n-1;++i){
			if(t[i+1]-t[i]<dt){
				ans+=t[i+1]-t[i];
			}else{
				ans+=dt;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1792
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int a, b;
	cin >> a >> b;
	cout << a * b / __gcd(a, b) << "\n";
}



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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vp;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define out(n) cout << (n) << endl;
#define vut(v) rep(i, v.size()) out(v[i]);

int main() {
	ios::sync_with_stdio(false);
  
  int n, m, d[100001] = {0};
  cin >> n >> m;

  int a, b;
  rep(i, 0, m) {
    cin >> a >> b;
    d[a]++, d[b]++;
  }

  rep(i, 0, n + 1) {
    if(d[i] & 1) {
      out("NO")
      return 0;
    }
  }

  out("YES")
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    int ans = 0;
    rep(i,n)rep(j,i){
        ans += a[i]*a[j];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#if 0
date +%Y.%m.%d
 
ABC 被这题调自闭了。。。
一个不容易错的稳妥做法是先根据反边 dfs 出哪些点能到终点，
然后只考虑这些点，一旦有正环就可以直接输 -1 了。
另外有正环的条件是入队次数大于 n 而不是更新次数大于 n ，这里卡了好久。
还有直接用 Bellman-Ford 是不对的，对于局部正环处理不当，还是得先 dfs 需要的点。
举个 hack 例子：
3 4 0
1 3 -100
3 2 -100
2 1 -100
2 2 1
#endif
#include <cstdio>
#include <queue>
#include <cassert>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;
inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 2505, maxm = 10005;
int head[maxn], nxt[maxm], to[maxm], val[maxm], hp;
int head2[maxn], nxt2[maxm], to2[maxm], hp2;
lolong dis[maxn];
int cnt[maxn];
bool fuck[maxn];
bool inq[maxn];

void dfs(int u) {
	// debug("fuck %d\n", u);
	fuck[u] = true;
	for(int i = head2[u]; i; i = nxt2[i])
		if(not fuck[to2[i]])
			dfs(to2[i]);
}

int main() {
	int n = input(), m = input(), p = input();
	for(int i = 1; i <= m; i++) {
		int u = input(), v = input(), w = input() - p;
		nxt[++ hp] = head[u];
		head[u] = hp;
		to[hp] = v;
		val[hp] = w;
		nxt2[++ hp2] = head2[v];
		head2[v] = hp2;
		to2[hp2] = u;
	}
	dfs(n);
	std::queue<int> q;
	q.push(1);
	for(int i = 2; i <= n; i ++)
		dis[i] = - 1000000000000ll;
	while(not q.empty()) {
		int u = q.front();
		q.pop();
		inq[u] = false;
		// debug("%d: %lld\n", u, dis[u]);
		cnt[u] ++;
		if(cnt[u] > n) {
			// assert(false);
			// FIXME
			debug("FUCK\n");
			puts("-1");
			return 0;
		}
		for(int i = head[u]; i; i = nxt[i])
			if(fuck[to[i]] and dis[u] + val[i] > dis[to[i]]) {
				dis[to[i]] = dis[u] + val[i];
				if(not inq[to[i]]) {
					q.push(to[i]);
					inq[to[i]] = true;
				}
			}
	}
	printf("%lld\n", std::max(dis[n], 0ll));
}

Measured memory_bytes: 384
n,m = map(int,raw_input().split())
a = {}
for i in xrange(m):
	step = int(raw_input())
	a[step] = 1
dp = [1]*(n+1)
mod = 10**9+7
for i in xrange(1,n+1):
	if i in a:
		dp[i] = 0
	elif i == 1:
		dp[i] = 1
	else:
		dp[i] = dp[i-1] + dp[i-2]
print dp[n]%mod

Measured memory_bytes: 459652
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)

int main(){
  ll a,b,c,n,h,w;
  cin >>  h>> w;
  cin >> a >> b;
  cout << (h-a)*(w-b) << endl;
}


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

const long long MOD = (1e9)+7;
long long factorial(long long key) {
	long long ans=1;
	do {
		ans *= key;
		ans %= MOD;
	}while(--key);
	return ans%MOD;
}
int main() {
	long long n,m;
	cin>>n>>m;
	if (m<n) {
		long long t=m; m=n; n=t;
	}
	// n<=m
	if (n + 1 == m) {
		long long ans=factorial(n)*factorial(m);
		cout<<ans%MOD<<endl;
	}
	else if (n==m) {
		long long ans=factorial(n)*factorial(m)*2;
		cout<<ans%MOD<<endl;
	}
	else {
		cout<<"0"<<endl;
	}
	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main(){
    int n; cin >> n;
    int t,a; cin >> t >> a;
    vector<int> h(n);
    double mi = 1e9;
    int ans = 0;
    rep(i,n){
        cin >> h[i];
        double num = t - h[i]*0.006;
        num = abs(a-num);
        if(num < mi){
            mi = num;
            ans = i+1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
#include <bitset>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <assert.h>
using namespace std;
#define e exp(1.0)
typedef long long ll;
#define MAXN 2005
#define mod 998244353
#define INF 0x3f3f3f3f3f3f3f
#define fe(i,st,en) for(i = (st);i <= (en);++i)
#define fne(i,st,en) for(i = (st);i < (en);++i)
#define ri register int
#define db double
struct node {
	string s;
	int score, id;
	friend bool operator<(const node& a, const node& b) {
		if(a.s != b.s) return a.s > b.s;
		if(a.score != b.score) return a.score < b.score;
		return a.id > b.id;
	}
};
priority_queue<node> q;
int main() {
	int n, score;
	cin >> n;
	ri i;
	string s;
	fe(i, 1, n) cin >> s >> score, q.push(node{ s,score,i });
	while (!q.empty()) {
		node t = q.top();
		q.pop();
		cout << t.id << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 1;

void solve(){
    int H, W, K;
    cin >> H >> W >> K;
    --K;
    ll dp[H + 1][W + 1] = {};
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            for (int bit = 0; bit < 1<<(W-1); ++bit) {
                bool ok = true;
                for (int k = 0; k < W-2; ++k) {
                    if ((bit & (1<<k)) && (bit & (1<<(k+1)))){
                        ok = false;
                    }
                }

                if (!ok) continue;
                int nj = j;
                if (bit & (1<<j)) nj = j+1;
                else if (j > 0 && (bit & (1<<(j-1)))) nj = j-1;
                dp[i+1][nj] += dp[i][j];
                dp[i+1][nj] %= MOD;
            }
        }
    }
    cout << dp[H][K] << '\n';

    return;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  string s;
  cin >> s;

  int n = s.size() + 1;

  vector<int> l(n), r(n), v(n);
  for (int i = 0; i < n; i++) {
    if (s[i] == '<') {
      l[i + 1] = l[i] + 1;
    }
  }

  for (int i = n - 2; i >= 0; i--) {
    if (s[i] == '>') {
      r[i] = r[i + 1] + 1;
    }
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += max(l[i], r[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6684
import java.util.Scanner;
 
class Main {
	public static void main(String[] args) {
 
	    Scanner sc = new Scanner(System.in);
	    
	    double A = sc.nextDouble(); // 辺
	    double B = sc.nextDouble(); // 辺
	    double H = sc.nextDouble(); // 時
	    double M = sc.nextDouble(); // 分
	    
	    double angle = 0;  // 角度
	    double h = (H * 30) + (M * 0.5);
	    double s = M * 6;
	    if (h > s) {
	      angle = h - s;
	    } else if (h < s) {
	      angle = s - h;
	    }
	    
	    // 残りの辺の長さ
	    double side = Math.sqrt(Math.pow(A,2)+Math.pow(B,2)-2*A*B*Math.cos(Math.toRadians(angle)));

	    System.out.println(side);
	    
	  }
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		var d = ria();
		H = d[0]; W = d[1];
		for(int i=0;i<H;i++){
			var s = rs();
			Console.WriteLine(s);
			Console.WriteLine(s);
		}
	}
	int H,W;
	public Sol(){
		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#include <stdio.h>

#define N 100

void display(int data[], int n);
void bubbleSort(int data[], int n);
void insertionSort(int data[], int n);

int main(){
	
	//??????
	int data[N];
	
	//??其?????即?????属
	int i, n;
	
	//????卒???属?????\???
	scanf("%d", &n);
	
	
	//??????????????\???
	for(i=0; i<n; i++){
		
		scanf("%d", &data[i]);
		
	}
	
	bubbleSort(data, n);
	
	return 0;
	
}



//?????????????卒???????????????????
void display(int data[], int n){
	
	int i;
	
	for(i=0; i<n; i++){
		if(i>0){
			printf(" ");
		}
		printf("%d", data[i]);
	}
	
	printf("\n");
	
	return;
}



//??????????????????
void bubbleSort(int data[], int n){
	
	int i, j, temp;
	int count = 0;
	
	for(i=0; i<n; i++){
		
		for(j=n-1; j>i; j--){
			
			if(data[j] < data[j-1]){
				
				temp = data[j];
				data[j] = data[j-1];
				data[j-1] = temp;
				
				//?????属????即????
				count++;
				
			}
			
		}
		
		//???????????其????????????
		//display(data, n);
		
	}
	
	
	//??????
	display(data, n);
	
	//???????????属?????????
	printf("%d\n", count);
	
	return;
}



//?????\?????????
void insertionSort(int data[], int n){
	
	int i, j, temp;
	
	for(i=1; i<n; i++){
		
		j = i;
		temp = data[j];
		
		while(j>0 && temp < data[j-1]){
			
			data[j] = data[j-1];
			j--;
			
		}
		data[j] = temp;
		
		//???????????其????????????
		//display(data, n);
	}
	
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
      //#define ll long long
      using namespace std;
      #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
      #define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
      #define ll long long
      #define pb push_back
      #define pll pair<ll,ll>
      #define ff first
      #define ss second
     
      #define N 2000001
      #define M 998244353
      #define INF 1000000000000000
      std::vector<ll> v;

int main()
{
  SPEED;
 ll t;
 t=1;

 while(t-->0)
 {
    char c;
    cin>>c;
    if(c-'a'<0)
    {
      cout<<"A"<<endl;
    } 
    else
      cout<<"a"<<endl;
 }

}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, m;
int s[5], c[5];

bool check(int x) {
	vector<int> xs;
	
	if (x == 0) {
		xs.push_back(0);
	}
	else {
		while (x > 0) {
			xs.push_back(x % 10);
			x /= 10;
		}
	}
	
	if (xs.size() != n) return false;
	
	int i;
	rep(i, m) {
		if (xs[n - s[i]] != c[i]) return false;
	}
	return true;
}

int main() {
	int i;
	
	cin >> n >> m;
	rep(i, m) { cin >> s[i] >> c[i]; }
	
	rep(i, 1000) {
		if (check(i)) { cout << i << endl; return 0; }
	}
	
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main()
{
    int N;
    float x;
    string s;
    cin >> N;
    float ans = 0.0;
    REP(i, N)
    {
        cin >> x >> s;
        if (s == "JPY")
            ans += x;
        else
            ans += x * 380000.0;
    }

    cout << ans;
}

Measured memory_bytes: 256
n=int(input())
s=input()
w=s.count('W')
r=s.count('R')

ans=10**9
if w==0 or r==0:
  print(0)
  exit(0)

left_white, right_red=0,r
for i in range(n):
  if s[i]=='W':
    left_white+=1
  else:
    right_red-=1
  ans=min(ans,max(left_white,right_red))
  
print(ans)

Measured memory_bytes: 9416
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;

  ll ans = 0;
  rep(i, N + 1) {
    if (i == 0) continue;
    ans += i * (N - i + 1);
  }

  rep(i, N - 1) {
    ll u, v;
    cin >> u >> v;
    ans -= min(u, v) * (N - max(u, v) + 1);
  }
  ANS;

  return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int a, b, t;
	cin >> a >> b >> t;
	int res = (t / a)*b;
	pv(res)
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define int long long 
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int gcd(int x,int y){
	if(!y)return x;
	return gcd(y,x%y);
}
signed main(){
	n=read();m=read();
	k=gcd(n,m);
	int ans=0;
	for(register int i=2;i*i<=k;i++){
		if(k%i==0){
			ans++;
			while(k%i==0)k/=i;
		}
	}
	if(k!=1)ans++;
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int ans = INF;
  rep(i, n) {
    int a, cnt = 0;
    cin >> a;
    while (a && a%2 == 0) {
      a /= 2;
      cnt++;
    }
    chmin(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

D = lines[0][0]
Inf = 10 ** 10

class Array
  def max_id
    max = - Inf
    tmp = -1
    for i in 1..self.length do
      if self[i-1] > max then
        tmp = i-1
        max = self[i-1]
      end
    end
    return tmp
  end
end

last_date = []
for i in 1..26 do
  last_date.push(0)
end

satis = 0
for i in 1..D do
  max_satis = - Inf
  best_contest = 0
  for k in 1..26 do
    now_satis = 0
    now_satis += lines[i+1][k-1]
    for j in 1..26 do
      if j != k then
        now_satis -= (i - last_date[k-1]) * lines[1][j-1]
      end
    end
    if now_satis > max_satis then
      max_satis = now_satis
      best_contest = k
    end
  end
  satis += lines[i+1][best_contest-1]
  last_date[best_contest-1] = i
  puts best_contest
end

Measured memory_bytes: 14216
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
void Main();
#ifdef ConanYu
#include "local.hpp"
#else
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

const int N = 2e5 + 5;
vector<int> edg[N];
int val[N];

void dfs(int x, int fa) {
  val[x] += val[fa];
  for(auto &y: edg[x]) {
    if(fa != y) {
      dfs(y, x);
    }
  }
}

void Main() {
  int n, q; cin >> n >> q;
  for(int i = 0; i < n - 1; i++) {
    int a, b; cin >> a >> b;
    edg[a].push_back(b);
    edg[b].push_back(a);
  }
  for(int i = 0; i < q; i++) {
    int p, x; cin >> p >> x;
    val[p] += x;
  }
  dfs(1, 0);
  for(int i = 1; i <= n; i++) {
    cout << val[i] << " \n"[i == n];
  }
}


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

int main() {
    size_t h, w;
    cin >> h >> w;
    for ( size_t i = 0; i < w + 2; ++i ) {
        cout << "#"s;
    }
    cout << "\n";
    vector<string> c( h );
    for ( size_t i = 0; i < h; ++i){
        cin >> c.at( i );
        cout << "#"s << c.at( i ) << "#\n"s;
    }
    for ( size_t i = 0; i < w + 2; ++i){
        cout << "#"s;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    bool f[100][100];
    for (int i = 0; i < 100; i++)for (int j = 0; j < 100; j++)f[i][j] = false;
    int n, u, k, v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            f[u - 1][v - 1] = true;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j)cout << " ";
            cout << f[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
/* 
 * Project: AtCoder Beginners Contest 173 A - Payment
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/07/05
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

int n;

void solve() {

    int rem = n%1000;
    if (!rem) {
        printf("%d\n", rem);
        return;
    }
    int rest = 1000 - rem;

    printf("%d\n", rest);

}

int main() {

    scanf("%d", &n);

    solve();

}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define endl '\n'
#define N 10000005
using namespace std;

struct kieuhinh{long x,y,mot,hai;};
kieuhinh hinh[N];
long ds[15],dau[5][5], w,h,n,so1,t,x,y,sohinh;

bool sosanhhinh(kieuhinh a, kieuhinh b){
	if(a.x==b.x) return a.y<b.y;
	return a.x<b.x;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin>>h>>w>>n;
	for(long i=1;i<=n;++i){
		cin>>x>>y;
		for(long j=x-2;j<=x;++j)
			for(long k=y-2;k<=y;++k) if(j>0&&k>0&&j<=h-2&&k<=w-2) hinh[++sohinh]={j,k,x-j,y-k};
	}
	sort(hinh+1,hinh+1+sohinh,sosanhhinh);
	dau[hinh[1].mot][hinh[1].hai]=1;
	for(long i=2;i<=sohinh+1;++i){
		if(hinh[i].x!=hinh[i-1].x||hinh[i].y!=hinh[i-1].y){
			t=0;
			for(int k=0;k<3;++k)
				for(int j=0;j<3;++j){
					t+=dau[k][j];
					dau[k][j]=0;
				}
			++ds[t];
		}
		dau[hinh[i].mot][hinh[i].hai]=1;
	}
	ds[0]=(w-2)*(h-2);
	for(int i=1;i<=9;++i) ds[0]-=ds[i];
	for(int i=0;i<=9;++i) cout<<ds[i]<<endl;
}

Measured memory_bytes: 28928
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    READV(N);
    READV(M);
    string S;
    cin>>S;
    vector<ll> last(N+1,-1);
    set<ll> A;
    FORI(i,0,N+1)
    {
        if(A.find(i-M-1)!=A.end())
        {
            A.erase(A.find(i-M-1));
        }        
        if (sz(A)!=0)
        {
            last[i]=*A.begin();
        }
        if (S[i]=='0')
        {
            A.insert(i);
        }
    }
    vector<ll> ans;
    ll k=N;
    bool ok=true;
    while (k>0)
    {
        if (last[k]<0)
        {
            ok=false;
            break;
        }
        ans.pb(k-last[k]);
        k=last[k];
    }
    if (ok)
    {
        FORD(i,sz(ans)-1,-1)
        {
            cout<<ans[i]<<" ";
        }
        cout<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
    
    
    

    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 3000000000;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    ll x,y;
    cin >> x >> y;
    ll a,b,c,d;
    ll z=0;
    a=max(y-x,z);
    b=max(x+y+1,z);
    c=max(-x-y+1,z);
    d=max(x-y+2,z);
    if(!a)a=INF;
    if(!b)b=INF;
    if(!c)c=INF;
    if(!d)d=INF;
    cout << min({a,b,c,d});
}

/*



 */



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

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, m = mi()
    print((n * (n-1) // 2) + (m * (m-1) // 2))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064