akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int n = sc.nextInt();
            int[] w = new int[n];
            int[] l = new int[n];
            int mmax = 0;
            int sum = 0;
            for (int i = 0; i < n; i++) {
                w[i] = sc.nextInt();
                sum += w[i];
                l[i] = sum;
                if (w[i] > mmax) mmax = w[i];
            }

            int mmin = Integer.MAX_VALUE;

            for (int i = 0; i < n; i++) {
                int tmp = sum - l[i];
                if (mmin > Math.abs(tmp-l[i])) mmin = Math.abs(tmp-l[i]);
            }

            System.out.println(mmin);

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

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 21460
s = input()
num = len(s)

tar_index = len(s) - 1
count = 0

while (count < num):
    tar = s[:tar_index]
    tar_num = len(tar)
    # 文字数が奇数の時は、偶文字列にはならない。
    if (tar_num % 2 == 0):
        half = int(tar_num / 2)

        if (tar[:half] == tar[half:]):
            print(int(2 * len(tar[:half])))
            exit()
        else:
            pass

    else:
        pass

    tar_index -= 1
    count += 1


Measured memory_bytes: 9124
import java.util.Scanner;

class Main {

    public int foo(int K, int N, int[] dist) {
        int last = K;
        int max = 0;
        for (int i = 1; i < N; i++) {
            int d = dist[i]-dist[i-1];
            max = Math.max(max, d);
            last -= d;
        }
        max = Math.max(max, last);
        return K - max;
    }

	public static void main(String[] args){
        Main o = new Main();

		Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int N = sc.nextInt();
        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
        // sc.close();

        System.out.println(o.foo(K, N, arr));
	}
}


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

n = int(input())
a = list(map(int, input().split()))
cost = 0

mean = round(sum(a) / len(a))

# print(n)
# print(a)
# print(mean)

for j in a:
    cost += (j - mean) * (j - mean)

print(cost)

Measured memory_bytes: 2940
fn main() {
    read::<String>();

    let mut weights: Vec<u64> = read_vec();
    weights.sort();

    println!("{}", (1..weights.len()).map(|k| weights[weights.len() - k/2 - 1]).sum::<u64>())
}

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

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


Measured memory_bytes: 6540
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int A = sc.nextInt();
   int B = sc.nextInt();

   if(A<=2*B)System.out.println(0);
   else System.out.println(A-2*B);
 }
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int S, B;
    cin >> S >> B;

    vvi bulb(B);
    for (int b = 0, k; b < B; b++) {
        cin >> k;
        bulb[b].resize(k);
        for (int i = 0; i < k; i++) {
            cin >> bulb[b][i];
            --bulb[b][i];
        }
    }

    vi par(B);
    for (int i = 0; i < B; i++) {
        cin >> par[i];
    }

    int ans = 0;
    for (int st = 0; st < (1 << S); st++) {
        bool good = true;
        for (int b = 0; b < B; b++) {
            bool res = par[b];
            for (int s : bulb[b])
                res ^= !!(st & (1 << s));
            good &= !res;
        }
        ans += good;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N;
    cin >> N;
    cout << lcm(2, N) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long   ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
#define offset 
const ll MOD= 998244353;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 1003455
bool cmp(ii par1, ii par2)
{
    return par1.fi+par1.se<par2.fi+par2.se;
}
int  main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    string txt2,txt3;
    int H=0;
    vector<ii> vpos,vneg;
    forr(i,0,n)
    {
        string txt;
        cin>>txt;
        
        int c=0,minn=0;
        forr(j,0,txt.size())
        {
            if (txt[j]=='(')
                c++;
            else
                c--;
            minn=min(minn,c);
        }
        if (minn==0)
            H+=c;
        else
        {
            if (c>=0)
                vpos.pb({-minn,c});
            else
                vneg.pb({-minn,c});
        }
    }    
    sort(vpos.begin(),vpos.end());
    sort(vneg.begin(),vneg.end(),cmp);
    reverse(all(vneg));
    bool invalid=0;

    for(auto par: vpos)
    {
        if (H>=par.fi)
            H+=par.se;
        else
            invalid=1;
    }
    for(auto par: vneg)
    {
        if (H>=par.fi)
            H+=par.se;
        else
            invalid=1;
    }
    if (invalid || H!=0)
        cout<<"No\n";
    else
        cout<<"Yes\n";
    
}
// PLUS ULTRA!!

Measured memory_bytes: 12112
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> hs(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> hs[i];
  }

  int ans = 0;
  double diff = 100000000.0;
  for (int i = 1; i <= N; i++) {
    double temp = (double)T - hs[i] * 0.006;
    double diff_temp = abs(A - temp);
    if (diff_temp < diff) {
      ans = i;
      diff = diff_temp;
    }
  }

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

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

using namespace std;

#define ll long long
#define INF 999999999
#define MOD 1000000007


int main()
{
	int i,o,t,j,l,s,z,g;
	ll res=0;
	cin >> i;
	cin >> o;
	cin >> t;
	cin >> j;
	cin >> l;
	cin >> s;
	cin >> z;
	g = i%2 + j%2 + l%2;
	res += (i/2) * 4;
	res += o*2;
	res += (j/2) * 4;
	res += (l/2) * 4;
	if(g == 3){
		res += 6;
	}
	if(g == 2 && i > 0 && j > 0 && l > 0){
		res += 2;
	}
	cout << res / 2;
}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <limits.h>
#define ll long long
#define xx first
#define yy second

using namespace std;

const int N = 1000 + 5;
int A[N][N], B[N][N], n, mp[N][N];
bool inq[N][N], flag;

inline int dfs (int u, int v) {
	if (mp[u][v]) return mp[u][v];
	if (!v) return 0;
	if (inq[u][v]) {
		flag = true;
		return 0;
	}
	if (flag) return 0;
	inq[u][v] = 1;
	int res = max (dfs (u, v - 1), dfs (A[u][v], B[ A[u][v] ][u] - 1)) + 1;
	return mp[u][v] = res;
}

int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j < n; ++j) {
			scanf ("%d", &A[i][j]);
			B[i][ A[i][j] ] = j;
		}
	}
	int ans = INT_MIN;
	for (int i = 1; i <= n; ++i)
		ans = max(ans, dfs (i, n - 1));
	if (flag) { printf ("-1\n"); return 0; }
	printf ("%d\n", ans);
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ULL = unsigned long long;



void solve() {
	int n; cin >> n;
	int p[100000]; rep(i, n) cin >> p[i];
	int rp[100001]; rep(i, n) rp[p[i]] = i;

	multiset<int> trash;
	trash.insert(-1); trash.insert(-1);
	trash.insert(n); trash.insert(n);

	long long ans = 0;
	for (int i = n; i > 0; i--) {
		int pp = rp[i];
		auto lb = trash.lower_bound(pp);
		int l1, l2, g1, g2;
		g2 = *(++lb);
		g1 = *(--lb);
		l1 = *(--lb);
		l2 = *(--lb);

		long long t = 0;
		t += (g2 - g1) * (pp - l1);
		t += (l1 - l2) * (g1 - pp);
		ans += t * i;

		trash.insert(pp);
	}

	cout << ans << endl;
}

int main() {

	solve();

	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main()
  {int A, B, C, X; cin >> A >> B >> C >> X;
  int ans = 0;
  for (int a = 0; a <= A; ++a)
    for (int b = 0; b <= B; ++b)
      for (int c = 0; c <= C; ++c) if (500 * a + 100 * b + 50 * c == X) ++ans;
  cout << ans << endl;}

Measured memory_bytes: 3604
from collections import deque
from collections import Counter

N,K,L=map(int, raw_input().split())

nl=[ [] for i in range(N+1) ]

for i in range(K):
	p,q=map(int, raw_input().split())
	nl[p].append(q)
	nl[q].append(p)

nl2=[ [] for i in range(N+1) ]

for i in range(L):
	p,q=map(int, raw_input().split())
	nl2[p].append(q)
	nl2[q].append(p)


v1=[ None for i in range(N+1) ]
v2=[ None for i in range(N+1) ]


def bfs(start,nl,V,l):
	q = deque([]) 
	V[start]=1
	l[start]=start
	q.append(start)

	while len(q)!=0:
		v=q.popleft()
		for i in nl[v]:
			if V[i] is None:
				V[i]=1
				q.append(i)
				l[i]=start
			
	return V

l1=[ "" for i in range(N+1) ]
l2=[ "" for i in range(N+1) ]


for i in range(1,N+1):
	if v1[i] is None:
		bfs(i,nl,v1,l1)

for i in range(1,N+1):
	if v2[i] is None:
		bfs(i,nl2,v2,l2)


c=[]
for idx,i in enumerate( zip(l1,l2) ):
	x=i[0]; y=i[1]
	if idx==0: continue
	c.append( (x,y) )


C=Counter(c)

for idx,i in enumerate( zip(l1,l2) ):
	x=i[0]; y=i[1]
	if idx==0: continue
	print C[(x,y)],





Measured memory_bytes: 103068
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;
// constexpr int MOD = 1e9+7;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, n, h);
    int a = 0;
    vector<int> b(n);
    For(i, n){
        Cin(int, x, y);
        b[i] = y;
        a = max(a, x);
    }
    Sort(b);
    int ans = 0;
    while(h > 0){
        if(!b.empty() && b.back() > a){
            h -= b.back();
            b.pop_back();
            ans ++;
        }
        else{
            int k = (h+a-1)/a;
            h -= k * a;
            ans += k;
        }
    }
    Cout(ans);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
inline int D()
{
    int t;
    scanf("%d",&t);
    return t;
}
inline ll llD()
{
    ll t;
    scanf("%lld",&t);
    return t;
}

const int Max=1e7+9;
const int OO=-1e6;
int st[4]= {1,0,0,-1};
int nt[4]= {0,1,-1,0};
int n,m;
bool valid(int x,int y)
{
    return x>-1 && y>-1 && x<n && y<m;
}
ll mem[100009][109];
void init()
{
    memset(mem,-1,sizeof mem);
}
//////////////////////////////////////////////////////////

ll a[106];
ll v[106];

ll solve (int i=0,int weight=0 )
{
    if(i==n)return 0;
    ll &ret=mem[weight][i];
    if(~ret)return ret;
   ll leave=solve(i+1,weight);
   ll take=0;
   if(weight+a[i]<=m)
    take=solve(i+1,weight+a[i])+v[i];
   return mem[weight][i]=max(leave,take);
}

void Fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
}
int main()
{
   init();
   n =D();
    m =D();
   for(int i=0; i<n;i++)
   {
       a[i]=D();
       v[i]=D();
   }
   printf("%lld",solve());

}


Measured memory_bytes: 88964
#include <iostream>
#include <bitset>

using namespace std;


int main(int argc, char const* argv[])
{
	unsigned long weight;
	int count = 0;
	while( cin >> weight ){
		count = 0;
		bitset<16> a( weight );
		for( int i = 0;i < 10;i++ ){
			if( a[i] == 1 ){ cout << ( ( count == 0 ) ? "" : " " ) << ( 1 << i ); count++;}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

string in;
int j = 0;
int index = -1;

string c_1 = ".,!? " ;
string c_2 = "abc";
string c_3 = "def";
string c_4 = "ghi";
string c_5 = "jkl";
string c_6 = "mno";
string c_7 = "pqrs";
string c_8 = "tuv";
string c_9 = "wxyz";

char func(string s)
{
	while (in[j] != '0')
	{
		index++;
		if (index >= s.size())index = 0;
		j++;
	}
	return s[index];
}

int main()
{
	int n;
	cin >> n;
	cin.ignore();
	REP(i, n)
	{
		in.clear();
		getline(cin, in);
		j = 0;
		while (in[j] != '\0')
		{
			index = -1;
			switch (in[j])
			{
			case '1':
				cout << func(c_1);
				break;
			case '2':
				cout << func(c_2);
				break;
			case '3':
				cout << func(c_3);
				break;
			case '4':
				cout << func(c_4);
				break;
			case '5':
				cout << func(c_5);
				break;
			case '6':
				cout << func(c_6);
				break;
			case '7':
				cout << func(c_7);
				break;
			case '8':
				cout << func(c_8);
				break;
			case '9':
				cout << func(c_9);
				break;
		    }
			j++;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3204
#import collections
#aa = collections.Counter(a) # list to list
def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n = int(input())
    dic = {}
    A = readInts()
    #print(*A)
    cnt = 0
    for i in range(n):
        #print('now')
        if A[i] in dic:
            if dic[A[i]] == A[i]:
                #print('collision')
                cnt += 1
            else:
                #print('add')
                dic[A[i]] += 1
        else:
            #print('Insert')
            dic[A[i]] = 1
    # まだ省かれいないもの
    for k,v in dic.items():
        if k != v:
            cnt += v
    print(cnt)



if __name__ == '__main__':
  main()


Measured memory_bytes: 18168
#include <iostream>
#include <cstdio>
#include <sstream>

using namespace std;

int main()
{
  string str, result;
  getline(cin, str);
  for (int i = 0; i < str.size(); i++) {
    if (str.substr(i, 5) == "peach") {
      result += "apple";
      i += 4;
    } else if (str.substr(i, 5) == "apple") {
      result += "peach";
      i += 4;
    } else {
      result += str[i];
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 0
def getORDER(n):
  order = list()
  
  while( n>0):
    order.append(n % 10)
    n //= 10
  return order

A,B = map(int,input().split())
res = 0

for i in range(A,B+1):
  order = list(getORDER(i))
  if (order[0] == order[4] and order[1] == order[3]):
    res += 1

print(res)

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

signed main(void)
{
	long long n, ans, tmp, tmp1;
	cin >> n;
	map<char, int> S;
	vector<long long> sum;

	rep(i, n)
	{
		string s;
		cin >> s;
		if (s[0] == 'M' || s[0] == 'A' ||\
				s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
			S[s[0]]++;
	}
	for (auto p: S)
	{
		auto v = p.second;
		sum.push_back(v);
	}
	ans = 0;
	int m = sum.size();
	rep(i, m - 2)
		FOR(j, i + 1, m - 1)
			FOR(k, j + 1, m)
				ans += sum.at(i) * sum.at(j) * sum.at(k);
	cout <<  ans << endl;
	return 0;
}


Measured memory_bytes: 256
program answer
  implicit none
  integer :: N, i
  integer, allocatable :: A(:)
  read(*,*) N
  allocate(A(N))
  read(*,*) A

  do i = 1, n
     if(mod(A(i),2)==0) then
        if(mod(A(i),3)/=0.and.mod(A(i),5)/=0) then
           write(*,*) 'DENIED'
           stop
        end if
     end if
  end do

  write(*,*) 'APPROVED'

  deallocate(A)
  stop
 end program answer


Measured memory_bytes: 2868
#include <stdio.h>

int main(){
    char a[200][200];
    int h,w,x,y;

    scanf("%d%d",&h,&w);


    for(x=0;x<h;x++){
        scanf("%s",&a[x]);
        for(y=0;y<w;y++){
            if(a[x][y]!=46) {
                break;
            }
            else if(y==w-1){
                x--;
                h--;
            }
        }
    }

    for(y=0;y<w;y++){
        for(x=0;x<h;x++){
            if(a[x][y]!=46){
                break;
            }
            else if(x==h-1){
                for(x=0;x<h;x++){
                    a[x][y]=1;
                }
                break;
            }
        }
    }



    for(x=0;x<h;x++){
        for(y=0;y<w;y++) {
            if (a[x][y] == 46 || a[x][y] == 35) {
                printf("%c", a[x][y]);
            }
        }
        printf("\n");
    }




    return 0;
}

Measured memory_bytes: 128
use std::io::stdin;use std::collections::HashMap;fn main() {let mut st = String::new();stdin().read_line(&mut st).unwrap();let _n = st.trim().parse::<usize>().unwrap();let mut st = String::new();stdin().read_line(&mut st).unwrap();let s:Vec<char> = st.trim().chars().collect();let mut map:HashMap<&char, i64> = HashMap::new();for i in &s {let count = map.entry(i).or_insert(1);*count += 1;};let mo = 1000000007;let mut result:i64 = 1;for (_i, j) in map.iter() {result = (result*j)%mo;};println!("{}", result-1)}

Measured memory_bytes: 4352
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)


K = readInt()

q = queue.Queue()

for i in range(1,10):
	q.put(i)

ans = 0
for i in range(K):
	ans = q.get()
	if str(ans)[-1]=="0":
		q.put(int(str(ans)+"0"))
		q.put(int(str(ans)+"1"))
	elif str(ans)[-1]=="9":
		q.put(int(str(ans)+"8"))
		q.put(int(str(ans)+"9"))
	else:
		q.put(int(str(ans)+str(int(str(ans)[-1])-1)))
		q.put(int(str(ans)+str(int(str(ans)[-1]))))
		q.put(int(str(ans)+str(int(str(ans)[-1])+1)))

print(ans)


Measured memory_bytes: 11536
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int a, b, c;

    cin >> a >> b >> c;

    cout << min(b / a, c) << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 100019;

int cl[N], cr[N], dp[N] , a[N];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    for(int i=0; i<n; i++)
        cin >> a[i];
    cr[0] = -1;
    cl[0] = -1;
    dp[0] = 1;
    for(int i=1; i<n; i++){

        if(a[i] >= a[i - 1])cl[i] = cl[i - 1];
        else cl[i] = i - 1;

        if(a[i] <= a[i - 1])cr[i] = cr[i - 1];
        else cr[i] = i - 1;

        if(cl[i] == -1 || cr[i] == -1){
            dp[i] = 1;
            continue;
        }
        dp[i] = n;
        dp[i] = min(dp[i], dp[cl[i]] + 1);
        dp[i] = min(dp[i], dp[cr[i]] + 1);
        //cout << i << " : " << dp[i] << endl;
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1792
import sys
import math
input = sys.stdin.readline

def main():
    N = int(input())
    if N == 1:
        print(0)
        quit()

    ans = float('INF')
    m = math.ceil(N ** 0.5)
    for a in range(1, m + 1):
        if N % a == 0:
            b = N // a
            ans = min(ans, (a + b - 2))

    print(ans)


if __name__ == "__main__":
    main()


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

#define M 1000000007

int64_t mpow(int64_t x, int64_t n) {
    x=x%M;
    if(n==0) return 1;
    else if(n%2==1) {
        return (x*(mpow(x,n-1)%M))%M;
    } 
    else return mpow((x*x)%M, n/2)%M;
}

int64_t con(int m, int n) {
    int64_t ans = 1;
    int64_t a = 1;
    int64_t b = 1;
    int64_t c = 1;

    for(int i=1; i<=m; i++) {
        a *= i;
        a = a%M;
    }

    for(int i=1; i<=n; i++) {
        b *= i;
        b = b%M;
    }
    b = mpow(b, M-2);

    for(int i=1; i<=m-n; i++) {
        c *= i;
        c = c%M;
    }
    c = mpow(c, M-2);

    ans = a;
    ans *= b;
    ans = ans%M;
    ans *= c;
    ans = ans%M;

    return ans;
}


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

    if((x+y)%3!=0) {
        cout<<0<<endl;
    }
    else if(fabs(x-y) > (x+y)/3) {
        cout<<0<<endl;
    }
    else {
        int m = (x+y)/3;
        int n = (m-fabs(x-y))/2;

        int64_t ans = con(m,n);

        ans = ans%M;

        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <ios>
#include <iomanip>

using namespace std;

int main(){
    int N,K;
    cin >> N >>K;
    cout << ( floor((N-1)/2)+1>=K ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for (long X = 1; X <= 1000000; ++X) {
			if (X * 108 / 100 == N) {
				System.out.println(X);
				return;
			}
		}
		System.out.println(":(");
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 22356
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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


int main(){

	int a[6]={500,100,50,10,5,1};
	int b,s;
	while(true){

	cin >> b;
	if(b==0) break;

	int coins=0;
	s=1000-b;
	rep(i,6){

	coins+=s/a[i]; s%=a[i];

	}

	cout << coins << endl;

	}

	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string.h>
 
int main(void){
 
  int n;
  scanf("%d", &n);
  char w[n][11];
  for (int i = 0; i < n; i++) {
    scanf("%s", w[i]);
  }
  int length;
  for (int i = 1; i < n; i++) {
    length = strlen(w[i-1]);
    if (w[i][0] != w[i-1][length-1]) {
      printf("No\n");
      return 0;
    }
    for (int j = 0; j < i; j++) {
      if (strcmp(w[j],w[i]) == 0) {
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
 
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
//#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cassert>
#include <unordered_map>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
#define debug(x) cout << #x << " " << x << "\n"
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
#ifdef DEBUG
const int MAX = 2e3 + 50;
#else
const int MAX = 1e6 + 50;
#endif
const int mod = 1e9 + 7;
void file_read() {
#ifdef DEBUG
	freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
#endif
}

int n, m;
int f[MAX];
int siz[MAX];
int Find(int x) {
	return f[x] == x ? x : f[x] = Find(f[x]);
}

int main() {
	file_read();
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) 
	{
		f[i] = i;
		siz[i] = 1;
	}
	for(int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		u = Find(u);
		v = Find(v);
		if(u == v) continue;
		f[u] = v;
		siz[v] += siz[u];
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		int u = Find(i);
		ans = max(ans, siz[u]);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 11568
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <fstream>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef vector<PI> VPI;
typedef unsigned long long ull;
typedef long long ll;

#define FOR(i, n) for(int i=0;i<(n);++i)
#define REP(i,s,n) for(int i=s;i<=n;++i)
#define SZ(x) ((int)(x).size())
#define LOOP(i,x) FOR(i,SZ(x))
#define IT(it,x) for(typeof((x).begin()) it = (x).begin();it!=(x).end();++it)
#define ALL(x) (x).begin(), (x).end()
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
#define gc getchar

#define MAXN 100 * 1000 + 7

int stones[MAXN], dp[MAXN];

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

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

	for (int i = 1; i <= n; i++) cin >> stones[i];

	dp[1] = 0;

	for (int i = 2; i <= n; i++) {
		dp[i] = dp[i - 1] + abs(stones[i] - stones[i - 1]);
		for (int j = 2; j <= k; j++) {
			if (j >= i) break;
			dp[i] = min(dp[i], dp[i - j] + abs(stones[i] - stones[i - j]));
		}
	}

	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

multiset<ll> mi, mx;

int main(){
	int q, qqq;
	ll x, f; scanf("%d%d%lld%lld", &q, &qqq, &x, &f);
	int ii = 0;
	REP(i, q-1){
		int qi; scanf("%d", &qi);
		if(qi==2){
			printf("%lld %lld\n", x, f);
			continue;
		}
		ll a, b; scanf("%lld%lld", &a, &b);
		if(ii%2){
			// DEBUG("Here mi=%d\n", mi.size());
			auto x1 = mi.end(); x1--;
			// DEBUG("There\n");
			auto x2 = mx.begin();
			if(a < *x1){
				x = *x1;
				mi.erase(x1);
				mi.insert(a);
			} else if(a > *x2){
				x = *x2;
				mx.erase(x2);
				mx.insert(a);
			} else {
				x = a;
			}
		} else {
			if(a<x){
				mx.insert(x);
				mi.insert(a);
				ll xx = *mi.rbegin();
				f = f + x-xx;
				x = xx;
			}else{
				mi.insert(x);
				mx.insert(a);
				ll xx = *mi.rbegin();
				f = f + xx-x;
				x = xx;
			}
		}
		f += abs(x-a) + b;
		ii++;
	
		// DEBUG("mi: "); for(ll i : mi) DEBUG("%lld ", i); DEBUG("\n");
		// DEBUG("mx: "); for(ll i : mx) DEBUG("%lld ", i); DEBUG("\n");
		// DEBUG("x=%lld f=%lld\n", x, f);
	}
}


Measured memory_bytes: 9600
import sys
input = sys.stdin.readline

n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x:x[1])

ans = 'Yes'
bef_b = 0
time = 0
for a,b in ab:
	if b-bef_b+time-a < 0:
		ans = 'No'
		break
	time += b-bef_b-a
	bef_b = b

print(ans)

Measured memory_bytes: 83420
mod=10**9+7
k=input()
d=int(input())

dp=[[[0]*2 for i in range(d)] for j in range(len(k)+1)]
dp[0][0][0]=1

for i in range(len(k)):
  x=int(k[i])
  for j in range(d):
    dp[i+1][(j+x)%d][0]+=dp[i][j][0]
    dp[i+1][(j+x)%d][0]%=mod
    for z in range(10):
      dp[i+1][(j+z)%d][1]+=dp[i][j][1]
      dp[i+1][(j+z)%d][1]%=mod
    
    for y in range(x):
      dp[i+1][(j+y)%d][1]+=dp[i][j][0]
      dp[i+1][(j+y)%d][1]%=mod
      

print((dp[-1][0][0]+dp[-1][0][1]-1)%mod)

Measured memory_bytes: 162268
import itertools

N = input()

element= [3,5,7]

nums = []

for i in range(3,len(N) + 1):
  num = itertools.product(element, repeat = i)
  for j in num:
    if len(set(j)) == 3:
      nums.append(j)

con = 0

numlist = []

for i in range(0,len(nums)):
  S = ""
  for j in range(0,len(nums[i])):
    S += str(nums[i][j])
  S = int(S)
  numlist.append(S)
  
print(len([i for i in numlist if i <= int(N)]))



Measured memory_bytes: 7796
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()
	m := readInt()
	p := make([]int, n)
	for i := range p {
		p[i] = readInt() - 1
	}

	uf := NewUnionFind(n)

	for i := 0; i < m; i++ {
		x := readInt() - 1
		y := readInt() - 1
		uf.Union(x, y)
	}

	var ans int
	for i := range p {
		if uf.Find(i) == uf.Find(p[i]) {
			ans++
		}
	}
	println(ans)
}

// -----------------------------------------------------------------------------
type UnionFind struct {
	parent []int
	rank   []int
	size   []int
}

// Initialize UnionFind for [0 - n) elements.
// Use n+1 if you need [1 - n] elements
func NewUnionFind(n int) *UnionFind {
	u := &UnionFind{
		parent: make([]int, n),
		rank:   make([]int, n),
		size:   make([]int, n),
	}

	for i := range u.parent {
		u.parent[i] = i
		u.rank[i] = 0
		u.size[i] = 1
	}

	return u
}

func (u *UnionFind) Find(i int) int {
	if u.parent[i] == i {
		return i
	}
	p := u.Find(u.parent[i])
	u.parent[i] = p
	return p
}

func (u *UnionFind) Union(i, j int) {
	p := u.Find(i)
	q := u.Find(j)

	if p == q {
		return
	}

	if u.rank[p] < u.rank[q] {
		p, q = q, p
	}
	u.parent[p] = q
	if u.rank[p] == u.rank[q] {
		u.rank[q]++
	}
	u.size[q] += u.size[p]
}

func (u *UnionFind) Size(i int) int {
	p := u.Find(i)
	return u.size[p]
}


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

#define MOD 1000000007
#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int c[3][3];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
        }
    }

    int a[3], b[3];
    a[0] = 0;
    for(int i = 0; i < 3; i++){
        b[i] = c[0][i] - a[0];
    }

    for (int i = 0; i < 3; i++){
        a[i] = c[i][0] - b[0];
    }

    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            if(c[i][j] != a[i] + b[j]){
                p("No");
                return 0;
            }
        }
    }
    p("Yes");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun May 31 15:34:56 JST 2020
 **/

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    // std::sort(a.begin(), a.end());
    a.erase(std::unique(a.begin(), a.end()), a.end());
    REP(i, a.size()) std::cout << a[i] << " \n"[i == a.size() - 1];
}



Measured memory_bytes: 3600
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan Mishra
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMakingTriangle solver = new BMakingTriangle();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMakingTriangle {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = in.readInt();

            int ans = 0;

            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    if (a[i] == a[j])
                        continue;
                    for (int k = j + 1; k < n; k++) {
                        if (a[k] == a[j] || a[k] == a[i])
                            continue;

                        if (a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[k] + a[j] > a[i])
                            ans++;
                    }
                }
            }

            System.out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 33048
#include<cstdio>

int main(){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        int t;
        if(b > a){
                t = a;
                a = b;
                b = t;
        }

        if(c > b){
                t = b;
                b = c;
                c = t;
                if(b > a){
                        t = a;
                        a = b;
                        b = t;
                }
        }

        printf("%d %d %d\n", c, b, a);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int A, B, K;
  cin >> A >> B >> K;

  int x = max(A, B);
  int cnt = 0;
  for (int i = x; i > 0; i--){
    if (A % i == 0 && B % i == 0) cnt ++;
    else continue;
    if (cnt == K){
      cout << i << endl;
      return 0;
    }
  }
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

int y, m, d;
const int yy[] = {1868, 1912, 1926, 1989};
const int mm[] = {   9,    7,   12,    1};
const int dd[] = {   8,   30,   25,    8};
const string era[] = {"pre-meiji", "meiji", "taisho", "showa", "heisei"};

int check(pair<int, pii> dat)
{
  rep(i, 4) if(dat < mp(yy[i], mp(mm[i], dd[i]))) return i;
  return 4;
}

int main()
{
  while(~scanf(" %d %d %d", &y, &m, &d)){
    int id = check(mp(y, mp(m, d)));
    string name = era[id];
    if(name == "pre-meiji") cout << name << endl;
    else cout << name << " " << y - yy[id-1] + 1 << " " << m << " " << d << endl;
  }

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int n;
    cin >> n;
    vector<int>h(n);
    bool ans = true;
    int cnt = 1;
    rep(i, n)cin >> h[i];
    for (int i = 1; i < n; i++) {
        ans = true;
        for (int j = i - 1; j >= 0; j--) {
            if (h[j] > h[i])ans = false;
        }
        if (ans)cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long K, long long X){
    if(K * 500 >= X) cout << YES << endl;
    else cout << NO << endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    long long X;
    scanf("%lld",&X);
    solve(K, X);
    return 0;
}


Measured memory_bytes: 3748
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int x = in.nextInt();
		int t = in.nextInt();
		int ans = n / x;
		if (n % x != 0)
			ans++;
		ans *= t;
		System.out.println(ans);
	}
}


Measured memory_bytes: 35632
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    map<string, int> mp;
    mp["SUN"] = 7;
    mp["MON"] = 6;
    mp["TUE"] = 5;
    mp["WED"] = 4;
    mp["THU"] = 3;
    mp["FRI"] = 2;
    mp["SAT"] = 1;
    cin >> S;
    cout << mp[S] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, N) for (int i = 0; i < N; ++i)

const double EPS = 1e-10;
struct V {
	double x, y;
	V(double x = 0, double y = 0) : x(x), y(y) {}
	int ort() const {
		if (abs(x) < EPS and abs(y) < EPS) return 0;
		if (y > 0) return x > 0 ? 1 : 2;
		else return x > 0 ? 4 : 3;
	}
	V& operator+=(const V& v) { x += v.x; y += v.y; return *this; }
	V operator+(const V& v) const { return V(*this) += v; }
	V& operator-=(const V& v) { x -= v.x; y -= v.y; return *this; }
	V operator-(const V& v) const { return V(*this) -= v; }
	V& operator*=(double s) { x *= s; y *= s; return *this; }
	V operator*(double s) const { return V(*this) *= s; }
	V& operator/=(double s) { x /= s; y /= s; return *this; }
	V operator/(double s) const { return V(*this) /= s; }
	double dot(const V& v) const { return x * v.x + y * v.y; }
	double cross(const V& v) const { return x * v.y - y * v.x; }
	double norm2() const { return x * x + y * y; }
	double norm() const { return sqrt(norm2()); }
	bool operator<(const V& v) const {
		if (ort() != v.ort()) return ort() < v.ort();
		return cross(v) > 0;
	}
	friend ostream &operator<<(ostream &os, const V &v) { os << "(" << v.x << ", " << v.y << ")"; return os; }
	friend istream &operator>>(istream &is, V &v) { is >> v.x >> v.y; return is; }
};

void chmax(V& v1, const V& v2) { if (v1.norm2() < v2.norm2()) v1 = v2; }

int main() {
	int N;	cin >> N;
	vector<V> engines(N);
	REP(i, N) cin >> engines[i];
	sort(engines.begin(), engines.end());
	V res;
	for (int l = 0; l < N; ++l) {
		V cand;
		for (int r = l, i = 0; i < N; ++i, r = (r + 1) % N) {
			cand += engines[r];
			chmax(res, cand);
		}
	}
	cout << fixed << setprecision(12) << res.norm() << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] arg){
        int x, y, r, w, h, maxx, maxy, minx, miny;
        Scanner scan = new Scanner(System.in);
        w = scan.nextInt();
        h = scan.nextInt();
        x = scan.nextInt();
       	y = scan.nextInt();
        r = scan.nextInt();
        maxx = x + r;
        maxy = y + r;
        minx = x - r;
        miny = y - r;
        if(w >= maxx && h >= maxy && 0 <= minx && 0 <= miny){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
        scan.close();
    }
}


Measured memory_bytes: 26380