akhauriyash/Code-Regression huggingface dataset:
from functools import partial
from itertools import islice


def take(n, iterable):
    return list(islice(iterable, n))


def chunked(iterable, n):
    return iter(partial(take, n, iter(iterable)), [])


def solve(s):
    h, w, *a = map(int, s.split())
    a = [[False if __a % 2 == 0 else True for __a in _a] for _a in chunked(a, w)]
    ans = []
    for i in range(h):
        for j in range(w - 1):
            if a[i][j]:
                ans.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
                a[i][j + 1] = not a[i][j + 1]
    for i in range(h - 1):
        if a[i][w - 1]:
            ans.append("{} {} {} {}".format(i + 1, w, i + 2, w))
            a[i + 1][w - 1] = not a[i + 1][w - 1]
    return "%d\n" % len(ans) + "\n".join(ans)


n, m = map(int, input().split())
print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 18736
#include <stdio.h>
#include <string.h>
int a[11][6], b[11][6];

int main(void)
{
    int n, m=5;
    while (scanf("%d", &n), n) {
        int i, j, k, l, res, changed;
        memset(a, -1, sizeof(a));
        for(i=0;i<n;++i) for(j=0;j<m;++j) scanf("%d", &b[i][j]);

        res=0;
        changed=1;
        while (changed) {
            memcpy(a, b, sizeof(a));
            changed=0;
            for(i=n-1;i>=0;--i) {
                for(j=m;j>=3;--j) {
                    for(k=0;k<=m-j;++k) {
                        int t=a[i][k], ok=t>0;
                        for(l=1;l<j;++l) ok=ok&(t==a[i][k+l]);
                        if (ok) {
                            for(l=0;l<j;++l) a[i][k+l]=0;
                            res+=t*j;
                            changed=1;
                            goto NEXTROW;
                        }
                    }
                }
NEXTROW:;
            }
            memset(b, 0, sizeof(b));
            for(j=0;j<m;++j)
                for(i=k=n-1;i>=0;--i)
                    if (a[i][j]) b[k--][j]=a[i][j];
        }
        printf("%d\n", res);
    }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define ll long long
const int maxn=100005;
using namespace std;
ll n,a[maxn],ans=1,N=1e18;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==0) {cout<<0;return 0;}
	}
	for(int i=1;i<=n;i++)
	{
		if(N/ans<a[i]) {cout<<-1;return 0;}
		ans*=a[i];
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 4408
#include <stdio.h>
int main()
{
    int x, i;
    i = 1;
    x = 0;
    
    while (x >= 0) {
        scanf ("%d", &x);
        if (x == 0) {
            break;
        }
        printf ("Case %d: %d\n", i, x);
        i++;
    }
    
    return 0;
}

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


def has_duplicates(seq):
    return len(seq) != len(set(seq))


N = INT()

S = []
for n in range(N):
    s = input()
    S.append(s)

import collections
S = collections.Counter(S)

T = S.most_common()

ans = []

num = T[0][1]
for t in T:
    if t[1] == num:
        ans.append(t[0])
    else:
        break
ans = sorted(ans)
for a in ans:
    print(a)





Measured memory_bytes: 49424
from collections import defaultdict

N, Ma, Mb = map(int, input().split())
M = [tuple(map(int, input().split())) for _ in range(N)]

d = defaultdict(lambda: float('inf'))
d[(0, 0)] = 0
for a, b, c in M:
    new_d = d.copy()
    for key_a, key_b in d:
        new_d[(a + key_a, b + key_b)] = min(new_d[(a + key_a, b + key_b)],
                                            d[(key_a, key_b)] + c)
    d = new_d

ans = float('inf')
for i in range(1, 401 // max(Ma, Mb)):
    ans = min(ans, d[(Ma * i, Mb * i)])
print(ans if ans != float('inf') else -1)


Measured memory_bytes: 8720
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		var ss = new HashSet<String>();
		
		for (int i=0; i<n; i++) {
			String s = sc.nextLine();
			ss.add(s);
		}
		
		System.out.println(ss.size());
		
		sc.close();
	}
}


Measured memory_bytes: 79632
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
        public static void main(String[] args) throws Exception {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st;
                PrintWriter pw = new PrintWriter(System.out);

                int n = Integer.parseInt(br.readLine());
                st = new StringTokenizer(br.readLine());
                char[] c1 = st.nextToken().toCharArray();
                char[] c2 = st.nextToken().toCharArray();
                for(int i=0 ; i<n ; i++) {
                        pw.print(c1[i]);
                        pw.print(c2[i]);
                }


                pw.flush();
                pw.close();
        }
}


Measured memory_bytes: 21460
#include <bits/stdc++.h> 
using namespace std; 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
const long long int m=pow(10,9)+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin >> n >> m;
    ll ans;
    if(n>=2&&m>=2) ans = (n-2)*(m-2);
    else ans = max(n-2, m-2);
    if(ans<0) ans=1;
    cout << ans;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    ll n ;
    cin >> n ;
    string ans = "" ;
    if(n==0){
        cout << 0 <<endl;
        return 0 ;
    }
    ll i = 0 ;
    ll hoge = 0 ;
    while(n!=hoge){
        ll powe = pow(2,i+1) ;
        if((n+INF)%powe!=(hoge+INF)%powe){
            ans = "1" + ans ;
            if(i%2==0){
                hoge += pow(2,i) ;
            }
            else{
                hoge -= pow(2,i) ;
            }
        }
        else{
            ans = "0" + ans ;
        }
        i++ ;
    }
    cout << ans <<endl;




    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 4040
#include<stdio.h>

int main()
{
    int i,j,a[60],b[60],n,flag;

    scanf("%d",&n);

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

    for(i=0,j=1;i<n;i++,j++)
    {
        b[i] = j;
    }

    for(i=0,flag=0;i<n;i++)
    {
        if(a[i]!=b[i])
            flag++;
    }

    if(flag<=2)
        printf("YES");
    else
        printf("NO");

    return 0;
}


Measured memory_bytes: 1700
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;

const int INF = 1e18;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

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

    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    int cnt2, cnt4;
    cnt2 = cnt4 = 0;
    rep(i, n)
    {
        if (a[i] % 4 == 0)
        {
            cnt4++;
        }
        else if (a[i] % 2 == 0)
        {
            cnt2++;
        }
    }

    bool isPossible = (n <= cnt4 * 2 + cnt2 || n - 1 <= cnt4 * 2);
    cout << ((isPossible) ? "Yes" : "No") << endl;
}

signed main()
{
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<lint> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int n;
    cin >> n;
    map<lint, lint> m;
    for (int i = 2; i <= n; i++)
    {
        int copy = i;
        for (int j = 2; j * j <= i; j++)
        {
            if (copy % j == 0)
            {
                while (copy % j == 0)
                {
                    copy /= j;
                    m[j]++;
                }
            }
        }
        if (copy != 1)
        {
            m[copy]++;
        }
    }
    lint ans = 1;
    for (auto i = m.begin(); i != m.end(); i++)
    {
        ans = (ans * (i->second + 1)) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
    int W,H,N;
    cin >> W >> H >> N;
    int d[150][150] = {0};
    int x[150];
    int y[150];
    int a[150];
    for(int i=0;i<N;i++){
        cin >> x[i] >> y[i] >>a[i];
    }
    
    for(int i=0;i<N;i++){
        if(a[i] == 1) {
            for(int j=0;j<x[i];j++){
                for(int k=0;k<H;k++){
                    d[j][k]++;
                }
            }
        }
        
        if(a[i] == 2){
             for(int j=x[i];j<=W;j++){
                for(int k=0;k<H;k++){
                    d[j][k]++;
                }
            }
        }
        
        if(a[i] == 4){
             for(int j=y[i];j<H;j++){
                for(int k=0;k<W;k++){
                    d[k][j]++;
                }
            }
        }
        
        if(a[i] == 3){
             for(int j=0;j<y[i];j++){
                for(int k=0;k<W;k++){
                    d[k][j]++;
                }
            }
        }
        
    }
    
    int res=0;
    for(int i=0;i<W;i++){
        for(int j=0;j<H;j++){
            if(d[i][j] == 0) res++;
        }
    }
    
    
    cout << res <<endl;
   
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	m1 := map[int]int{}
	m2 := map[int]int{}
	for i := 0; i < m; i++ {
		a := getNextInt(scanner)
		b := getNextInt(scanner)
		if a == 1 {
			m1[b] = 1
		}
		if b == n {
			m2[a] = 1
		}
	}

	ans := "IMPOSSIBLE"
	for to := range m1 {
		if _, ok := m2[to]; ok {
			ans = "POSSIBLE"
			break
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while( ch < '0' || ch > '9' ) { if( ch == '-' ) f = -1; ch = getchar(); }
	while( ch >= '0' && ch <= '9' ) sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

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

int n, m, dis[MAXN][MAXN], K, qx[MAXN * MAXN], qy[MAXN * MAXN], ql, qr, ans;
char ch[MAXN][MAXN];

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	fill( dis, ans = 0x3f3f3f3f );
	n = read(), m = read(), K = read();
	for( int i = 1 ; i <= n ; i++ ) scanf( "%s", ch[ i ] + 1 );
	for( int i = 1 ; i <= n ; i++ ) for( int j = 1 ; j <= m ; j++ ) if( ch[ i ][ j ] == 'S' ) qx[ ++qr ] = i, qy[ qr ] = j, dis[ i ][ j ] = 0;
	while( ql ^ qr )
	{
		int x = qx[ ++ql ], y = qy[ ql ];
		if( dis[ x ][ y ] >= K ) break;
		for( int k = 0 ; k < 4 ; k++ )
		{
			int nx = x + dx[ k ], ny = y + dy[ k ];
			if( ch[ nx ][ ny ] == '.' && dis[ nx ][ ny ] == 0x3f3f3f3f ) dis[ nx ][ ny ] = dis[ x ][ y ] + 1, qx[ ++qr ] = nx, qy[ qr ] = ny;
		}
	}
	for( int i = 1 ; i <= n ; i++ )
		for( int j = 1 ; j <= m ; j++ )
			if( dis[ i ][ j ] <= K )
				ans = min( ans, ( min( i - 1, min( j - 1, min( n - i, m - j ) ) ) + ( K - 1 ) ) / K + 1 );
	return printf( "%d\n", ans ), 0;
}


Measured memory_bytes: 8448
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    int size[3];
    for (int i = 0; i < 3; i++) {
        std::cin >> size[i];
    }

    int k;
    std::cin >> k;

    std::vector<std::vector<long long>> cakes(3);

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < size[i]; j++) {
            long long temp;
            std::cin >> temp;

            cakes[i].push_back(temp);
        }
        std::sort(cakes[i].begin(), cakes[i].end(), std::greater<long long>());
    }

    std::vector<std::pair<long long, std::tuple<long long, long long, long long>>> already_added;

    std::priority_queue<std::pair<long long, std::tuple<long long, long long, long long>>> q;

    std::pair<long long, std::tuple<long long, long long, long long>> first = std::make_pair(cakes[0][0] + cakes[1][0] + cakes[2][0], std::make_tuple(0, 0, 0));
    q.push(first);
    already_added.push_back(first);

    for (int i = 0; i < k; i++) {
        std::pair<long long, std::tuple<long long, long long, long long>> top = q.top();
        q.pop();

        std::cout << top.first << std::endl;

        for (int j = 0; j < 3; j++) {
            std::vector<long long> next_idx = { std::get<0>(top.second), std::get<1>(top.second), std::get<2>(top.second) };
            next_idx[j]++;

            if (next_idx[j] >= size[j]) {
                continue;
            }

            std::pair<long long, std::tuple<long long, long long, long long>> next = std::make_pair(0, std::make_tuple(next_idx[0], next_idx[1], next_idx[2]));
            for (int idx = 0; idx < 3; idx++) {
                next.first += cakes[idx][next_idx[idx]];
            }

            if (std::find(already_added.begin(), already_added.end(), next) == already_added.end()) {
                q.push(next);
                already_added.push_back(next);
            }
        }
    }
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    int N, M;
    vector<i_i> v;
    cin >> N >> M;
    v.resize(M);
    for(int i = 0; i < M; i++) cin >> v[i].second >> v[i].first;
    sort(v.begin(), v.end());
    int Last = -1;
    int ans = 0;
    for(int i = 0; i < M; i++) {
        if(v[i].second <= Last) continue;
        Last = v[i].first - 1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

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

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}


void solve(void){
    int n;
    cin >> n;
    ll t[n],a[n];
    rep(i,0,n) cin >> t[i] >> a[i];
    ll sum1 = t[0],sum2 = a[0];
    rep(i,1,n){
        ll tmp = sum1 % t[i] ? 1 : 0, tmp2 = sum2 % a[i] ? 1 : 0;
        ll p = max(sum1/t[i] + tmp, sum2/a[i] + tmp2);
        sum1=p*t[i];
        sum2=p*a[i];
    }
    cout << sum1+sum2<<endl;
}

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

Measured memory_bytes: 256
#include <stdio.h>

long bsqrt(long p){
  long i,m=0,a=0,b;
  for(i=0;i<32;i++){
    a=(a<<2)|((p>>62)&3);
    p<<=2;
    m<<=1;
    b=a-((m<<1)|1);
    if((b>>i)&1^1){
      m|=1;
      a=b;
    }
  }
  return(m);
}

int main(){
  long a,b,c;
  scanf("%ld",&a);
  scanf("%ld",&b);
  scanf("%ld",&c);
  if(a+b+bsqrt(a*b*4)<c){
    printf("Yes");
  }else{
    printf("No");
  }
  return(0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;

  i64 ans = 0, now = 0;
  for(int i = s.size() - 1; i > 0; --i) {
    if(s[i] == 'W') now++;

    if(s[i] == 'W' && s[i - 1] == 'B') {
      ans += now;
      now--;
      s[i - 1] = 'W';
    }
    else if(s[i] == 'B') now = 0; 
  }
  cout << ans << endl;
}


Measured memory_bytes: 720
#include <iostream>
#include<math.h>
using namespace std;

int main(void)
{
  int n, k, i, b[32];

    cin >> n >> k;
  for (i = 0; n > 0; i++) {
    b[i] = n % k;
    n = n / k;
  }
  
    cout << i <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int N, L;
	cin >> N >> L;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	sort(S.begin(), S.end());
	for (int i = 0; i < N; i++) {
		cout << S[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
ll dp[1015][st(12) + 5];
int n, m;
struct keys
{
    ll cost;
    int state;
} a[1050];

void solve()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; ++i)
    {
        int b;
        scanf("%lld", &a[i].cost);
        scanf("%d", &b);
        while (b--)
        {
            int x;
            scanf("%d", &x);
            a[i].state |= st(x - 1);
        }
    }
    memarray(dp, llinf);
    dp[0][0] = 0;
    for (int i = 1; i <= m; ++i)
    {
        for (int s = 0; s < st(n); ++s)
        {
            dp[i][s | a[i].state] = min(dp[i][s | a[i].state], dp[i - 1][s] + a[i].cost);
            dp[i][s] = min(dp[i][s], dp[i - 1][s]);
        }
    }
    ll ans = llinf;
    for (int i = 0; i <= m; ++i)
    {
        ans = min(ans, dp[i][st(n) - 1]);
    }
    if (ans == llinf)
        ans = -1;
    cout << ans;
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 36292
using System;

namespace MSB_A {
    class Program {
        static void Main(string[] args) {
            var a = int.Parse(Console.ReadLine().Split(' ')[0]);
            var b = int.Parse(Console.ReadLine().Split(' ')[0]);

            Console.WriteLine(a == b ? 0 : 1);
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = CRLF;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  int N; cin >> N;
  using Pair = pair<int, int>;
  using Node = pair<int, vector<int>>;

  map<Pair, int> edges{};
  vector<Node> nodes(N);
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    edges[{a, b}] = i;
    nodes[a].second.push_back(b);
    nodes[b].second.push_back(a);
  }
  vector<int> edges_iro(N - 1);
  int K{};

  nodes[0].first = -1;
  std::deque<int> que{};
  que.push_back(0);
  while (!que.empty()) {
    int cur = que.front();
    que.pop_front();
    int iro_next = 1, iro_cur = nodes[cur].first;

    for (const auto& next : nodes[cur].second) {
      if (nodes[next].first != 0) continue;
      if (iro_next == iro_cur)
        ++iro_next;
      chmax(K, iro_next);
      nodes[next].first = iro_next;
      que.push_back(next);
      Pair p(std::min(cur, next), std::max(cur, next));
      edges_iro[edges[p]] = iro_next;

      ++iro_next;
    }
  }

  cout 
    << K << CRLF
    << edges_iro << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = int(1e9)+10;
const ll INFll = ll(1e18)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;

int main() {
	int A, B, M; cin >> A >> B >> M;
	V a(A);
	rep(i, A) cin >> a[i];
	V b(B);
	rep(i, B) cin >> b[i];

	int cmin = *min_element(ALL(a)) + *min_element(ALL(b));

	rep(i, M) {
		int x, y, c, z;
		cin >> x >> y >> c;
		x--; y--;
		z = a[x] + b[y] - c;
		cmin = min(cmin, z);
	}
	cout << cmin << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int64_t a[n], sum=0, ct=0, ans=pow(10, 15);
  for(int i=0; i<n; i++){
    cin >> a[i];
    sum+=a[i];
  }
  ct=a[0];
  sum-=a[0];
  ans=abs(ct-sum);
  for(int i=1; i<n-1; i++){
    ct+=a[i];
    sum-=a[i];
    if(abs(ct-sum)<ans)
      ans = abs(ct-sum);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 5092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
map<int,int> mp;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int ans=0;
    rep(i,1,n){
        int ii=i;while(ii>9)ii/=10;
        
        int id=i%10+ii*10;
         /*
        int inv=i%10*10+ii;
        
        if(i==0||ii==10)continue;
        
        ans+=2*mp[inv];
        //debug(i),debug(id),debug(inv),debug(mp[inv]);
        if(ii==i%10)ans++; */
        mp[id]++; 
    }
    rep(i,0,9)rep(j,0,9){
        ans+=mp[i*10+j]*mp[j*10+i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.regex.Pattern
import java.util.{ArrayList, Collections, Comparator, List => JList}

import scala.collection.immutable.TreeMap
import scala.math._
import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val Array(n, k) = input.split(LINE_SEPARATOR).head.split(" ").map(_.toInt)
    val a = input.split(LINE_SEPARATOR).tail
    (n - (0 until k).toList.foldLeft(List.empty[Int]){(list, i) =>
      a(i * 2 + 1).split(" ").map(_.toInt).toList ::: list
    }.distinct.size).toString
  }


  def factorize(x: Long): List[Long] = {
    def foo(x: Long, a: Long = 2, list: List[Long] = Nil): List[Long] = a*a > x match {
      case false if x % a == 0 => foo(x / a, a    , a :: list)
      case false               => foo(x    , a + 1, list)
      case true                => x :: list
    }
    foo(x)
  }

  def divisors(n: Long): Vector[Long] = {
    val halfList = (1 to sqrt(n).toInt).toVector.filter(_ % n == 0).map(_.toLong)
    val reversedList = if (sqrt(n).floor == sqrt(n)) halfList.reverse.tail.map(n/_) else halfList.reverse.map(n/_)
    halfList ++ reversedList
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """3 2
      |2
      |1 3
      |1
      |3""".stripMargin -> """1
                                 |
                                   |""".stripMargin,
    """3 3
      |1
      |3
      |1
      |3
      |1
      |3""".stripMargin -> """2""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 55404
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,10000000));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);

int n;

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

signed main(){
    int m;
    cin >> n >> m;
    vec(a,n);
    input(a,n);
    twovec(dp,m,n+1);
    int tmp = a[0];
    while(true){
        if(tmp > n) break;
        dp[0][tmp] = tmp/a[0];
        tmp += a[0];
    }
    FOR(i,1,m){
        dp[i][a[i]] = 1;
        REP(j,n+1){
            if(dp[i-1][j] != 10000000 || dp[i][j] != 10000000){
                dp[i][j] = min(dp[i-1][j],dp[i][j]);
                if(j+a[i] <= n) dp[i][j+a[i]] = dp[i][j] + 1;
            }
        }
    }
    print(dp[m-1][n]);

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}




Measured memory_bytes: 11520
/// sultanov

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;

template<typename T> 
using ordered_set = tree<T, null_type,   
less<T>, rb_tree_tag,
tree_order_statistics_node_update>;

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

const int INF32 = 1e9;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<pii> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x;
        a[i].y = i + 1;
    }
    sort(a.begin(), a.end());
    for (pii x : a)
        cout << x.y << " ";   
    return false;                                                       
}

Measured memory_bytes: 1664
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

ex = [[1,2], [0,2], [0,1]]
dp = [abc[0]] + [[0]*3 for _ in range(n-1)]

for i in range(n-1):
    for j in range(3):
        dp[i+1][j] = abc[i+1][j] + max([dp[i][k] for k in ex[j]])

print(max(dp[-1]))

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		//ArrayList<Integer> numArray = new ArrayList<>();
		long numArray[] = new long[N];

		long ans1 = 0,ans2 = 0,up=0,down=0;
		for(int i = 0; i < N; i++){
			numArray[i] = sc.nextLong() - i;
			}

		Arrays.sort(numArray);
		up = numArray[N/2];
		down = numArray[(N-1)/2];

		for(int i = 0; i < N; i++){
			ans1 += Math.abs(numArray[i]-up);
			ans2 += Math.abs(numArray[i]-down);
		}

		System.out.println(Math.min(ans1, ans2));
		sc.close();

	}

}


Measured memory_bytes: 87292
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,sum=0;
	scanf("%d%d",&n,&m);
	double a,b,c;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		if(sqrt(a*a+b*b)<=m)
		sum++;
	}
   	cout<<sum;
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
int main(){
    char a,b;
    cin>>a;
    if(a=='A')
    b='T';
    if(a=='T')
    b='A';
    if(a=='G')
    b='C';
    if(a=='C')
    b='G';
    cout<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
using namespace std;

int n;
int a[50],b[50],c[50];

int main(){
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
        a[i]-=1;

    }
    for(int i=0; i<n; i++){
        cin>>b[i];
    }
    for(int i=0; i<n-1; i++){
        cin>>c[i];
    }

    int ans=0;
    int pos=-1;

    for(int i=0; i<n; i++){
        ans+=b[a[i]];
        if(pos>=0){
            if(pos+1==a[i]){
                ans+=c[pos];
            }
        }
        pos=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main(){
int n,k,i,flag;
cin>>n>>k;
int d[k];
char nst[100],dst[100];
for(i=0;i<k;i++)cin>>d[i];
while(1){
for(i=0;i<k;i++){
sprintf(nst,"%d",n);
sprintf(dst,"%d",d[i]);
if(strstr(nst,dst)!=NULL){
n++; 
flag=0;
break;
}else{
flag++;
}
}
if(flag==k)break;
flag=0;
}
cout<<n<<endl;
return 0;
}

Measured memory_bytes: 256
N = list(input())
if N[0] == N[1] == N[2]:
    print("".join(N))
else:
    num_N = int("".join(N))
    if num_N < int(N[0] * 3):
        print(N[0] * 3)
    else:
        for _ in range(3):
            print(int(N[0]) + 1,end = "")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

int main() {
	int n, a,maxv=0,ans;
	cin >> n;
	map<int, int> m;
	for (int i = 0; i < n; i++) {
		cin >> a;
		m[a]++; m[a - 1]++; m[a + 1]++;
	}
	for (auto it=m.begin();it!=m.end();it++) {
		pair<int, int>p = *it;
		int x = p.second;
		if (maxv < x) {
			maxv = x;
		}
	}
	cout << maxv << endl;
}

Measured memory_bytes: 4736
#!/usr/bin/env python3
import sys
# input = sys.stdin.r/eadline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    H,W = MAP()
    s = [input() for _ in range(H)]
    dp = [[0]*W for _ in range(H)]

    if s[0][0] == "#":
        dp[0][0] = 1

    for i in range(H):
        for j in range(W):
            if i == 0:
                if j == 0:
                    continue

                if s[i][j] == "#" and s[i][j-1] == ".":
                    dp[i][j] = dp[i][j-1]+1
                else:
                    dp[i][j] = dp[i][j-1] 
            else:
                if j == 0:
                    if s[i-1][j] == "." and s[i][j] == "#":
                        up = dp[i-1][j]+1
                    else:
                        up = dp[i-1][j]
                    dp[i][j] = up
                    continue
                else:
                    if s[i-1][j] == "." and s[i][j] == "#":
                        up = dp[i-1][j]+1
                    else:
                        up = dp[i-1][j]
                    
                    if s[i][j-1] == "." and s[i][j] == "#":
                        left = dp[i][j-1]+1
                    else:
                        left = dp[i][j-1]
                    
                    dp[i][j] = min(left,up)

    print(dp[H-1][W-1])

if __name__ == '__main__':
    main()


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

int a[200005];

int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    sort(a, a + n);
    int j = k - 1;
    int mn = 987654321;

    for(int i = 0; i + j < n; ++i){
        mn = min(mn, a[i + j] - a[i]);
    }

    cout << mn << "\n";
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL dp[20][20];
LL ma[205][205];
int main(void)
{
    int n,m;
    cin>>n>>m;
    for(int i = 0;i < 10;i++)
    {
    	for(int j = 0;j < 10;j++)
    	{
    		cin>>dp[i][j];
		}
	}
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < m;j++)
		{
			cin>>ma[i][j];
		}
	}
	for(int k = 0;k <= 9;k++)
	{
		for(int i = 0;i <= 9;i++)
		{
			for(int j = 0;j <= 9;j++)
			{
				dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}
	LL sum = 0;
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < m;j++)
		{   if(ma[i][j]!=-1)
			sum += dp[ma[i][j]][1];
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 512
i = gets.chomp.split(" ").map(&:to_i)
i.sort!
if i[0]==i[1]
  if i[1]==i[2]
    puts "No"
  else
    puts "Yes"
  end
else
  if i[1]==i[2]
    puts "Yes"
  else
    puts "No"
  end
end

Measured memory_bytes: 1788
#include <iostream>
#include <stdio.h>
using namespace std;



int main()
{

    int JumlahGarisVertikal;
    int JumlahGarisHorizontal;
    int DaftarAngka[30];
    int TukarNilai[30][2];

    cin >> JumlahGarisVertikal;
    cin >> JumlahGarisHorizontal;

    for(int x = 0 ; x < JumlahGarisVertikal; x++)
    {
        DaftarAngka[x] = x+1;
    }

    for(int y = 0; y < JumlahGarisHorizontal; y++)
    {
        scanf("%d,%d",&TukarNilai[y][0],&TukarNilai[y][1]);

        int temp = DaftarAngka[TukarNilai[y][0] - 1];
        DaftarAngka[TukarNilai[y][0] - 1] = DaftarAngka[TukarNilai[y][1] - 1];
        DaftarAngka[TukarNilai[y][1] - 1] = temp;
    }

    for(int z = 0; z < JumlahGarisVertikal; z++)
    {
        cout << DaftarAngka[z] << endl;
    }

}

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

vector<int> adj[100005];

map<pair<int, int>, int> col;

void fix(int node) {
	
	set<int> colours_used;
	
	for (int i=0; i<adj[node].size(); i++) {
		int ot = adj[node][i];
		int a = min(node, ot), b = max(node, ot);
		colours_used.insert(col[make_pair(a, b)]);
	}
	
	int curr = 1;
	for (int i=0; i<adj[node].size(); i++) {
		int ot = adj[node][i];
		int a = min(node, ot), b = max(node, ot);
		if (col[make_pair(a, b)] == 0) {
			while (colours_used.find(curr) != colours_used.end()) curr++;
			col[make_pair(a, b)] = curr;
			colours_used.insert(curr);
		}
	}
	
}

int main() {
    
	int n;
	cin >> n;
	int k = 0;
	vector<pair<int, int> > vc;
	for (int i=0; i<n-1; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
		k = max(k, (int) adj[a].size());
		k = max(k, (int) adj[b].size());
		vc.push_back(make_pair(min(a, b), max(a, b)));
	} 
    cout << k << endl;
    for (int i=1; i<=n; i++) fix(i);
    
    for (int i=0; i<n-1; i++) {
		cout << col[vc[i]] << endl;
	}
}


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

int main() {
  
  int N; cin >> N; int sum = 0;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
    
    int T; cin >> T;
    
    vec[i] = T; sum += T;
    
  }
  
  int M; cin >> M;
  
  for (int i = 0; i < M; i++) {
    
    int P, X; cin >> P >> X;
    
    cout << sum - vec[P - 1] + X << endl;
    
  }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void check(int N, int num, bool use[10], int &min, int pos);
int main(){
    int N,K;
    int i,temp;
    bool use[10];
    int ans = -1;
    cin >> N >> K;

    for(i=0;i<10;i++){
        use[i] = true;
    }
    for(i=0;i<K;i++){
        cin >> temp;
        use[temp] = false;
    }
    check(N,0,use,ans,1);
    cout << ans << endl;
    return 0;
}
void check(int N, int num, bool use[10], int &min, int pos){
    int i;
    if( min != -1 && num > min ){
        return;
    }
    if( N <= num ){
        if( min == -1 || min > num){
            min = num;
        }
        return;
    }else if( pos > N * 10){
        return;
    }
    for(i=0;i<10;i++){
        if( use[i]){
            check(N,num*10+i,use,min,pos*10);
        }
    }

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
# input = sys.stdin.r/eadline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    N = INT()
    A=[]
    B = []
    for _ in range(N):
        a,b = MAP()
        A.append(a)
        B.append(b)

    answer = 0
    for i in range(N-1,-1,-1):
        if (answer+A[i])%B[i] > 0:
            need = B[i]-(answer+A[i])%B[i]
            answer += need
    print(answer)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 11060
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def distance(x,y):
    dist=0
    for i in range(len(x)):
        dist+=(x[i]-y[i])**2.0
    dist=(dist**0.5)
    return dist

def do():
    n,d=INTM()
    xs=[]
    ct=0
    for i in range(n):
        xs.append(LIST())
    for i in range(n-1):
        for k in range(i+1,n):
            temp=0
            distan=distance(xs[i],xs[k])
            if distan==int(distan):
                ct+=1
    print(ct)
            
if __name__ == '__main__':
    do()

Measured memory_bytes: 3188
n = int(input())
s = []
t = []
for i in range(n):
    ss,tt = map(str,input().split())
    s.append(ss)
    t.append(tt)
x = input()

ans = 0
for i in range(n-1):
    if ans != 0:
        ans += int(t[i+1])
    elif s[i] == x:
        ans += int(t[i+1])
print(ans)

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

using namespace std;

int n;
int h[100000];
int m[100000];

int calc(int x)
{
	if (m[x] == -1)
	{
		if (x >= 2)
			m[x] = min(calc(x - 1) + abs(h[x] - h[x - 1]), calc(x - 2) + abs(h[x] - h[x - 2]));
		else
			m[x] = calc(x - 1) + abs(h[x] - h[x - 1]);
	}

	return m[x];
}

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

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
		m[i] = -1;
	}

	m[0] = 0;

	cout << calc(n - 1);

	return 0;
}

Measured memory_bytes: 2560
def make(nums, now):
    # print(nums, now)
    if len(nums) == 0:
        dic.append(now)

    for i in range(len(nums)):
        tmp = nums[:i]
        if i+1 < len(nums):
            tmp += nums[i+1:]
        make(tmp, now+[nums[i]])

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
dic = []
original_nums = [i for i in range(1, n+1)]
make(original_nums, [])
for i in range(len(dic)):
    if dic[i] == p:
        num_p = i
    if dic[i] == q:
        num_q = i
# print(num_p, num_q)
print(abs(num_q - num_p))


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

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

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795;

int main()
{
	int n,x,_min = 0,ret=0;
	int m[100];
	cin >> n >> x;
	for (int i = 0; i < n; ++i)
	{
		cin >> m[i];
		x -= m[i];
		ret++;
	}
	sort(m, m+n);
	_min = m[0];
	ret += x / _min;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define eb emplace_back
using ll=long long;
using vi=vector<ll>;
using vvi=vector<vi>;
template<class T> void out(T a){cout<<a<<'\n';}

void solve() {
  ll mod=2019;
  string s;
  cin>>s;
  ll n=s.size();
  vvi v(mod);
  vi t(n);
  ll sum=0;
  ll k=1,ans=0;
  for(ll i=n-1; i>=0; i--){
    sum+=(s[i]-'0')*k;
    k*=10;
    k%=mod;
    sum%=mod;
    v[sum].eb(n-1-i);
    t[n-1-i]=sum;
    if(sum==0) ans++;
  }
  rep(i,mod) ans+=(v[i].size()*(v[i].size()-1))/2;
  out(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 7676