akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  cin >> n;
  vl c(n-1),s(n-1),f(n-1);
  rep(i,n){
    cin >> c[i] >> s[i] >> f[i];
  }
  vl a(n);
  rep(i,n){
    ll t=0;
    FOR(j,i,n-1){
      if(t<s[j])
        t=s[j];
      else{
        while((t-s[j])%f[j]!=0){
          t++;
        }
      }
      t+=c[j];
    }
    a[i]=t;
  }
  rep(i,n){
    cout << a[i] << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	long int w;
	cin>>w;
	long int arr[n+1][2];
	for(int i=1;i<=n;i++)
	cin>>arr[i][0]>>arr[i][1];
	long long int dp[n+1][w+1];
	for(int i=0;i<=n;i++){
		for(long int j=0;j<=w;j++)
		dp[i][j]=0;
	}
	for(long int i=0;i<=w;i++){
		if(i>=arr[1][0])
		dp[1][i]=arr[1][1];
		else
		dp[1][i]=0;
		//cout<<dp[1][i]<<" ";
	}
	//cout<<endl;
	for(long int i=2;i<=n;i++){
		for(long int j=0;j<=w;j++){
			if(arr[i][0]<=j){
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-arr[i][0]]+arr[i][1]);
			//cout<<dp[i-1][j-arr[i][0]]+arr[i][1]<<" check\n";
			}
			else
			dp[i][j]=dp[i-1][j];
			//cout<<dp[i][j]<<" ";
		}
		//cout<<endl;
	}
//	long long int ans=0;
//	for(long int j=0;j<=w;j++){
//		if(dp[n][j]>ans)
//		ans=dp[n][j];
//}
	cout<<dp[n][w];
	return 0;
}

Measured memory_bytes: 79104
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

#define pb push_back
#define fi first
#define se second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template <class T>
istream& operator>>(istream& ss, vector<T>& v) {
    for (int i = 0; i < v.size(); i++) ss >> v[i];
    return ss;
}

template <class T> 
ostream& operator<<(ostream& ss, const vector<T>& v) {
    for (int i = 0; i < v.size(); i++) ss << v[i] << ' ';
    return ss;
}

ll binpow(ll a, ll n, ll m) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res *= a;
            res %= m;
        }
        a *= (a % m);
        a %= m;
        n >>= 1;
    }
    return res % m;
}

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

ll lcm(ll a, ll b) {
    return a * b / gcd(a,b);
}

const int mod = 1e9 + 7;
const int inf = 1e9;
const ll N = 1e18;

void solve() {
    int n;
    cin >> n;
    ll ans = 1;
    vll a(n);
    cin >> a;
    for (ll i : a) {
        if (!i) {
            cout << 0;
            return;
        }
    }
    for (ll i : a) {
        if (N / ans < i) {
            cout << -1;
            return;
        }
        ans *= i;
    }
    cout << ans;
}

int main() {
    speed;
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
}

Measured memory_bytes: 3984
def run(N, S, T):
    ans = ''
    for i in range(N):
        ans += S[i]
        ans += T[i]
    return ans


def main():
    N = int(input())
    S, T = input().split()
    print(run(N, S, T))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll A,B,C;
    cin >> A >> B >> C;
    ll K;
    cin >> K;
    
    if(K&1){
        pr(B-A);
    }else{
        pr(A-B);
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String t = sc.next();

		char[] cs = s.toCharArray();
		char[] ct = t.toCharArray();

		sort(cs);
		rsort(ct);
		
//		printArray(cs);
//		printArray(ct);
		
		s = new String(cs);
		t = new String(ct);


		System.out.println(s.compareTo(t) < 0 ? "Yes" : "No");
	}
	
	public static void sort(char[] a){
		
		for(int i = 1 ; i < a.length ; ++i){
			char c = a[i];
			int j = i-1;
			while(j >= 0 && Character.compare(c , a[j]) < 0){
				a[j+1] = a[j];
				--j;
			}
			
			a[j+1] = c;
		}
	}
	
	public static void rsort(char[] a){
		
		for(int i = a.length -1 ; i >= 0 ; --i){
			char c = a[i];
			int j = i+1;
			while(j < a.length && Character.compare(c , a[j]) < 0){
				a[j-1] = a[j];
				++j;
			}
			a[j -1] = c;
		}
	}
	
	public static void printArray(char[] a){
		
		StringBuilder s = new StringBuilder();
		
		for(char c : a){
			s.append(c);
		}
		s.append("\n");
		System.out.println(s);
	}
}

Measured memory_bytes: 21972
from math import pi, fabs, cos, sqrt
a, b, h, m = (int(s) for s in input().split())
theta_a = 2*pi * (m/60 + h)/12
theta_b = 2*pi * m/60
theta = fabs(theta_a - theta_b)
if theta > pi/2:
    theta = 2 * pi - theta

result = sqrt(a**2 + b**2 - 2*a*b*cos(theta))
print(result)

Measured memory_bytes: 9456
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
    long long H, W;

    cin >> H >> W;

    if (H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        cout << (H * W + 1) / 2 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
int main(){
  int H,i,A[MAX+1];
  scanf("%d",&H);
  for(i=1;i<=H;i++)
    scanf("%d",&A[i]);
  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i/2 >= 1)
      printf("parent key = %d, ",A[i/2]);
    if(i*2 <= H)
      printf("left key = %d, ",A[i*2]);
    if(i*2+1 <= H)
      printf("right key = %d, ",A[i*2+1]);
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2108
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
ll n,A[MAXN];
int main()
{
	FAST
	cin>>n;
	FOR(i,0,n)cin>>A[i];
	sort(A,A+n);
	cout<<A[n/2]-A[n/2-1]<<'\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
  ll a,b; cin>>a>>b;
  if(2*b<=a)cout<<a-2*b<<endl;
  else cout<<0<<endl;
  
  
  
}

Measured memory_bytes: 256
while 1:
    s = raw_input().replace("north","0").replace("west","1")[::-1]
    if s == "#": break
    u = 90*int(s[0])
    s = s[1:]
    d = 2**len(s)
    for i in s:
        u = 2*u+(90 if i == "1" else -90)
    while u%2 == 0 and d > 1:
        u /= 2; d /= 2
    print u if d == 1 else "%d/%d"%(u,d)

Measured memory_bytes: 4220
def main():
    word = input().replace("BC", "X") + " "
    answer = 0
    count_a = 0
    for i in range(len(word)):
        if word[i] == "A":
            count_a += 1
        elif word[i] == "X":
            answer += count_a
        else:
            count_a = 0
    print(answer)


if __name__ == '__main__':
    main()



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

int main() {
  int n,m,k,t,f,q,j;
  cin >> n; cin >> m; cin >> k;
  vector<int> a; vector<int> b; vector<int> c; vector<int> prices;
  for (int i = 0; i < n; ++i)
  {
    cin >> t;
    a.push_back(t);
  }
  for (int i = 0; i < m; ++i)
  {
    cin >> t;
    b.push_back(t);
  }
  for (int i = 0; i < k; ++i)
  {
    cin >> f;
    cin >> q;
    cin >> j;
    prices.push_back(a[f-1]+b[q-1]-j);
  }
  sort(prices.begin(),prices.end());
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  cout << min(prices[0],a[0]+b[0]);
}

Measured memory_bytes: 1784
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
  int n,d,x[11][11],i,j,k,ans=0,c=0;double diff,ans1;
  scanf("%d%d",&n,&d);
  for(i=1;i<=n;i++)
  {
    for(j=1;j<=d;j++)
    {
      scanf("%d",&x[i][j]);
    }
    printf("\n");
  }
  for(i=1;i<n;i++)
  {
    for(k=i+1;k<=n;k++)
    {
      for(j=1;j<=d;j++)
      {
        ans=ans+((x[i][j]-x[k][j])*(x[i][j]-x[k][j]));
        
      }
      ans1=(double)sqrt(ans);
      diff=(double)ceil(ans1);
      diff=(double)diff-ans1;
      if(diff==0)
      {
        c++;
      }
      ans=0;
    }
    ans=0;
  }
  printf("%d",c);
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int MAX = 1000000;
constexpr int inf = 1<<30;


int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto & b : a)cin>>b;
    vector<int> ret(n);
    for(int b=0;b<=60;++b){
        int count = 0;
        for(int i=0;i<n;++i){
            if(a[i] &(1ll<<b))count++;
        }
        if(count%2){
            for(int i=0;i<n;++i){
                if(!(a[i]&(1ll<<b)))ret[i]+=1ll<<b;
            }
        }else for(int i=0;i<n;++i){
            if(a[i]&(1ll<<b))ret[i] += 1ll<<b;
        }
    }
    for(int i=0;i<n;++i){
        if(i)cout << " ";
        cout << ret[i];
    }
    return 0;
}


Measured memory_bytes: 4772
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long takahashi = scan.nextLong();
		long aoki = scan.nextLong();
		long koudou = scan.nextLong();
		int countT = 0;
		int countA = 0;

			if(koudou <= takahashi) {
				 takahashi = takahashi - koudou;

			}else if( koudou <= takahashi+aoki) {

				aoki = aoki - (koudou - takahashi);
				takahashi = 0;

			}else if(takahashi + aoki < koudou) {
				takahashi = 0;
				aoki = 0;
			}

		System.out.println(takahashi);
		System.out.println(aoki);

		scan.close();

	}

}


Measured memory_bytes: 23764
void main()
{
    string[] tmp = rdRow!string;
    string s = tmp[0], t = tmp[1];

    writeln(t, s);
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    private static final int MOD = (int) 1e9 + 7;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        sc.nextLine();
        char[][] X = new char[h][w];
        for(int i = 0; i < h; i++) {
            int j = 0;
            for(char c : sc.nextLine().trim().toCharArray()) {
                X[i][j++] = c;
            }
        }
        long[][] dp = new long[h][w];
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                if(X[i][j] == '#') {
                    continue;
                }
                if(i == 0 && j == 0) {
                    dp[i][j] = 1;
                } else if(i == 0) {
                    dp[i][j] = dp[i][j - 1];
                } else if(j == 0) {
                    dp[i][j] = dp[i - 1][j];
                } else {
                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                    dp[i][j] %= MOD;
                }
            }
        }
        System.out.println(dp[h - 1][w - 1]);
    }
}


Measured memory_bytes: 45948
/* AUTHOR :  SHIVANK JAIN */

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false)
#define itt cin.tie(0)
#define now cout.tie(0)

using namespace std;

#define ll long long
#define li long int

#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define reprev(i,n,a) for(int i=n;i>=a;i--)
#define endl "\n"

#define vi vector<int>
#define vll vector<ll>
#define vpi vector< pair<int , int> >
#define mapi map<int , int>
#define mapll map<ll ,ll >
#define seti set<int> 

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define sort(v) sort(v.begin() , v.end())

#define BIG 1000000007
int gcd(int a, int b) 
{ // builtin function __gcd(a,b)
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
int main(){

     fast;itt;now;
 
//    #ifndef ONLINE_JUDGE
//    // for getting input from input.txt
//    freopen("input.txt", "r", stdin);
//    // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
//    #endif
    
     int s,w;   cin>>s>>w;
     
      if(w >= s)
       cout<<"unsafe"<<endl;
      else
	   cout<<"safe"<<endl; 
}

Measured memory_bytes: 3612
n, m = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))

sum_a = sum(a)
count = 0
for val in a:
    if val >= sum_a / (4 * m):
        count += 1
if count >= m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <cctype>
#include <climits> // INT_MAX ...
#include <cstring> // 

using namespace std;
using int64 = long long;
const int MOD = 1e9 + 7;

// Ai * Bi = A(i+1) * B(i+1) = ... 
// Bi = LCM / Ai
// lcm = a * b / gcd(a, b) --> overflow --> https://en.wikipedia.org/wiki/Least_common_multiple#Formulas


int64 POW(int64 e, int64 n, int64 md = MOD) {
	if (n == 0) return 1;
	int64 ans = POW(e, n >> 1);
	ans = (ans * ans) % md;
	if (n & 1) ans = (ans * e) % md;
	return ans;
}

vector<pair<int, int>> factors(int n) {
	vector<pair<int, int>> ans;
	for (int i = 2; i * i <= n; ++i) {
		int cnt = 0;
		while (n % i == 0) {
			cnt++;
			n /= i;
		}
		if (cnt) ans.emplace_back(i, cnt);
	}
	if (n > 1) ans.emplace_back(n, 1);
	return ans;
}


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

	int n;
	cin >> n;

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

	map<int, int> fl; // lcm factors
	for (int x : A) {
		vector<pair<int, int>> fs = factors(x);
		for (auto k : fs) {
			fl[k.first] = max(fl[k.first], k.second);
		}
	}

	int64 lcm = 1;  // cal lcm
	for (auto x : fl) {
		// cout << x.first << " " << x.second << endl;
		lcm = (lcm * POW(x.first, x.second)) % MOD;
	}
	// cout << lcm << endl;

	int64 ans = 0; // cal ans
	for (int x : A) {
		ans = (ans + POW(x, MOD - 2) * lcm) % MOD; // POW(x, MOD - 2) * lcm --> Bi: lcm / x 
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int linersearch(int a[], int n, int x);
void insetrtionsort(int a[], int n);
void printarray(int n, int a[]);
void babblesort(int n, int a[]);
void selectionsort(int n, int a[]);
void countingsort(int n, int a[]);

int linersearch(int a[], int n, int x)
{
    int ret = 0;
    for (int i = 1; i < n; i++)
    {
        if (a[i] == x)
        {
            ret = 1;
            break;
        }
    }
    return ret;
}

void insetrtionsort(int a[], int n)
{
    int j, v;
    for (int i = 1; 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 (int i = 0; i < n; i++)
        {
            cout << a[i] << " ";
        }
        cout << endl;
    }
}

void babblesort(int n, int a[])
{
    int flag = 1;
    int counter = 0;
    int tmp;
    while (flag)
    {
        flag = 0;
        for (int j = n - 1; j > 0; j--)
        {
            if (a[j] < a[j - 1])
            {
                swap(a[j], a[j - 1]);
                counter++;
                flag = 1;
            }
        }
    }
    printarray(n, a);
    cout << counter << endl;
}

void selectionsort(int n, int a[])
{
    int minj;
    int counter = 0;
    for (int i = 0; i < n; i++)
    {
        minj = i;
        for (int j = i; j < n; j++)
        {
            if (a[j] < a[minj])
                minj = j;
        }
        if (i != minj)
        {
            swap(a[minj], a[i]);
            counter++;
        }
    }
    printarray(n, a);
    cout << counter << endl;
}

void countingsort(int n, int a[])
{
    int b[n] = {};
    int k = 0;
    for (int i = 0; i < n; i++)
        k = max(a[i], k);
    int c[k + 1] = {};
    for (int i = 0; i < n; i++)
        c[a[i]]++;
    for (int i = 1; i < k + 1; i++)
        c[i] += c[i - 1];
    for (int i = n-1; i > -1; i--)
    {

        b[c[a[i]] - 1] = a[i];
        c[a[i]]--;
    }
    printarray(n, b);
}

void printarray(int n, int a[])
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        if (i != n - 1)
            cout << " ";
    }
    cout << endl;
}

int gcd(int a, int b)
{
    if (a < b)
    {
        int t = a;
        a = b;
        b = t;
    }
    cout << a << " " << b << endl;
    if (b == 0)
        return a;
    else
        return gcd(b, b % a);
}

int main()
{
    int n, m, ans;
    ans = 0;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    countingsort(n,a);
    return 0;
}



Measured memory_bytes: 18756
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  if(H%h == 0 && W%w == 0){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  int ans[H][W];
  if(H%h != 0){
    REP(i,H){
      int temp;
      if(i%h == 0){
        temp = 1000*h - 1001;
      }else{
        temp = -1000;
      }
      REP(j,W){
        ans[i][j] = temp;
      }
    }
  }else{
    REP(j,W){
      int temp;
      if(j%w == 0){
        temp = 1000*w - 1001;
      }else{
        temp = -1000;
      }
      REP(i,H){
        ans[i][j] = temp;
      }
    }
  }
  
  REP(i,H){
    REP(j,W){
      cout<<ans[i][j]<<' ';
    }
    cout<<endl;
  }
      
  return 0;
}


Measured memory_bytes: 2688
A, B, C, X, Y = map(int, input().split())

ans = 10**10

ans = min(ans, A*X + B*Y, C*max(X, Y)*2)

if X <= Y:
    ans = min(ans, C*X*2 + B*(Y-X))
else:
    ans = min(ans, C*Y*2 + A*(X-Y))

print(ans)


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
N = int(input())
A = [[x-1 for x in list(map(int, input().split()))] for _ in range(N)]

def can_match(i, A, next_set):
  if not A[i]:
    return
  j = A[i][0]
  if A[j][0] == i:
    if i < j:
      next_set.add((i,j))
    else:
      next_set.add((j,i))
      
next_set = set()
for i in range(N):
  can_match(i, A, next_set)
  
day = 0
battle = 0
while next_set:
  day += 1
  current_set, next_set = next_set, set()
  for match in current_set:
    battle += 1
    del A[match[0]][0]
    can_match(match[0], A, next_set)
    del A[match[1]][0]
    can_match(match[1], A, next_set)
    
if battle == N*(N-1)//2:
  print(day)
else:
  print(-1)


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

if N == 1 and M == 1:
    print(1)
elif N == 1:
    print(M-2)
elif M == 1:
    print(N-2)
elif N >= 3 and M >= 3:
    print((N-2)*(M-2))
else:
    print(0)


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

/**
 * Created by tela on 2017/06/18.
 */
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);
        TaskC solver = new TaskC();
        solver.solve(in, out);
        out.close();
    }

    static class TaskC {
            public void solve(InputReader in, PrintWriter out) {
                int H, W, h, w = 0;
                H = in.nextInt();
                W = in.nextInt();
                h = in.nextInt();
                w = in.nextInt();

                if(H % h == 0 && W % w ==0){
                    out.println("No");
                }else{
                    out.println("Yes");
                    for(int r = 1; r <=H; r++){
                        for(int c = 1; c <=W; c++){
                            if(r % h == 0 && c % w == 0){
                                out.print(" "+(-1000*w*h+999));
                            }else{
                                out.print(" "+1000);
                            }
                        }
                        out.println("");
                    }
                }
            }
    }


    //input
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}

Measured memory_bytes: 40916
#define DEBUG 0

/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 5/4/2019, 9:10:38 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

ll H, W;
ll N;
string S, T;
ll sr, sc;
int A[200010];
int B[200010];
typedef tuple<int, int> event;

bool solve(int X, int s, vector<event> V)
{
#if DEBUG == 1
  cerr << "X = " << X << ", s = " << s << endl;
#endif
  int maxi = s, mini = s;
  for (auto x : V)
  {
    int player = get<0>(x);
    int move = get<1>(x);
    if (player == 0 && move == 0)
    {
      mini--;
    }
    else if (player == 0 && move == 1)
    {
      maxi++;
    }
    else if (player == 1 && move == 0)
    {
      if (maxi > 0)
      {
        maxi--;
      }
    }
    else
    {
      if (mini < X - 1)
      {
        mini++;
      }
    }
#if DEBUG == 1
    cerr << "(" << player << ", " << move << ") : ";
    cerr << "maxi = " << maxi << ", mini = " << mini << endl;
#endif
    if (mini < 0 || maxi >= X)
    {
      return true;
    }
  }
  return false;
}

int main()
{
  cin >> H >> W >> N >> sr >> sc >> S >> T;
  sr--;
  sc--;
  for (auto i = 0; i < N; i++)
  {
    if (S[i] == 'L')
    {
      A[i] = 0;
    }
    else if (S[i] == 'R')
    {
      A[i] = 1;
    }
    else if (S[i] == 'U')
    {
      A[i] = 2;
    }
    else
    {
      assert(S[i] == 'D');
      {
        A[i] = 3;
      }
    }
  }
  for (auto i = 0; i < N; i++)
  {
    if (T[i] == 'L')
    {
      B[i] = 0;
    }
    else if (T[i] == 'R')
    {
      B[i] = 1;
    }
    else if (T[i] == 'U')
    {
      B[i] = 2;
    }
    else
    {
      assert(T[i] == 'D');
      {
        B[i] = 3;
      }
    }
  }
  vector<event> V;
  for (auto i = 0; i < N; i++)
  {
    if (A[i] < 2)
    {
      V.push_back(event(0, A[i]));
    }
    if (B[i] < 2)
    {
      V.push_back(event(1, B[i]));
    }
  }
  vector<event> U;
  for (auto i = 0; i < N; i++)
  {
    if (A[i] >= 2)
    {
      U.push_back(event(0, A[i] - 2));
    }
    if (B[i] >= 2)
    {
      U.push_back(event(1, B[i] - 2));
    }
  }
  if (solve(H, sr, U) || solve(W, sc, V))
  {
    cout << "NO" << endl;
  }
  else
  {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 8568
#include <cstdio>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>


using namespace std;
typedef long long LL;

int main(void) {

	int A, B;

	cin >> A >> B;

	if (A <= 8 && B <= 8)
		cout << "Yay!" << endl;
	else
		cout << ":(" << endl;


	return 0;
}


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

int main(){
    long long q, sum_a = 0, sum_b = 0;
    cin >> q;
    vector<int> A;
    for (int i = 0; i < q; i++)
    {
        int id;
        cin >> id;
        if (id == 1)
        {
            int a, b;
            cin >> a >> b;
            sum_b += b;
            vector<int>::iterator itr = upper_bound(A.begin(), A.end(), a);
            if (A.size() % 2 == 1)
            {
                sum_a += abs(A[A.size()/2] - a);
            }
            A.insert(itr, a);
            if (A.size() % 2 == 1)
            {
                sum_a += abs(A[A.size()/2] - a);
            }
        }
        else
        {
            cout << A[(A.size()-1)/2] << " " << sum_a + sum_b << endl;
        }
    }
    
}

Measured memory_bytes: 3956
#include <stdlib.h>
#include <iostream>
#include <climits>
#include <map>
using namespace std;

#define REP(i,n) for(long i=0; i<(long)(n); ++i)
#define FOR(i,k,n) for(long i=(k);i<(long)(n);++i)

bool does_exist(long n, bool* in, bool first, bool second);
bool answer(long n, bool* in, bool first, bool second);
void out_sw(bool in);

int main(){
	long n;
	cin >> n;
	bool *in = (bool *)calloc(n, sizeof(bool));
	char s;
	REP(i, n){
		cin >> s;
		if(s == 'o'){
			in[i] = true;
		}else{
			in[i] = false;
		}
	}
	if(does_exist(n, in, true, true)){
		answer(n, in, true, true);
		return 0;
	}
	if(does_exist(n, in, true, false)){
		answer(n, in, true, false);
		return 0;
	}
	if(does_exist(n, in, false, true)){
		answer(n, in, false, true);
		return 0;
	}
	if(does_exist(n, in, false, false)){
		answer(n, in, false, false);
		return 0;
	}
	cout << -1 << endl;
	return 0;
}

bool does_exist(long n, bool* in, bool first, bool second){
	bool *res = (bool *)calloc(n, sizeof(bool));
	res[0] = first;
	res[1] = second;
	FOR(i, 1, n-1){
		if(res[i]==in[i]){
			res[i+1] = res[i-1];
		}else{
			res[i+1] = !res[i-1];
		}
	}
	return ((in[n-1]==res[n-1])==(res[0] == res[n-2])) && 
			((in[0]==res[0])==(res[1] == res[n-1]));

}
bool answer(long n, bool* in, bool first, bool second){
	bool *res = (bool *)calloc(n, sizeof(bool));
	res[0] = first;
	res[1] = second;
	out_sw(res[0]);
	out_sw(res[1]);
	FOR(i, 1, n-1){
		if(res[i]==in[i]){
			res[i+1] = res[i-1];
		}else{
			res[i+1] = !res[i-1];
		}
		out_sw(res[i+1]);
	}
	cout << endl;
	return true;
}
void out_sw(bool in){
	if(in){
		cout << 'S';
	}else{
		cout << 'W';
	}

}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        string s = to_string(i);
        if(s.size() % 2 != 0) ans++;
    }

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


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

int main(){
  char C[2][3];
  for(int  i=0;i<2;i++){
    string S;
    cin>>S;
    for(int j=0;j<3;j++){
      C[i][j]=S[j];     
    }
  }
  int cnt=0;
  for(int i=0;i<3;i++){
    cnt+=C[0][i]==C[1][2-i];
  }
  if(cnt==3) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3];
    while(cin>>a[0]>>a[1]>>a[2])
    {
        int s=10000000;
        do
        {
            int c=0;
            c=abs(a[1]-a[0])+abs(a[2]-a[1]);
            s=min(s,c);
        }while(next_permutation(a,a+3));
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define maxn 100005
using namespace std;

int main()
{
    int n,m;
    int ans=0;
    cin>>n>>m;
    if(n>=2)
    {
        ans+=n*(n-1)/2;
    }
    if(m>=2)
    {
        ans+=m*(m-1)/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=101000;
int n,u,v,sg[N];
VI e[N];
void dfs(int u,int f) {
	for (auto v:e[u]) if (v!=f) {
		dfs(v,u);
		sg[u]^=sg[v]+1;
	}
}
int main() {
	scanf("%d",&n);
	rep(i,1,n) {
		scanf("%d%d",&u,&v);
		e[u].pb(v);
		e[v].pb(u);
	}
	dfs(1,0);
	puts(sg[1]?"Alice":"Bob");
}


Measured memory_bytes: 12416
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars,
    }

    for (prev, next) in s.iter().by_ref().zip(s.iter().by_ref().skip(1)) {
        if prev == next {
            println!("Bad");
            return;
        }
    }
    println!("Good");
}


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

int main() {

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cnt = 1;
    for (int i=1; i<n; i++){
        if (s[i]!=s[i-1]) cnt++;
    }
    cout<<cnt;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;

int a[26]={0};
char b[26];
char str1[5005];
char str2[5005];
char temp[5005];
int	main()
{
	cin>>str1;
	int q;
	cin>>q;
	int t=0;
	for(int i=0;i<strlen(str1);i++)
	{
		a[str1[i]-'a']=1;
	}
	
	for(int i=0;i<26;i++)
	{
		if(a[i])
			b[t++]=i+'a';			
	}
	
	int k=0,m=0,n=0;
	str2[m]=temp[m]=b[n];
	str2[m+1]=temp[m+1]='\0';
	int flag=0;
	while(1)
	{
		//cout<<str2<<" "<<k<<endl;
		flag=0;
		if(strstr(str1,str2)!=NULL)
		{
			k++;
			if(k>=q)
				break;
			flag=1;
		}
		
		if(flag)
		{
			str2[++m]=b[0];
			str2[m+1]='\0';
			
		}
		else
		{
			int w=0;
			for(w=0;w<t;w++)
				if(str2[m]==b[w])
					break;
						
			while(w+1>=t)
			{
				--m;
				for(w=0;w<t;w++)
					if(str2[m]==b[w])
						break;
			}
			
			str2[m]=b[w+1];
			str2[m+1]='\0';
			
		}
		
			
	}
	
	cout<<str2<<endl;
	
	
	
	return 0;
}

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

#define int ll
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9;
const int MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 1e5 + 5;

int A[N];
vector<int> IDX[N];

int32_t main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, ans = 1; cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i], IDX[A[i]].push_back(i);
	for (int i = n - 1; i >= 1; i--) {
		if (sz(IDX[i]) > sz(IDX[i - 1]) || sz(IDX[i]) > 3) die(0);
		for (int j = 0; j < sz(IDX[i]); j++) {
			int k = lower_bound(all(IDX[i - 1]), IDX[i][j]) - IDX[i - 1].begin();
			if (k - j <= 0) die(0);
			ans = 1LL * ans * (k - j) % MOD;
		}
	}
	if (sz(IDX[0]) == 1) ans = 1LL * ans * 3 % MOD;
	else if (sz(IDX[0]) == 2 || sz(IDX[0]) == 3) ans = 1LL * ans * 6 % MOD;
	else ans = 0;
	cout << ans << endl;

	return 0;
}


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

int D[100];
int mat[100][100];

void bfs(int src);

int main() {
  int n;
  for (int i=0;i<100;++i) {
    for (int j=0;j<100;++j)
      mat[i][j] = 0;
    D[i] = -1;
  }
  cin >> n;
  for (int i=0;i<n;++i) {
    int buf1,buf2;
    cin >> buf1 >> buf2;
    for (int j=0;j<buf2;++j) {
      int buf3;
      cin >> buf3;
      mat[i][buf3-1] = 1;
    }
  }
  bfs(0);
  for (int i=0;i<n;++i)
    cout << i+1 << " " << D[i] << endl;
}

void bfs(int src) {
  // cout << "bfs root = " << src << endl;
  queue<int> Q; // 整数を管理するキューの定義
  Q.push(src);
  D[src] = 0; // 出発点
  while (!Q.empty()) {
    int cur = Q.front(); // 先頭要素を取り出す
    Q.pop();
    // 動作確認用表示
    // cout << "visiting " << cur << " " << D[cur] << endl;
    for (int dst=0;dst<100;++dst) { // 各行き先 dst に対して
      if (mat[cur][dst]==1&&D[dst]==-1) {
	// cur から dst に辺があり, dst が未訪問なら
	D[dst] = D[cur]+1;
	Q.push(dst); // dst を訪問先に加える
      }
    }
  }
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N, K;
    cin >> N >> K;
    vector<ll> x(N);
    rep(i, N) { cin >> x[i]; }
    // full search
    ll ans = INF;
    rep(i, N - K+1)
    {
        ll l = x[i], r = x[i + K - 1];
        ans = min(ans, min(abs(l), abs(r)) + r - l);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int n,m,x;
ll ans=INF;
vector<ll> c;
vector<vector<ll>> a;

void dfs(vector<int> T){
    if(T.size()>=n){
        ll res = 0;
        rep(i,n)if(T[i])res+=c[i];
        rep(i,m){
            int d = 0;
            rep(j,n){
                if(T[j])d+=a[j][i];
            }
            if(d<x)return;
        }
        ans = min(ans,res);
        return;
    }
    T.push_back(1);
    dfs(T);
    T.back()=0;
    dfs(T);
}

int main(){
    cin >> n >> m >> x;
    c = vector<ll>(n);
    a = vector<vector<ll>>(n,vector<ll>(m));
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }
    dfs(vector<int>());
    if(ans!=INF)cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3596
# coding: utf-8
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


N = int(input())
A = list(map(int, input().split(" ")))
L = [0 for i in range(N)]
R = [0 for i in range(N)]
M = [0 for i in range(N)]

for i in range(1, N):
    L[i] = gcd(L[i-1], A[i-1])
for i in range(N-2, -1, -1):
    R[i] = gcd(R[i+1], A[i+1])
for i in range(N):
    M[i] = gcd(L[i], R[i])
print(max(M))

Measured memory_bytes: 14584
#include <bits/stdc++.h> 
using namespace std; 
  
typedef long long int ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pll> vll; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
  
double EPS = 1e-9; 
long long INF = 1000000000000000005ll; 
double PI = acos(-1); 
#define M 1000000007ll
#define D 998244353ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound  
#define SQR(x) ((LL)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a))
#define GCD(a,b) __gcd(a,b)
#define setbits(x)   __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x) 
#define ps(x,y)  fixed<<setprecision(y)<<x
#define endl '\n'
#define ff first 
#define ss second 
#define mp make_pair  
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
  
inline string IntToString(ll a) 
{ 
    char x[100]; 
    sprintf(x, "%lld", a); 
    string s = x; 
    return s; 
} 
  
inline ll StringToInt(string a) 
{ 
    char x[100]; 
    ll res; 
    strcpy(x, a.c_str()); 
    sscanf(x, "%lld", &res); 
    return res; 
} 
  
 
inline string uppercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'a' && s[i] <= 'z') 
        s[i] = s[i] - 'a' + 'A'; 
    return s; 
} 
  
inline string lowercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'A' && s[i] <= 'Z') 
        s[i] = s[i] - 'A' + 'a'; 
    return s; 
}
 
 
int main() {
    FAST
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll n;
    cin>>n;
    ll a[n];
    map <ll,ll> m;
    ll sum=0;
    for(ll i=0;i<n;i++){
    	cin>>a[i];
    	m[a[i]]++;
    }
    for(auto i=m.begin();i!=m.end();i++){
    	sum+=(i->ff*i->ss);
    }
    ll q;
    cin>>q;
    for(ll i=0;i<q;i++){
    	ll x,y;
    	cin>>x>>y;
    	sum-=x*m[x];
    	sum+=y*m[x];
    	m[y]+=m[x];
    	m[x]=0;
    	cout<<sum<<endl;
    }    
    return 0;
}

Measured memory_bytes: 10352
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function 素因数分解(n)
  n=Int(n)
  res=Tuple[]
  for a=2:isqrt(n)
    if n%a!=0; continue; end
    ex=0
    while n%a==0
      ex+=1
      n/=a
    end
    push!(res,(a,ex))
  end
  if n!=1; push!(res,(Int(n),1)); end
  return res
end
function main()
  x=pI(readline())
  if x<4
    println(1)
    return 0
  end
  for i=x:-1:1
    k=素因数分解(i)
    if all(x->x==k[1][2],[j[2] for j=k]) && k[1][2]>1
      println(i)
      break
    end
  end
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 111536
#!/usr/bin/env python3
import sys


def solve(N: int, P: int):
    if N == 1:
        print(P)
        return
    ret = 1
    i = 2
    while i * i <= P:
        count = 0
        while P % i == 0:
            P //= i
            count += 1
        if count > 0:
            #print(i, count)
            for _ in range(count // N):
                ret *= i
        i += 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    solve(N, P)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ull cnt1;
ull cnt2;

int main(){
	ll n;
	cin >> n;
	arep(1,a,sqrt(n)+1){
		arep(a+1,b,n){
			if(a*b<n)
				cnt1++;
		}
	}

	arep(1,a,sqrt(n)+1){
		if(a*a<n)
			cnt2++;
	}

	cout << cnt1*2+cnt2 << endl;
}

Measured memory_bytes: 3676
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int mod = (int)1e9+7;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,x;
	bool ans = true;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		if(x&1) 
			continue;
		if(x%3==0)
			continue;
		if(x%5==0)
			continue;
		ans = false;	
	}
	if(ans){
		cout<<"APPROVED";
	}
	else cout<<"DENIED";
	return 0;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=107;
struct node
{
	string s;
	int n;
	int x;
}a[N];
bool cmp(node a,node b)
{
	if(a.s!=b.s)return a.s<b.s;
	else return a.n>b.n;
}
int main()
{
	int t;
	cin>>t;
	for (int i = 1; i < t+1; ++i)
	{
		cin>>a[i].s>>a[i].n;
		a[i].x=i;
	}
	sort(a+1,a+1+t,cmp);
	for (int i = 1; i < t+1; ++i)
	{
		cout<<a[i].x<<endl;
	}
	return 0;
}






Measured memory_bytes: 256
s = input()
t = input()


o = []
for i in range(0, (len(s) - len(t) + 1)):
    num = 0
    for j in range(len(t)):
        # print(i, j+i)
        if t[j] != s[i + j]:
            num += 1
    o.append(num)

# print(o)
o = min(o)
print(o)

Measured memory_bytes: 9048