akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>

#define Lens 500010
using namespace std;
struct Node
{
	int key;
	Node *p, *l, *r;
};
int N;
Node *root, *Nil;
char A[20];

void insert(int i)
{
	Node *x = root;
	Node *y = Nil;
	Node *z;
	z = (Node*)malloc(sizeof(Node));
	z->l = z->p = z->r = Nil;
	z->key = i;
	while (x != Nil)
	{
		y = x;
		if (z->key < x->key)
			x = x->l;
		else
			x = x->r;
	}
	if (y == Nil)
		root = z;
	else
	{
		if (z->key < y->key)
		{
			y->l = z;
			z->p = y;
		}
		else
		{
			y->r = z;
			z->p = y;
		}
	}
}

bool Find(int i)
{
	Node *x = root;
	while (x != Nil)
	{
		if (x->key == i)
			return true;
		else if (i < x->key)
			x = x->l;
		else
			x = x->r;
	}
	return false;
}

void Pre(Node *x)
{
	if (x == Nil)
		return;
	cout << ' ' << x->key;
	Pre(x->l);
	Pre(x->r);
}

void In(Node *x)
{
	if (x == Nil)
	{
		return;
	}
	In(x->l);
	cout << ' ' << x->key;
	In(x->r);
}

void Print()
{
	In(root);
	cout << endl;
	Pre(root);
	cout << endl;
}

int main()
{
	int k;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A;
		if (A[0] == 'i')
		{
			cin >> k;
			insert(k);

		}
		else if (A[0] == 'f')
		{
			cin >> k;
			if (Find(k))
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}
		else if (A[0] == 'p')
			Print();
			
	}
	return 0;
}


Measured memory_bytes: 21824
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>

#define ll long long

int main()
{
    ll N;
    std::cin >> N;

    std::vector<ll> L(N);
    for(ll i=0; i < N; i++) {
        std::cin >> L[i];
    }
    
    std::sort(L.begin(), L.end());

    ll sum = 0;
    for(ll i=0; i < (N-2); i++) {
        for(ll j=i+1; j < (N-1); j++) {
            for(ll k= j+1; k < N; k++) {
                if(L[i] == L[j]) {
                    break;
                }
                else {
                    if(!(L[i] == L[k] or L[j] == L[k])) {
                        if(L[i] + L[j] > L[k]) {
                            sum++;
                        }
                    }
                }
            }
        }
    }
    std::cout << sum << std::endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define endl "\n"

using namespace std;

char znak;
bool ans1[1010][1010], ans2[1010][1010];
int n, m;

int main()
{
	ios_base::sync_with_stdio( 0 );
	cin.tie( 0 );
	cin>>n>>m;
	for( int a = 1; a <= n; a++ )for( int b = 1; b <= m; b++ )
	{
		cin>>znak;
		if( znak == '#' )ans1[a][b] = 1, ans2[a][b] = 1;
	}
	for( int a = 1; a <= n; a++ )ans1[a][1] = 1;
	for( int a = 1; a <= n; a++ )
	{
		if( a%2 )
		{
			for( int b = 1; b < m; b++ )ans1[a][b] = 1;
		}
	}
	for( int a = 1; a <= n; a++ )ans2[a][m] = 1;
	for( int a = 1; a <= n; a++ )
	{
		if( a%2 == 0)
		{
			for( int b = 2; b <= m; b++ )ans2[a][b] = 1;
		}
	}
	for( int a = 1; a <= n; a++ )
	{
		for( int b = 1; b <= m; b++ )
		{
			if( ans1[a][b] )cout<<'#';
			else cout<<'.';	
		}
		cout<<endl;
	}
	cout<<endl;
	for( int a = 1; a <= n; a++ )
	{
		for( int b = 1; b <= m; b++ )
		{
			if( ans2[a][b] )cout<<'#';
			else cout<<'.';
		}
		cout<<endl;
	}
	return 0;	
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main(){
int A[3];
 
cin >> A[0] >> A[1] >> A[2];
 
sort(A,A+3);
 
cout << A[0]  << " "<< A[1] << " " <<A[2] << endl;
 
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;

int main(){
    int n;
    cin >> n;
    Graph G(n);
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        a--;
        G[i].push_back(a);
    }
    vector<int> dist(n,-1);
    queue<int> que;
    dist[0] = 0;
    que.push(0);

    while(!que.empty()){
        int v = que.front(); //qの先頭の数
        que.pop();

        for(int nv : G[v]){
            if(dist[nv] != -1) continue; //nvを訪れたことがあるなら飛ばす

            dist[nv] = dist[v] + 1;
            que.push(nv); //nvを探索待ちにする
        }
    }
    cout << dist[1] << endl;
}

Measured memory_bytes: 6144
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

N=int(input())
T=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
lst=[0 for i in range(N)]


lst[0]=T[0]
lst[N-1]=A[N-1]
if T[N-1]!=A[0]:
    print(0)
    exit()
for i in range(1,N):
    if T[i]>T[i-1]:
        if lst[i] and lst[i]!=T[i]:
            print(0)
            exit()
        lst[i]=T[i]

for i in range(N-2,-1,-1):
    if A[i]>A[i+1]:
        if lst[i] and lst[i]!=A[i]:
            print(0)
            exit()
        elif not lst[i] and T[i]<A[i]:
            print(0)
            exit()
        lst[i]=A[i]

count=1
for i in range(N):
    if not lst[i]:
        count=count*min(T[i],A[i])%mod
print(count)


Measured memory_bytes: 86628
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n, d, cnt = 0;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	rep(i, 0, n) {
		rep(j, 0, d) {
			cin >> x[i][j];
		}
	}
	rep(i, 0, n - 1) {
		rep(j, i + 1, n) {
			double sum_val = 0, dist;
			rep(k, 0, d) {
				sum_val += pow(x[i][k] - x[j][k],2);
			}
			dist = sqrt(sum_val);
			if (ceil(dist) == floor(dist)) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int a[] = {
        1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
    };
    int k; cin >> k; k--;
    cout << a[k] << endl;
    return 0;
}


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

int main(){
  int N;
  long M=0;
  cin >> N;
  vector<int> A(N+1),B(N);
  for(int i=0; i<N+1; i++){
    cin >> A.at(i);
  }
  for(int i=0; i<N; i++){
    cin >> B.at(i);
  }
  
  for(int i=0; i<N; i++){
    if(B.at(i)>=A.at(i)){
      M+=A.at(i);
      B.at(i)-=A.at(i);
    }
    else{
      M+=B.at(i);
      B.at(i)=0;
    }
    if(B.at(i)>=A.at(i+1)){
      M+=A.at(i+1);
      A.at(i+1)=0;
    }
    else{
      M+=B.at(i);
      A.at(i+1)-=B.at(i);
    }
  }
  cout << M << endl;
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
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);
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int ans = 0;
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> a(n);
  rep(i, n) cin >> v[i];
  a = v;
  sort(v.begin(), v.end());
  rep(i, n)
  {
    if (a[i] != v[i])
      ans++;
  }
  if (ans == 2 || ans == 0)
    YES();
  else
    NO();
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

a = max(A)
cnt = 0
while a >= N:
    d, m = divmod(a, N)
    mxidx = A.index(a)
    for i in range(N):
        if i == mxidx:
            A[i] = m
        else:
            A[i] += d
    cnt += d
    a = max(A)
print(cnt)


Measured memory_bytes: 3064
def main():
    a, b, c = map(int, input().split())
    if a == b and b == c:
        print(-1 if a % 2 == 0 else 0)
        return
    cnt = 0
    for i in range(10 ** 9):
        if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
            break
        a, b, c = (b + c) // 2, (a + c) // 2, (a + b) // 2
        cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

#define N 10001
vector<int> A[N];
vector<int> sorted;
int color[N];
int indeg[N];

void topologicalsort(int root) {
    queue<int> Q;
    Q.push(root);
    color[root] = 1;
    while (!Q.empty()) {
        int node = Q.front();
        Q.pop();
        sorted.push_back(node);
        for (vector<int>::iterator it=A[node].begin(); it != A[node].end(); it++) {
            indeg[*it]--;
            if (color[*it] == 0 && indeg[*it] == 0) {
                color[*it] = 1;
                Q.push(*it);
            }
        }
    }
}

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

    for (int i = 0; i < n; i++) {
        color[i] = 0;
        indeg[i] = 0;
    }

    int v1, v2;
    for (int i = 0; i < e; i++) {
        cin >> v1 >> v2;
        A[v1].push_back(v2);
        indeg[v2]++;
    }

    for (int i = 0; i < n; i++) {
        if (color[i] == 0 && indeg[i] == 0) {
            topologicalsort(i);
        }
    }

    for (int i = 0; i < sorted.size(); i++) {
        cout << sorted[i] << endl;
    }

    return 0;
}


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


int main(){
    int n;
    cin >> n;
    vector<vector<int>> a(n,vector<int>(n - 1));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n - 1; j++){
            int b;
            cin >> b;
            a.at(i).at(j) = b - 1;
        }
    }
    
    double start_time = clock();
    
    vector<int> game(n);
    int game_num = 0;
    int max_game_num = n * (n - 1) / 2;
    int answer = 0;
    
    
    while(true){
        
        bool played_one_game = false;
        
        vector<int> aite(n);
        
        for(int i = 0; i < n; i++){
            if(game.at(i) == n - 1){
                aite.at(i) = -1;
                continue;
            }
            aite.at(i) = a.at(i).at(game.at(i));
        }
        
        for(int i = 0; i < n; i++){
            int teki = aite.at(i);
            if(teki == -1)continue;
            if(aite.at(teki) == i && i < teki){
                game.at(i)++;
                game.at(teki)++;
                game_num++;
                played_one_game = true;
            }
        }
        
        if(!played_one_game){
            answer = -1;
            break;
        }
        
        answer++;
        
        bool finished = true;
        for(int i =0; i < n; i++){
            if(game.at(i) != n - 1)finished = false;
        }
        
        if(finished)break;
        
        double now_time = clock();
        if((now_time - start_time) / CLOCKS_PER_SEC >= 1.5){
            answer = n * (n - 1) /2;
            break;
        }

    }
    
    cout << answer << endl;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
const int  M = 201;
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    int n, x;
    cin >> n;
    int mx = 0, mn = 100000;
    fore(i, 0, n){
        cin >> x;
        mn = min(mn, x);
        mx = max(mx, x);
    }
    cout << mx - mn << '\n';
    return 0;
}   

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
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 (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007

int main(){

    string s;

    cin >> s;

    int n = (int)s.length();
    
    int count[3] = {0};

    REP(i,n){
        count[s[i]-'a']++;
    }

    int mx = max(count[0],count[1]);
    mx = max(mx,count[2]);
    int mn = min(count[0],count[1]);
    mn = min(mn,count[2]);
    if(mx - mn <=1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    int N;
    cin >> N;
    deque<int> a;
    REP0(i, N)
    {
        int a_i;
        cin >> a_i;
        if (i % 2 == 0)
            a.push_back(a_i);
        else
            a.push_front(a_i);
    }

    if (N % 2 == 0)
    {
        for (int i = 0; i < N; i++)
        {
            cout << a[i];
            if (i < N - 1)
                cout << " ";
            else
                cout << endl;
        }
    }
    else
    {
        for (int i = N - 1; i >= 0; i--)
        {
            cout << a[i];
            if (i > 0)
                cout << " ";
            else
                cout << endl;
        }
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 3072
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	l := make([]int, n)
	al := make([]int, n+1)

	for i := 1; i < n; i++ {
		l[i] = nextInt()
		if i == 1 {
			continue
		}
		al[i] = min(l[i-1], l[i])
	}
	al[1] = l[1]
	al[n] = l[n-1]

	sum := 0
	for _, v := range al {
		sum += v
	}

	fmt.Println(sum)

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N,P;
bool odd;

int main(){
	cin >> N >> P;
	repp(i,0,N){
		int A;
		cin >> A;
		if(A%2) odd = 1;
	}
	if(odd) cout << ((LL)1<<(N-1)) << endl;
	else cout << (P?0:((LL)1<<N)) << endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N, M;
	int[] a, b;
	long[] c;
	Node[] nodes;
	Edge[] edges;
	boolean enable = true;

	static class Node {
		int id;
		long dist;

		Node(int id) {
			this.id = id;
			dist = Long.MAX_VALUE / 2;
		}
	}

	static class Edge {
		int src, dst;
		long value;

		Edge(int src, int dst, long value) {
			this.src = src;
			this.dst = dst;
			this.value = value;
		}
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
		a = new int[M];
		b = new int[M];
		c = new long[M];
		for (int i = 0; i < M; ++i) {
			tokens = in.readLine().split(" ");
			a[i] = Integer.parseInt(tokens[0]) - 1;
			b[i] = Integer.parseInt(tokens[1]) - 1;
			c[i] = Long.parseLong(tokens[2]);
		}
		nodes = new Node[N];
		for (int i = 0; i < N; ++i) {
			nodes[i] = new Node(i);

		}
		edges = new Edge[M];
		for (int i = 0; i < M; ++i) {
			edges[i] = new Edge(a[i], b[i], -1L * c[i]);
		}
	}

	void calc() {
		// 最短長を求める
		nodes[0].dist = 0;
		for (int i = 0; i < N - 1; ++i) {
			for (int j = 0; j < M; ++j) {
				Edge edge = edges[j];
				if (nodes[edge.dst].dist > nodes[edge.src].dist + edge.value) {
					nodes[edge.dst].dist = nodes[edge.src].dist + edge.value;
				}
			}
		}
		// 閉路チェック
		boolean[] isLoop = new boolean[N];
		Arrays.fill(isLoop, false);
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < M; ++j) {
				Edge edge = edges[j];
				if (isLoop[edge.src]) {
					isLoop[edge.dst] = true;
				}
				if (nodes[edge.dst].dist > nodes[edge.src].dist + edge.value) {
					nodes[edge.dst].dist = nodes[edge.src].dist + edge.value;
					isLoop[edge.dst] = true;
				}
			}
		}
		if (isLoop[N - 1]) {
			enable = false;
		}
	}

	void showResult() {
		if (enable) {
			long result = -1L * nodes[N - 1].dist;
			System.out.println(result);
		} else {
			System.out.println("inf");
		}
	}
}


Measured memory_bytes: 27960
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
            Scanner sc = new Scanner(System.in);
        
            int M = sc.nextInt();
            int D = sc.nextInt();
            
            int count = 0;
            
            for(int i = 1; i <= M; i++){
                for(int j = 22; j <= D; j++){
                    String dd = "" + j;
                    int x = Integer.parseInt(dd.substring(0,1));
                    int y = Integer.parseInt(dd.substring(1,2));
                    
                    if(i==x*y && y >= 2 && x >= 2){
                        count++;
                    }
                }   
            }
            System.out.println(count);
            
    }
}

Measured memory_bytes: 23508
//Author : Sidiq Tri Pratikto
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
//order_of_key(x) = number of elements stricly smaller than x
//find_by_order(x) = return x-th largest element
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	set<string> tmp;
	int n;
	cin >> n;
	while (n--) {
		string s;
		cin >> s;
		tmp.insert(s);
	}
	cout << tmp.size() << "\n";
}

Measured memory_bytes: 19256
#include <stdio.h>

void	swap(int *A, int *B)
{
	int		save;

	save = *A;
	*A = *B;
	*B = save;
}

int		main()
{
	int		A, B;
	int		save, nb, rest;
	double	ans;

	scanf("%d %d\n", &A, &B);
	if (A > B)
		swap(&A, &B);
	nb = B;
	rest = A;
	while (nb % rest)
	{
		save = rest;
		rest = nb % rest;
		nb = save;
	}
	ans = (double)A * (double)B / (double)rest;
	printf("%.0f\n", ans);
	return (0);
}


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


int main() {
  ll H, W;
  cin >> H >>W;
  ll ans;
  ans = (H * W) / 2;
  bool flag = true;
  if( H == 1 || W == 1) {
    ans = 1;
  }
  else if( H % 2 == 1 && W % 2 == 1) {
    ans++;
    flag = false;
  }
  cout << ans << endl;
}

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++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
const int mod = 1000000007;
using pint=pair<ll,ll>;
 
// union by size + path having
class UnionFind {
public:
   vector <ll> par; // 各元の親を表す配列
   vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
   // Constructor
   UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
       for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
   }
   void init(ll sz_) {
       par.resize(sz_);
       siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
       for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
  }
 
   // Member Function
   // Find
   ll root(ll x) { // 根の検索
      while (par[x] != x) {
           x = par[x] = par[par[x]]; // x の親の親を x の親とする
       }
       return x;
  }
 
   // Union(Unite, Merge)
   bool unite(ll x, ll y) {
       x = root(x);
       y = root(y);
       if (x == y) return false;
       // merge technique（データ構造をマージするテク．小を大にくっつける)
       if (siz[x] < siz[y]) swap(x, y);
       siz[x] += siz[y];
       par[y] = x;
       return true;
  }
 
  bool same(ll x, ll y) { // 連結判定
       return root(x) == root(y);
  }
 
  ll size(ll x) { // 素集合のサイズ
      return siz[root(x)];
  }
};
 
ll modpow(ll x, ll n) {
   x = x%mod;
   if(n==0) return 1;  //再帰の終了条件
 
   else if(n%2==1) {
       return (x*modpow(x, n-1))%mod;  //nが奇数ならnを1ずらす
   }
   else return modpow((x*x)%mod, n/2)%mod;  //nが偶数ならnが半分になる
}
 
ll com(ll n, ll k) {
   ll x = 1;
   for(int i=n-k+1; i<=n; i++) {
      x = x*i%mod;
   }
 
   ll y = 1;
   for(int i=1; i<=k; i++) {
       y = y*i%mod;
   }
   y = modpow(y, mod-2);
 
   return x*y%mod;
}
 
int main(){

  ll n,aa=0,bb=0;
  cin >> n;
  vector<ll> data(n);
  rep(i,n){
    cin >> data.at(i);
  }
  sort(data.begin(),data.end());
  reverse(data.begin(),data.end());
  for(ll i=0; i<n; i++){
    if(i%2==0) aa+=data.at(i);
    else bb+=data.at(i);
  }

  cout << aa-bb << endl;

}

Measured memory_bytes: 256
N=int(input())
A=[]
for n in range(N):
    a=int(input())
    A.append(a)
dai=max(A)
basyo=A.index(max(A))
A.pop(basyo)
for n in range(N):
    if n==basyo:
        print(max(A))
    else:
        print(dai)


Measured memory_bytes: 68568
l=[]
for i in range(3):
            a=list(input())
            l.append(a)
print("")
x=l[0][0]
X=0
for  i in range(len(l[0])+len(l[1])+len(l[2])):
            if x=='a':
                        del l[X][0]
                        if len (l[0])!=0:
                                    x=l[0][0]
                        else:
                                    print('A')
                                    break
                        X=0
            elif x=='b':
                        del l[X][0]
                        if len(l[1])!=0:
                                    x=l[1][0]
                        else:
                                    print('B')
                                    break
                        X=1
            else:
                        del l[X][0]
                        if len(l[2])!=0:
                                    x=l[2][0]
                        else:
                                    print('C')
                                    break
                        X=2

            

            
                        


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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

int w,h;
vector<string> ss;
bool is_white[103][103];
bool is_black[103][103];

void dfs(int x_,int y_,bool (*f_)[103],bool f2) {
    //cout<<x_<<","<<y_<<endl;
    if(f_[x_][y_]||(ss[x_][y_]!='.'&&f2)) return;
    f_[x_][y_]=true;
    rep(i,4) {
        int x = x_ + dx[i];
        int y = y_ + dy[i];
        if(0<=x&&x<ss.size() && 0<=y&&y<ss[x].size()) {
            dfs(x,y,f_,true);
        }
    }
}

void solve() {
    rep(i,103) rep(j,103) is_white[i][j]=is_black[i][j]=false;
    ss.resize(h);
    rep(i,h) {
        string t; cin>>t;
        ss[i]=t;
    }
    int ans_b=0,ans_w=0;
    rep(i,ss.size()) {
        rep(j,ss[i].size()) {
            if(ss[i][j]=='B') dfs(i,j,is_black,false);
            if(ss[i][j]=='W') dfs(i,j,is_white,false);
        }
    }
    rep(i,ss.size()) rep(j,ss[i].size()) {
        //cout<<i<<","<<j<<":"<<is_white[i][j]<<","<<is_black[i][j]<<ss[i][j]<<endl;
        if(ss[i][j]=='.'&&(is_white[i][j]^is_black[i][j])) {
           if(is_white[i][j]) ans_w++;
           else ans_b++; 
        }
    }
    cout<<ans_b<<" "<<ans_w<<endl;
    ss.clear();
}

int main() {
    while(cin>>w>>h) {
        if(w+h==0) return 0;
        solve();
    }

    return 0;
}

Measured memory_bytes: 1332
P = [1 for _ in range(55556)]
P[0]=0
P[1]=0
for i in range(2,int(55555*0.5)+1):
    for j in range(i*i,55556,i):
        P[j] = 0
Q = []
for i in range(2,55556):
    if P[i]==1:
        Q.append(i)
imax = len(Q)
N = int(input())
A = [2]
for i in range(3,imax):
    if str(Q[i])[-1]=="3":
        A.append(Q[i])
print(*A[:N])       

Measured memory_bytes: 41840
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n,m;
    int cnt=0;
    vector<int> ans1;
    vector<int> ans2;
    while(1){
        cin>>n>>m;
        if(n==0 && m==0){
            //cout<<"o"<<endl;
            for(int i=0;i<cnt;i++){
                //cout<<ans1[i]<<" "<<ans2[i]<<endl;
                if(ans1[i]==120) cout<<"-1"<<endl;
                else cout<<ans1[i]<<" "<<ans2[i]<<endl;
            }
            return 0;
        }
        cnt++;
        vector<int> vn(n,-1),vm(m,0);
        rep(i,n) cin>>vn[i];
        rep(i,m) cin>>vm[i];
        int sumn=0,summ=0;
        for(int i=0;i<n;i++) sumn+=vn[i];
        for(int i=0;i<m;i++) summ+=vm[i];
        int now1=120,now2=120;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                sumn-=vn[i];
                summ+=vn[i];
                sumn+=vm[j];
                summ-=vm[j];
                if(sumn==summ && (now1+now2)>=(vn[i]+vm[j])){
                    now1=vn[i];
                    now2=vm[j];
                }
                sumn+=vn[i];
                summ-=vn[i];
                sumn-=vm[j];
                summ+=vm[j];
            }
        }
        ans1.push_back(now1);
        ans2.push_back(now2);
        //cout<<now1<<" "<<now2<<endl;
    }
    return 0;
}


Measured memory_bytes: 3048
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int H, W;
  char b[55][55];
  cin >> H >> W;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> b[i][j];
    }
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      int cnt = 0;
      if(b[i][j] == '#'){cout << '#'; continue;}
      for(int k = 0; k < 8; k++){
	int nx = j + ddx[k], ny = i + ddy[k];
	if(0 <= nx && nx < W && 0 <= ny && ny < H){
	  if(b[ny][nx] == '#')cnt++;
	}
      }
      cout << cnt;
    }
    cout << endl;
  }
  
  return 0;
}


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

int main(){
    using namespace std;
    auto chmin = [](auto& a, auto b) -> bool{return a > b && ((a = b), true);};
    unsigned long K;
    cin >> K;
    deque<unsigned long> dfs(1, 1), dist(K, 50);
    dist[1] = 1;
    while(!dfs.empty()){
        auto i = dfs.front(), d = dist[i];
        dfs.pop_front();
        if(!i)return 0 % printf("%lu\n", d);
        if(chmin(dist[i * 10 % K], d))dfs.push_front(i * 10 % K);
        if(chmin(dist[++i %= K], d + 1))dfs.push_back(i);
    }
}

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


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			cout<<i<<"x"<<j<<"="<<i*j<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1156
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
n,m = i2()
if n == 1:
    a = 0
a = n*(n-1)//2
b = m*(m-1)//2
print(a+b)

Measured memory_bytes: 3064
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

M = getN()
# dがc個並ぶ
que = [getList() for i in range(M)]

# 圧縮を繰り返して１桁になったら終了
# 圧縮する順番を工夫する
# なるべく繰り上がるようにする
# 5 + 5 = 10, 6 + 7 = 13

# 10 - 1消費することでラウンドを一つ増やせる
cnt = 0
left = 0
for d, c in que:
    cnt += c
    left += d * c

while left >= 10:
    t = left // 10
    cnt += t
    left %= 10
    left += t
print(cnt - 1)

Measured memory_bytes: 114612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
typedef pair<int,int>pii;
int n,w;
const int mxN=1e5+10,M=1e9+7;
int val[110],peso[110];
int dp[110][mxN];

int solve(int obj,int aguenta){
    if(obj==n || !aguenta)return dp[obj][aguenta]=0;
    if(dp[obj][aguenta]>=0)return dp[obj][aguenta];

    int naoc=solve(obj+1,aguenta);
    if(peso[obj]<=aguenta){
        int col=solve(obj+1,aguenta-peso[obj])+val[obj];

        return dp[obj][aguenta]=max(col,naoc);
    }
    return dp[obj][aguenta]=naoc;
}
//ALWAYS CHECK THE FUCKING LONG LONG INT CASE YOUR DUMBASS
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>n>>w;
    for(int i=0;i<n;i++){
        cin>>peso[i]>>val[i];   
    }
    /*for(int i=0;i<n;i++){
        cout<<peso[i]<<val[i]<<"\n";   
    }*/
    solve(0,w);
    cout<<dp[0][w];
}

Measured memory_bytes: 86272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n;
    cin >> n;

    ll a[n];
    rep(i, 0, n){
        cin >> a[i];
        a[i]--;
    }

    ll count = 0;
    rep(i, 0, n){
        if(a[i] == i){
            if(i == n - 1){
                swap(a[i], a[i - 1]);
                count++;
            }else{
                swap(a[i], a[i + 1]);
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1024
num = list(map(int, input().split()))

point = []
point.append(num[1])
for i in range(num[0] - 1):
  point.append(num[1] + i + 1)
  point.append(num[1] - i - 1)

m = 0
for i in range(len(point)):
  if point[i - m] > 1000000 or point[i - m] < -1000000:
    del point[i - m]
    m = m + 1

point.sort()

print(' '.join(map(str, point)))

Measured memory_bytes: 3064
use proconio::input;

fn main() {
    input! {
        a: u128,
        b: String,
    }

    if let [s, t] = *b.split('.').collect::<Vec<_>>() {
        let s = s.parse::<u128>().unwrap();
        let t = t.parse::<u128>().unwrap();
        let ans = a * (100 * s + t) / 100;
        println!("{}", ans);
    } else {
        unreachable!();
    }
}


Measured memory_bytes: 2172
#include<stdio.h>
int main()
{
    int a,i;
    scanf("%d",&a);

    char s[10];

    scanf("%s/n",&s);



     if(2800<=a && a<5000)
     {
         if(a<3200)
         {
             printf("red\n");
         }
         else {
            printf("%s\n",s);

         }
     }

}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;

	scanf("%d %d %d", &a, &b, &c);

	if (a < b && b < c)
	{
		printf("Yes\n");

		return 0;

	}

	else 

		printf("No\n");

	return 0;
}

Measured memory_bytes: 580
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        // 主処理
        String[] array = s.split("");
        Arrays.sort(array);
        String word = String.join("", array);
        boolean judge = "abc".equals(word);
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<math.h>
int main(){
   long a,b,n;
   scanf("%ld %ld %ld",&a,&b,&n);
   long x,ans;
   if(n>=b){
      x=b-1;
   }else{
      x=n;
   }
   ans = floor(a*x/b)-a*floor(x/b);
   printf("%ld\n",ans);
   return 0;
}


Measured memory_bytes: 1720
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
  string S;
  lint K;
  cin >> S >> K;

  set<string> cand;
  lint N = S.length();
  for(lint i=0; i<N; i++) {
    for(lint k=0; k<10; k++) {
      string s = S.substr(i,k);
      if(s.length()) cand.insert(s);
    }
  }
  cout << *next(cand.begin(), K-1) << endl;
}

Measured memory_bytes: 6316
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H,W;
  cin >> H >> W;
  vector<string> G(H);
  for(int i=0; i<H; i++){
    cin >> G[i];
  }
  vector<vector<int>> dp(H+1,vector<int> (W+1,inf));
  dp[0][0] = 0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(i+1<H and G[i][j] != G[i+1][j]){
        chmin(dp[i+1][j],dp[i][j]+1);
      }else{
        chmin(dp[i+1][j],dp[i][j]);
      }
      if(j+1<W and G[i][j] != G[i][j+1]){
        chmin(dp[i][j+1],dp[i][j]+1);
      }else{
        chmin(dp[i][j+1],dp[i][j]);
      }
    }
  }
  if(G[H-1][W-1] == '#'){
    dp[H-1][W-1]++;
  }
  cout << (dp[H-1][W-1]+1)/2 << endl;
  return 0;
}


Measured memory_bytes: 384
H,W=map(int,input().split())
h,w=H//2,W//3
s=sorted([w*H,(W-w)*(H-h),(W-w)*h])
a=s[2]-s[0]
s=sorted([(w+1)*H,(W-w-1)*(H-h),(W-w-1)*h])
a=min(s[2]-s[0],a)
a=min(H*(W-3*w),a)
a=min(H*(3+3*w-W),a)
h,w=H//3,W//2
s=sorted([W*h,(W-w)*(H-h),w*(H-h)])
a=min(s[2]-s[0],a)
s=sorted([W*(h+1),(W-w)*(H-h-1),w*(H-h-1)])
a=min(s[2]-s[0],a)
s=sorted([W*(h+2),(W-w)*(H-h-2),w*(H-h-2)])
a=min(s[2]-s[0],a)
a=min((H-3*h)*W,a)
a=min((3+3*h-H)*W,a)
print(a)

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repc(i, a, b) for(int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;



int main() {
  int n, k;
  cin >> n >> k;
  vec<bool> having(n, false);
  rep(i, k){
    int d;
    cin >> d;
    rep(j, d){
      int a;
      cin >> a;
      having[a-1] = true;
    }
  }
  int ans = 0;
  rep(i, n){
    if(!having[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	int ans = 1, max, temp;
	cin >> temp;
	max = temp;
	for(int i = 1; i < n; i++){
		cin >> temp;
		if(temp < max){
			continue;
		}
		max = temp;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int h, w, n;

bool isIn(int x, int y){
    return 0 <= x && x < h && 0 <= y && y < w;
}

void fall(vector<string> & field){
    for(int i=h-1; 1 <= i; i--){
        for(int j=0; j < w; j++){
            int p = i;
            while(p < h && field[p][j] == '.' && field[p-1][j] != '.'){swap(field[p][j], field[p-1][j]); p++;}
        }
    }
}

bool run(vector<string> field){
    fall(field);
    while(true){
        bool erase = false;
        bool f[h][w];
        for(int i=0; i< h; i++)for(int j=0; j< w; j++) f[i][j] = false;

        for(int i=0; i < h; i++){
            for(int j=0; j < w; j++){
                if(field[i][j] == '.') continue;
                int count = 1;
                while(isIn(i, j+count) && field[i][j] == field[i][j+count]) count++;
                if(n <= count){for(int k=0; k < count; k++) f[i][j+k] = true; erase = true;}
                count = 1;
                while(isIn(i+count, j) && field[i][j] == field[i+count][j]) count++;
                if(n <= count){for(int k=0; k < count; k++) f[i+k][j] = true; erase = true;}
            }
        }
        if(!erase) break;

        for(int i=0; i < h; i++)for(int j=0; j < w; j++)if(f[i][j]) field[i][j] = '.';
        fall(field);
    }
    for(int i=0; i < h; i++)for(int j=0; j < w; j++) if(field[i][j] != '.') return false;
    return true;
}

int main(){
    cin >> h >> w >> n;
    vector<string> field(h);
    for(int i=0; i < h; i++) cin >> field[i];
    for(int i=0; i < h; i++){
        for(int j=0; j < w; j++){
            for(int k=0; k < 2; k++){
                if(isIn(i, j+1)){
                    swap(field[i][j], field[i][j+1]);
                    if(run(field)){cout << "YES" << endl; return 0;}
                    swap(field[i][j], field[i][j+1]);
                }
            }
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 1216
#!/usr/bin/python
def shortestPath(g,s,dist,prev):
	n = len(g)-1
	Q=[]
	heapq.heappush(Q,(0,-2,s))
	while Q:
		e = heapq.heappop(Q)
		if prev[e[2]]!=-1: continue
		prev[e[2]] = e[1]
		for f in g[e[2]]:
			if dist[f[2]] > e[0] + f[0]:
				dist[f[2]] = e[0] + f[0]
				heapq.heappush(Q,(e[0]+f[0],f[1],f[2]))

import sys,heapq
if sys.version_info[0]>=3:raw_input=input

n=int(raw_input())
g=[[] for _ in range(n+1)]
for _ in range(n-1):
	a,b=map(int,raw_input().split())
	g[a-1]+=[(1,a-1,b-1)]
	g[b-1]+=[(1,b-1,a-1)]
z=[-1]*n
for _ in range(int(raw_input())):
	a,b=map(int,raw_input().split())
	g[n]+=[(b,n,a-1)]
	z[a-1]=b
a=[1e9]*n+[0]
shortestPath(g,n,a,[-1]*(n+1))
if any(z[i]>=0 and z[i]!=a[i] for i in range(n)):
		print('No')
		sys.exit()
for _ in g:
	if any(e[1]!=n and abs(a[e[1]]-a[e[2]])!=1 for e in _):
			print('No')
			sys.exit()
print('Yes')
print("\n".join(map(str,a[:n])))


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

int main() {

    int n, k;
    cin >> n >> k;

    int res = n;
    int ans = 1;
    bool ok = false;
    while(res >= k){
        res /= k;
        ans++;
        ok = true;
    }
//    if(ok) ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define D 365
typedef long long ll;
ll calcSat(int *tmpt, int s[][26], int *c) {
	// int tmpt[D];
	int last[26] = {0};
	ll tmpSat = 0;
	// for (int i = 0; i < D; i++) {
	// 	tmpt[i] = rand() % 26 + 1;
	// }
	for (int i = 0; i < D; i++) {
		tmpSat += s[i][tmpt[i] - 1];
		last[tmpt[i] - 1] = i + 1;
		for (int j = 0; j < 26; j++) {
			tmpSat -= (c[j] * (i + 1 - last[j]));
		}
		/**/
		printf("%lld\n", tmpSat);
		/**/
	}
}
int main() {
	srand(628);
	scanf("%*d");
	int c[26], s[D][26];
	int t[D] = {0};
	ll bestSat = 0;
	for (int i = 0; i < 26; i++) {
		scanf("%d", &c[i]);
	}
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			scanf("%d", &s[i][j]);
		}
	}
	/**/
	for (int i = 0; i < D; i++) {
		scanf("%d", &t[i]);
	}
	/**/

	// for (int cnt = 0; cnt < 1000; cnt++) {
	ll tmpSat = calcSat(t, s, c);
	// if (tmpSat < bestSat) {
	// 	bestSat = tmpSat;
	// 	for (int i = 0; i < D; i++) {
	// 		t[i] = tmpt[i];
	// 	}
	// }
	//}
	return 0;
}

Measured memory_bytes: 1724
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let hn: Vec<usize> = read_vec();
    let h = hn[0];
    let n = hn[1];
    let abv: Vec<Vec<u32>> = read_vec2(n);
    let mut dp: Vec<u32> = vec![0; 10001];

    for i in 1..h + 1 {
        let mut tmp = 1000000000;
        for k in 0..n {
            let a = abv[k][0];
            let b = abv[k][1];
            let tmp1;
            if (a as usize) < i {
                tmp1 = b + dp[i - a as usize];
            } else {
                tmp1 = b;
            }
            if tmp1 < tmp {
                tmp = tmp1;
            }
        }
        dp[i] = tmp;
    }

    println!("{}", dp[h]);
}


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

typedef long long ll;
using namespace std;
const ll m = 1e9 + 7;

int main() {
	int n; cin >> n;
	vector<int>vec(n);
	for (int i = 0; i < n; ++i)
		cin >> vec[i];

	int mx = 0;
	ll res = 0;
	for (int i = 0; i < n; ++i) {
		mx = max(mx, vec[i]);
		int x = mx;
		res += x - vec[i];
	}
	cout << res << endl;
    return 0;
}

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

const int mo=998244353;
const double pi=acos(-1),eps=1e-10;
int n,x[205],y[205],s[205],ans;
double a[205]; 

int qpow(int a,int b)
{
	int x=a;  a=1;
	while (b)
		{
			if (b&1)  a=1LL*a*x%mo;
			x=1LL*x*x%mo,b>>=1;
		}
	return a;
}

int f(int x){return (qpow(2,x)+mo-(1+x+1LL*x*(x-1)/2)%mo)%mo;}
int dcmp(double x){return (x>eps)-(x<-eps);}

void work()
{
	scanf("%d",&n),ans=f(n);
	for (int i=1; i<=n; i++)  scanf("%d %d",&x[i],&y[i]);
	for (int i=1; i<=n; i++)
		{
			for (int j=1,k=0; j<=n; j++)
				if (i!=j)  a[++k]=atan2(y[i]-y[j],x[i]-x[j]);
			for (int j=1; j<n; j++)  a[j]+=pi*(dcmp(a[j])<=0);
			sort(a+1,a+n);
			for (int l,r=1; r<n; )
				{
					l=r;
					while ((r<n)&&(dcmp(a[r]-a[l])==0))  r++;
					s[r-l+1]++;
				}
		}
	for (int i=1; i<=n; i++)  ans=(ans+mo-1LL*s[i]/i*f(i)%mo)%mo;
	printf("%d",ans);
}

int main()
{
	work();
	return 0;
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

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

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

    vector<int> a(m);
    int ans=0, point;
    for(int in=0;in<n;in++) {
        point = 0;
        for(int im=0;im<m;im++) {
            cin >> a.at(im);
            point += a.at(im) * b.at(im);
        }
        point += c;
        if(point>0) ans++;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256