akhauriyash/Code-Regression huggingface dataset:
aoj = True
while aoj:
    h, w = map(int, input().split(" "))
    if h == 0 or w == 0:
        break
    else:
        for i in range(h):
            if i % 2 == 0:
                for j in range(w):
                    if j % 2 == 0:
                        print("#", end="")
                    else:
                        print(".",end="")
                print()
            else:
                for j in range(w):
                    if j % 2 == 0:
                        print(".", end="")
                    else:
                        print("#",end="")
                print()
        print()

Measured memory_bytes: 9080
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par; 
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i; 
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d,e, H, W,L;
long long A[200005] = {};
long long B[200005] = {};
long long C[200005] = {};
long long D[200005] = {};
long long E[200005] = {};
bool f, ff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


bool fs[2005][2005] = {};
char cc[1000000] = {};

int main() {


	cin >>N;
	a = 0;
	b = 0;
	c = 0;
	d = 0;
	
	for (int i = 0; i < N; i++) {
		cin >> cc[i];
		if (cc[i] == 'G') {
			a = 1;
		}
		if (cc[i] == 'W') {
			b = 1;
		}
		if (cc[i] == 'Y') {
			c = 1;
		}
		if (cc[i] == 'P') {
			d = 1;
		}
	}
	
	if (a + b + c + d == 4) {
		cout << "Four" << endl;
	}
	else {
		cout << "Three" << endl;
	}
	
	return 0;

}


Measured memory_bytes: 2304
n=int(input())
a=[input().split() for i in range(n)]
for i in range(n):
  a[i][1]=int(a[i][1])*-1
b=sorted(a)
for i in range(n):
  for j in range(n):
    if a[j][0]==b[i][0]and a[j][1]==b[i][1]:
      print(j+1)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r,c,count;
    r = sc.nextInt();
    c = sc.nextInt();
    int[][] cells = new int[r+1][c+1];
    for(int i=0;i <= r;i++)cells[i][c] = 0;
    for(int j=0;j <= c;j++)cells[r][j] = 0;
    for(int i=0;i < r;i++){
      for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      }
    }
    for(int i=0;i <= r;i++){
      for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      }
      System.out.println("");
    }
    sc.close();
  }
}



Measured memory_bytes: 42540
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include <set>

#define DIV 1000000007
using namespace std;
using ll = long long;


long long mypow(long long k, long long n) {
    long long temp = 1;

    k = k % DIV;
    while (n) {
        if (n % 2) temp = temp * k % DIV;
        k = k * k % DIV;
        n = n / 2;
    }
    return temp % DIV;
}


int main() {
    ll N, M;
    cin >> N >> M;

    map<ll,ll> p;
    ll temp = M;
    ll mx = 0;
    for (ll i = 2; i <= sqrt(M); i++) {
        while (temp % i == 0) {
            temp /= i;
            p[i]++;
        }
        mx = max(mx, p[i]);
    }
    if (temp > 1)p[temp]++;
    mx = max(mx, p[temp]);

    vector<ll> comb(mx + 1);
    comb[0] = 1;
    for (ll i = 0; i < mx; i++) {
        ll kari = ((i + N) * mypow(i + 1, DIV - 2)) % DIV;
        comb[i + 1] = (kari * comb[i])%DIV;
    }

    ll ans = 1;
    for (auto x:p) {
        ans = (ans * comb[x.second])%DIV;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2176
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long LL;
//#pragma comment(linker, "/STACK:102400000,102400000")

int main()
{
    LL a,b,c;
    LL aa,bb,cc;
//    while(1){
//        printf("begin:\n");
    LL cas=0;

    scanf("%lld%lld%lld",&a,&b,&c);
    bool flag=false;
    while(1)
    {
//        printf("%lld:  %lld %lld %lld\n",cas,a,b,c);
        if((a%2) || (b%2) || (c%2)) break;
        if(a==b && b==c){
            flag=true;
            break;
        }
        aa = (b+c)/2;
        bb = (a+c)/2;
        cc = (a+b)/2;
        a = aa;
        b = bb;
        c = cc;
        cas++;
    }
    if(!flag)
        printf("%lld\n",cas);
    else
        puts("-1");
    return 0;
}



Measured memory_bytes: 256
using System;


class AOJ
{

    public static void Main()
    {

        string[] s = Console.ReadLine().Split(' ');
        int mosf = 0, mosl = 0,letternum=0;
        int[] a = new int[s.Length];

        for (int i = 0; i < s.Length; i++)
        {
            a[i] = 0;
        }

            for (int i = 0; i < s.Length; i++)
            {
                for (int j = 0; j < s.Length; j++)
                {
                    if (s[i] == s[j] && i != j)
                    {
                        a[i]++;
                    }
                }
            }

        for (int i = 0; i < s.Length; i++)
        {
            if (a[i] > mosf)
                mosf = i;
        }

        for (int i = 0; i < s.Length; i++)
            {
                if (s[i].Length > letternum)
                {
                    letternum = s[i].Length;
                    mosl = i;
                }
            }

        Console.WriteLine("{0} {1}", s[mosf], s[mosl]);
    }
}

Measured memory_bytes: 5308
#include<bits/stdc++.h>
using namespace std;
bool check(int init[],int goal[],int n){
    for(int i=0;i<n;i++){
        if(init[i]!=goal[i]){
            return false;
        }
    }
    return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  int init[n];
  int goal[n];
  memset(init,0,sizeof(init));
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    goal[i]=x;
  }
  int ans = 0;
  while(true){
    if(check(init,goal,n))break;
    bool start_set = false;
    for(int i=0;i<n;i++){
        if(init[i]<goal[i]){
            init[i]++;
            start_set=true;
        }else{
            if(start_set){
                ans++;
                break;
            }else{
                continue;
            }
        }
        if(i==n-1){
            ans++;
        }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

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

    bool b = false;
    for (int i = 1; i <= 9; ++i){
    	for (int j = 1; j <= 9; ++j){
    		if (i*j == N) b = true;
        }
    }

	cout << (b ? "Yes" : "No") << endl;
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

constexpr ll INF = TEN(18);

int main() {
    int N, K;
    cin >> N >> K;
    V<int> P(N), C(N);
    rep(i, N) cin >> P[i], --P[i];
    rep(i, N) cin >> C[i];

    ll ans = -INF;

    rep(i, N) {
        int v = i;
        ll cycle_sum = 0;
        int cycle_cnt = 0;

        while (true) {
            cycle_cnt++;
            cycle_sum += C[v];
            v = P[v];
            if (v == i) break;
        }

        ll path = 0;
        int cnt = 0;

        while (true) {
            cnt++;
            path += C[v];

            if (cnt > K) break;

            int num = (K - cnt) / cycle_cnt;
            ll score = path + max(0ll, cycle_sum) * num;
            chmax(ans, score);

            v = P[v];
            if (v == i) break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3672
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			int height = sc.nextInt();
			int width = sc.nextInt();

			if(height == 0 && width == 0) {
				break;
			} else {

				for(int i = 0;i < height;i++) {
					for(int j = 0;j < width;j++) {
						if((i + 1) % 2 != 0 && (j + 1) % 2 != 0) {
							System.out.print("#");
						} else  if((i + 1) % 2 != 0 && (j + 1) % 2 == 0){
							System.out.print(".");
						} else if((i + 1) % 2 == 0 && (j + 1) % 2 != 0) {
							System.out.print(".");
						} else {
							System.out.print("#");
						}
					}
					System.out.println();
				}
				System.out.println();

			}

		}
		sc.close();
	}
}

Measured memory_bytes: 36596
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int H,W,N;
  cin >> H >> W >> N;

  vector<int> a(N);
  for(int i = 0;i < N;i++) {
    cin >> a.at(i);
  }

  vector<vector<int>> ans(H,vector<int>(W));

  int num = 0;
  for(int i = 0;i < H;i++) {
    if(i % 2 == 0) {
      for(int j = 0;j < W;j++) {
        ans.at(i).at(j) = num+1;
        a.at(num)--;
        if(a.at(num) == 0) num++;
      }
    }else {
      for(int j = W-1;j >= 0;j--) {
        ans.at(i).at(j) = num+1;
        a.at(num)--;
        if(a.at(num) == 0) num++;
      }
    }
  }

  for(int i = 0;i < H;i++) {
    for(int j = 0;j < W;j++) {
      cout << ans.at(i).at(j) << " ";
    }
    cout << endl;
  }
  

}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  cin >> S;
  if(S.at(5)=='0'){
    if(S.at(6)=='4' || S.at(6)=='3' || S.at(6)=='2' || S.at(6)=='1')
      cout << "Heisei" << endl;
    else 
      cout << "TBD" << endl;
  }
  if(S.at(5)=='1')
    cout << "TBD" << endl;
}

    
  

Measured memory_bytes: 384
from sys import stdin
import sys, math

n,m = [int(x) for x in stdin.readline().rstrip().split()]
h = [int(x) for x in stdin.readline().rstrip().split()]

c = [1 for x in range(n)]
for i in range(m):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]

    if h[a-1] >= h[b-1]: c[b - 1] = 0
    if h[a-1] <= h[b-1]: c[a - 1] = 0

print(sum(c))





Measured memory_bytes: 20088
n=int(input())
A=[]

for i in range(n):
    X=list(map(str,input().split()))
    X[0]=int(X[0])
    X[1]=int(X[1])
    X[3]=int(X[3])
    A.append(X)

A=sorted(A)
for i in range(n):
    print(str(A[i][0])+" "+str(A[i][1])+" "+A[i][2]+" "+str(A[i][3])+" "+A[i][4])



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

#define MAXN 100010

int n,a[MAXN],d[MAXN];
vector<int> edge[MAXN];

long long dfs(int u,int fa)
{
	if(d[u]==1)return a[u];
	long long sum=2*a[u];
	for(auto v : edge[u])
	{
		if(v==fa)continue;
		long long res=dfs(v,u);
		if(res>a[u]){puts("NO");exit(0);}
		sum-=res;
	}
	if(sum<0 || sum>a[u]){puts("NO");exit(0);}
	return sum;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	if(n==1)
	{
		puts(a[1]?"NO":"YES");
		exit(0);
	}
	if(n==2)
	{
		puts(a[1]==a[2]?"YES":"NO");
		exit(0);
	}
	for(int i=1;i<n;++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
		++d[u];
		++d[v];
	}
	for(int i=1;i<=n;++i)
	{
		if(d[i]>1)
		{
			puts(dfs(i,0)?"NO":"YES");
			exit(0);
		}
	}
}

Measured memory_bytes: 11776
/* ex 9_2
   kanon */

#include <stdio.h>
#include <stdlib.h>

//リストのノード（スタック内の各データ）の定義
typedef struct node
{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem)
{
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if (new == NULL)
        exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first)
{
    char elem;
    node *tmp = *first;
    if (tmp == NULL)
        exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void)
{
    int ans = 0;
    char input_char, temp;

    //最初のノードの指す先
    node *first = NULL;

    while (1)
    {
        scanf("%c", &input_char);
        //最後の文字まで来たら終了
        if (input_char == '\n')
            break;
        //スタックに比較する対象がなければ文字をスタックに入れるだけ
        if (first == NULL)
        {
            push(&first, input_char);
            continue;
        }
        //現在のスタックの一番上を取り出す
        temp = pop(&first);

        //もし文字が一致していれば新しい文字を追加
        if (input_char == temp)
        {
            //スタックにノードを追加
            push(&first, temp);
            push(&first, input_char);
        }
        else
            //一致していなければansに除去した分加える
            ans += 2;
    }

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


Measured memory_bytes: 4732
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Solve(int N, int[] S)
        {
            var T = S.Where(s => s % 10 != 0);
            int sum = S.Sum();
            return (sum % 10 != 0) ? sum
                 : (T.Count() > 0) ? sum - T.Min()
                                   : 0;
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            int[] S = new int[N];
            for (int i = 0; i < N; ++i) { S[i] = ReadInt(); }
            Console.WriteLine(Solve(N, S));
        }
    }
}


Measured memory_bytes: 13396
#! env/bin/local python3
# -*- coding: utf-8 -*-

import math

a, b = map(int, input().split())

result = -1
for i in reversed(range(0, 1250)):
    if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b:
        result = i
print(result)


Measured memory_bytes: 2940
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<list>
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a,b) memset(a,b,sizeof(a))
#define ll rt<<1
#define rr rt<<1|1
#define mid int m=(x+((y-x)>>1))
#define lson x,m,rt<<1
#define rson m+1,y,rt<<1|1
#define lowbit(x) (x&-x)
#define PB push_back
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define fi freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
using namespace std;

const int N = 3e5 + 10;
const int inf = 1e9;
priority_queue<LL>que1;
priority_queue<LL, vector<LL>, greater<LL> > que2;
LL sum1[N], sum2[N], a[N];
int n;
int main()
{
#ifndef ONLINE_JUDGE

#endif

	SC(n);
	FF(i, 1, 3*n)
	{
		scanf("%lld", &a[i]);
	}
	FF(i, 1, n){
		que2.push(a[i]);
		sum1[n] += a[i];
	}
	//PR(que2.top());
	FF(i, n+1, 2*n)
	{
		sum1[i] = sum1[i-1];
		que2.push(a[i]);	sum1[i] += a[i];
		sum1[i] -= que2.top();	que2.pop();
	}
	RR(i, 3*n, 2*n+1){
		que1.push(a[i]);
		sum2[2*n+1] += a[i];
	}
	RR(i, 2*n, n+1)
	{
		sum2[i] = sum2[i+1];
		que1.push(a[i]);	sum2[i] += a[i];
		sum2[i] -= que1.top();	que1.pop();
	}
	///
	LL ans = -1e18;
	FF(i, n, 2*n)
	{
		LL cur = sum1[i] - sum2[i+1];
		ans = max(ans, cur);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 8820
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long a,b,c,d,flag=0;
  cin>>a>>b>>c>>d;
  while(a>0&&c>0)
  {
    if(flag==0)
      c=c-b;
    if(flag==1)
      a=a-d;
    flag=flag^1;
  }
  if(a>0)
    cout<<"Yes";
  else
    cout<<"No";
}

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

#define forn(i, n) for(int i = 0; i < (int)n; ++i)

int main()
{
	int n, m, x, y;
	cin >> n >> m >> x >> y;

	vector<int> v(n), w(m);
	forn(i, n) cin >> v[i];
	forn(i, m) cin >> w[i];

	sort(v.begin(), v.end());
	sort(w.begin(), w.end());

	bool flag_1 = v[v.size()-1] < w[0];
	bool flag_2 = (v[v.size()-1] >= x) && (w[0] <= y);

	if(flag_1 && flag_2) cout << "No War" << "\n";
	else cout << "War" << "\n";

	return 0;
}

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

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

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

struct Edge {
  ll u, v, w;
  Edge () {}
  Edge (ll u, ll v, ll w): u(u), v(v), w(w) {}
};

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  ll n, m, p;
  cin >> n >> m >> p;
  vector <Edge> edge;
  vector <vector <int>> G(n + 1), RG(n + 1);
  for (int i = 0; i < m; i++) {
    ll u, v, w;
    cin >> u >> v >> w;
    edge.emplace_back(u, v, p - w);
    G[u].pb(v);
    RG[v].pb(u);
  }
  const ll INF = 1e12;
  auto bfs = [&] (const vector <vector <int>>& g, int s, vector <bool>& vis) {
    vis[s] = true;
    queue <int> Q;
    Q.push(s);
    while (not Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int v: g[u]) {
        if (not vis[v]) {
          vis[v] = true;
          Q.push(v);
        }
      }
    } 
  };
  vector <bool> vis1(n + 1, false);
  vector <bool> vis2(n + 1, false);
  bfs(G, 1, vis1);
  bfs(RG, n, vis2);
  for (int i = 0; i < m; i++) {
    if (vis1[edge[i].u] and vis2[edge[i].v]) continue;
    edge[i].w = INF;
  }
  bool can = true;
  auto bellmand = [&] (vector <ll>& dis) {
    fill(all(dis), INF);
    dis[1] = 0;
    for (int it = 0; it + 1 < n; it++) {
      for (int i = 0; i < m; i++) {
        if (edge[i].w == INF) continue;
        dis[edge[i].v] = min(dis[edge[i].v], dis[edge[i].u] + edge[i].w);
      }
    }
    for (int i = 0; i < m; i++) {
      if (dis[edge[i].v] == INF or dis[edge[i].u] == INF) continue;    
      if (dis[edge[i].v] > dis[edge[i].u] + edge[i].w) {
        can = false;
      }
    }
  };
  vector <ll> dis(n + 1);
  bellmand(dis);
  if (not can) cout << -1 << '\n';
  else cout << max(0LL, -dis[n]) << '\n';
  return (0);
}


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

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

    int result = 0;
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    for (int i = 0; i < K; i++)
    {
        result += A[i];
    }
    cout << result << endl;
}

Measured memory_bytes: 256
use itertools::Itertools as _;
use proconio::{input, marker::Usize1};

fn main() {
    input! {
        n: usize,
        m: usize,
        h: [i32; n],
        d: [[Usize1;2]; m],
    }

    let mut good_n = vec![true; n];

    for v in d.into_iter() {
        // eprintln!();
        // eprintln!("{:?}", h);
        // eprintln!("{:?}", v);
        // eprintln!("{:?}", good_n);
        if h[v[0]] >= h[v[1]] {
            good_n[v[1]] = false;
        }
        if h[v[0]] <= h[v[1]] {
            good_n[v[0]] = false;
        }
        // eprintln!("{:?}", good_n);
    }

    // //before
    // let before = d.iter().filter(|b| b[0] == now).map(|b| b[1]);
    // //after
    // let after = d.iter().filter(|a| a[1] == now).map(|a| a[0]);
    // //combine
    // let max = before
    //     .chain(after)
    //     .map(|target| h[target])
    //     .max()
    //     .unwrap_or(0);
    // if h[now] > max {
    //     ans += 1;
    // }

    println!("{}", good_n.into_iter().filter(|b| *b).count());
}


Measured memory_bytes: 10160
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
string S[100];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> S[i];
  }

  int a_num = 0;
  int un_num = 0;
  for(int i = N - 1; i >= 0; i--){
    if(S[i] == "A"){
      a_num ++;
    } else {
      un_num ++;
    }

    if(a_num > un_num){
      cout << "NO" << endl;
      return 0;
    }
  }

  if(a_num != un_num){
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iomanip>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.0000000001;

int main() {
    int n, m;
    cin >> n >> m;
    map<int, multiset<int>> t;
    vector<pair<int, int>> ab(n);
    for (int i = 0; i < n; i++) cin >> ab[i].first >> ab[i].second;
    for (auto e:ab) t[e.first].insert(e.second);
    sort(ab.begin(), ab.end());
    priority_queue<int> q;
    int s = 0;
    for (int i = 1; i <= m; i++) {
        for (auto e:t[i]) q.push(e);
        if (!q.empty()) {
            s += q.top();
            q.pop();
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 15740
#include <vector>
#include <iostream>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;

int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int h,w,c;
void fill_map(int x,int y,vvi &map,int from,int to){
	map[x][y]=to;
	for(int i=0;i<4;i++){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx>=0&&nx<w&&ny>=0&&ny<h){
			if(map[nx][ny]==from){
				fill_map(nx,ny,map,from,to);
			}
		}
	}
}
int search(int n,vvi &map){
	if(n==5){
		if(map[0][0]!=c)return 0;
		fill_map(0,0,map,map[0][0],7);
		int ret=0;
		for(int i=0;i<w;i++){
			for(int j=0;j<h;j++){
				if(map[i][j]==7){
					ret++;
				}
			}
		}
		return ret;
	}
	int best=0;
	for(int i=1;i<=6;++i){
		if(map[0][0]==i)continue;
		vvi new_map(map);
		fill_map(0,0,new_map,map[0][0],i);
		best=max(best,search(n+1,new_map));
	}
	return best;
}
int main(){
	while(cin>>h>>w>>c,h){
		vvi map(w,vi(h,0));
		for(int i=0;i<h;++i){
			for(int j=0;j<w;++j){
				cin>>map[j][i];
			}
		}
		cout<<search(0,map)<<endl;
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a += b;
	a %= MOD;
}

ll l[225816],r[225816],c[410410];
vector<ll> v;

int main(void){
	int n,i;
	ll t,ans=0ll;
	cin >> n >> t;
	v.push_back(0ll);
	for(i=0; i<n; ++i){
		cin >> l[i];
		r[i] = l[i]+t;
		v.push_back(l[i]);
		v.push_back(r[i]);
	}
	sort(v.begin(),v.end());
	for(i=0; i<n; ++i){
		++c[(int)(lower_bound(v.begin(),v.end(),l[i])-v.begin())];
		--c[(int)(lower_bound(v.begin(),v.end(),r[i])-v.begin())];
	}
	for(i=0; i<n*2; ++i){
		if(c[i]){
			ans += (v[i+1]-v[i]);
		}
		c[i+1] += c[i]; 
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10732
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        sc.close();

        boolean flag = true;
        while (a > 0 && c > 0) {
            if (flag) {
                flag = false;
                c -= b;
            } else {
                flag = true;
                a -= d;
            }
        }

        if (c <= 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 27048
using System;

namespace ABC127 {
	class Program {
		static void Main (string[] args) {
			// 入力
			int A, B;
			int[] array = Array.ConvertAll (Console.ReadLine ().Split (' '), int.Parse);
			A = array[0];
			B = array[1];
			// 処理・出力
			if (A <= 5) {
				Console.WriteLine (0);
			} else if (A <= 12) {
				Console.WriteLine (B / 2);
			} else {
				Console.WriteLine (B);
			}
		}
	}
}

Measured memory_bytes: 13140
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	/**
	 *AOJテァツ板ィテ」ツδ療」ツδュテ」ツつクテ」ツつァテ」ツつッテ」ツδ?
	 */
	public static void main(String[] args) {
		// TODO ティツ?ェテ・ツ仰陛ァツ板淌ヲツ按静」ツ?陛」ツつ古」ツ?淌」ツδ。テ」ツつステ」ツδε」ツδ嘉」ツδサテ」ツつケテ」ツつソテ」ツδ?
		Scanner scan = new Scanner(System.in);
		int n = 0;
		int sum = 0;
		while (true) {
			n = scan.nextInt();
			if(n == 0)	break;
			int s[] = new int[n];
			for (int i = 0; i < n; i++) {
				s[i] = scan.nextInt();
			}
			Arrays.sort(s);
			sum = 0;
			for (int i = 1; i < n - 1; i++) {
				sum += s[i];
			}
			System.out.println((int)Math.ceil(sum / (n - 2)));
			Arrays.fill(s, 0);
		}

	}

}

Measured memory_bytes: 20932
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, N) for (int i=0; i<(int)N; i++)
#define rep1(i, N) for (int i=1; i<(int)N; i++)

using namespace std;

int N;

int main() {
  cin >> N;
  cout << floor((N+1)/2);
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


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

int main()
{
	string str;
	cin >> str;
	if(str.size() < 3){
		cout << "NO" << endl;
		return 0;
	}
	
	REP(i,str.size()-1){
		if(str[i] == 'A' && str[i+1] == 'A'){
			cout << "NO" << endl;
			return 0;
		}
	}
	bool flag = false;
	REP(i,str.size()-2){
		if(str[i] == 'K' && str[i+1] == 'I' && str[i+2] == 'H')flag = true;
	}
	
	
	string tmp = "";
	
	REP(i,str.size()){
		if(str[i] != 'A'){
			tmp += str[i];
		}
	}
	
	if(tmp == "KIHBR" && flag){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

const int MOD=1000000007;

int inv(int a,int p){
  if(p==0)return 1;
  int c=inv(a,p/2);
  int s=c*1LL*c%MOD;
  return (p&1)?s*1LL*a%MOD:s;
}

int comb(int n,int k){
  if(k<0||n<k)return 0;
  int num=1,den=1;
  for(int i=0;i<k;i++){
    num=(num*1LL*(n-i))%MOD;
    den=(den*1LL*(k-i))%MOD;
  }
  return num*1LL*inv(den,MOD-2)%MOD;
}

int main(){
  int N,M,K;
  cin>>N>>M>>K;
  int ans=0;
  for(int i=0;i<=K;i++){
    ans=(ans+comb(N+M+2*K,N+2*i)*1LL*((comb(N+2*i,i)-comb(N+2*i,i-1)+MOD)%MOD)%MOD*((comb(M+2*(K-i),K-i)-comb(M+2*(K-i),K-i-1)+MOD)%MOD)%MOD)%MOD;
  }
  cout<<ans<<endl;
}

    

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define LL long long
#define db double

using namespace std;
const int N=1e5+10,mod=1e9+7;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
void ad(int &x,int y){x+=y,x-=x>=mod?mod:0;}
char cc[N];
int n,k,f[N],c[3];

int main()
{
/////////ghdhdjfjhfjkghjgk
	scanf("%s",cc+1),n=strlen(cc+1);
	bool fg=1;
	for(int i=1;i<n;++i) fg&=cc[i]!=cc[i+1];
	if(fg){puts("1");exit(0);}
	f[0]=1;
	c[1]=c[2]=-1;
	for(int i=1;i<=n;++i)
	{
		k+=cc[i]-'a'+1,k%=3;
		if(!k&&i<n) f[i]=1;
		if(c[(k+1)%3]>=0) ad(f[i],f[c[(k+1)%3]]);
		if(c[(k+2)%3]>=0) ad(f[i],f[c[(k+2)%3]]);
		c[k]=i;
	}
	/*c[1]=c[2]=-1,f[0]=f[1]=1,s[0]=0,s[1]=cc[1]=='a'?1:2;
	k=1;
	while(k<n&&cc[k]!=cc[k+1]) ++k;
	for(int i=2,j=-1;i<=n;++i)
	{
		if(i<=k){f[i]=1;continue;}
		f[i]=f[i-1];
		s[i]=(s[i-1]+(cc[i]=='a'?1:2))%3;
		if(cc[i-1]==cc[i])
			while(j+1<i-1) ++j,itt(j);
		if(cc[i]=='a')
			if(c[(s[i]-2+3)%3]>=0) ad(f[i],g[c[(s[i]-2+3)%3]]);
		if(cc[i]=='b')
			if(c[(s[i]-1+3)%3]>=0) ad(f[i],g[c[(s[i]-1+3)%3]]);
		ad(f[i],z[(s[i]-1+3)%3]),ad(f[i],z[(s[i]-2+3)%3]);
		if(cc[i-1]==cc[i])
			while(j<i-1) ++j,itt(j);
		if(i>k+1&&j==k&&(bool)((s[i]-s[k]+3)%3)) ad(f[i],mod-f[k]);
		g[i]=f[i];
	}*/
	printf("%d\n",f[n]);
	return 0;
}


Measured memory_bytes: 768
#include<stdio.h>

int main(void)
{
	int a,b,i,j;
	scanf("%d %d",&a,&b);
	while(1)
	{
	 if(a == 0 && b == 0)
	 {
		 break;
	 }
	 for(i = 0;i < a;i++)
	 {
		 for(j = 1;j <= b;j++)
		 {
			 if((j == 1 || j == b) || (i == 0 || i == a-1))
			 {
				printf("#");
			 }
			 else
			 {
				 printf(".");
			 }
		 }
		 printf("\n");
	 }
	 printf("\n");
	 scanf("%d %d",&a,&b);
	}
	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s = "ACL";
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) cout << s;
    puts("");
    return 0;
}

Measured memory_bytes: 3572
import numpy as np
import itertools
def resolve():
    n,m = map(int,input().split())
    ss = []
    for i in range(m):
        k, *s = map(int, input().split())
        ss.append(s)
    p = list(map(int,input().split()))
    ans = 0
    for s_pattern in itertools.product(range(0,2),repeat=n):
        light_bool = []
        for light_num, each_s in enumerate(ss):
            ssum = 0
            for num in each_s: ssum += s_pattern[num-1]
            light_bool.append(ssum % 2 == p[light_num])
        if all(light_bool):
            ans+=1
    print(ans)

resolve()

Measured memory_bytes: 12512
#include<bits/stdc++.h>
typedef long long ll;
#define vll vector<long long> 
#define pll pair<ll,ll>
#define f(i,a,b) for(long long i=a;i<b;i++)
#define F first
#define S second
#define pb(i) push_back(i)
#define mp(x,y) make_pair(x,y)
#define all(v)  (v).begin(),(v).end()
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll n,m,a,b,ans;vll v[100005],vis(100005,0),dp(100005,0);

void dfs(ll src){
	vis[src]=true;
	ll d = 0;
	f(i,0,v[src].size()){
		ll cur = v[src][i];
		if(vis[cur]==0){
			dfs(cur);
		}
		dp[src] = max(dp[src],1+dp[cur]);
	}
}

int main(){
	FIO;cin>>n>>m;
	while(m--){
		cin>>a>>b;
		v[a].pb(b);
	}
	f(i,1,n+1){
		if(vis[i]==0) dfs(i);
	}
	f(i,1,n+1) ans = max(ans,dp[i]);
	cout<<ans<<"\n"; 
}

Measured memory_bytes: 12320
# 0: black, 1: white
s = gets.strip

def chkmin(a, b) a < b ? a : b end

b2w = 0
w2b = 0

s.split('').each_with_index do |c, i|
  if i.even?
    if c == '1'
      b2w += 1
    else
      w2b += 1
    end
  else
    if c == '0'
      b2w += 1
    else
      w2b += 1
    end
  end
end

puts chkmin(b2w, w2b)

  


Measured memory_bytes: 9468
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(s,n) for(int i=s;i<n;i++)
#define inf 10000000000 //1e10
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
const int MAXN = 110,MAXS=100100;

int32_t main(){
    fastio;
    string a,b;
    cin >> a >> b;
    int na = a.size(),nb = b.size();
    int tab[na+1][nb+1];
    for(int i=0;i<=na;i++)
        tab[i][0]=0;
    for(int i=0;i<=nb;i++)
        tab[0][i]=0;
    for(int i=1;i<=na;i++){
        for(int j=1;j<=nb;j++){
            if(a[i-1]==b[j-1]){
                tab[i][j]=tab[i-1][j-1]+1;
            }
            else tab[i][j]=max(tab[i-1][j],tab[i][j-1]);
        }
    }
    string resp = "";
    int at = tab[na][nb];
    int i = na,j=nb;
    while(at){
        while(tab[i][j]==tab[i][j-1]){
            j--;
        }
        while(tab[i][j]==tab[i-1][j]){
            i--;
        }
        resp+=a[i-1];
        i--;
        j--;
        at = tab[i][j];
    }
	reverse(resp.begin(),resp.end());
    cout << resp << endl;
}

Measured memory_bytes: 70656
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(usize, usize); n],
    }
    let mut ab = ab;
    ab.sort_by_key(|row| row.0);

    let mut v = Vec::with_capacity(n);
    let mut index = 0;
    let mut total = 0;
    for remains in 1..m + 1 {
        while index < n && ab[index].0 <= remains {
            let b = ab[index].1;
            let j = match v.binary_search(&b) {
                Ok(j) => j,
                Err(j) => j,
            };
            v.insert(j, b);
            index += 1;
        }
        if let Some(b) = v.pop() {
            total += b;
        }
    }
    println!("{}", total);
}


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

/// --- Union Find Library {{{ ///

struct UF {
  int n;
  vector<int> par, rank;
  UF(int n): n(n), par(n, -1), rank(n, 0) {}
  int find(int x) {
    return par[x] < 0 ? x : par[x] = find(par[x]);
  }
  int size(int x) {
    return -par[find(x)];
  }
  bool same(int a, int b) {
    return find(a) == find(b);
  }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if(a == b) return;
    if(rank[a] > rank[b]) swap(a, b);
    par[b] += par[a];
    par[a] = b;
    if(rank[a] == rank[b]) rank[b]++;
  }
};

/// }}}--- ///

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m, k; cin >> n >> m >> k;
  vector<int> c(n);
  for(int &e : c) cin >> e;
  vector<tuple<int, int, int>> g;
  for(int i = 0; i < m; i++) {
    int a, b, w; cin >> a >> b >> w;
    a--; b--;
    g.emplace_back(w, a, b);
    if(c[a]) g.emplace_back(0, a, n + c[a]);
    if(c[b]) g.emplace_back(0, b, n + c[b]);
  }
  sort(begin(g), end(g));
  UF uf(n + k + 10);
  ll ans = 0, cnt = 0;
  for(auto e : g) {
    int w, a, b;
    tie(w, a, b) = e;
    if(uf.same(a, b)) continue;
    uf.unite(a, b);
    if(w) cnt++, ans += w;
    if(cnt == k - 1) return(cout << ans << endl, 0);
  }
  cout << -1 << endl;
}


Measured memory_bytes: 8432
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
const long long INF = 1LL << 60;


int main(){
    int n;
    cin >> n;
    int num = 1000 - (n % 1000);
    if(num == 1000) num = 0;
    cout << num << endl;
    return 0;
}


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

#define endl '\n'
#define PB push_back
#define PF push_front
#define MP make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

int main(){
    ios_base::sync_with_stdio(false); //cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> v(n);
    ll sum = 0;
    for (auto& a : v) {
        cin >> a;
        sum += a;
    }

    ll ans = 0;
    for (size_t i = 0; i < v.size(); i++) {
        sum -= v[i];
        ans = (ans + ((v[i] % INF) * (sum % INF)) % INF) % INF;
    }
    cout << ans;
    return 0;
} 


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

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

typedef unsigned long long ullong;

ullong power(ullong x, ullong n, ullong M) {
    ullong res = 1;
    if (n > 0) {
        res = power(x, n / 2, M);
        if (n % 2 == 0) res = (res * res) % M;
        else res = (((res * res) % M) * x) % M;
    }
    return res;
}

main() {
    int m, n;
    cin >> m >> n;

    cout << power(m, n, 1000000007) << endl;

    return 0;
}


Measured memory_bytes: 3092
N=int(input())
data=[input().split() for i in range(N)]

data=[{"city":data[i][0],"score":int(data[i][1]),"number":i+1} for i in range(N)]

data.sort(key=lambda x: x['score'],reverse=True)
data.sort(key=lambda x: x['city'])


for i in [i["number"] for i in data]:
    print(i)


Measured memory_bytes: 3060
import numpy as np

n=int(input())
a = np.array(list(map(int, input().split())))
ans = np.array([0]*n)
c=0
while (a>0).any():
    ama = a%2
    a=(a-ama)//2

    if sum(ama)%2==1:
        ama = (ama+1)%2
    ans += ama*(2**c)
    c+=1

ans=ans.tolist()    
print(*ans)

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

int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        vector<int> a(n+1),vis(n+1);    
        for(int i=1;i<=n;i++) a[i]=0,vis[i]=false;
        int x,y;
        bool flag=true;
        if(n>1) a[1]=1;
        for(int i=1;i<=m;i++)
        {
            cin>>x>>y;
            if(vis[x]==true and a[x]!=y)
                flag=false;
            else{
                a[x]=y; 
                vis[x]=true;
            }
        }
        if(n!=1 and a[1]==0) flag=false;
        if(flag)
            for(int i=1;i<=n;i++)
                cout<<a[i];
        else
            cout<<-1;       
        cout<<endl;
    }
    return 0;
}


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

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

int main() {
  int r,d,x2000,ans;
  cin >> r >> d >> x2000;
  ans = x2000;
  for (int i = 0; i < 10; i++) {
    ans = r * ans - d;
    cout << ans << endl;
  }
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

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

#define MAX 100005
#define INF 1001001001

vector<int> seg;
int segwidth;

void init(int n) {
  segwidth = 1;
  while (segwidth < n) segwidth <<= 1;
  seg.assign(segwidth*2-1, INT_MAX);
}

void update(int i, int x) {
  int k = i+segwidth-1;
  seg[k] = x;
  while (k > 0) {
    k = (k-1)/2;
    seg[k] = min(seg[k*2+1], seg[k*2+2]);
  }
}

int find(int s, int t, int k, int l, int r) {
  if (r <= s || t <= l) return INT_MAX;
  if (s <= l && r <= t) return seg[k];
  int vl = find(s,t,k*2+1,l,(l+r)/2);
  int vr = find(s,t,k*2+2,(l+r)/2,r);
  return min(vl,vr);
}

int find (int s, int t) {
  return find(s, t, 0, 0, segwidth);
}

int main(int, char**)
{
  int n, q;
  cin >> n >> q;
  init(n);

  vector<int> ans;
  rep(i,q) {
    int command;
    cin >> command;
    if (command == 0) {
      int x, y;
      cin >> x >> y;
      update(x,y);
    } else {
      int x, y;
      cin >> x >> y;
      ans.push_back(find(x,y+1));
    }
  }
  for (auto a : ans) cout << a << endl;

  return 0;
}



Measured memory_bytes: 4232
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
typedef unsigned long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/***********************************************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n; cin >> n;
  int k; cin >> k;
  string s; cin >> s;
  int d = 1;
  for (int i = 1; i < n; ++i) {
    if (s[i] != s[i - 1]) ++d;
  }
  while (d > 2 && k > 0) {
    k--;
    d -= 2;
  }
  if (d <= 2) {
    if (k > 0) d = 1;
  }
  kek(n - d);
}


Measured memory_bytes: 512
use proconio::input;


fn pow(a: u64, b: u64) -> u64 {
  let m = 1_000_000_007u64;
  if b == 0  { return 1; }
  if b % 2 == 1 {
    return a * pow(a, b-1) % m;
  } else {
    let r = pow(a, b/2);
    return r * r % m;
  }
}

fn main() {
  input! {
    n: u64, 
    k: usize,
  }
  let m = 1_000_000_007u64;
  let mut v = vec![0; k+1];
  let mut res: u64 = 0;

  for i in (1..=k).rev(){
    v[i] = pow((k / i) as u64, n);
    let mut j = i * 2;
    while j <= k {
      v[i] = (v[i] + m - v[j]) % m;
      j += i;
    }
    res += v[i] * i as u64 % m;
    res %= m;
  }
  println!("{}", res);
}

Measured memory_bytes: 2768
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    for (int i = 0; i < s.length(); i++) {
      if (i % 2 == 0) {
        System.out.print(s.charAt(i));
      }
    }
    System.out.println();
  }
}

Measured memory_bytes: 31360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

	string S, T; cin >> S >> T;
	cout << T << S << endl;
}

Measured memory_bytes: 256