akhauriyash/Code-Regression huggingface dataset:
using System;



class Program
{
    static void Main(string[] args)
    {
        Input CInput = new Input();
        int[] input = new int[(int)Input.Define.MAX_ArraySize];
        //int[,] input = new int[(int) Input.Define.MAX_ArraySize, (int) Input.Define.ArraySize2d];
        //int num = 0;
        input = CInput.Line1_int(' ', 2);
        //input = CInput.Multiline_int(' ' ,2, ref num);

        int count = 0;
        for (int i = input[0]; i <= input[1]; i++)
        {
            if (input[2] % i == 0) count++;
        }

        Console.WriteLine("{0} {1} " + ((double)input[0] / (double)input[1]).ToString("f5"), input[0]/input[1], input[0] % input[1]) ;

    }








    class Input
{
    public enum Define
    {
        MAX_ArraySize = 1000000,
        ArraySize2d = 2,                // 2?¬?????????????[][?] ???????
    }

    public string Line1_string()
    {
        return Console.ReadLine();
    }

    public int Line1_int()
    {
        var input = Console.ReadLine();
        return int.Parse(input);
    }

    public int[] Line1_int(int chr, int num)
    {
        var input = Console.ReadLine();
        var split = input.Split(' ');
        int[] spliti = new int[100];
        for (int i = 0; i < num; i++)
        {
            spliti[i] = int.Parse(split[i]);
        }
        return spliti;
    }

    public int[] Multiline_int(ref int datanum)
    {
        int i = 0;
        int[] data = new int[(int)Input.Define.MAX_ArraySize];
        while (true)
        {
            var input = Console.ReadLine();
            var value = int.Parse(input);
            if (value == 0) break;
            data[i] = value;
            i++;
        }
        datanum = i;
        return data;
    }
    /// <summary>
    /// ?????°??????int??????????????????????????????
    /// </summary>
    /// <param name="chr">???????????????</param>
    /// <param name="num">?????????????????????????????°</param>
    /// <param name="datanum">??????????????????????????°</param>
    /// <returns></returns>
    public int[,] Multiline_int(int chr, int num, ref int datanum)
    {
        int i = 0;
        int[,] data = new int[(int)Input.Define.MAX_ArraySize, (int)Input.Define.ArraySize2d];
        while (true)
        {
            var input = Console.ReadLine();
            var split = input.Split(' ');
            int[] spliti = new int[100];
            for (int j = 0; j < num; j++)
            {
                spliti[j] = int.Parse(split[j]);
            }
            if (spliti[0] == 0 && spliti[1] == 0) break;
            data[i, 0] = spliti[0];
            data[i, 1] = spliti[1];
            i++;
        }
        datanum = i;
        return data;
    }

}
}

Measured memory_bytes: 13180
n = int(input())
s = [input() for _ in range(n)]
prefix = ['M', 'A', 'R', 'C', 'H']
cnt = [0] * 5
ans = 0
for i in range(n):
    for j in range(5):
        if s[i][0] == prefix[j]:
            cnt[j] += 1
for i in range(2 ** 5):
    flag = [False] * 5
    for j in range(5):
        if (i >> j) & 1:
            flag[j] = True
    if flag.count(True) == 3:
        tmp = 1
        for k in range(5):
            if flag[k]:
                tmp *= cnt[k]
        ans += tmp
print(ans)

Measured memory_bytes: 9752
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

#define MAX 100000

struct TRAMP{
    char mark;
    int number,inputed_order;
};

TRAMP cards[MAX];

int n;

int Partition(int left,int right){
    int i = left-1,pivot = cards[right].number;
    for(int start = left; start < right; start++){
        if(cards[start].number <= pivot){
                i++;
                std::swap(cards[i],cards[start]);
        }
    }

    std::swap(cards[i+1],cards[right]);

    return i+1;
}

void quickSort(int left,int right){
    if(left < right){
        int q = Partition(left,right);
        quickSort(left,q-1);
        quickSort(q+1,right);
    }
}


int main(){

    bool stableFLG = true;
    scanf("%d",&n);

    for(int i = 0; i < n; i++){
        scanf("%s %d",&cards[i].mark,&cards[i].number);
        cards[i].inputed_order = i;
    }

    quickSort(0,n-1);

    for(int i = 1; i < n; i++){
        if(cards[i].number == cards[i-1].number && cards[i].inputed_order < cards[i-1].inputed_order){
        	stableFLG = false;
        	break;
        }
    }

    if(stableFLG){
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }

    for(int i = 0; i < n; i++)   printf("%c %d\n",cards[i].mark,cards[i].number);
}



 





Measured memory_bytes: 4324
n = int(input())
a = list(map(int,input().split()))
a.append(0)
t = abs(a[0])
for i in range(n):
    t += abs(a[i+1]-a[i])
print(t-abs(a[0])-abs(a[1]-a[0])+abs(a[1]))
for i in range(n-1):
    print(t-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i]))


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

int gcd(int a, int b)
{
	if(b == 0)
	{
		return a;
	}
	
	return gcd(b, a % b);
}

int main()
{
	int a, b;
	cin >>a >> b;
	cout << gcd(a, b) << endl;

    return 0;
}



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

using namespace std;

int a[100010];
map<int,int> M;
int main()
{
	// freopen("read.in","r",stdin);
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		sort(a+1,a+1+n);
	for(int i=n;i>=1;i--) M[a[i]]++;
	n=unique(a+1,a+1+n)-a-1;
	int cnt=0,dim=1; for(int i=n;i>=1;i--)
	{
		if(M[a[i]]>=2&&cnt==0) cnt=1, dim=a[i], M[a[i]]-=2;
		if(M[a[i]]>=2&&cnt==1) {printf("%lld\n",1ll*dim*a[i]); return 0;} 
	}
	cout << 0 << endl;
	return 0;
}

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

using namespace std;

const int MAXN = 100 + 5;

pair<int, int> p[MAXN];

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, t;
    cin >> n >> t;
    for (int i = 0; i < n; i++)
        cin >> p[i].first >> p[i].second;
    sort(p, p + n);
    for (int i = 0; i < n; i++) {
        if (p[i].second <= t) {
            cout << p[i].first << endl;
            return 0;
        }
    }
    cout << "TLE" << endl;
    return 0;
}


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

int main(){
    long long n;
    cin >> n;
    vector<long long> v(n);
    for(long long i = 0; i < n;i++){
        cin >> v.at(i);
    }
    long long ans = 0;
    long long b = 1;
    for(long long i = 0; i < n; i++){
        b = v.at(b-1);
        ans++;
        if(b == 2){
            break;
        }
    }
    if(b != 2){
        ans = -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s;
	cin>>s;
	ll n=sz(s);
	if(n%2)
	{
		cout<<"No\n";
		return 0;
	}
	for(ll i=0;i<n;i++)
	{
		if(i%2 && s[i]!='i')
		{
			cout<<"No\n";
			return 0;
		}
		if(i%2==0 && s[i]!='h')
		{
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}

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

#define MAX 3

int main() {
	long long K, A, B;

	cin >> K >> A >> B;

	long long ans1 = K + 1;
	long long ans2 = 0;
	int flag = 0;
	K -= A - 1;
	while( 1 ) {
		if( K == 1 ) {
			ans2++;
			break;
		}
		K--;
		if( K <= 0 ) {
			break;
		}
		if( flag == 0 ) {
			ans2 += B;
			flag = 1;
		}
		else {
			ans2 += B - A;
		}
		K--;
	}
	long long ans = max( ans1, ans2 );

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// --------------------------------------------------------------------------


struct UnionFind {
    vector<int> par, w;

    UnionFind(int n) : par(n, -1), w(n, 0) { }
    void init(int n) { par.assign(n, -1); w.assign(n, 0); }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) {
            ++w[x];
            return false;
        }
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        w[x] += w[y];
        ++w[x];
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }

    int wei(int x) {
        return w[root(x)];
    }
};


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin >> N >> M;
  UnionFind uf(N);
  for(int i=0; i<M; i++){
    int a,b;
    cin >> a >> b;
    a--;b--;
    uf.merge(a,b);
  }
  int mx = 0;
  for(int i=0; i<N; i++){
    chmax(mx,uf.size(i));
  }
  cout << mx << "\n";
  return 0;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
#include <unordered_map> 
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI1 3.14159265358979311599796346854418516159057617187500
 
typedef long long int ll;  
 
 
int main() 
{ 
    FIO
    int t;
    t=1;
 
    while(t--)
    {
        ll a,b,x;
        cin >>  x >> a >> b;

        ll num = a/x;
        ll num2 = b/x;

        if(num!=num2)
            cout << "OK" << endl;
        else
        {
            if(a%x==0 || b%x==0)
                cout << "OK" << endl;
            else
                cout << "NG" << endl;
        }
    }
 
    return 0; 
} 

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

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

  int ok[3][3] = {};
  
  int n; cin >> n;
  for(int k = 0; k < n; k++) {
    int b; cin >> b;
    for(int i = 0; i < 3; i++) {
      for(int j = 0; j < 3; j++) {
        if(a[i][j] == b) ok[i][j] = true;
      }
    }
  }

  bool flag = false;

  for(int i = 0; i < 3; i++) {
    bool f = true;
    for(int j = 0; j < 3; j++) if(!ok[i][j]) f = false;
    if(f) flag = true;
  }

  for(int j = 0; j < 3; j++) {
    bool f = true;
    for(int i = 0; i < 3; i++) if(!ok[i][j]) f = false;
    if(f) flag = true;
  }

  if(ok[0][0] and ok[1][1] and ok[2][2]) flag = true;
  if(ok[0][2] and ok[1][1] and ok[2][0]) flag = true;

  if(flag) cout << "Yes" << endl;
  else  cout << "No" << endl;
  

  return 0;
}


Measured memory_bytes: 256
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

a,b,c,d = load_list()

turn = True 
while True:
    if turn:
        c -= b
    else:
        a -= d
    if a <= 0:
        print('No')
        break
    elif c <= 0:
        print('Yes')
        break

    turn = not turn
    





Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef pair<int, int> P;

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {
  int L;
  cin >> L;
  ld ans = (L * L * L) / 27.0;
  cout << fixed << setprecision(20) << ans << endl;
  return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

template<class Type> Type igcd(Type x,Type y){return (y==0)?x:igcd(y,x%y);}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}

int main(){
	int k;
	cin>>k;
	
	llong ans=0;
	REP(i,k)for(int j=i;j<k;++j)for(int l=j;l<k;++l){
		if(i==j and j==l) ans+=igcd(i+1,igcd(j+1,l+1));
		else if(i==j or j==l) ans+=3*igcd(i+1,igcd(j+1,l+1));
		else ans+=6*igcd(i+1,igcd(j+1,l+1));
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int r;
	scanf("%d",&r);
	if(r<1200)
	{
		printf("ABC");
	}
	else if(r<2800)
	{
		printf("ARC");
	}
	else
	{
		printf("AGC");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int n; string s;

char add(string st, int ind)
{
  if(st[ind]=='S'){
    if(s[ind]=='o') return st[ind-1];
    else return (st[ind-1]=='S' ? 'W' : 'S');
  }else{
    if(s[ind]=='x') return st[ind-1];
    else return (st[ind-1]=='S' ? 'W' : 'S');
  }
}

bool chk1(string st)
{
  if(st[n-1]=='S'){
    if(s[n-1]=='o') return (st[n-2]==st[0]);
    else return (st[n-2]!=st[0]);
  }else{
    if(s[n-1]=='x') return (st[n-2]==st[0]);
    else return (st[n-2]!=st[0]);
  }
}

bool chk2(string st)
{
  if(st[0]=='S'){
    if(s[0]=='o') return (st[n-1]==st[1]);
    else return (st[n-1]!=st[1]);
  }else{
    if(s[0]=='x') return (st[n-1]==st[1]);
    else return (st[n-1]!=st[1]);
  }
}
      

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  cin >> n >> s;
  string ans = "-1";
  REP(k,4){
    string tmp = "";
    if(k & 1) tmp.push_back('S');
    else tmp.push_back('W');
    if(k & (1<<1)) tmp.push_back('S');
    else tmp.push_back('W');
    
    FOR(i,1,n-1){
      tmp.push_back(add(tmp, i));
    }
    
    if(chk1(tmp) && chk2(tmp)){
      ans = tmp;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define INF 100000000
int n;
int A, B, C;
vector<int> l;
int mi = INF;

int calc(vector<int> v){
    int a = 0, b = 0, c = 0;
    int a_c = 0, b_c = 0, c_c = 0;
    int mp = 0;
    rep(i, n){
        if(v[i] == 0){
            a += l[i];
            a_c++;
        }
        if(v[i] == 1){
            b += l[i];
            b_c++;
        }
        if(v[i] == 2){
            c += l[i];
            c_c++;
        }
    }
    if(a_c == 0 || b_c == 0 || c_c == 0)
        return INF;
    else
        return (a_c + b_c + c_c - 3) * 10 + abs(A - a) + abs(B - b) + abs(C -c);
}

void dfs(int depth, vector<int> v){
    if(depth == n){
        mi = min(mi, calc(v));
        return;
    }

    rep(i, 4){
        v[depth] = i;
        dfs(depth + 1, v);
    }
}

int main(void){
    cin >> n >> A >> B >> C;

    rep(i, n){
        int tmp;
        cin >> tmp;
        l.push_back(tmp);
    }
    vector<int> v(n);
    dfs(0, v);
    cout << mi << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;
const  ll NUM=10e8+7;


int main(){
  ll N,K;
  cin>>N>>K;
  ll L[K],R[K];
  for(ll i=0;i<K;i++){
   cin>>L[i]>>R[i];
  }
 vector<ll> dp(N+2,0);
 vector<ll> sumdp(N+2,0);
  dp[0]=0;
  dp[1]=1;
  sumdp[0]=0;
  sumdp[1]=1;
  for(ll i=1;i<N+1;i++){

    for(ll j=0;j<K;j++){
      dp[i]=dp[i]%998244353;
      //cout<<i<<endl;
      if(i-L[j]<=0){continue;}
      if(i-R[j]-1<=0){
         dp[i]=dp[i]+(sumdp[i-L[j]]-sumdp[0]);
        //cout<<i<<" "<<dp[i]<<endl;
        continue;
        }
      dp[i]=dp[i]+(sumdp[i-L[j]]-sumdp[i-R[j]-1]);
//      if(i+L[i]<=N)dp[i+L[j]]=dp[i+L[j]]+dp[i];
//      if(i+R[i]<=N)dp[i+R[j]+1]=dp[i+R[j]+1]-dp[i];  
    }
       dp[i]=dp[i]%998244353;
    if(dp[i]<0)dp[i]=dp[i]+998244353;
       sumdp[i]=sumdp[i-1]+dp[i];
       sumdp[i]=sumdp[i]%998244353;
  }
  
//for(ll i=1;i<N+1;i++)
  //cout<<dp[i]<<" "<<sumdp[i]<<endl;
  cout<<dp[N]<<endl;
}


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

int main()
{
    int a, b, c, d;

    cin >> a >> b >> c >> d;

    a *= b;
    c += d;

    if( a % 2 != 0 && c % 2 != 0 )
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}


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

public class Main{

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){
    StringBuilder sb=new StringBuilder();
    for(int i=0;i<s1.length();i++){sb.append(s1.charAt(i));}
    return Integer.parseInt(sb.toString());
}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split("\\s+");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split("\\s+");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
//......................................@uthor_Alx..............................................

public static void main(String[] args) throws  IOException{
                assign();
                	int[] x=int_arr();
                	int n=x[0],k=x[1];
                	List<List<Integer>> cycles=new ArrayList<>();
                	int[] p=int_arr();
                	int[] c=int_arr();
                	for(int i=0;i<n;i++){p[i]--;}
                	boolean[] b=new boolean[n];
                    for(int i=0;i<n;i++){
                    	if(b[i]) continue;
                    	List<Integer> tmp=new ArrayList<>();
                    	tmp.add(i);b[i]=true;
                    	int z=p[i];
                    	while(!b[z]){
                    		b[z]=true;
                    		tmp.add(z);
                    		z=p[z];
                    	}
                    	cycles.add(tmp);
                    }
                    long res=Long.MIN_VALUE;
                    for(int i=0;i<cycles.size();i++){
                    	long tmp=Long.MIN_VALUE; int sz=cycles.get(i).size();
                    	long sum=0;
                    	for(int j=0;j<sz;j++){sum+=c[cycles.get(i).get(j)];}
                    	for(int j=0;j<sz;j++){
                    		long tmp1=0;
                    		int f=k/sz,kr=k%sz;
                    		if(f>0&&sum>0) tmp1=(long)f*sum;
                    	    if(f>0&&sum<0){
                    	    	kr=Math.min(k,sz);
                    	    }
                    	    if(k%sz==0&&f>0&&tmp1>0){tmp1-=sum;kr=sz;}
                    		long ss1=0,ss2=Long.MIN_VALUE;
                    		for(int j1=1;j1<=kr;j1++){
                    			ss1+=c[cycles.get(i).get((j+j1)%sz)];
                    			ss2=Math.max(ss2,ss1);
                    		}
                    		 tmp1+=ss2;
                    		 tmp=Math.max(tmp1,tmp);
                    	}
                    	res=Math.max(res,tmp);
                    }
                    out.write(res+"\n");            
                out.flush();

    }
}

Measured memory_bytes: 41040
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int n = ni(), q = ni();
        int[] com = new int[q];
        int[] x = new int[q];
        int[] y = new int[q];
        for (int i = 0; i < q; i++) {
            com[i] = ni();
            x[i] = ni();
            y[i] = ni();
        }

        RMQ rmq = new RMQ(n);
        for (int i = 0; i < q; i++) {
            if (com[i] == 0) {
                rmq.update(x[i], y[i]);
            } else {
                out.println(rmq.query(x[i], y[i]));
            }
        }
    }

    class RMQ {
        int n;
        int[] dat;

        RMQ (int n1) {
            n = 1;
            while (n < n1) {
                n <<= 1;
            }
            dat = new int[2 * n - 1];
            Arrays.fill(dat, Integer.MAX_VALUE);
        }

        void update(int k, int a) {
            k += n - 1;
            dat[k] = a;
            while (k > 0) {
                k = (k - 1) / 2;
                dat[k] = Math.min(dat[k * 2 + 1], dat[k * 2 + 2]);
            }
        }

        int query(int a, int b) {
            return query(a, b + 1, 0, 0, n);
        }

        private int query(int a, int b, int k, int l, int r) {
            if (r <= a || b <= l) return Integer.MAX_VALUE;

            if (a <= l && r <= b) {
                return dat[k];
            } else {
                int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
                int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
                return Math.min(vl, vr);
            }
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 66324
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll r, d, x;
    cin >> r >> d >> x;
    for (ll i = 0; i < 10; i++)
    {
        x = r * x - d;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
long long ex[333];
long long sum[333];
int main()
{
	int k=io::F(),n=io::F();
	if(k%2==0)
	{
		printf("%d",k/2);
		for(register int i=1;i<n;++i)printf(" %d",k);
		puts("");
		return 0;
	}
	if(k==1)
	{
		for(register int i=1;i<=(n+1>>1);++i)printf("1 ");
		return 0;
	}
	if(n==1)
	{
		printf("%d\n",k+1>>1);
		return 0;
	}
	ex[0]=1;
	sum[0]=1;
	int pe=0;
	for(pe=1;sum[pe-1]<1000000000LL;++pe)ex[pe]=ex[pe-1]*k,sum[pe]=sum[pe-1]+ex[pe];
	--pe;
	int now=dmax(1,n-pe);
	long long tot=sum[n-now]-now+1+1>>1;
	tot--;
	for(register int i=1;i<=now;++i)printf("%d ",k+1>>1);
	if(tot==0)return 0;
	for(++now;now<=n;++now)
	{
		int ans=(tot-1)/sum[n-now]+1;
		printf("%d ",ans);
		tot-=sum[n-now]*(ans-1)+1;
		if(tot==0)return 0;
	} 
	return 0;
}



Measured memory_bytes: 2176
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>

int main(void) {
  int a, b;
  std::cin >> a >> b;
  if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
    std::cout << a * b << std::endl;
  }
  else {
    std::cout << -1 << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

const li mod = 1e9 + 7;

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

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

    vector<li> acc(n + 1);
    for (int j = 0; j < n; ++j) {
        acc[j + 1] = acc[j] + xs[j];
    }

    map<li, li> count;
    for (auto && v: acc) {
        count[v] += 1;
    }

    li ans = 0;
    for (auto &&p  : count) {
        ans += p.second * (p.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int N;
    string S;
    cin >> N >> S;

    vector<int> A(N+1,0);

    for(int i=0;i<N;i++){
        if(S.at(i)=='I')A[i+1]=A[i]+1;
        else A[i+1]=A[i]-1;
    }
    
    sort(A.begin(),A.end());

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

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

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

    int n, k;
    cin >> n >> k;
    int count = 0;
    for (int i = 0; i < n; ++i) {
        int h; cin >> h;
        if (h >= k) count++;
    }
    cout << count << endl;

    return 0;
}

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

int main(void){
	char str[10001];
	int len, i, n = 1;
	int cnt_j = 0, cnt_i = 0;
	
	while (scanf("%s", str) != EOF){
		cnt_j = 0;
		cnt_i = 0;
		
		len = strlen(str);
		
		for (i = 0; i < len; i++){
			if (str[i] == 'J' && str[i+1] == 'O' && str[i+2] == 'I') cnt_j++;
			if (str[i] == 'I' && str[i+1] == 'O' && str[i+2] == 'I') cnt_i++;
		}
		printf("%d\n%d\n", cnt_j, cnt_i);
	}
	
	return 0;
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N;
    cin >> N;
    
    if(N==1) cout << "Hello World" << endl;
    else{
        int A,B;
        cin >> A >> B;
        cout << A+B << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

int main() {
  string s;
  cin >> s;

  int n = s.length();
  
  int ans = 0;

  FOR(i,0,n-1){
    if(s[i]=='p') --ans;
  }

  cout << ans + n/2 << endl;

}



Measured memory_bytes: 512
import math
if __name__ == "__main__":
    N, K = list(map(int, (input().split(' '))))
#    ans = N * N
#    buf = 0
#    for i in range(0, K):
#        for j in range(1, N+1):
#            if i == 0:
#                if j == 0:
#                    buf += N
#                else:
#                    buf += math.floor(N / j)
#            else:
#                if j != 1:
#                    if (N % j) >= i:
##                        print(i, j, math.floor(N / j) + 1)
#                        buf += math.floor(N / j) + 1
#                    else:
##                        print(i, j, math.floor(N / j))
#                        buf += math.floor(N / j)
#    ans -= buf
    ans = 0
    if K == 0:
        ans = N**2
    else:
        for b in range(1, N+1):
            p = N // b
            r = N % b
            ans += (p * max(0, b-K))
            ans += max(0, r-K+1)
    print(ans)

Measured memory_bytes: 3064
class Main{
    public static void main(String[] a){
        for(int i = 1; i <= 9; i++){
             for(int j = 1; j <= 9; j++){
                 int N = i * j;
                 System.out.println(i +"x" + j +"=" + N);
             }
        }
    }
}

Measured memory_bytes: 24136
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush =
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadInt;
			var K = cin.ReadInt;
			var C = cin.ReadInt;
			var S = cin.ReadLine;
			var earliestDate = new int[K];
			var latestDate = new int[K];
			var workDay = 0;
			for(int d = 0; d < N; d++) {
				if(S[d] != 'o') continue;
				if(workDay >= K) return;
				earliestDate[workDay] = d;
				d += C;
				workDay++;
			}
			workDay = K - 1;
			for(int d = N - 1; d >= 0; d--) {
				if(S[d] != 'o') continue;
				if(workDay < 0) return;
				latestDate[workDay] = d;
				d -= C;
				workDay--;
			}
			var Z = earliestDate.Zip(latestDate, (x, y) => new Tuple<int, int>(x, y));
			var Res = Z.Where(t => t.Item1 == t.Item2).Select(x => x.Item1 + 1);
			Console.WriteLine(Res.Join("\n"));
		}
	}
	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);

	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i < N; ++i)
				ret[i] = Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek() == -1; }
		}
	}

}


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

int main() {
  int a, b;
  int ans = 0;

  cin >> a >> b;
  ans = a + b;
  if (ans < a - b) ans = a - b;
  if (ans < a * b) ans = a * b;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main() {
	char h[6][6]={"abcde","fghij","klmno","pqrst","uvwxy","z.?! "},c[202];
	int i,n;
	while(cin >> c) {
    n=strlen(c);
	for (i=0;i<n-1;i+=2) if (c[i]<'1' || c[i]>'6' || c[i+1]<'1' || c[i+1]>'5') break;
	if ((n % 2!=0) || (i!=n)) { cout << "NA" << endl; continue;} 
	for (i=0;i<n-1;i+=2) cout << h[c[i]-'0'-1][c[i+1]-'0'-1];
	cout << endl;
	}
 return 0;
}

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

#define ll long long

ll dp[105][100005], value[105], weight[105];
int n, w;

ll knapsack(int pos, int rem)
{
    if(pos == n || rem == 0)
    {
        return 0;
    }

    if(rem < 0)
    {
        return -INT_MAX;
    }

    if(dp[pos][rem] != -1)
    {
        return dp[pos][rem];
    }

    ll ret = 0;

    if(weight[pos] <= rem)
    {
        ret = max(knapsack(pos+1, rem), value[pos] + knapsack(pos+1, rem-weight[pos]));
    }
    else
    {
        ret = knapsack(pos+1, rem);
    }

    return dp[pos][rem] = ret;
}

int main()
{
    //int n, w;
    scanf("%d %d", &n, &w);

    memset(dp, -1, sizeof dp);

    for(int i = 0; i < n; i++)
    {
        scanf("%lld %lld", &weight[i], &value[i]);
    }


    ll ans = knapsack(0, w);

    printf("%lld\n", ans);
}


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

ll MOD = 1000000007;
vector<ll> a,b,c,d;
ll n,m,q;
vector<ll> arr;
ll maxi = -1;
void check()
{
	ll i;
	ll ans = 0;
	

	for(i=0;i<q;i++)
	{
		if(arr[b[i]] - arr[a[i]] == c[i])
		{
			ans += d[i];
		}
	}
	maxi = max(maxi,ans);


}
void recurse( ll idx)
{
	if(idx == n)
	{
		check();
	}
	else
	{
		ll i;
		for(i=arr[idx-1];i<=m;i++)
		{
			arr[idx] = i;
			recurse(idx+1);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//cin >>t;
	ll t= 1;

	while(t--)
	{
		//ll n,m,q;
		cin >> n >> m >> q;
		//ll a[q],b[q],c[q],d[q];
		ll i;
		a.resize(q);
		b.resize(q);
		c.resize(q);
		d.resize(q);
		arr.resize(n);

		for(i=0;i<q;i++)
		{
			cin >> a[i] >> b[i] >> c[i] >> d[i] ;
			a[i]--;
			b[i]--;

		}

		arr[0] = 1;
		
      
 		recurse(1);
		cout << maxi << endl;
		break;


	}
	return 0;
	
}

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

int main(){
  int n,m;
  cin>>n>>m;
  vector<ll> h(n);
  vector<bool> ok(n,true);
  rep(i,n) cin>>h[i];
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    if(h[a]>=h[b]){
      ok[b]=false;
    }
    if(h[a]<=h[b]){
      ok[a]=false;
    }
  }
  int ans=0;
  rep(i,n){
    if(ok[i]){
      ans++;
    }
  }
  cout<<ans<<endl;
 
  
  return 0;
}

Measured memory_bytes: 4064
import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
A = [[False,MAP()] for _ in range(N)]
B = [[False,MAP()] for _ in range(N)]

A = sorted(A, key=lambda x:-x[1][1])
B = sorted(B, key=lambda x:x[1])

#after reading answer
count = 0
for b in B:
	cand = []
	for a in A:
		if b[0] or a[0] : continue
		#print(b[1],a[1])
		if b[1][0] > a[1][0] and b[1][1] > a[1][1]:
			#print('make pair')
			b[0] = True
			a[0] = True
			count += 1

print(count)

Measured memory_bytes: 3064
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> inline void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> inline void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

int main() {
    set<char> c; 
    rep(i, 3) {
        char t;
        cin >> t;
        c.insert(t);
    }

    print((c.size()==1)?"No":"Yes");

    return 0;
}


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


int main() {
  int a,b; cin >> a >> b;
  int ans = 0;
  int plag = 1;
  while(true){
    if(plag >= b)break;
    else{
      ans++;
      plag += a - 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>

using namespace std;

int n;
int main()
{
	cin >> n;
	if(n%10 == 0 && n % 100 == 0 && n % 1000 == 0)
	{
		printf("0\n");
	}
	else
	{
		cout << 1000 - (n % 1000) << endl;
	}
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int N;
  cin>>N;
  int A[200000],B[200000];
  for(int i=0;i<N;i++) cin>>A[i];
  for(int i=0;i<N;i++) cin>>B[i];
  sort(B,B+N,greater<int>());
  vector<int> same;
  for(int i=0;i<N;i++){
    if(A[i]==B[i]) same.push_back(i);
  }
  int j=0;
  int judge=0;
  for(int i=0;i<same.size();i++){
    while(A[same[i]]==B[same[i]]){
      if(j==N){
        judge++; break;
      }
      if(A[j]!=B[same[i]]&&B[j]!=B[same[i]]) swap(B[same[i]],B[j]);
      j++;
    }
    if(judge==1) break;
  }
  if(judge==0){
    cout<<"Yes"<<endl;
    for(int i=0;i<N-1;i++) cout<<B[i]<<' ';
    cout<<B[N-1]<<endl;
  }
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 5332
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#define F(A, B) for(int A=0; A<B; A++)
using namespace std;

namespace dice{				// 0 1 2 3 4 5 6
	int ThirdFace[7][7]={	{0,0,0,0,0,0,0},	//0
												{0,0,3,5,2,4,0},	//1
												{0,4,0,1,6,0,3},	//2
												{0,2,6,0,0,1,5},	//3
												{0,5,1,0,0,6,2},	//4
												{0,3,0,6,1,0,4},	//5
												{0,0,4,2,5,3,0} };//6
	/*ThirdFace[1][2] = 3;
	ThirdFace[1][3] = 5;
	ThirdFace[1][4] = 2;
	ThirdFace[1][5] = 4;
	ThirdFace[2][1] = 4;
	ThirdFace[2][3] = 1;
	ThirdFace[2][4] = 6;
	ThirdFace[2][6] = 3;
	ThirdFace[3][1] = 2;
	ThirdFace[3][2] = 6;
	ThirdFace[3][5] = 1;
	ThirdFace[3][6] = 5;
	ThirdFace[4][1] = 5;
	ThirdFace[4][2] = 1;
	ThirdFace[4][5] = 6;
	ThirdFace[4][6] = 2;
	ThirdFace[5][1] = 3;
	ThirdFace[5][3] = 6;
	ThirdFace[5][4] = 1;
	ThirdFace[5][6] = 4;
	ThirdFace[6][2] = 4;
	ThirdFace[6][3] = 2;
	ThirdFace[6][4] = 5;
	ThirdFace[6][5] = 3;*/
}
	
enum DICE{
	TOP=0,
	HEIGHT=1
};

enum DIRECTION{
	NORTH=0,
	EAST,
	SORTH,
	WEST
};

int moveh(int map[][200][2], int posx, int posy, int dic){
	switch(dic){
		case(NORTH):
			return map[posx-1][posy][HEIGHT];
		case(SORTH):
			return map[posx+1][posy][HEIGHT];
		case(WEST):
			return map[posx][posy-1][HEIGHT];
		case(EAST):
			return map[posx][posy+1][HEIGHT];
	}
}

void roll(int& posx, int& posy, int& top, int& front, int dic, int* dicface){
	switch(dic){
		case(NORTH):
			front = 7-top;
			top = dicface[SORTH];
			posx -= 1;
			break;
		case(SORTH):
			front = top;
			top = dicface[NORTH];
			posx += 1;
			break;
		case(WEST):
			top = dicface[EAST];
			posy -= 1;
			break;
		case(EAST):
			top = dicface[WEST];
			posy += 1;
			break;
	}
}

int main(){
	int n;
	cin >> n;
	while(n != 0){
		int map[200][200][2]={{ {0, 0} }};
		int *top=new int[n];
		int *front=new int[n];
		F(i, n){
			cin >> top[i] >> front[i];
		}
		F(i, n){
			int posx=100, posy=100;
			while(1){
				int firstdic, seconddic;
				int dicface[4];
				dicface[SORTH] = front[i];
				dicface[EAST ] = dice::ThirdFace[top[i]][front[i]];
				dicface[NORTH] = 7-dicface[SORTH];
				dicface[WEST ] = 7-dicface[EAST ];
				stack<int> FS;
				F(j, 3){
					F(k, 4){
						if(dicface[k] == j+4){
							FS.push(k);
						}
					}
				}
				firstdic	= FS.top(); FS.pop();
				seconddic	= FS.top(); FS.pop();

				//cout << firstdic << ' ' << seconddic << endl;

				if(map[posx][posy][HEIGHT] > moveh(map, posx, posy, firstdic) ){
					//cout << posx << ' ' << posy << ' ' << top[i] << ' ' << front[i] << endl;
					roll(posx, posy, top[i], front[i], firstdic, dicface);
					//cout << posx << ' ' << posy << ' ' << top[i] << ' ' << front[i] << endl;
				}else if(map[posx][posy][HEIGHT] > moveh(map, posx, posy, seconddic) ){
					roll(posx, posy, top[i], front[i], seconddic, dicface);
				}else{
					map[posx][posy][TOP] = top[i];
					map[posx][posy][HEIGHT]++;
					break;
				}
			}
		}
		int cnt[7]={0};
		F(i, 200)F(j, 200){
			if(map[i][j][TOP] > 0){
				cnt[map[i][j][TOP]]++;
			}
		}
		for(int i=1; i<=6; i++){
			if(i >= 2)cout << ' ';
			cout << cnt[i];
		}
		cout << endl;

		cin >> n;
	}

}

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

void Swap(int *a,int *b) {
  int tp=*a;
  *a=*b;
  *b=tp;
}
int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin>>n;
  int A[n],r=n-1;
  for (int i=0; i<n; i++) {
    cin>>A[i];
  }
  int x=A[n-1],i=(-1);
  for (int j=0; j<r; j++) {
    if (A[j]<=x) {
      i++;
      Swap(&A[i],&A[j]);
    }
  }
  Swap(&A[i+1],&A[r]);
  int t=i+1;
  for (int k=0; k<n; k++) {
    if (k) {
      cout<<" "<<flush;
    }
    if (k==t) {
      cout<<"["<<flush;
    }
    cout<<A[k]<<flush;
    if (k==t) {
      cout<<"]"<<flush;
    }
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3400
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>


int main(){

    vector<pair<int,int>> tasks;

    int n;
    cin >> n;
    for(int i=0;i < n;i++){
        ll a;
        ll b;
        cin >> a >> b;
        tasks.push_back(make_pair(b,a));
    }

    sort(tasks.begin(),tasks.end());//firstを基準にソート
    ll sum = 0LL;
    bool f = true;
    for(auto task:tasks){
        sum += task.second;
        if( sum > task.first){
            f = false;
            break;
        }
    }

    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N*A, B) << endl;
}

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

int main(){
    ll a,b,v,w,t;
    cin>>a>>v;
    cin>>b>>w;
    cin>>t;
    bool can;
    if(a<b){
        if(a+v*t>=b+w*t)can=true;
        else can=false;
    }else{
        if(a-v*t<=b-w*t)can=true;
        else can=false;
    }
    if(can)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3620
def solve(N, K, XYs):
    ans = 10 ** 19 + 1

    XYs.sort(key=lambda x: x[0])
    for i in range(N):
        for j in range(i+K-1, N):
            narrowedXY = XYs[i:j+1]
            narrowedXY.sort(key=lambda x: x[1])
            for y1 in range(len(narrowedXY)):
                for y2 in range(y1+K, len(narrowedXY)+1):
                    min_x = XYs[i][0]
                    max_x = XYs[j][0]
                    ys = [xy[1] for xy in narrowedXY[y1:y2]]
                    max_y = max(ys)
                    min_y = min(ys)
                    ans = min(ans, abs(max_x - min_x) * abs(max_y - min_y))

    return ans

if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    XYs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, K, XYs))


Measured memory_bytes: 3064