akhauriyash/Code-Regression huggingface dataset:
#functions for getting rows and columns
def getRow(graph, index):
  return graph[index]
def getElem(row, index):
  return row[index]
def getAbove(graph, h, w):
  try:
    return getElem(getRow(graph, h-1), w)
  except:
    return "#"
def getBelow(graph, h, w):
  try:
    return getElem(getRow(graph, h+1), w)
  except:
    return "#"
def getRight(graph, h, w):
  try:
    return getElem(getRow(graph, h), w+1)
  except:
    return "#"
def getLeft(graph, h, w):
  try:
    return getElem(getRow(graph, h), w-1)
  except:
    return "#"

#getting input
h, w = [int(x) for x in input().split()]
graph = []
for hh in range(h):
  graph.append(input())


#processing
pos = "Yes"
for height in range(h):
  if pos == "No":
    break
  for width in range(w):
    element = getElem(getRow(graph, height), width)
    if element == ".":
      continue
    else:
      if getAbove(graph, height, width) == "#":
        continue
      elif getBelow(graph, height, width) == "#":
        continue
      elif getRight(graph, height, width) == "#":
        continue
      elif getLeft(graph, height, width) == "#":
        continue
      else:
        pos = "No"
        break


print(pos)

Measured memory_bytes: 3064
class Dice():
    
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]


    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def get_Top(self):
        return self.number[0]


dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

loc_array = str(input())
for tmp_loc in loc_array:
    dice.roll(tmp_loc)
print("%d"%(dice.get_Top()))



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

using namespace std;

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    for(int i=0;i<tx-sx;i++){
        cout << 'R';
    }
    for(int i=0;i<ty-sy;i++){
        cout << 'U';
    }
    for(int i=0;i<tx-sx;i++){
        cout << 'L';
    }
    for(int i=0;i<ty-sy;i++){
        cout << 'D';
    }
    cout << 'L';
    for(int i=0;i<ty-sy+1;i++){
        cout << 'U';
    }
    for(int i=0;i<tx-sx+1;i++){
        cout << 'R';
    }
    cout << 'D';
    cout << 'R';
    for(int i=0;i<ty-sy+1;i++){
        cout << 'D';
    }
    for(int i=0;i<tx-sx+1;i++){
        cout << 'L';
    }
    cout << 'U';
    cout << endl;
}

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

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
class tsort {
 public:
  int V;
  vector<vector<int>> G;
  vector<int> deg, res;
  tsort(int node_size) : V(node_size), G(V), deg(V, 0) {}
  void add_edge(int from, int to) {
    G[from].push_back(to);
    deg[to]++;
  }
  bool sort() {
    queue<int> que;
    for (int i = 0; i < V; i++) {
      if (deg[i] == 0) {
        que.push(i);
      }
    }
    while (!que.empty()) {
      int p = que.front();
      que.pop();
      res.push_back(p);
      for (int v : G[p]) {
        if (--deg[v] == 0) {
          que.push(v);
        }
      }
    }
    return (*max_element(deg.begin(), deg.end()) == 0);
  }
};
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  tsort t(n);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    t.add_edge(x, y);
  }
  t.sort();

  vector<int> dp(n, 0);
  for (int i : t.res) {
    for (int to : t.G[i]) {
      chmax(dp[to], dp[i] + 1);
    }
  }
  cout << MAX(dp) << endl;
  ret;
}


Measured memory_bytes: 9972
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        Queue queue = new Queue();
        for (int i = 0; i < n; i++) {
            queue.enqueue(new Process(scanner.next(), scanner.nextInt()));
        }
        int t = 0;
        while (queue.hasNode()) {
            Process process = queue.dequeue();
            t += Math.min(process.time, q);
            if (process.time <= q) {
                System.out.println(process.name + " " + String.valueOf(t));
            } else {
                process.time -= q;
                queue.enqueue(process);
            }
        }
    }

    private static class Process {
        private String name;
        private int time;

        private Process(String name, int time) {
            this.name = name;
            this.time = time;
        }
    }

    private static class Queue {
        private static class Node {
            private Process process;
            private Node next;
            private Node prev;

            private Node(Process process, Node next) {
                this.process = process;
                this.next = next;
            }
        }

        private Node first;
        private Node last;

        private void enqueue(Process process) {
            last = new Node(process, last);
            if (last.next != null) {
                last.next.prev = last;
            }
            if (first == null) {
                first = last;
            }
        }

        private Process dequeue() {
            Process process = first.process;
            first = first.prev;
            return process;
        }

        private boolean hasNode() {
            return first != null;
        }
    }
}

Measured memory_bytes: 78844
L, R = [int(_) for _ in input().split()]

def solve(L, R):
    if L // 2019 != R // 2019:
        return 0
    l, r = L % 2019, R % 2019
    if l == 0 or r == 0:
        return 0
    result = min(
        (i * j) % 2019
        for i in range(l, r)
        for j in range(i + 1, r + 1)
    )
    return result

print(solve(L, R))


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

#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int W, H;
int front[10];
int side[10];
int need[10][10];

int main(){
	while(cin >> W >> H and W + H){
		memset(front, 0, sizeof(front));
		memset(side, 0, sizeof(side));
		memset(need, 0, sizeof(need));
		REP(i, W) cin >> front[i];
		REP(i, H) cin >> side[i];
		REP(i, W) REP(j, H) need[i][j] = front[i];
		int res = 0;
		REP(i, W) res += front[i];
		REP(i, H) res += side[i];
		bool found[W];
		memset(found, 0, sizeof(found));
		REP(j, H) REP(i, W){
			if(side[j] == need[i][j] and !found[i]) { res -= side[j]; found[i] = true; break;}
		} 
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  bool is4=false;
 
  for(int i=0;i<N;i++){
	string color;
    cin >> color;
    if(color=="Y"){is4=true; break;}
  }
  cout << (is4 ? "Four":"Three") <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll n;
    cin>>n;
    ll ans = 1000000000001;
    for(ll i = 1;i<=sqrt(n);i++){
        if(n%i==0){
            ll n2 = n/i;
            n2--;
            ll i2 = i-1;

            if(n2+i2<ans)ans=n2+i2;
        }
    }
cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>


using namespace std;

int main()
{
	int evens, odds; cin >> evens >> odds;

	cout << ((evens * (evens-1)) / 2) + ((odds * (odds-1)) / 2);

    return 0;
}


Measured memory_bytes: 256
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
 */
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
        int c=0,ans=0;
        ArrayDeque<Integer> st=new ArrayDeque<>();
        for (int i = 1; i < a + 1; i++) {
            if(a%i==0&&b%i==0)st.addFirst(i);
        }
        while (c<k){
            ans=st.pollFirst();
            c++;
        }
        out.println(ans);
    }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int ask(int a,int b,int c,int d){
	cout<<"? "<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"<<flush;
	int res;
	cin>>res;
	return res;
}

ll h, w, n, K;
int a[55][55];

int main() {
    cin >> h >> w >> n >> K;
    rep(i,h)rep(j,w)a[i][j] = -1;

    int sol = 0;
    if(sol == 1){
        rep(i,h){
            rep(j,w){
                if(i%2==0&&j%2==0){
                    int res = ask(i,j,i+1,j+1);
                    if(res == 0){
                        a[i][j] = a[i][j+1] = a[i+1][j] = a[i+1][j+1] = 0;
                    }
                    if(res == 4){
                        a[i][j] = a[i][j+1] = a[i+1][j] = a[i+1][j+1] = 1;
                    }
                }
            }
        }
    }
        





    // 愚直
    int cnt = 0;
    rep(i,h){
        rep(j,w){
            if(a[i][j] == 1){
                cnt++;
                if(cnt == n)break;
                continue;
            }
            if(a[i][j] == -1){
                cout << "? " << i << " " << j << " " << i << " " << j << endl << flush;
                int res;
                cin >> res;
                a[i][j] = res;
                cnt += a[i][j];
            }
            if(cnt == n)break;
        }
        if(cnt == n)break;
    }

    // ans出力
    ll ans = 0;
    rep(i,h){
        rep(j,w){
            if(a[i][j]==1)ans = (ans + mod_pow(2,i*w+j,K)) % K;
        }
    }
    cout << "! " << ans << endl << flush;
    return 0;
}




Measured memory_bytes: 3808
#include<iostream>
using namespace std;
int a[1000000];
int main()
{
	int s;
	cin>>s;
	int temp=s,temp1;
	for(int i=1;i<=1000000;i++)
	{
		a[temp]++;
		if(temp%2==0)
		{
			temp1=temp/2;
		}
		else
		{
			temp1=temp*3+1;
		}
		if(a[temp]>1)
		{
			cout<<i;
			return 0;
		}
		temp=temp1;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll X[55], Y[55];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    map<P, bool> is_exist;
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
        is_exist[P(X[i], Y[i])] = true;
    }
    map<P, int> cnt;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            ll p = X[i] - X[j], q = Y[i] - Y[j];
            if (cnt[P(p, q)]) continue;
            for (int k = 0; k < N; k++) {
                int new_x = X[k] + p, new_y = Y[k] + q;
                if (is_exist[P(new_x, new_y)]) cnt[P(p, q)]++;
            }
        }
    }
    ll max_cnt = 0;
    for (auto i = cnt.begin(); i != cnt.end(); i++) {
        max_cnt = max(max_cnt, (ll)i->second);
    }
    cout << N - max_cnt << endl;
    return 0;
}

Measured memory_bytes: 2816
N = int(input())
h = list(map(int, input().split()))
dp = [0] * N
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
                dp[i - 2] + abs(h[i] - h[i - 2])            
                )
print(dp[N - 1])


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

bool less_second(pair<int,int> A,pair<int,int> B){
  return A.second<B.second;
}
int main(){
  int N;
  
  scanf("%d",&N);
  vector<pair<int, int> >tasklist(N);
    
  for(int i=0;i<N;i++)
    scanf("%d %d", &tasklist[i].first, &tasklist[i].second);

  sort( tasklist.begin(), tasklist.end(), less_second);

  int flag=0;
  int task=0;
  for(int i=0;i<N;i++){
    task += tasklist[i].first;
    if( task > tasklist[i].second )
      flag++;
  }

  if(flag)
    printf("No\n");
  else
    printf("Yes\n");
  
  return 0;
}


Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map(String::toInt)
    var flug = true
    for(a in A) {
        if(a % 2 == 0) {
            if(a % 3 != 0 && a % 5 != 0)
                flug = false
        }
    }

    if (flug) {
        print("APPROVED")
    } else {
        print("DENIED")
    }
}

Measured memory_bytes: 37996
N, M = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(M)]  #sの各要素のはじめはk
p = list(map(int, input().split()))
ans = 0

# 0をoffとして2進数でパターンを表現

for i in range(2 ** N):
    ptn = bin(i)[2:].rjust(N, "0")  # N桁の2進表現にする,さらに0を足している（左に）
    light = True  # 着目している電球が点灯していないときはこれがFalseになる
    for j in range(M):
        tmp = 0  # 着目している電球について、スイッチのonの個数をカウントする
        for n in range(1, s[j][0] + 1):
            if ptn[s[j][n] - 1] == "1":
                tmp += 1
        if tmp % 2 != p[j] % 2:
            light = False
    if light:
        ans += 1

print(ans)

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

int main() {
	int n;
	cin>>n;
	if(n>999)cout<<1111;
	else cout<<((n-1)/111+1)*111;
	return 0;
}

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

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=n-1;i>=m;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-9

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

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<vector<pair<int, int>>> v(n, vector<pair<int, int>>(0, { 0,0 }));
	vector<vector<vector<int>>> p(n, vector<vector<int>>(n, vector<int>(1, -1)));
	REP(i, m) {
		int a, b, c;
		
		cin >> a >> b >> c;
		a--;b--;
		v[a].push_back({ b, c });
		v[b].push_back({ a,c });
		p[a][b][0] = b;
		p[b][a][0] = a;
	}
	
	vector<vector<int>> d(n, vector<int>(n, INF));
	REP(i, n) {
		REP(j, v[i].size()) {
			d[i][v[i][j].first] = v[i][j].second;
			d[v[i][j].first][i] = v[i][j].second;
			
		}
	}
	REP(k, n) {
		REP(i, n) {
			REP(j, n) {
				if (d[i][j] > d[i][k] + d[k][j]) {
					d[i][j] = d[i][k] + d[k][j];
					p[i][j].clear();
					REP(s, p[i][k].size())p[i][j].push_back(p[i][k][s]);
					REP(t, p[k][j].size())p[i][j].push_back(p[k][j][t]);
				}
			}
		}
	}
	vector<vector<bool>> used(n, vector<bool>(n, false));

	REP(i, n) {
		REP(j, n) {
			if (p[i][j][0] != -1) {
				int a = i, b;
				REP(k, p[i][j].size()) {
					b = p[i][j][k];
					used[a][b] = true;
					a = b;
				}
			}
		}
	}
	int cnt = 0;
	REP(i, n) {
		REP(j, n) {
			if (!used[i][j]) cnt++;
		}
	}

	cout << (cnt -n*n+2*m)/2<< endl;
	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){

  int a,b;
  int i;

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

  i = 0;
  while(a*i - i + 1 < b) i++;

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

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> dp(N + 1, 0);
	dp[0] = 1;
	vector<int> X(N + 1, 1);
	int a;
	for (int i = 0; i < M; i++) {
		cin >> a;
		X[a] = 0;
	}
	for (int i = 1; i <= N; i++) {
		if (X[i] == 1) {
			dp[i] = dp[i - 1];
			if (i - 2 >= 0) {
				dp[i] += dp[i - 2];
			}
			dp[i] %= MOD;
		}

	}
	cout << dp[N] << endl;
}

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

//#define debug
using namespace std;
int n, m, i, j, k;

int main() {
#ifdef debug
	freopen("1.in", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	while (cin >> n >> k) {
		int d = 0;
		while (n) {
			n /= k;
			d++;
		}
		cout << d << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a= n/1000;
  int b=(n/100)%10;
  int c=(n/10)%100%10;
  int d=(n%1000)%100%10;

  if(a+b+c+d==7)
    cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
  else if(a+b+c-d==7)
    cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
  else if(a+b-c-d==7)
    cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
  else if(a+b-c+d==7)
    cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
  
  else if(a-b+c+d==7)
    cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
  else if(a-b+c-d==7)
    cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
  else if(a-b-c-d==7)
    cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
  else if(a-b-c+d==7)
    cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;



  
 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    char a, b;

    cin >> a >> b;

    if (a == 'H' && b == 'H') {
        cout << 'H' << endl;
    } else if (a == 'H' && b == 'D') {
        cout << 'D' << endl;
    } else if (a == 'D' && b == 'H') {
        cout << 'D' << endl;
    } else if (a == 'D' && b == 'D') {
        cout << 'H' << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ini = [a[0]]
for i in range(n-1):
    if a[i] > a[i+1]:
        ini.append(a[i]-a[i+1])
        a[i+1] = a[i]
    else:
        ini.append(0)
        # a[i+1] = a[i]
print(sum(ini)-ini[0])


Measured memory_bytes: 32384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl
 
int main() {
    int n, m1=0, m2=0;
    cin >> n;
    map<int, int> sec;
    rep(i,n) {
        int c;
        cin >> c;
        sec[c]++;
    }
    for (auto x : sec) {
        if (x.second >= 2) {
            if (x.first > m1) {
                m2 = m1;
                m1 = x.first;
                if (x.second >= 4) m2 = m1;
            }
            else if (x.first > m2) m2 = x.first;
        }
    }
    ct((int64_t)m1*m2);
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

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

    ll N;
    cin >> N;
    vll A(N);
    rep(i, N) cin >> A[i];

    vvll c(N, vll(2, 0));
    rep(i, N) c[i] = {A[i], i};
    sort(all(c), [&](auto x, auto y){ return x[0]>y[0]; });
    vvll dp(N+1, vll(N+1, 0));
    rep(i, N+1){
        rep(j, N+1-i){
            if(i>0) dp[i][j] = max(dp[i][j], dp[i-1][j]+(c[i+j-1][1]-i+1)*c[i+j-1][0]);
            if(j>0) dp[i][j] = max(dp[i][j], dp[i][j-1]+(N-j-c[i+j-1][1])*c[i+j-1][0]);
        }
    }
    ll res = 0;
    rep(i, N+1) res = max(res, dp[i][N-i]);
    cout << res << endl;
}


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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 200*1000+10;
int k, n, a[maxn], mx;

int main()
{
	cin >> k >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (i > 0)
			mx = max(mx, a[i] - a[i - 1]);
		if (i == n - 1)
			mx = max(mx, a[0] + k - a[n - 1]);
	}
	cout << k - mx;
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  string X, Y;
  cin >> X >> Y;
  X = ' ' + X;
  Y = ' ' + Y;
  int X_size = X.size();
  int Y_size = Y.size();
  vector<vector<int>> dp(X_size, vector<int>(Y_size));
  for (int i = 1; i < X_size; i++) {
    for (int j = 1; j < Y_size; j++) {
      if (X[i] == Y[j]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }
  int c1 = X_size, c2 = Y_size;
  string ret = "";
  while (c1 > 0 && c2 > 0) {
    if (X[c1] == Y[c2]) {
      ret += X[c1];
      --c1;
      --c2;
    } else {
      if (dp[c1][c2] == dp[c1][c2 - 1]) {
        --c2;
      } else {
        --c1;
      }
    }
  }
  reverse(ret.begin(), ret.end());
  ret.pop_back();
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 38644
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
int n,a[555],ans=0;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
	
	cin >> n;
	for(int i=1;i<=n;i++)cin >> a[i];
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			ans+= a[i]*a[j];
		}
	}
	cout << ans << endl;
 

return 0;
}
///....


Measured memory_bytes: 256
from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
#from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.buffer.readline().strip().decode()
def mdata(): return map(int, data().split())
out=sys.stdout.write
#sys.setrecursionlimit(100000)
INF=int(10e9)


s=data()
t=data()
dp=[[0]*(len(s)+1) for i in range(len(t)+1)]
for i in range(1,len(t)+1):
    for j in range(1,len(s)+1):
        if s[j-1]==t[i-1]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
m=max(max(dp))
ans=''
for i in range(len(t)-1,-1,-1):
    for j in range(len(s)-1,-1,-1):
        if dp[i+1][j+1]==m and s[j]==t[i]:
            ans=s[j]+ans
            m-=1
            break
print(ans)



Measured memory_bytes: 112604
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a); i >= (b); i--)
#define ALL(container) container.begin(), container.end()
using namespace std;
const int INF = 1e9;

int main() {
  long long int k, a, b;
  cin >> k >> a >> b;
  long long int currentBisNum = 1, count = k;
  long long int increaseBisNum = b-a;

  if (increaseBisNum > 2) {
    if (currentBisNum < a) {
      long long int shortage = a - currentBisNum;
      if (count <= shortage) {
        currentBisNum += count;
      } else {
        currentBisNum = a;
        count -= shortage;
        if (count % 2 == 0) {
          currentBisNum += (increaseBisNum) * (count / 2);
        } else {
          currentBisNum += (increaseBisNum) * ((count-1) / 2) + 1;
        }
      }
    } else {
      if (count % 2 == 0) {
        currentBisNum += (increaseBisNum) * (count / 2);
      } else {
        currentBisNum += (increaseBisNum) * ((count-1) / 2);
        currentBisNum++;
      }
    }
  } else {
    currentBisNum += count;
  }

  cout << currentBisNum << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

struct edge {
    int from, to; ll cost;
    edge(int s, int t, ll w = 0) : from(s), to(t), cost(w) {}
};
bool tpz(vector<vector<edge>> g, VI& ans, VI& len) {//最長経路
    int v = g.size(); ans.clear(), len.resize(v, 0);
    VI in(v, 0);
    for (auto es : g)for (edge e : es)in[e.to]++;
    queue<int> que;
    FOR(i, 0, v)if (in[i] == 0) {
        que.push(i);
        len[i] = 0;
    }

    while (!que.empty()) {
        int now = que.front(); que.pop();
        ans.push_back(now);
        for (edge next : g[now]) {
            if (--in[next.to] == 0) {
                que.push(next.to);
                chmax(len[next.to], len[now] + 1);
            }
        }
    }
    return v == ans.size();
}

int main() {
    init();

    int n, m;
    cin >> n >> m;

    vector<vector<edge>> g(n);
    int x, y;
    FOR(i, 0, m) {
        cin >> x >> y;
        g[--x].emplace_back(x, --y);
    }

    VI ans, len;
    tpz(g, ans, len);
    int ml = 0;
    for (int i : len)chmax(ml, i);
    cout << ml << "\n";
}


Measured memory_bytes: 12672
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;;
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
ll desc_cmp(const void* X,const void* Y){ll x=*(ll*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
int asc_cmp_str(const void* X,const void* Y){char *x=(char*)X,*y=(char*)Y;return strcmp(x,y);}

typedef struct{
    int cnt;
    char str[20];
}v_t;

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

    qsort(s,n,sizeof(s[0]),asc_cmp_str);

    v_t v[200000];for(int i=0;i<n;i++)v[i].cnt=1;
    int ii=0;
    int max=-1;
    for(int i=0;i<n-1;i++){
        strcpy(v[ii].str,s[i]);
        if(!strcmp(s[i],s[i+1])){
            v[ii].cnt++;
        }else{
            max=max(max,v[ii].cnt);
            ii++;
        }
    }
    strcpy(v[ii].str,s[n-1]);
    max=max(max,v[ii].cnt);
    //printf("--- max:%d\n",max);
    for(int i=0;i<=ii;i++){
        //printf("%s %d\n",v[i].str,v[i].cnt);
        if(max==v[i].cnt){
            printf("%s\n",v[i].str);
        }
    }


}

Measured memory_bytes: 10516
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int K = sc.nextInt();

		System.out.println(N - (K - 1));
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
#define endl "\n";
typedef  long long int lli;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inf (1000*1000*1000+5)
const int NODE =1e4+9;

const int mod=1e9+7;
const lli num=1e5+5;

void init(){

}


int main()
{
   boost;
   int t=1;
   //cin>>t;
   init();
   while(t--){
      int n;
      cin>>n;
      cout<<fixed<<setprecision(10);
      double a[n];
      for(int i=0;i<n;i++)cin>>a[i];
      double dp[n+1][n+1];
      memset(dp,0.0,sizeof(dp));
      dp[0][0]=1;
      for(int i=1;i<=n;i++){
         for(int j=0;j<=i;j++){
            if(j==0)dp[i][j]=dp[i-1][j]*(1-a[i-1]);
            else dp[i][j]=dp[i-1][j]*(1-a[i-1])+dp[i-1][j-1]*a[i-1];   
         }
      }
      double ans=0.0;
      for(int i=n;i>n/2;i--)ans+=dp[n][i];
      cout<<ans<<endl;
   }
   return 0;
}


Measured memory_bytes: 74052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  string ans;
  if(a + b > c + d)
    ans = "Left";
  else if(a + b == c + d)
    ans = "Balanced";
  else
    ans = "Right";
  cout << ans << endl;
}

Measured memory_bytes: 3612
import           Control.Monad
import qualified Data.Array.IO               as IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

main = do
  [l, r] <- getIntList
  let r'= min (l + 5000) r
      ans = minimum [x * y `mod` 2019 | x <- [l..(r'-1)], y <- [(x+1)..r']]
  print ans


Measured memory_bytes: 2428
#include<stdio.h>
int main(){
    int a,b,c,d,e,f,g;
    int z[4][3][10]={0};
    scanf("%d",&a);
    for(b=0;b<a;b++){
        scanf("%d %d %d %d",&c,&d,&e,&f);
        z[c-1][d-1][e-1]+=f;
    }
    for(a=0;a<4;a++){
    for(b=0;b<3;b++){
    for(c=0;c<10;c++){
        printf(" %d",z[a][b][c]);
    }
    printf("\n");
    }
    if(a!=3)
    printf("####################\n");
    }
return 0;
}

Measured memory_bytes: 612
n = int(input())
a = list(map(int, input().split()))

num = {}
for i in range(n):
    if not a[i] in num.keys():
        num[a[i]] = 1
    else:
        num[a[i]] += 1
    if not a[i]-1 in num.keys():
        num[a[i]-1] = 1
    else:
        num[a[i]-1] += 1
    if not a[i]+1 in num.keys():
        num[a[i]+1] = 1
    else:
        num[a[i]+1] += 1

ans = 0
for k in num.keys():
    ans = max(ans, num[k])
print(ans)


Measured memory_bytes: 18760
#ARC079C

n,m=map(int,raw_input().split())
l=[]
for i in xrange(m):
 a,b=map(int,raw_input().split())
 l.append([a,b])
s1=set()
s2=set()
for i in xrange(m):
 if l[i][0]==1:
  s1.add(l[i][1])
 if l[i][1]==n:
  s2.add(l[i][0])
if s1&s2:
 print 'POSSIBLE'
else:
 print 'IMPOSSIBLE'


Measured memory_bytes: 42096
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

char judge(char c) {
  if (c == 'r')
    return 'p';
  if (c == 's')
    return 'r';
  if (c == 'p')
    return 's';
}

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

  ll n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;

  string result = "";
  rep(i, 0, n) {
    char c = judge(t[i]);
    if (i < k) {
      result += c;
    } else {
      if (result[i - k] == c)
        result += '?';
      else
        result += c;
    }
  }

  map<int, int> mp;
  rep(i, 0, n) mp[result[i]]++;

  ll ans = 0;
  ans += mp['r'] * r;
  ans += mp['s'] * s;
  ans += mp['p'] * p;
  cout << ans << endl;
}


Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,i,j;
  cin>>a>>b>>c;
  for(i=1;i<=1000;i++)
    {
      j=a*i;
	  if(j%b==c)
	    {
	      cout<<"YES"<<endl;
		  return 0;	
		}	
	}	
  cout<<"NO"<<endl;
  return 0;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int a,b,c,d;
	cin>>a>>b;
	cin>>c>>d;
	if(a==c||b==d){
		cout<<"0"<<endl;
		return 0;
	}
	cout<<a*b-(c*b+d*(a-c))<<endl;

	return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char alp1, alp2;
	char tmp = 'A';
	
	while (scanf(" %c,%c", &alp1, &alp2) != EOF){
		if (alp1 == tmp){
			tmp = alp2;
		}
		else if (alp2 == tmp){
			tmp = alp1;
		}
	}
	
	printf("%c\n", tmp);
	
	return (0);
}

Measured memory_bytes: 540
x, n = map(int, input().split())
if n == 0: print(x); exit()
C = [0]*(101+1) # candidate:[0,101]
for p in map(int, input().split()):
    C[p] = 1
ans = x
d = 1000000000
for c in range(101+1):
    if not C[c] and d > abs(x - c):
        d = abs(x - c)
        ans = c
print(ans)


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

struct Pair {
  public string a, b;
  public Pair(string x, string y) { a = x; b = y; }
}

class Program {
  static List<Pair> Combinations(List<string> lst) {
    return lst.SelectMany((x, idx) => lst.Skip(idx + 1).Select(y => new Pair(x, y))).ToList();
  }
  static void Main() {
    var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int n = a[0];
    int f = a[1];
    var p = new List<Pair>();
    var d = new Dictionary<Pair, int>();
    for (int i = 0; i < n; i++) {
      p.AddRange(Combinations(Console.ReadLine().Split().Skip(1).OrderBy(x => x).ToList()));
    }
    foreach (var item in p) {
      if (d.ContainsKey(item)) d[item]++;
      else d[item] = 1;
    }
    var r = new List<Pair>();
    foreach (var item in d) {
      if (item.Value >= f) r.Add(item.Key);
    }
    r = r.OrderBy(x => x.a).ThenBy(x => x.b).ToList();
    Console.WriteLine(r.Count);
    foreach (var item in r) Console.WriteLine("{0} {1}", item.a, item.b);
  }
}


Measured memory_bytes: 21584
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    tmd = collections.defaultdict(list)
    ab = []
    for i in range(n-1):
        tma, tmb = list(map(int, input().rstrip('\n').split()))
        tmd[tma-1] += [tmb-1]
        tmd[tmb-1] += [tma-1]
        ab.append([tma-1, tmb-1])

    ql = [[0, 0]]
    ql = collections.deque(ql)
    fq = collections.defaultdict(list)
    fq[0]
    ans = collections.defaultdict(int)
    ls = [1] * n
    while True:
        if len(ql) != 0:
            cost, tmp = ql.popleft()
            for tmv in tmd[tmp]:
                if tmv not in fq:
                    fq[tmv]
                    if ls[tmp] == cost:
                        ls[tmp] += 1
                    ql.append([ls[tmp], tmv])
                    ans[tmp, tmv] = ls[tmp]
                    ls[tmp] += 1
        else:
            break
    print(max(ans.values()))
    for a, b in ab:
        print(ans[a, b])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 117852
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			String line = br.readLine();
			StringBuilder sb = new StringBuilder(line);
			String result = sb.reverse().toString();
			System.out.println(result);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24112
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define _GLIBCXX_DEBUG
const int INF=1e18;
map<int,int>memo;
map<int,int>ans;

bool piyo(int x){
  	for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
          	memo[i]++;
          	if(x/i!=i)memo[x/i]++;
        }
    }
}

signed main(){
  	int N;cin>>N;
    int ansk=0;
    vector<int>A(N);
    REP(i,N)cin>>A[i];
    for(int i=N;i>0;i--){
        if((memo[i]%2)!=A[i-1]){
            piyo(i);
            ans[i]++;
            ansk++;
        }
    }
    cout<<ansk<<endl;
    for(auto it=ans.begin();it!=ans.end();it++){
        cout<<it->first<<" ";
    }
    cout<<endl;
}

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

int main(){
	long N, D;
	cin >> N >> D;
	vector<double> X(N), Y(N);
	for(long i=0; i<N; i++) cin >> X[i] >> Y[i];

	long count=0;
	for(long i=0; i<N; i++){
		if(sqrt(X[i]*X[i]+Y[i]*Y[i])<=D) count++;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 6484
N,M = map(int,input().split())

lisN = [0] + [1]*N
ansSet = set([1])

for _ in range(M):
    # print(ansSet,lisN)
    x,y = map(int,input().split())
    if x in ansSet:
        ansSet.add(y)
    lisN[x] -= 1
    lisN[y] += 1
    if lisN[x] == 0:
        ansSet.discard(x)

print(len(ansSet))


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

int main()
{
    const int inf = 1000000007;
    int n;
    cin >> n;
    unsigned long long a[1010];
    for(int i = 0; i < 1010; i++){
        a[i] = 0;
    }
    for(int i = 2; i <= n; i++){
        int j = i;
        int divider = 1;
        while(j > 1){
            divider++;
            while(j % divider == 0){
                a[divider]++;
                j = j / divider;
            }
        }
    }
    unsigned long long answer = 1;
    for(int i = 2; i <= n; i++){
        answer = answer * (a[i] + 1);
        answer = answer % inf;
    }
    cout << answer << endl;
    return 0;
}
            

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  map<int,int> o;
  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    o[a]=i;
  }
  for(int i=1;i<=n;i++){
    cout<<o.at(i);
    if(i<o.size())
      cout<<" ";
    else
      cout<<endl;
  }
}

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

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x){
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind tree(N);

    for(int i = 0; i < M; i++){
        int x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1);
    }

    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(tree.same(i, P[i]-1)) cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 1152