akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define ff(i, a, b) for(int i = (a); (i <= (b)); ++i)
#define FF(i, a, b) for(int i = (a); (i >= (b)); --i)
#define ll long long
#define sz(a) (int)a.size()

struct re {
    int x, y;
    const bool operator < (const re &a) const {
        if (x != a.x) return x < a.x;
        return y < a.y;
    }
};

const ll M = 10000000000000 + 7;
const int N = 310;

int n, m, l;
ll w[N][N];
int a[N][N];

void floyd() {
    ff(k, 1, n)
    ff(i, 1, n)
    ff(j, 1, n)
    w[i][j] = min(w[i][k] + w[k][j], w[i][j]);

    ff(i, 1, n)
    ff(j, 1, n) {
        if (i == j) a[i][j] = 0; else {
            if (w[i][j] <= l) a[i][j] = 1; else a[i][j] = n;
        }
    }

    ff(k, 1, n)
    ff(i, 1, n)
    ff(j, 1, n)
    a[i][j] = min(a[i][k] + a[k][j], a[i][j]);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("", "r" , stdin);
    //freopen("", "w", stdout);
    cin >> n >> m >> l;
    ff(i, 1, n)
    ff(j, 1, n)
    if (i != j) w[i][j] = M;

    ff(i, 1, m) {
        int u, v;
        cin >> u >> v;
        cin >> w[u][v];
        w[v][u] = w[u][v];
    }

    floyd();
    int q;
    cin >> q;
    while (q--) {
        int x, y;
        cin >> x >> y;
        if (a[x][y] == n) cout << -1 << endl; else
        cout << a[x][y] - 1 << endl;
    }
}
//This code belongs to s34vv1nd


Measured memory_bytes: 1664
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
#sort = sorted(a)[::-1] 降順
import math
x, k, d = map(int, input().split())

num = k*d

x = abs(x)
flag = 0

if x >= num:
    print(x - num)
else:
    if x > d:
        j = int(x / d)
    else:
        if x*2 > d:
            j = 1
            flag = 1
        else:
            j = 0

    if j == 0:
        b = x
    elif j == 1 and flag == 1:
        b = d - x
    else:
        b = x % (d*j)
    min = min(b, d - b)
    max = max(b, d - b)
    if min == d - b:
        j += 1

    if (k - j) % 2 == 0:
        print(min)
    else:
        print(max)


Measured memory_bytes: 9212
import sys
H, W, M = map(int, input().split())
h_list, w_list = [0]*H, [0]*W
check = set()
for _ in range(M):
    h, w = map(int, input().split())
    check.add((h-1, w-1))
    h_list[h-1] += 1
    w_list[w-1] += 1
h_max, w_max = max(h_list), max(w_list)
h_bom = [i for i in range(H) if h_list[i]==h_max]
w_bom = [i for i in range(W) if w_list[i]==w_max]
for h in h_bom:
    for w in w_bom:
        if not (h, w) in check:
            print(h_max+w_max)
            sys.exit()
print(h_max+w_max-1)

Measured memory_bytes: 83424
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

bool solve() {
    int N; cin >> N;
    vector<int> a(N);
    rep(i, 0, N) cin >> a[i];
    sort(a.begin(), a.end());
    map<int, int> ma;
    rep(i, 0, N) ma[a[i]]++;
    vector<int> b;
    for(auto p : ma) b.push_back(p.first);
    if(ma.size() == 1 && a[0] == 0) return true;
    if(ma.size() == 2 && a[0] == 0) return ma[0] * 2 == ma[b[1]];
    if(ma.size() != 3) return false;
    for(auto p : ma) if(ma[a[0]] != p.second) return false;
    return (b[0]^b[1]^b[2]) == 0;
}

int main() {
    cout << (solve() ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	return a/(gcd(a,b))*b;
}
ll ans=1;
int main(){
    int n;
    cin>>n;
    ll t;
    for(int i=0;i<n;i++){
      cin>>t;
      ans=lcm(ans,t);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  while(cin >> n >> m && n) {
    map<int,int> ma;
    rep(i,n) {
      int x,y;
      cin >> x >> y;
      if(!ma.count(x)) ma[x]=y;
      else ma[x]=max(ma[x],y);
    }
    int ans=0;
    REP(i,1,m+1) ans+=ma[i];
    pr(ans);
  }
}

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


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

using namespace std;

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.14159265358979323846;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N, W;
int v[110], w[110];
int dp[110][220000];

signed main() {
    cin >> N >> W;
    for (int i = 0; i <= N; i++)for (int j = 0; j < 110000; j++)dp[i][j] = 1e13;
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
        for (int j = 0; j < 110000; j++) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
        }
    }
    int ans = 0;
    for (int i = 0; i < 110000; i++)if (dp[N][i] <= W)ans = max(ans, i);
    cout << ans << endl;
}


Measured memory_bytes: 173440
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    let a = 0
    let w = 0
    let t = 0
    let r = 0
    while(hasNext()){
        let tmp = next()
        if(tmp == "AC") a++
        if(tmp == "WA") w++
        if(tmp == "TLE") t++
        if(tmp == "RE") r++
    }
    console.log(`AC x ${a}`)
    console.log(`WA x ${w}`)
    console.log(`TLE x ${t}`)
    console.log(`RE x ${r}`)

}
Main()


Measured memory_bytes: 37012
// もしかしてすべてのxorが0になれば大丈夫説
package main
import "fmt"
func main(){
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	for i:=0; i<N; i++{
		fmt.Scan(&A[i])
	}
	xor := A[0]
	for i:=1; i<N; i++{
		xor = xor^A[i]
	}
	if xor==0{
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}

Measured memory_bytes: 6312
import java.util.Scanner;

public class Main{
	static Scanner in = new Scanner(System.in);
	   
	static int n;
	static String[] before, after;
	static int m;
	
    public static void main(String[] args) {
    	while (input()) {
    		System.out.println(result());
    	}
    	
	    in.close();
	    return;
    }
    
    static String result() {
    	String input;
    	StringBuilder buf = new StringBuilder();
    	int count = 0;
    	
 	   for (int i = 0; i < m; i ++) {
 		   input = in.next();
 		   count = 0;
 		   for (int j = 0; j < n; j ++) {
 			   if (input.equals(before[j])) {
 				   buf.append(after[j]);
 				   break;
 			   }
 			   count ++;
 		   }
 		   
 		   if (count == n) buf.append(input);
 	   }
 	   
 	   return buf.toString();
    }
    
   static boolean input() {	   
	   n = in.nextInt(); if (n == 0) return false;
	   before = new String[n]; after = new String[n];
	   
	   for (int i = 0; i < n; i ++) {
		   before[i] = in.next();
		   after[i] = in.next();
	   }
	   
	   m = in.nextInt();

	   return true;
   }
}

Measured memory_bytes: 67512
W, H, N = map(int,input().split())
#白い領域の端
l = 0
r = W
u = H
d = 0
for i in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        l = max(x,l)
    elif a == 2:
        r = min(x,r)
    elif a == 3:
        d = max(y,d)
    else:
        u = min(y,u)
print(max((r-l),0)*max((u-d),0))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int A[maxn];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&A[i]);
    for(int i=k+1;i<=n;i++)
        if(A[i]>A[i-k])
            printf("Yes\n");
        else
            printf("No\n");

    return 0;
}

Measured memory_bytes: 4492
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var [nm,arr]= input.trim().split("\n");
arr=arr.split(" ").map(Number);
var cnt = 0;
for(var i=0;i<=1000;i++){
   if(arr.length==0)break;
   if(arr[0] != i+1) {
      arr.pop();
      cnt++;
   }else {
      arr.shift();
   }
}
console.log(cnt);


Measured memory_bytes: 16312
#include<bits/stdc++.h>
using namespace std;
const int N=3005;
char a[N],b[N],c;
int put[N][N],dp[N][N];
void pri(int x,int y){
	if(!x||!y) return;
	if(put[x][y]==1){
		pri(x-1,y-1);
		cout<<a[x];
	}
	else if(put[x][y]==2) pri(x-1,y);
	else pri(x,y-1);
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int la,lb;
	for(la=1;cin.get(c)&&c!='\n';la++) a[la]=c;
	for(lb=1;cin.get(c)&&c!='\n';lb++) b[lb]=c;
	for(int i=1;i<la;i++){
		for(int j=1;j<lb;j++){
			if(a[i]==b[j]){
				dp[i][j]=dp[i-1][j-1]+1;
				put[i][j]=1;
			}
			else if(dp[i-1][j]>=dp[i][j-1]){
				put[i][j]=2;
				dp[i][j]=dp[i-1][j];
			}
			else{
				put[i][j]=3;
				dp[i][j]=dp[i][j-1];
			}
		}
	}
	pri(la-1,lb-1);
	return 0;
}

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

typedef pair<int, int> P;

int main() {
	int N, M, A, B, X[100000] = {};
	bool check = true;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> A >> B;
		A--, B--;
		X[A]++, X[B]++;
		X[A] = X[A] % 2, X[B] = X[B] % 2;
	}
	for (int i = 0; i < N; i++) {
		if (X[i] == 1) check = false;
	}
	if (check) cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 768
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;

// Greatest Common Divisor
ll gcd(ll a, ll b)
{
  while (b != 0) {
    a = a % b;
    std::swap(a, b);
  }
  return a;
}

int main(int argc, char* argv[])
{
  int A, B;
  std::cin >> A >> B;

  std::string judge = "Impossible";
  if ((A+B) % 3 == 0 || (A) % 3 == 0 || (B) % 3 == 0) {
    judge = "Possible";
  }

  std::cout << judge << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int n;
int list[200001];
long long int abs(long long int x) { return x < 0 ? -x : x; }
int main() {
	while (scanf("%d", &n) != EOF) {
		long long int sum = 0;
		for (int i = 0; i < n; i++) {
			scanf("%d", &list[i]);
			sum += list[i];
		}
		long long int sumi = 0;
		long long int ans = 1e18;
		for (int i = 0; i < n - 1; i++) {
			sumi += list[i];
			long long int tmp = abs(sum - 2 * sumi);
			if (tmp < ans)  ans = tmp;
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 896
k,n = map(int, input().split())
a = [int(x.strip()) for x in input().split()]
min_dist = k
for i in range(n):
  if i != 0 and i != n-1:
    dist_r = a[i-1] + (k - a[i])
    dist_l = a[i] + (k - a[i+1])
    if min_dist > min(dist_r,dist_l):
      min_dist = min(dist_r,dist_l)
  elif i == 0:
    dist_r = a[n-1] - a[i]
    dist_l = a[i] + (k - a[i+1])
    min_dist0 = min(dist_r,dist_l)
  else:
    dist_r = a[i-1] + (k - a[i])
    dist_l = a[i] - a[0]
    min_distn = min(dist_r,dist_l)
ans = min(min_dist,min_dist0,min_distn)
print(ans) 

Measured memory_bytes: 33584
k = int(input())

s = 0
c = 1

for i in range(1000000):
    s = (s * 10 + 7) % k
    
    if s % k != 0:
        c = c + 1
    else:
        break

if c > i+1:
    print('-1')
else:
    print(c)


Measured memory_bytes: 9184
#pragma once
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const ll MAX = 210000;
const ll MOD = 1000000007;

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string & S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
const ll ainf = 998244353;

struct cell {
	int x, y;
	int deep;
	cell(int x, int y, int deep) : x(x), y(y), deep(deep) {}
};

int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
ll ca(ll v) {
	if (v % 4 == 0) return v;
	if (v % 4 == 1) return 1;
	if (v % 4 == 2) return v + 1;
	return 0;
}
void solv() {

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

	ll av = ca(max(a - 1LL,0LL));
	ll bv = ca(b);
	cout << (bv ^ av) << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 256
using System;

class Cicle
{
    public static void Main()
    {
        String[] s = Console.ReadLine().Split();
        int W = int.Parse(s[0]);
        int H = int.Parse(s[1]);
        int x = int.Parse(s[2]);
        int y = int.Parse(s[3]);
        int r = int.Parse(s[4]);

        int left = x - r;
        int right = x + r;

        int top = y + r;
        int bottom = y - r;

        if(0 <= left && right <= W && 0 <= bottom && top <= H)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 8996
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<utility>
using namespace std;

struct shi{
  int x;
  int y;
  int z;
};


int main(){
int N,M;
cin>>N>>M;
shi P[M];
for(int i=0;i<M;i++){
  int a,b;
  cin>>a>>b;
  P[i].x=a;
  P[i].y=b;
  P[i].z=i;
}
 
sort(P,P+M,[](const shi& a,const shi& b){if(a.x==b.x) return a.y < b.y; else return a.x < b.x;});

int count[N+1]={};
int simo[M];
for(int i=0;i<M;i++){
  count[P[i].x]++;
  simo[P[i].z]=count[P[i].x];
}
sort(P,P+M,[](const shi& a,const shi&b){return a.z <b.z;});
for(int i=0;i<M;i++){
cout<<setfill('0')<<setw(6)<<P[i].x<<setfill('0')<<setw(6)<<simo[i]<<endl;
}
return 0;
}






Measured memory_bytes: 3456
n = int(input())
t = [int(input()) for _ in range (n)]

def gcd(a, b):
    while b:
        a,b = b,a%b
    return a

def lcm(a, b):
    return a*b // gcd(a,b)

time = t[0]
for i in range(1, n):
    time = lcm(max(time,t[i]),min(time,t[i]))
print(time)



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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N;
  cin >> N;
  if(N == 1){
    cout << "Hello World" << endl;
  } else { 
    int a,b;
    cin >> a >> b;
    cout << a + b << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    while(1)
    {
        int n,x,i,j,k,s=0;
        scanf("%d %d",&n,&x);
        if(n==0 && x==0) break;

        for(i=1;i<=n;i++)
        {
            for(j=i+1;j<=n;j++)
            {
                for(k=j+1;k<=n;k++)
                {
                    if((i+j+k)==x) s++;
                }
            }
        }

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

    }
}



Measured memory_bytes: 2728
#if 0

#endif
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <queue>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define INF (1 << 30)
using namespace std;
using ll = long long;
string S;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> S;
    int blue,red;
    blue = red = 0;
    for (auto s : S) {
        if (s == '0') {
            ++blue;
        } else {
            ++red;
        }
    } 
    cout << min(red, blue) * 2 << endl;

    return 0;
}

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

int main()
{

    int N;
    cin >> N;
    //    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<vector<int>::value_type>());

    int64_t total = 0;
    for (int i = 0; i < N; i++)
    {
        total += a[i];
    }
    for (int i = 0; i < N; i++)
    {
        if (total % 10 == 0)
        {
            total -= a[N - i];
            if (total % 10 == 0)
            {
                total += a[N - i];
            }
            else
            {
                cout << total << endl;
                return 0;
            }
        }
        else
        {
            cout << total << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m=1000000000;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int j=-100;j<=100;j++){
    int c=0;
    for(int i=0;i<n;i++){
      c+=pow((a[i]-j),2);
    }
    m=min(m,c);
  }
  cout<<m<<endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int d[] = new int[N];
		for (int i=0; i<N; i++) {
			d[i] = sc.nextInt(); 
		}
		Integer num[] = new Integer[101];
		Arrays.fill(num,  0);
		for (int i=0; i<N; i++) {
			num[d[i]]++; 
		}
		int count = 0;
		for (int i=0; i<=100; i++) {
			if (num[i]>0 ) count++;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60ll;
const ll MINF = -1 * (1ll << 60ll);
struct Edge { ll to, from, cost; };

ll E, V;
Edge es[2005];

void bellman_ford(int s, ll d[]) {
    
    for (int j = 0; j < V - 1; j++) {
        for (int i = 0; i < E; i++) {
            Edge e = es[i];

            if (d[e.to] < d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
}

int main() {
    ll d[1005];
    ll tmp[1005];
    
    cin >> V >> E;
    for (int i = 0; i < E; i++) {
        cin >> es[i].from >> es[i].to >> es[i].cost;
    }

    for (int i = 0; i <= V; i++) {
        d[i] = MINF;
    }

    d[1] = 0;
    bellman_ford(1, d);

    for (int i = 0; i <= V; i++) {
        tmp[i] = d[i];
    }

    bellman_ford(1, tmp);

    if (tmp[V] > d[V]) {
        cout << "inf" << endl;
    }
    else {
        cout << d[V] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;

int main(){
	int n, a;
	cin >> n;
	cin >> a;
	cout << n*n-a <<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N; cin >> N;
  if (N > 888) cout << 999 << endl;
  else if (N > 777) cout << 888 << endl;
  else if (N > 666) cout << 777 << endl;
  else if (N > 555) cout << 666 << endl;
  else if (N > 444) cout << 555 << endl;
  else if (N > 333) cout << 444 << endl;
  else if (N > 222) cout << 333 << endl;
  else if (N > 111) cout << 222 << endl;
  else cout << 111 << endl;
  return 0;
}

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

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

using ll = long long;
using P = pair<int, int>;

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

  ll a1, a2, b = 0, tmp;
  cin >> a1 >> a2;
  rep(i,n-2) {
    cin >> tmp; b ^= tmp;
  }

  ll msk = 1, mskb = 0;
  ll ans = 0;
  for (;b^a1^a2;msk <<= 1) {
    if ((b&msk) != ((a1^a2)&msk)) {
      mskb = msk>>1;
      if (!mskb || a1 <= mskb || (a1&mskb) != (a2&mskb)) {
        cout << -1 << endl;
        return 0;
      }
      a1 -= mskb;
      a2 += mskb;
      ans += mskb;
    }
  }
  for(msk = mskb; msk; msk >>= 1) {
    if (!(a1&msk) && (a2&msk)) ans -= msk;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll a, b;
  cin >> a >> b;
  cout << a / __gcd(a, b) * b << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 256
from itertools import combinations

N, M, X = map(int, input().split())
books = []
for _ in range(N):
	C, *l = map(int, input().split())
	books.append((C, l))

best = None
for bs in range(1, 2 ** N):
	lev = [0] * M
	pri = 0
	for j in range(N):
		if bs & (1 << j) == 0: continue
		pri += books[j][0]
		for k, v in enumerate(books[j][1]):
			lev[k] += v
	if all(v >= X for v in lev):
		if best is None or pri < best:
			best = pri
print(-1 if best is None else best)


Measured memory_bytes: 69292
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
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; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{
    int N;
    cin >> N;
    vector<int> v;
    for(int i=0; i<N; ++i)
    {
        v.push_back(i+1);
    }

    int p[N]; int q[N];
    for (int i=0; i<N; ++i)
    {
        cin >> p[i];
    }

    for (int i=0; i<N; ++i)
    {
        cin >> q[i];
    }

    int cnt = 0;
    int a,b;
    do{
        ++cnt;
        bool isP = true;
        bool isQ = true;
        for(int i=0; i<v.size(); ++i)
        {
            if(v[i] != p[i]) isP = false;
            if(v[i] != q[i]) isQ = false;
        }
        if(isP) a = cnt;
        if(isQ) b = cnt;
    }
    while (std::next_permutation(v.begin(), v.end()));

    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int memo[51];

int main() {
  for (int a = 0; a <= 9; ++a) {
    for (int b = 0; b <= 9; ++b) {
      for (int c = 0; c <= 9; ++c) {
        for (int d = 0; d <= 9; ++d) {
          memo[a + b + c + d]++;
        }
      }
    }
  }
  int n;
  while (~scanf("%d", &n)) {
    printf("%d\n", memo[n]);
  }
}


Measured memory_bytes: 2668
// Problem : E - Sequence Sum
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff         first
#define ss         second
#define endl       '\n'
#define pb         push_back
#define int        long long
#define vi         vector<int>
#define mii        map<int, int>
#define pii        pair<int, int>
#define all(x)     (x).begin(), (x).end()
#define fill(a,b)  memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define px(a)      for(auto x: a) cout<<x<<" "; cout<<'\n';
#define pxy(a,n)   rep(i,0,n) {px(a[i])};

/*_________________________________________________________*/
const long long MOD=1e9+7,N=1e5+5;
int power(int x, unsigned int y)  
{  
    int res = 1;
    x = x % MOD;
    if (x == 0) return 0;
  
    while (y > 0)  
    { 
        if (y & 1)  
            res = (res*x) % MOD;
        y = y>>1;
        x = (x*x) % MOD;  
    }  
    return res;  
}

int solve()
{
	int n,x,m,ans=0;
	cin>>n>>x>>m;
	int a[m]={0},b[m+1]={0};
	int t=x%m, i=1,j=-1;
	for(i=1;i<=n;i++){
		if(a[t]!=0){
			j=a[t];
			break;
		}
		a[t]=i;
		ans+=t;
		b[i]=ans;
		t=(t*t)%m;
	}
	//cout<<i<<" "<<j<<endl;
	ans+=(b[i-1]-b[j-1])*((n-i+1)/(i-j));
	ans+=b[j-1+(n-i+1)%(i-j)]-b[j-1];
	return ans;
}
int32_t main()
{	
	std::ios::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<solve()<<endl;
}

Measured memory_bytes: 5184
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mp make_pair
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k,m) for(auto k:m)
#define in_edges(m) repp(i, 1, m){ ll a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define MOD 1000000007
#define sz(a) ll((a).size())
#define pii 3.1415926535897
#define ld long double
#define print(a,n) rep(i,1,n)cout <<a[i] <<" ";
#define BRAHAMASTRA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// stoll(s);
int main()
{
   BRAHAMASTRA
   ll t; t=1;
//    cin >>t;
   while(t--)
   { 
       ll n; cin >>n;
       map<string,ll>m;
       rep(i,0,n)
       {
           string f; cin >>f;
           m[f]++;
       }
           cout<<"AC"<<" x "<<m["AC"]<<endl;
           cout<<"WA"<<" x "<<m["WA"]<<endl;
           cout<<"TLE"<<" x "<<m["TLE"]<<endl;
           cout<<"RE"<<" x "<<m["RE"]<<endl;
   }
}

Measured memory_bytes: 3648
from collections import deque
s = deque(list(input()))
q = int(input())
que = [list(input().split()) for _ in range(q)]
counter = 0
for i in que:
    if i[0] == "1":
        counter += 1
    else:
        if (counter+int(i[1]))%2==1:
            s.appendleft(i[-1])
        else:
            s.append(i[-1])
if counter%2==0:
    print("".join(list(s)))
else:
    print("".join(list(s)[::-1]))

Measured memory_bytes: 36452
#include<iostream>

using namespace std;

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

	for (int i = 1; i <= 9; i++)for (int j = 1; j <= 9; j++) {
		if (i * j == N) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

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

Measured memory_bytes: 596
#include<stdio.h>

int operation(int n,int s[])
{
    int c[12]={0},num[1000]={0};
    int i,count=0,flag=0;

    for(i=0;i<n;i++) num[s[i]]++;

    for(i=0;i<n;i++) c[i]=num[s[i]];

    for(i=0;i<n;i++){
        if(s[i]!=c[i]) flag=1;
        s[i]=c[i];
    }   

    if(flag) return 1;
    else return 0;

}

int main()
{
    int n,i;
    int s[12];

    while(scanf("%d",&n),n){
        for(i=0;i<n;i++) scanf("%d",&s[i]);

        for(i=0;operation(n,s);i++);

        printf("%d\n%d",i,s[0]);
        for(i=1;i<n;i++) printf(" %d",s[i]);
        puts("");
    }   
    return 0;
}

Measured memory_bytes: 612
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

int main() {
	string s;
	cin >> s;
	int a=0, b=0, c = 0;
	int n = s.size();

	rep(i, n) {
		if (s[i] == 'a') a++;
		if (s[i] == 'b') b++;
		if (s[i] == 'c') c++;
	}
	if (max({ a,b,c }) - min({ a,b,c }) <= 1) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
    int N,K,i,ai,bi;
    scanf("%d%d",&N,&K);
    if(N%2==0)
    {
        for(i=0;i<K;i++)
        {
            scanf("%d %d",&ai,&bi);
            if(ai>N/2&&bi<=N/2)
            {
                ai=N/2-(N/2-(N-ai)-1);
            }
            else if(ai<=N/2&&bi>N/2)
            {
                bi=N/2-(N/2-(N-bi)-1);
            }
            else if(ai>N/2&&bi>N/2)
            {
                ai=N/2-(N/2-(N-ai)-1);
                bi=N/2-(N/2-(N-bi)-1);
            }
            if(ai==bi)
            {
                ai=ai+3;
                ai=ai%3;
                if(ai==0)ai=3;
                printf("%d\n",ai);
            }
            else if(ai>bi)
            {
                bi=bi+3;
                bi=bi%3;
                if(bi==0)bi=3;
                printf("%d\n",bi);
            }
            else if(ai<bi)
            {
                ai=ai+3;
                ai=ai%3;
                if(ai==0)ai=3;
                printf("%d\n",ai);
            }
        }
    }
    else if(N%2==1)
    {
        for(i=0;i<K;i++)
        {
            scanf("%d %d",&ai,&bi);
            if(ai>N/2+1&&bi<=N/2+1)
            {
                ai=N/2-(ai-N/2-2);
            }
            else if(ai<=N/2+1&&bi>N/2+1)
            {
                bi=N/2-(bi-N/2-2);
            }
            else if(ai>N/2+1&&bi>N/2+1)
            {
                ai=N/2-(ai-N/2-2);
                bi=N/2-(bi-N/2-2);
            }
            if(ai==bi)
            {
                ai=ai+3;
                ai=ai%3;
                if(ai==0)ai=3;
                printf("%d\n",ai);
            }
            else if(ai>bi)
            {
                bi=bi+3;
                bi=bi%3;
                if(bi==0)bi=3;
                printf("%d\n",bi);
            }
            else if(ai<bi)
            {
                ai=ai+3;
                ai=ai%3;
                if(ai==0)ai=3;
                printf("%d\n",ai);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, m, k, r[200010], c[200010], v[200010];
int g[3010][3010];
int dp[3010][3010][4];




int32_t main(){
INIT
cin>>n>>m; cin>>k;
for(int i=1; i<=k; i++){
    cin>>r[i]>>c[i]>>v[i];
    g[r[i] ][c[i] ]=v[i];
}


for(int i=1; i<=n; i++){
    for(int j=1; j<=m; j++){

        for(int cnt=1; cnt<=3; cnt++){
            if(cnt==1){
            dp[i][j][cnt]=max(dp[i][j-1][cnt-1]+g[i][j], g[i][j]+dp[i-1][j][3]  );
             }
                dp[i][j][cnt]=max(max(dp[i][j-1][cnt], dp[i][j-1][cnt-1]+g[i][j]), dp[i][j][cnt]);

        }
        dp[i][j][3]=max(dp[i][j][3], max(dp[i][j][2], max(dp[i][j][1], dp[i][j][0]) ) );
    }
}
cout<<max(max(dp[n][m][3], max(dp[n][m][2], dp[n][m][1]) ), dp[n][m][0] );






return 0;
}





Measured memory_bytes: 360980
from bisect import bisect_left,bisect_right
S=input()
n=len(S)
B=[]
for i in range(n-1):
    if S[i]!=S[i+1]:
        B.append(i)

def move(k):
    if S[k]=='R':
        idx=bisect_left(B,k)
        b=B[idx]
        m=b-k
        return b+(m%2)
    idx=bisect_left(B,k)-1
    b=B[idx]
    m=k-b
    return b+1-((m%2)^1)

Ans=[0]*n
for i in range(n):
    idx=move(i)
    Ans[idx]+=1
print(*Ans)

Measured memory_bytes: 51244
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(n**0.5) + 1):
        if n % k == 0:
            return False

    return True
  
n = int(input())
c = 1
d = 11
L = [2]
while c<n:
  if is_prime(d):
    L.append(d)
    c += 1
  d += 10
print(*L, sep=" ")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

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 main() {
    int N,M; cin>>N>>M;
    string S; cin>>S;

    //まずは貪欲
    /*
    int cnt=0,itr=0;
    while(itr<N){
        ++cnt;
        if(itr+M>=N) break;
        int i=M;
        while(S[itr+i]=='1'){
            --i;
        }
        if(i==0){
            cout<<-1<<endl;
            return 0;
        }
        itr+=i;
    }
     */

    vector<int> pos;
    for (int i = 0; i < N+1; ++i) {
        if(S[i]=='0') pos.push_back(i);
    }

    //vector<int> ans[100010];
    vector<int> last(N+1);
    for (int i = 1; i <= N; ++i) {
        if(S[i]=='1') continue;
        auto itr=lower_bound(pos.begin(),pos.end(),max(0,i-M));
        if(*itr>=i){
            cout<<-1<<endl;
            return 0;
        }
        last[i]=*itr;
    }
    vector<int> ans;
    int posi=N;
    while(posi>0){
        ans.push_back(posi-last[posi]);
        posi=last[posi];
    }
    reverse(ans.begin(),ans.end());
    for(auto i:ans){
        cout<<i<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1976
#include<iostream>
using namespace std;
int main(){
	int A[100][100], B[100];
	int n, m;
		cin >> n >> m;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				int a;
				cin >> a;
				A[i][j] = a;
			}
		}
		for (int i = 0; i < m; i++){
			int b;
			cin >> b;
			B[i] = b;
		}
		for (int i = 0; i < n; i++){
			int c = 0;
		for (int j = 0; j < m; j++){
				c += A[i][j] * B[j];
			}
		cout << c << endl;
		}
		return 0;
}


Measured memory_bytes: 3120
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long W = sc.nextInt();
		
		ArrayList<ArrayList<Integer>> value = new ArrayList<>();
		for(int i=0; i<4; i++)
			value.add(new ArrayList<>());
		
		int w1 = sc.nextInt();
		value.get(0).add(sc.nextInt());
		for(int i=1; i<N; i++) {
			int w = sc.nextInt();
			value.get(w-w1).add(sc.nextInt());
		}
		for(int i=0; i<4; i++)
			Collections.sort(value.get(i), Comparator.reverseOrder());
		
		long ans = 0;
		HashMap<Long, Integer> used = new HashMap<>();
		used.put(0l, 0);
		for(int i=0; i<4; i++) {
			HashMap<Long, Integer> next = new HashMap<>();
			Iterator<Long> it = used.keySet().iterator();
			while(it.hasNext()) {
				long w = it.next();
				int v = used.get(w);
				next.put(w, v);
				for(int vv : value.get(i)) {
					w += w1+i;
					if(w>W)
						break;
					v += vv;
					Integer check = next.get(w);
					if(check==null || check<v)
						next.put(w, v);
					ans = Math.max(ans, v);
				}
					
			}
			used = next;
		}
		
		System.out.println(ans);
		
		sc.close();
	}
}


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

int main() {
  int K,S;
  scanf("%d %d", &K,&S);
  int count = 0;
  
  for(int a = 0; a <= K; ++a){
    for (int b = 0; b <= K; ++b) {
      if(S-a-b<=K && S-a-b>=0) ++count;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import collections
s = list(input())
n = len(s)
mod = [0]*(n+1)
pow10 = 1
for i in range(n):
    mod[i+1] = (mod[i] + int(s[-1-i])*pow10)%2019
    pow10 = pow10*10%2019
d = collections.Counter(mod)
ans = 0
for i in d.values():
    ans += i*(i-1)//2
print(ans)


Measured memory_bytes: 85324
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  ll n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  n-=1;
  bool f=false;
  ll k=b-a;
  for(ll i=0;i<=n;i++){
    ll l=c*i-d*(n-i);
    ll r=d*i-c*(n-i);
    //dbg(l);dbg(r);
    if(l<=k&&k<=r)f=true;
  }
  cout<<(f?"YES":"NO")<<endl;
  return 0;
}


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

int main(){
  int n,l;
  cin >> n >> l;
  int total = 0;
  int tmp;

  if (l > 0){
    for (int i=0;i<n;i++){
      tmp = l + i;
      total += tmp;
    }
    total -= l;
  }
  else if (l < 0 && n <= abs(l)){
    for (int i=0;i<n;i++){
      tmp = l + i;
      total += tmp;
    }
    total -= l+n-1;
  }
  else{
    for (int i=0;i<n;i++){
      tmp = l + i;
      total += tmp;
    }
  }
  cout << total << endl;
  return 0;
  
}



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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++)cin >> a[i];
  sort(a.begin(), a.end());
  int ans = a[n-1] - a[0];
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
const ll T = 1e9+7;
int main(){
        vector<ll> t(4);
        ll w[4][4]={};
        ll a,b;
        for(int i=0;i<3;i++){
                cin >> a >> b;
                if(w[a-1][b-1]!=0||w[b-1][a-1]!=0){
                        cout << "NO";
                        return 0;
                }
                w[a-1][b-1]++;w[b-1][a-1]++;
                t[a-1]++;t[b-1]++;
        }
        sort(t.begin(),t.end());
        if(t[0]==1&&t[1]==1&&t[2]==2&&t[3]==2) cout << "YES";
        else cout << "NO";  
        return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <ctime>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <climits>
#include <set>
#include <vector>
#define int long long
using namespace std;
inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
inline void write(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
inline void writeln(int x){
	write(x);puts("");
}
int n,a[100010],s[100010];
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	int ans=1e9,sum=0;
	for(int i=1;i<=n;i++){
		s[i]=s[i-1]+a[i];
		if(i&1){
			if(s[i]>=0)sum+=abs(-1-s[i]),s[i]=-1;
		}else{
			if(s[i]<=0)sum+=abs(1-s[i]),s[i]=1;
		}
	}
	ans=sum;sum=0;
	for(int i=1;i<=n;i++){
		s[i]=s[i-1]+a[i];
		if(i&1){			
			if(s[i]<=0)sum+=abs(1-s[i]),s[i]=1;
		}else{
			if(s[i]>=0)sum+=abs(-1-s[i]),s[i]=-1;
		}
	}
	ans=min(ans,sum);
	writeln(ans);
	return 0;
}

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

void solve()
{        
    string a;
    cin >> a;
    int sum=0;
    for (int c=0;c<a.size();c++)
        {
            sum+=a[c]-'0';
            sum%=9;
        }
    if (sum==0)
        cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);     
    int t;
    //cin >> t;
    t=1;
    for (int tt=1;tt<=t;tt++)
        {
            solve();
        }
        return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

using namespace std;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

void solve(string s1, string s2) {
    vector<int> dp[s1.size() + 1];
    vector<int> tmp(s2.size() + 1, 0);
    rep(i, s1.size() + 1) {
        dp[i] = tmp;
    }
    rep(i, s1.size() + 1) {
        rep(j, s2.size() + 1) {
            if(i == 0 || j == 0) {
                continue;
            } else {
                if(s1[i-1] == s2[j-1]) {
                    dp[i][j] = dp[i-1][j-1] + 1;
                }
                dp[i][j] = max(dp[i][j], max(dp[i-1][j], dp[i][j-1]));
            }
        }
    }
    // rep(i, s1.size() + 1) {
    //     rep(j, s2.size() + 1) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[s1.size()][s2.size()] << endl;
}

int main(){
    int n; cin >> n;
    rep(i, n) {
        string s1, s2; cin >> s1 >> s2;
        solve(s1, s2);
    }
}



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

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

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

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int a, b, k; cin>>a>>b>>k;
    if(b-a+1<=k*2-1){
        for(int i=a; i<=b; i++){
            cout << i << endl;
        }
    }
    else{
        for(int i=a; i<a+k; i++){
            cout << i << endl;
        }
        for(int i=b-k+1; i<=b; i++){
            cout << i << endl;
        }
    }
}

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

alphabets = 'abcdefghijklmnopqrstuvwxyz'


def solve(C: str):
    print(alphabets[alphabets.index(C)+1])
    return


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


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
a, b, c, d = map(int, input().split())

if a < d and c < b:
  if b < d:
    if a < c:
      print(b - c)
    else:
      print(b - a)
  else:
    if a < c:
      print(d - c)
    else:
      print(d - a)
else:
  print(0)


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


int main(){
  int n,k;
  cin >> n >> k;
  int p[n];
  for(int i=0; i<n; i++){
    cin >> p[i];
  }
  int64_t m=0;
  int64_t g=0;
  for(int i=0; i<k; i++){
    m += p[i];
  }
  g = m;
  for(int i=1; i<n-k+1; i++){
    m -= p[i-1];
    m += p[i+k-1];
    if(g<m){g=m;}
  }
  double s = g;
  s = (s*0.5)+(k*0.5);
  cout << fixed << setprecision(10);
  cout << s << endl;
}

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

bool str_m(string &s){
  // sの末尾がmだった時の処理. dream
  int ss = s.size();
  if (ss<5) return false;
  s.pop_back(); // drea
  ss = s.size();
  if (s.at(ss-1)!='a' || s.at(ss-2)!='e' ||
      s.at(ss-3)!='r' || s.at(ss-4)!='d'){
    return false;
  }else{
    s.pop_back(); s.pop_back(); s.pop_back(); s.pop_back();
    return true;
  }
}
bool str_e(string &s){
  // sの末尾がeだった時の処理. erase
  int ss = s.size();
  if (ss<5) return false;
  s.pop_back(); // eras
  ss = s.size();
  if (s.at(ss-1)!='s' || s.at(ss-2)!='a' ||
      s.at(ss-3)!='r' || s.at(ss-4)!='e'){
    return false;
  }else{
    s.pop_back(); s.pop_back(); s.pop_back(); s.pop_back();
    return true;
  }
}

bool str_r(string &s){
  // sの末尾がrだった時の処理. dreamer or eraser
  if (s.size()<6) return false;
  if (s.at(s.size()-2)!='e') return false;
  s.pop_back(); // dreame or erase
  if (s.at(s.size()-2)=='m'){
    s.pop_back(); // dream
    return str_m(s);
  }else{
    // erase
    return str_e(s);
  }
}

int main() {
  string s; cin >>s;
  string ans = "YES";
  bool possible = true;
  int slast;
  while (s.size()>0 && possible){
    slast = s.size()-1;
    if (s.at(slast)=='r'){
      possible = str_r(s);
    }else if (s.at(slast)=='e'){
      possible = str_e(s);
    }else if (s.at(slast)=='m'){
      possible = str_m(s);
    }else{
      possible = false;
    }
    if (!possible) break;
  }
  if (!possible) ans = "NO";
  cout <<ans <<endl;
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;

lli n;
mat red;
mat blue;
set<lli> avail;
lli ans=0;

int main(){
	cin >> n;
	red = mat(n,vll(2));
	blue = mat(n,vll(2));
	for(lli i = 0;i < n;i++){
		cin >> red[i][0] >> red[i][1];
	}
	for(lli i = 0;i < n;i++){
		cin >> blue[i][0] >> blue[i][1];
	}
	sort(red.begin(),red.end());
	sort(blue.begin(),blue.end());
	for(lli i = 0,j = 0;i < n;i++){
		while(j < n && blue[i][0] > red[j][0]){
			avail.insert(red[j][1]);
			j++;
		}
		auto upper = avail.lower_bound(blue[i][1]);
		if(upper != avail.begin()){
			upper--;
			avail.erase(upper);
			ans++;
		}

	}
	cout << ans << endl;
}


Measured memory_bytes: 256
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

int a[24],b[23],c[24];
void solve(){  
	int n;
	cin>>n;
	int ans=0;
	rep(i,1,n+1) cin>>a[i];
	rep(i,1,n+1) cin>>b[i];
	rep(i,1,n) cin>>c[i];
	rep(i,1,n+1){
		ans+=b[a[i]];
		if(i>=2 and a[i]-a[i-1]==1){
			ans+=c[a[i]-1];
		}
	} 
	cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256