akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
double ans = 0.0;
vector<pair<int,int> > vec;
#define ll long long
#define pb push_back

void display(ll a[], ll n)
{

    vector<int>v;

    for (int i = 0; i < n; i++) {
        v.pb(a[i]);
    }


    double c1 = 0.0 , c2 = 0.0;

    for(int i=1;i<v.size();i++){



        c1 = ((vec[v[i]].first-vec[v[i-1]].first) * (vec[v[i]].first - vec[v[i-1]].first));



        c2 = ((vec[v[i]].second - vec[v[i-1]].second) * (vec[v[i]].second - vec[v[i-1]].second));

        c1+=c2;

        c1 = sqrt(c1);



        ans +=(c1);
    }






}


void solve(ll a[], ll n)
{

    sort(a, a + n);

   do {
        display(a, n);
    } while (next_permutation(a, a + n));
}


ll fact(ll n){

    ll f = 1;
    for(int i=2;i<=n;i++){
        f = f * i;
    }

    return f;

}

int main(){

    ll n;
    cin>>n;

    ll a[n+1];
    for(int i=0;i<=n;i++)
        a[i] = i;

    ll x,y;

    for(int i=1;i<=n;i++){
        cin>>x>>y;
        vec.pb({x,y});
    }



    solve(a,n);

    cout<<fixed<<setprecision(9);

    n = fact(n);

    ans = ans / n;
    cout<<ans<<"\n";

}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int count=0;
    for(int i=1;i<C+1;i++){
    	if(i%A==0){
        count++;
        }
    }
    count *=B;
   System.out.println(count);
  }
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

signed main() {
  int n = read();
  vi abDiff(n);
  REP(i, n)
  abDiff[read()]++;
  bool ok = true;
  int ab0 = (n & 1 ? 1 : 0);
  if (ab0 != abDiff[0])
    ok = false;
  REP(i, n) {
    if (abDiff[i] > 2) {
      ok = false;
      break;
    }
  }
  if (ok) {
    int ans = 1;
    REP(i, n / 2)
    ans = (ans * 2) % mod;
    print(ans);
  } else
    print(0);
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void) {
    string s;
    cin >> s;
    int month = stoi(s.substr(5, 6));

    if (month <= 4) {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (ans.at(s) == -1) {
      ans.at(s) = c;
    } else if (ans.at(s) != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (n == 1) {
    if (ans.at(0) == -1) {
      cout << 0 << endl;
    } else {
      cout << ans.at(0) << endl;
    }
    return 0;
  }
  if (ans.at(0) == -1) {
    ans.at(0) = 1;
  } else if (ans.at(0) == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans.at(0);
  for (int i = 1; i < n; ++i) {
    if (ans.at(i) == -1) {
      ans.at(i) = 0;
    }
    cout << ans.at(i);
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

int main() {
    int n, m, k;
    cin >> n >> m >> k;

    set<int> s = {n, m, k};
    cout << (s.size() == 2 ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 256
N = int(input())
ans = [0]*(1+N)

for x in range(1, 10**2+1):
    for y in range(1, 10**2+1):
        for z in range(1, 10**2+1):
            v = x*x+y*y+z*z+x*y+y*z+z*x
            
            if v<=N:
                ans[v] += 1

for i in range(1, N+1):
    print(ans[i])

Measured memory_bytes: 74736
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
const int N=2e5+7;
typedef long long ll;
ll dp[2][2][N];//dp[l/r][][n]
int L,a[N];
int main(){
	memset(dp,0x3f,sizeof(dp));
	scanf("%d",&L);
	ll sum=0;
	dp[0][0][0]=dp[0][1][0]=dp[1][0][L+1]=dp[1][1][L+1]=0;
	rep(i,1,L){
		scanf("%d",&a[i]);
		sum+=a[i];
		dp[0][0][i]=min(sum, dp[0][0][i-1] + (a[i] ? (a[i]&1) : 2));
		dp[0][1][i]=min(dp[0][0][i], dp[0][1][i-1] + (a[i] ? !(a[i]&1) : 1));
	}
	sum=0;
	rep2(i,L,1){
		sum+=a[i];
		dp[1][0][i]=min(sum, dp[1][0][i+1] + (a[i] ? (a[i]&1) : 2));
		dp[1][1][i]=min(dp[1][0][i], dp[1][1][i+1] + (a[i] ? !(a[i]&1) : 1));
	}
	ll ans=0x3f3f3f3f3f3f3f3full;
	rep(i,1,L)ans=min(ans,dp[0][1][i-1] + dp[1][1][i]);
	printf("%lld\n",ans);
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int h,w;
string field[1100];

ll dp[1100][1100];


int main(){
	cin>>h>>w;
    rep(i,h) cin>>field[i];

    dp[h-1][w-1]=1;

    for(int i=h-1;i>=0;i--){
        for(int j=w-1;j>=0;j--){
            if(i==h-1 && j==w-1) continue;
            dp[i][j]=0;
            if(i+1<h) dp[i][j]+=dp[i+1][j];
            if(j+1<w) dp[i][j]+=dp[i][j+1];
            dp[i][j]%=MOD;
            if(field[i][j]=='#') dp[i][j]=0;
        }
    }
    cout<<dp[0][0]<<endl;
}

Measured memory_bytes: 9856
N = int(input())
ary = [int(_) for _ in input().split()]


def bubble_sort(ary, verbose=True):
    flag = True
    count = 0
    i = 0
    while flag:
        flag = False
        for j in range(N - 1, i, -1):
            if ary[j] < ary[j - 1]:
                ary[j], ary[j - 1] = ary[j - 1], ary[j]
                flag = True
                count += 1
        i += 1

    print(' '.join([str(_) for _ in ary]))

    if verbose:
        print(count)


bubble_sort(ary)



Measured memory_bytes: 5608
/*
    Problem 15
    https://atcoder.jp/contests/abc145/tasks/abc145_c
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
double dist(double x1, double y1, double x2, double y2) {
    double dx = x1 - x2, dy = y1 - y2;
    return sqrt(dx * dx + dy * dy);
}
double fact(double x) {
    double ret = 1.0;
    for (double i = 1; i <= x; i++) ret *= i;
    return ret;
}
/* main */
int main(){
    int N;
    cin >> N;
    vector<double> x(N), y(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> p(N);
    iota(p.begin(), p.end(), 0);
    do {
        for (int i = 0; i < N - 1; i++)
            sum += dist(x[p[i]], y[p[i]], x[p[i+1]], y[p[i+1]]);
    } while (next_permutation(p.begin(), p.end()));
    cout << setprecision(10) << sum / fact(N) << '\n';
}

Measured memory_bytes: 3748
#!/usr/bin/env ruby

@N, @A, @B = gets.split(' ').map &:to_i

if $0 == __FILE__
  ans = 0
  (0..@N).each do |i|
    j = i.to_s.split('').map(&:to_i).inject(&:+)
    ans += i if @A <= j and j <= @B
  end
  puts ans
end


Measured memory_bytes: 2044
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

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

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

int main(){
	long long int N, D, A;
	cin >> N >> D >> A;
	priority_queue<P, vector<P>, greater<P>> que;
	vector<P> v;
	for(int i = 0; i < N; i++){
		long long int X, H;
		cin >> X >> H;
		v.push_back(P(X, H));
	}
	sort(v.begin(), v.end());
	que.push(P(INF, 0));
	long long int S = 0;
	long long int ans = 0;
	for(P p : v){
		long long int pos = p.first;
		while(que.top().first < pos){
			S -= que.top().second;
			que.pop();
		}
		long long int H = p.second;
		H -= S;
		if(H > 0){
			long long int cnt = H / A + (H % A != 0);
			que.push(P(pos + 2 * D, A * cnt));
			S += A * cnt;
			ans += cnt;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7532
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<map>
#include<queue>
#include<bitset>
#define mk make_pair
#define fi first
#define nd second
#define pii pair<int,int>
#define pb push_back
#define sqr(x) ((x)*(x))
using namespace std;
typedef long long ll;
inline ll read() {ll x = 0; char ch = getchar(), w = 1;while(ch < '0' || ch > '9') {if(ch == '-') w = -1;
ch = getchar();}while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0';ch = getchar();}return x * w;}
void write(ll x) {if(x < 0) putchar('-'), x = -x;if(x > 9) write(x / 10);putchar(x % 10 + '0');}
inline void writeln(ll x) {write(x);puts("");}
const int N = 3e5;
struct T {
	int c, w;
}a[N];
int n, x, y; 
ll inv[N], fac[N];
const ll p = 1e9 + 7;
ll ksm(ll x, ll y) {
	ll res = 1;
	for(; y; y >>= 1, x = x * x % p)
		if(y & 1) res = res * x%p;
	return res;
}
ll ans[N];
int mn[N];
int t1, t2;
int siz[N];
ll C(int n, int m) {
	return fac[n] * inv[m] % p * inv[n - m] % p;
}
int main() {
	n = read(), x = read(), y = read();
	inv[0] = fac[0]= 1;
	for(int i = 1; i <= n; ++i) {
		fac[i] = fac[i - 1] * i % p;
		inv[i] = ksm(fac[i], p - 2);
		//inv[i] = fac[i]; 
		mn[i] = 1e9 + 9;
	}
	for(int i = 1 ; i <= n; ++i) {
		a[i].c = read(), a[i].w = read();
		mn[a[i].c] = min(mn[a[i].c], a[i].w);
	}
	for(int i = 1; i <= n; ++i) {
		if(!t1 || mn[i] < mn[t1]) t2 = t1, t1 = i;
		else if(!t2 || mn[i] < mn[t2]) t2 = i;
	}
	int tot = 0;
	for(int i = 1; i <= n; ++i){
		if(a[i].w + mn[a[i].c] <= x) a[i].w = mn[a[i].c];
		if(a[i].c == t1) {
			if(mn[t2] + a[i].w <= y) {
				++siz[t1];
				++tot;
			}
		} else if(mn[t1] + a[i].w <= y) {
			//++siz[t1];
			++siz[a[i].c];
			++tot;
		}
	}
	ll res = 1;
	for(int i = 1; i <= n; ++i) if(siz[i]) {
		res = res * C(tot, siz[i]) % p;
		tot -= siz[i];
	}
	writeln(res);
}

Measured memory_bytes: 8704
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    while (cin >> n && n){
        int d[100][100] = {};
        REP(i,n){
            int p;
            cin >> p;
            while (p--){
                int a;
                cin >> a;
                d[i][a] = 1;
            }
        }
        int m;
        cin >> m;
        VI l(m);
        REP(i,m) cin >> l[i];
        int ans = -1;
        bool g = 1;
        REP(i,n){
            bool f = 1;
            REP(j,m) f &= d[i][l[j]];
            if (f) {
                if (ans > 0) g = 0;
                else ans = i+1;
            }
        }
        cout << (g ? ans : -1) << endl;
    }
    return 0;
}

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

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

    int frag=0;
    for (int i = 1; i < 10; i++){
        for (int j = 1; j < 10; j++){
            if (a == i*j){
                cout << "Yes";
                frag = 1;
                break;
            }
        }
        if (frag == 1){
            break;
        }
    }
    if (frag == 0){
        cout << "No";
    }

    

    return 0;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n; cin >> n;
    vector<ll> a(n); REP(i, n) cin >> a[i];
    vector<ll> b(n); REP(i, n) cin >> b[i];

    vector<ll> diff(n);
    int cnt = 0;
    REP(i, n) {
        if (a[i] >= b[i]) cnt++;
        diff[i] = a[i] - b[i];
    }
    sort(diff.begin(), diff.end(), greater<ll>());

    ll sum = accumulate(diff.begin(), diff.end(), 0LL);

    int ans = 0;
    if (cnt == n) ans = 0;
    else if (sum < 0) ans = -1;
    else {
        ll sumM = 0;
        REP(i, n) {
            if (diff[i] < 0) {
                ans++;
                sumM += abs(diff[i]);
            }
        }
        REP(i, n) {
            sumM -= diff[i];
            ans++;
            if (sumM <= 0) break ;
        }
    }

    cout << ans << '\n';
    return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    // aとbが等しい
    if (a == b && a != c) {
        cout << "Yes" << endl;
    } else if (a == c && a != b) {
        cout << "Yes" << endl;
    } else if (b == c && b != a) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import copy
import math
import time
import statistics
import math
import itertools
import bisect
import sys
from decimal import *
from collections import deque


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

def get_int_multi():
    return map(int, input().split())

def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# a_list = [0] * a
sys.setrecursionlimit(10 ** 6)

def main():
    start = time.time()

    s = get_int()

    a = [0] * 2001

    a[1] = 0
    a[2] = 0
    a[3] = 0

    a[3] = 1
    a[4] = 1
    a[5] = 1

    for i in range(6,2001):
        a[i] = 1
        for ii in range(0,i-2):
            a[i] += a[ii]
    print(a[s] % (10**9+7))


if __name__ == '__main__':
    main()

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

public class Main {

	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		double w = sc.nextDouble();
		double h = sc.nextDouble();
		double x = sc.nextDouble();
		double y = sc.nextDouble();
		
		out.println(w*h/2 + " " + ((x*2==w&&y*2==h) ? "1" : "0"));
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21204
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,K;
    char s[100];
    cin>>N>>K;
    cin>>s;
    if(s[K-1]=='A') s[K-1]='a';
    else if(s[K-1]=='B') s[K-1]='b';
    else if(s[K-1]=='C') s[K-1]='c';
    cout<<s;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define clear(a) memset(a,0,sizeof(a))
#define full(a) memset(a,0x3f,sizeof(a))
#define iosfast cin.tie(NULL),cout.tie(NULL),ios::sync_with_stdio(false)
#define fornext(x,i) for(int i=head[x]; i; i=nxt[i])
#define mset(a,b) memset(a,b,sizeof(a))
#define dbg cout<<"c "
using namespace std;
typedef long long ll;
ll n,k,s;
int a[100005];

int main() {
	cin>>n>>k>>s;
	for(int i=1; i<=k; ++i) cout<<s<<' ';
	int val=(s == 1||s == 2?s+1:s-1);
	for(int i=k+1; i<=n; ++i) cout<<val<<' ';
	return 0;
}



Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  for(int i = 0; i < M; i++){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  vector<int> vect_M(M);
  vector<int> vect_M1(0);
  for(int i=0; i<M; i++) vect_M[i] = i;

  int count = 0;
  //for(int i: vect_M) cout << vect_M[i];

  while(vect_M.size() > 0){
    int min_b = INF;
    for (int i: vect_M) min_b = min(b[i], min_b);

    //cout << "min_b: " << min_b << endl;

    vect_M1.clear();
    for(auto i : vect_M){
      if(a[i] >= min_b){
        vect_M1.push_back(i);
        //cout << vect_M1[i] << i << endl;
      }
    }
    vect_M = vect_M1;
    //for(int j: vect_M1) cout << j << endl;
    // cout << endl;
    // for(int j: vect_M) cout << vect_M[j];
    // cout << endl;
    count++;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 2044
#include <cstdio>

#define MAX (105)

void search(int x, int y);

int h, w;
char data[MAX][MAX];
char flag[MAX][MAX];

int main(void)
{
    int i, j;
    
    while (1){
        scanf("%d %d", &h, &w);
        if (h == 0 && w == 0) break;
        for (i = 0; i < MAX; i++){
            for (j = 0; j < MAX; j++){
                data[i][j] = '\0';
                flag[i][j] = '0';
            }
        }
        for (i = 0; i < h; i++){
            scanf("%s", data[i]);
        }
        search(0, 0);
    }
    
    return (0);
}

void search(int x, int y)
{
    if (flag[x][y] == '1'){
        printf("LOOP\n");
        return;
    }
    if (data[x][y] == '.'){
        printf("%d %d\n", y, x);
        return;
    }
    if (data[x][y] == '>'){
        flag[x][y] = '1';
        search(x, y + 1);
    }
    else if (data[x][y] == '<'){
        flag[x][y] = '1';
        search(x, y - 1);
    }
    else if (data[x][y] == '^'){
        flag[x][y] = '1';
        search(x - 1, y);
    }
    else if (data[x][y] == 'v'){
        flag[x][y] = '1';
        search(x + 1, y);
    }
    
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static String[] s;
	public static int[][] dis;
	public static int h;
	public static int w;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt();
		w = sc.nextInt();
		s = new String[h];
		for(int i = 0; i < h; i++) {
			s[i] = sc.next();
		}
		dis = new int[h][w];
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				dis[i][j] = Integer.MAX_VALUE;
			}
		}
		dis[0][0] = 1;
		djk(0, 0);
		if(dis[h - 1][w - 1] == Integer.MAX_VALUE) {
			System.out.println(-1);
		} else {
			int cnt = 0;
			for(int i = 0; i < h; i++) {
				for(int j = 0; j < w; j++) {
					if(s[i].charAt(j) == '#')
						cnt++;
				}
			}
			int ans = h * w - cnt - dis[h - 1][w - 1];
			System.out.println(ans);
		}
	}

	public static void djk(int i, int j) {
		int tmp = dis[i][j];
		if(i > 0 && dis[i - 1][j] > tmp + 1 && s[i].charAt(j) == '.') {
			dis[i - 1][j] = tmp + 1;
			djk(i - 1, j);
		}
		if(i < h - 1 && dis[i + 1][j] > tmp + 1 && s[i + 1].charAt(j) == '.') {
			dis[i + 1][j] = tmp + 1;
			djk(i + 1, j);
		}
		if(j > 0 && dis[i][j - 1] > tmp + 1 && s[i].charAt(j - 1) == '.') {
			dis[i][j - 1] = tmp + 1;
			djk(i, j - 1);
		}
		if(j < w - 1 && dis[i][j + 1] > tmp + 1 && s[i].charAt(j + 1) == '.') {
			dis[i][j + 1] = tmp + 1;
			djk(i, j + 1);
		}
	}

}

class Pair {
	private int i;
	private int j;

	protected Pair(int i, int j) {
		super();
		this.i = i;
		this.j = j;
	}

	public int getI() {
		return i;
	}

	public void setI(int i) {
		this.i = i;
	}

	public int getJ() {
		return j;
	}

	public void setJ(int j) {
		this.j = j;
	}

}


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

typedef long long ll;

int N;
int A[200010], B[200010];

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d %d", &A[i], &B[i]);
    }

    ll ans = 0;
    int mn = 2e9;
    for(int i = 0; i < N; i++) {
        if(A[i] > B[i]) {
            if(mn > B[i]) {
                mn = B[i];
            }
        }
        ans += A[i];
    }
    if(mn == 2e9) {
        printf("0");
        return 0;
    }
    ans -= mn;

    printf("%lld", ans);
}


Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,m; cin>>n>>m;
    vector<int> cnt(n,1);
    set<int> s; s.insert(0);
    rep(i,m){
        int x,y; cin>>x>>y;
        x--; y--;
        cnt[x]--; cnt[y]++;
        if(s.count(x)) s.insert(y);
        if(cnt[x]==0) s.erase(x);
    }
    int ans=0;
    rep(i,n){
        if(s.count(i) && cnt[i]>0) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8064
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

vector<int> op, sweet;
int k;

struct Node{
    Node* left;
    Node* right;
    int id;
    int bit;
};

Node* newNode(){
    Node* ret = (Node*)(malloc(sizeof(Node)));
    ret->left = NULL;
    ret->right = NULL;
    return ret;
}

Node* build(int &pos, string s){
    Node* ret = newNode();
    if(s[pos] == '('){
        ret->id = k++;
        pos++;
        ret->left = build(pos, s);
        pos++;  // space
        ret->right = build(pos, s);
        pos++;  // )
    }else{
        int num = s[pos++]-'0';
        ret->bit = sweet[num-1];
    }
    return ret;
}

int play(Node* root){
    if(root->left != NULL){
        int x = play(root->left), y = play(root->right);
        if(op[root->id] == 0)   root->bit = x&y;
        if(op[root->id] == 1)   root->bit = x|y;
        if(op[root->id] == 2)   root->bit = x^y;
    }
    return root->bit;
}

int main(){
    string s;
    while(getline(cin, s), s != "END"){
        int n;
        cin >> n;
        k = 0;
        sweet.clear();
        for(int i = 0; i < n; i++){
            int bit = 0;
            for(int j = 0; j < 4; j++){
                int x;  cin >> x;
                bit += x * (1<<j);
            }
            sweet.push_back(bit);
        }
        int pos = 0;
        Node* root = build(pos, s);
        op.assign(k, 0);
        int ans = 0;
        for(int i = 0; i < pow(3,k); i++){
            int cp = i;
            for(int j = 0; j < k; j++){
                op[j] = cp%3;
                cp /= 3;
            }
            if(play(root) == (1<<4)-1)  ans++;
        }
        cout << ans << endl;
        cin.ignore();
    }
    return 0;
}


Measured memory_bytes: 3204
#include <stdio.h>
#include <string.h>

int main(void){
    int n,i,j,min,num,flg=1;
    char k[4];
    char a[36][4];
    char b[36][4];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",a[i]);
        strcpy(b[i],a[i]);
    }
    
    for(i=0;i<n-1;i++){
        for(j=0;j<n-i-1;j++){
            if(a[j][1]>a[j+1][1]){
                strcpy(k,a[j]);
                strcpy(a[j],a[j+1]);
                strcpy(a[j+1],k);
            }
        }
    }
    
    for(i=0;i<n;i++){
        printf("%s",a[i]);
        if(i!=n-1){
            printf(" ");
        }
    }
    printf("\nStable\n");
    
    for(i=0;i<n-1;i++){
        min = b[i][1];
        num = i;
        for(j=i+1;j<n;j++){
            if(min>b[j][1]){
                min = b[j][1];
                num = j;
                
            }
        }
        if(num!=i){
            strcpy(k,b[i]);
            strcpy(b[i],b[num]);
            strcpy(b[num],k);
        }
    }
    for(i=0;i<n;i++){
        printf("%s",b[i]);
        if(i!=n-1){
            printf(" ");
        }
    }
    printf("\n");
    for(i=0;i<n;i++){
        if(strcmp(a[i],b[i])!=0){
            printf("Not stable\n");
            flg = 2;
            break;
        }
    }
    if(flg==1){
        printf("Stable\n");
    }
    
    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string S;
void input(){
    fast_io();
    cin >> S;
}

#define NO do{cout << -1 << endl; return 0;}while(false);

int solve(){
    int N = S.length();
    if(S[0]!='1') NO
    if(S[N-1]!='0') NO
    for (int i = 0; i < N-1; i++) if(S[i]!=S[N-2-i]) NO
    int lastone = 0;
    for (int i = 1; i < N; i++)
    {
        if(S[i-1]=='1'){
            cout << lastone+1 << " " << i+1 << "\n";
            lastone = i;
        }
        else{
            cout << lastone+1 << " " << i+1 << "\n";
        }
    }
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3752
/// 11:57 AM 04/04/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template<typename T>
void ContainerError(T &v);

ll powmod(ll base, ll exp, ll MOD);

ll mpow(ll base, ll exp);

ll gcd(ll a, ll b);
bool isv(ll n) {
    return (n>=0 && n<=9);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin>>n;
    map<ll,ll> m;
    priority_queue<ll, vector<ll>, greater<ll> > q;
    for(ll i=1;i<=9;i++) {
        q.push(i);
    }
    ll i=0;
    while (!q.empty()) {
        ll k = q.top();
        q.pop();
        i++;
        if(i==n) {
            cout<<k<<endl;
            return 0;
        }
        ll ld = k%10;
        if(isv(ld-1)) {
            ll num = 10*k + (ld-1);
            if(m[num]==0) {
                q.push(num);
                m[num] = 1;
            }
        }
        if(isv(ld)) {
            ll num = 10*k + (ld);
            if(m[num]==0) {
                q.push(num);
                m[num] = 1;
            }
        }
        if(isv(ld+1)) {
            ll num = 10*k + (ld+1);
            if(m[num]==0) {
                q.push(num);
                m[num] = 1;
            }
        }
    }
    return 0;
}

template<typename T>
void ContainerError(T &v) {
    cout << "{";
    for (auto &x:v) { cout << x << ','; }
    cout << "}" << endl;
    return;
}

ll powmod(ll base, ll exp, ll MOD) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return (res % MOD);
}

ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp > 0) {
        if (exp % 2 == 1) res = (res * base);
        base = (base * base);
        exp /= 2;
    }
    return (res);
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }



Measured memory_bytes: 19952
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,x,t;
  cin>>n>>x>>t;
  if(n<=x)
    cout<<t<<endl;
  else
  {
    int d = ceil((double)n/x);
    cout<<d*t<<endl;
  }
}

Measured memory_bytes: 3752
N, A, B = map(int, input().split())
output = 0
for i in range(1, N + 1):
    # set each condition for i < 10^4
    if i < 10:
        digitsum = i
    elif i < 100:
        digitsum = i // 10 + i % 10
    elif i < 1000:
        digitsum = i // 100 + (i % 100) // 10 + (i % 100) % 10
    elif i < 10000:
        digitsum = i // 1000 + (i % 1000) // 100 + ((i % 1000) % 100) // 10 + ((i % 1000) % 100) % 10
    else:
        digitsum = 1

    if A <= digitsum and digitsum <= B:
        output = output +  i

print (output)

Measured memory_bytes: 3064
from itertools import permutations

N, M = map(int, input().split())
gr = set()

for i in range(M):
    a, b = map(int, input().split())
    gr |= {(a-1,b-1),(b-1,a-1)}

ans = 0
for p in permutations(range(N)):
    if p[0]==0:
        cnt = 0
        cntp = 0
        for i in range(N-1):
            cnt += 1
            if (p[i],p[i+1]) in gr:
                cntp += 1
            else:
                break
        if cnt == cntp:
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


//////////////////////////////////////
using namespace std;
#define dp(arg) do { cout << #arg << ":"; dprint(arg); } while(0)

template <typename T> void dprint(T arg) { cout << arg << "\n"; }
template <typename T> void dprint(const vector<T>& arg) { for_each(begin(arg), end(arg), [](T value){ cout << value << " "; }   ); cout << "\n";  }
template <typename T> void dprint(const vector<vector<T>>& arg) { for_each(begin(arg), end(arg), [=](vector<T> arg2){ dprint(arg2); cout << "\n";} );  }

// #define dprint(arg) ;
//////////////////////////////////////

using namespace std;
int main() {
    queue<pair<string, int>> jobs;
    int n, q;
    cin >> n >> q;
    string name;
    int t;
    REP(qq, n){
        cin >> name >> t;
        jobs.push(make_pair(name, t));
    }
    int keika = 0;
    pair<string , int> item;
    while(!jobs.empty()){
        item = jobs.front(); jobs.pop();
        name = item.first; t = item.second;
        if (t <= q) {
            keika += t;
            cout << name << " " << keika << "\n";
        } else {
            t -= q;
            keika += q;
            jobs.push(make_pair(name, t));
        }
    }
}



Measured memory_bytes: 6308
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    vector<pair<ll,ll> > v;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        v.pb({x,i});
    }
    sort(v.begin(),v.end());
    for(i=0;i<n;i++)
        cout<<v[i].second<<" ";
    cout<<endl;
    return 0;
}



Measured memory_bytes: 5336
#include<stdio.h>

int main()
{
  int i,j,v,n,A[1000];
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  for(i = 0; i < n; i++){
    v = A[i];
    j = i -1;
    while((j >= 0) && (A[j] > v)){
      A[j+1] = A[j];
      j--;
    }
      A[j+1] = v;
      for(j = 0; j < n; j++){
      printf("%d",A[j]);
      if(j < n-1)
      printf(" ");
      }
      printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
#include <iostream>
#include <cstring>

#define REP(i,a,b)for(long long i=(long long)a;i<(long long)b;i++)
#define min(a,b)(a<b?a:b)

using namespace std;

int mem[200]={0};
int ary[1000010]={0};
int ary_kisu[1000010]={0};

int cul(int n){
	return 	((n*(n+1)*(n+2))/6);
}

int main(void){

	REP(i,0,200) mem[i]=cul(i);
	
	REP(i,1,1000010) ary[i]=999999;
	REP(i,1,1000010) ary_kisu[i]=999999;

	REP(j,1,200){
		REP(i,mem[j],1000001){
			if(i-mem[j]>=0)
				ary[i]=min(ary[i],ary[i-mem[j]]+1);
		}
	}

	REP(j,1,200){
		if(1&mem[j]){
			REP(i,mem[j],1000001){
				if(i-mem[j]>=0)
					ary_kisu[i]=min(ary_kisu[i],ary_kisu[i-mem[j]]+1);
			}
		}
	}

	while(1){

		int n;
		cin >> n;

		if(!n)break;

		cout << ary[n]<<" "<<ary_kisu[n]<<endl;

	}


	return 0;
}

Measured memory_bytes: 8972
S = str(input())
n = len(S)

def dfs(i,f,total):
  if i == n - 1:
    if total == 7:
      print(f + '=7')
      exit()
  else:
    dfs(i+1,f + '+' + S[i+1],total + int(S[i+1]))
    dfs(i+1,f + '-' + S[i+1],total - int(S[i+1]))

dfs(0,S[0],int(S[0]))

Measured memory_bytes: 61836
#include<bits/stdc++.h>
#define ll long long

const int MAX = 14;
const int N = 5010;
const int M = 210;

std::pair <int, int> seg[1 << MAX + 1];
int mat[N][M], n, m;
ll max[N][N], dis[N];

void build(int j){
	memset(seg, 0, sizeof(seg));
	for (int i = 1 << MAX; i < (1 << MAX) + n; ++ i){
		seg[i] = {mat[i + 1 - (1 << MAX)][j], i + 1 - (1 << MAX)};
	}
	for (int i = (1 << MAX) - 1; i; -- i){
		seg[i] = std::max(seg[i << 1], seg[(i << 1) + 1]);
	}
}

std::pair <int, int> query(int left, int right){
	std::pair <int, int> ret = {0, 0};
	for (int l = (1 << MAX) + left - 1, r = (1 << MAX) + right; l < r; l >>= 1, r >>= 1){
		if (l & 1){
			ret = std::max(ret, seg[l ++]);
		}
		if (r & 1){
			ret = std::max(ret, seg[-- r]);
		}
	}
	return ret;
}

void solve(int left, int right){
	if (left > right){
		return;
	}
	std::pair <int, int> p = query(left, right);
	int x = p.first, sit = p.second;
	max[left][sit] += x;
	max[left][right + 1] -= x;
	max[sit + 1][sit] -= x;
	max[sit + 1][right + 1] += x;
	solve(left, sit - 1);
	solve(sit + 1, right);
}
	
int main(){
	scanf("%d%d", &n, &m);
	for (int i = 2; i <= n; ++ i){
		scanf("%lld", &dis[i]);
		dis[i] += dis[i - 1];
	}
	for (int i = 1; i <= n; ++ i){
		for (int j = 1; j <= m; ++ j){
			scanf("%d", &mat[i][j]);
		}	
	}
	for (int j = 1; j <= m; ++ j){
		build(j);
		solve(1, n);
	}
	for (int i = 1; i <= n; ++ i){
		for (int j = 1; j <= n; ++ j){
			max[i][j] += max[i][j - 1];
		}
	}
	for (int j = 1; j <= n; ++ j){
		for (int i = 1; i <= n; ++ i){
			max[i][j] += max[i - 1][j];
		}
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++ i){
		for (int j = i; j <= n; ++ j){
			ans = std::max(ans, max[i][j] - (dis[j] - dis[i]));
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 200320
n,m = map(int, input().split( ))
cnt = [0]*n
#出現奇数回は不可
#出現偶数回なら勝手になる
for i in range(m):
    ai,bi = map(int, input().split( ))
    ai-=1;bi-=1
    cnt[ai]+=1;cnt[bi]+=1

for i in range(n):
    if cnt[i]%2:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 46336
#coding:utf-8
import queue

k = int(input())

q = queue.Queue()
ans = 0

for i in [1,2,3,4,5,6,7,8,9]:
    q.put(i)

for i in range(k):
    x = q.get()
    if i == k-1:
        ans = x
        break
    
    if x % 10 != 0:
        q.put(10*x + x%10 - 1)

    q.put(10*x + x%10)
    
    if x % 10 != 9:
        q.put(10*x + x%10 + 1)

print("{}".format(ans))

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

long long int nikou(long long int x){
    return x*(x-1)/2;
};

int main(){
    long long int n;
    cin >> n;
    map<long long int,long long int> mp;
    long long int sum=0;
    int a[n];

    for(int i=0; i<n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    for(int i=0; i<n+1; i++){
        sum+=nikou(mp[i]);
    }

    for(int k=0; k<n; k++){
        cout << sum-nikou(mp[a[k]])+nikou(mp[a[k]]-1) << endl;
    }

    return 0;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second
using ll = long long;
using P = pair<ll ,ll>;
//using Tu = tuple<ll, ll, ll>;
const ll INF = 1LL<<61LL;
const ll MOD = 1e9+7;



using ld = long double;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

int main(){
  ll N, M;
  cin >> N >> M;
  vector<vector<ll> > x(N, vector<ll>(M));
  for(int i=0;i<N;i++)
    for(int j=0;j<M;j++){
      cin >> x[i][j];
      x[i][j]--;
    }
  vector<bool> alive(M, true);
  vector<ll> now(N);
  vector<ll> player(M);
  ll ans = INF;
  for(int i=0;i<N;i++)
    player[x[i][0]]++;
  for(int i=0;i<M;i++){
    //for(auto &&x : player)
    //  cout << x << " ";
    //cout << endl;
    ll ma = -1;
    ll maarg = -1;
    for(int j=0;j<M;j++){
      if(player[j] > ma){
	ma = player[j];
	maarg = j;
      }
      player[j] = 0;
    }
    alive[maarg] = false;
    //cout << ans << " " << ma << endl;
    ans = min(ans, ma);
    if(i == M-1)
      break;
    for(int j=0;j<N;j++){
      while(!alive[x[j][now[j]]])
	now[j]++;
      player[x[j][now[j]]]++;
    }
    
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <memory>
using namespace std;

const int N = 1005;
char grid[N][N];
int dp[N][N];
int n, m, mod = 1e9 + 7;

bool valid(int i, int j){
	return (i >= 0 && i < n && j >= 0 && j < m && grid[i][j] == '.');
}

int solve(int i, int j){
	if (i == n - 1 && j == m - 1)
		return 1;
	if (dp[i][j] != -1)
		return dp[i][j];
	int ways = 0;
	if (valid(i + 1, j)){
		ways += solve(i + 1, j);
		ways %= mod;
	}
	if (valid(i, j + 1)){
		ways += solve(i, j + 1);
		ways %= mod;
	}
	return dp[i][j] = ways % mod;
}

int main() {
	memset(dp, -1, sizeof dp);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> grid[i][j];
	cout << solve(0, 0) << '\n';
	return 0;
}

Measured memory_bytes: 5248
#include <stdio.h>
int main(void)
{
  int x,a,b;
  scanf("%d%d%d",&x,&a,&b);
  if(a>=b)
  {
    printf("delicious\n");
  }
  else if(b-a<=x)
  {
    printf("safe\n");
  }
  else
  {
    printf("dangerous\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
#include <map>
#include <cstring>
#include <cassert>
 
using namespace std;

int main(){

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

	map<int,int> cnt;
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		cnt[a]++;
	}
	
	vector<int> v;
	for(auto x:cnt){
		v.push_back(x.second);
	}
	sort(v.begin(),v.end(),greater<int>());
	int res=0;
	for(int i=k;i<v.size();i++){
		res+=v[i];
	}
	cout<<res<<endl;



	return 0;
}


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

int main()
{
	int n,k;
	int i,j;
	int* list;
	int white;
	while(scanf("%d %d",&n,&k),n)
	{
		white = 0;
		list = (int*)malloc(sizeof(int)*n);
		for(i = 0;i < n;i++)
		{
			list[i] = 0;
		}
		for(i = 0;i < k;i++)
		{
			int m;
			scanf("%d",&m);
			if(m != 0)
				list[m-1] = 1;
			else
				white = 1;
		}
		int maxlen = 0;
		if(white != 1)
		{
			int len;
			i = 0;
			while(i < n)
			{
				while(i < n && !list[i])i++;
				if(i >= n)break;
				len = 1;
				i++;
				while(i < n && list[i])
				{
					i++;
					len++;
				}
				if(len > maxlen)
				{
					maxlen = len;
				}
				if(i >= n)break;
			}
		}
		else
		{
			int len[2] = {0,0};
			int flug = 0;
			i = 0;
			while(1){
				while(i < n && !list[i])i++;
				if(i >= n)break;
				while(i < n && list[i])
				{
					i++;
					len[0]++;
					len[1]++;
				}
				if(len[0] > maxlen)
					maxlen = len[0];
				if(len[1] > maxlen)
					maxlen = len[1];
				if(i >= n)break;
				if(i != (n-1) && list[i+1])
				{
					if(flug == 0)
					{
						len[0]++;
						len[1] = 0;
						flug = 1;
						continue;
					}
					else
					{
						len[1]++;
						len[0] = 0;
						flug = 0;
						continue;
					}
				}
				else
				{
					len[0] = 0;
					len[1] = 0;
					flug = 0;
					continue;
				}
			}
		}
		printf("%d\n",maxlen);
	}
	return 0;
}

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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e6;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 1, (int)A.size()) out << A[i] + 1 << " ";
    return out;
}

int32_t main() {
    int n;  cin>>n;
    map<int, int > my;
    vector<int > A(n);  fr(i,0,n){
        cin>>A[i];
        my[A[i]]++;
    }
    int ans = 0;
    for(auto x : my){
        ans += x.ss*(x.ss-1)/2;
    }
    fr(i,0,n){
        int ele = my[A[i]];
        int temp = ans - ele*(ele-1)/2;
        ele--;
        temp += ele*(ele-1)/2;
        cout << temp << endl;
    }
    return 0;
}


Measured memory_bytes: 12744
#include <iostream>
using namespace std;
int a,b,c;
int main()
{
  cin >> a >> b >> c;
  if(a+b==c||b+c==a||c+a==b){
    cout << "Yes" << "\n";
  }
  else {
    cout << "No" << "\n";
  }
  return 0;
}


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

bool is_exponential(int x)
{
    if (x == 1) return true;
    for (int i = 2; i <= x; i++) {
        int pow = i;
        while (true) {
            pow *= i;
            if (pow == x) return true;
            if (pow > x) break;
        }
    }
    return false;
}

int main()
{
    int x; cin >> x;
    while (!is_exponential(x)) x--;
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
#define foR for

// FHCまでにスタックオーバーフローの罠を解決する


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


    ll n;cin>>n;
    if(n >= 30)cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3644