akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
using namespace std; 
int main(){
  int x, y; 
  cin>>x>>y; 
  for(int i=0;i<=x; i++){
    if((2*i+4*(x-i))==y){
      cout<<"Yes";
      return 0;
    }
    
    
 }
  cout<<"No";
  }


Measured memory_bytes: 3632
import java.util.*;

public class Main {
public static void main(String[] args) {

			Scanner keyboard = new Scanner(System.in);

			 String S = keyboard.next();
			 long sum = 0;
			 String ans = "No";
			 		
			for (int s=0; s<S.length(); s++) {
				sum += (long)S.charAt(s)-48;
			}			
		
			if(sum%9 == 0) {
				ans = "Yes"; 
			}
		
		System.out.println(ans);
		keyboard.close();	
	}
}


Measured memory_bytes: 40496
import itertools

N = int(input())
P = list(map(str, input().split()))
Q = list(map(str, input().split()))
permutation = list(itertools.permutations(list(range(1, N+1))))
sum_list = [int("".join(map(str,x))) for x in permutation]
sorted(sum_list)

P_comb = int("".join(P))
Q_comb = int("".join(Q))

P_poji = sum_list.index(P_comb)
Q_poji = sum_list.index(Q_comb)

print(abs(P_poji-Q_poji))

Measured memory_bytes: 15604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P, ll> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n;
vector<int> dp;

int main() {
    cin >> n;
    dp.resize(n+1, IINF);
    REP(i,n){
        int a;
        cin >> a;
        *upper_bound(ALL(dp), -a) = -a;
    }
    cout << lower_bound(ALL(dp),IINF) - dp.begin() << endl;
    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int n;
    cin>>n;
    ll res = 0;
    ll hi = 0;
    while (n--) {
	ll x;
	cin>>x;
	res += max(0ll,hi-x);
	hi=max(hi,x);
    }

    cout<<res<<endl;    
    return 0;
}


Measured memory_bytes: 3604
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void Solver(int numberOfString,int lengthOfString,String[] arr)
    {
        Arrays.sort(arr);
        String k = "";
        for (int i = 0; i < arr.length; i++) {
            k += arr[i];
        }
        System.out.println(k);
    }
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int numberOfString = input.nextInt();
        int lengthOfStrings = input.nextInt();
        String[] arr = new String[numberOfString];
        String temp;
        for (int i = 0; i < numberOfString; i++) {
            temp = input.next();
            if(temp.length() == lengthOfStrings)
                arr[i] = temp;
        }
        Solver(numberOfString,lengthOfStrings,arr);
    }
}


Measured memory_bytes: 26580
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll N,K;
ll A[200005];
ll sosuu[200005];
bool found;
ll ans;
ll si;
vector<ll> so;
map<ll,ll> m;

int main() {
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A,A+N);
    for(int i=0;i<N;i++){
        found=false;
        if(i>=1 && A[i]==A[i-1]){
            continue;
        }
        for(int j=0;j<si;j++){
            if(A[i]%sosuu[j]==0){
                found = true;
                break;
            }
            if(sosuu[j]*sosuu[j]>=1000000){
                if(m.find(A[i])!=m.end()){
                    found = true;
                }
                break;
            }
        }
        if(!found){
            sosuu[si]=A[i];
            for(int k=2;k<1000;k++){
                if(k*A[i]>1000000){
                    break;
                }
                m[k*A[i]] = 1;
            }
            si++;
            if(A[i+1]!=A[i]){
                ans++;
            }
        }
        
    }
    cout << ans << endl;
    
    
    
}


Measured memory_bytes: 49544
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;

//素数判定。計算量はO(√n)。
bool IsPrime(Int n) {

	if (n < 2)return false;
	else if (n == 2)return true;
	else if (n % 2 == 0)return false;

	for (Int i = 3; i * i <= n; ++i) {
		if (n % i == 0)return false;
	}

	return true;

}


void calc() {

	Int Q; std::cin >> Q;
	std::vector<Int> l(Q), r(Q);
	Int max = -1;
	rep(i, Q) {
		std::cin >> l[i] >> r[i];
		max = std::max(max, r[i]);
	}
	std::vector<Int> primes;

	for (Int i = 2; i <= max; ++i)if (IsPrime(i) && IsPrime((i + 1) / 2))primes.push_back(i);

	rep(i, Q) {
		auto itr1 = std::lower_bound(primes.begin(), primes.end(), l[i]);
		auto itr2 = std::upper_bound(primes.begin(), primes.end(), r[i]);
		auto num = std::abs(std::distance(itr1, itr2));
		std::cout << num << "\n";
	}

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 2176
from sys import stdin

n, a, b, c, d = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()

# A..C 二つの岩 あったらだめ
# B..D二つの岩 あったらだめ
# D < Cのとき、 AがBを追い越せななかったらだめ

ans = "Yes"

rock = 0
for i in range(a, c):
    if '#' == s[i-1]:
        rock += 1
        if rock >= 2:
            ans = "No"
            break
    else:
        rock = 0

rock = 0
for i in range(b, d):
    if '#' == s[i-1]:
        rock += 1
        if rock >= 2:
            ans = "No"
            break
    else:
        rock = 0


space = 0
if d < c:
    ok = 0
    for i in range(b-1, d+1):
        if '.' == s[i-1]:
            space += 1
            if space >= 3:
                ok = 1
                break
        else:
            space = 0
    if '.' == s[d-1-1] and '.' == s[d+1-1]:
        ok = 1
    if '.' == s[d-1-1] and '.' == s[d-2-1]:
        ok = 1
    if '.' == s[b-1-1] and '.' == s[b+1-1]:
        ok = 1
    if '.' == s[b+1-1] and '.' == s[b+2-1]:
        ok = 1
    if 0 == ok:
        ans = "No"

print(ans)


Measured memory_bytes: 40432
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
int N;
long long A[MAXN];
void solve(){
    sort(A, A + 3 * N, greater<int>());
    long long sum = 0, cnt = 0;
    for(int i = 1; cnt < N; i += 2, cnt++)
        sum += A[i];
    cout << sum;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int test = 1;
    //cin >> test;
    while(test--){
        cin >> N;
        int i = 0;
        for(i = 0; i < 3 * N; i++)
            cin >> A[i];
        solve();
    }
    return 0;
}

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

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

    ll output = 0;
    ll now = 0;

    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'B') {
            now++;
        } else {
            output += now;
        }
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll v[100], w[100], m[100], dp[10005];

int main() {
    init();
    ll N,W;
    cin >> N >> W;
    rep(i, N) cin >> v[i] >> w[i] >> m[i];

    vl deq(W + 1), deqv(W + 1);

    rep(i,N){
        rep(r, w[i]){
            ll s = 0, t = 0;
            rep(j, (W-r)/w[i]+1){
                ll val = dp[j * w[i] + r] - j * v[i];
                while (s < t and deqv[t - 1] <= val) t--;
                deq[t] = j, deqv[t] = val;
                t++;

                dp[j * w[i] + r] = deqv[s] + j * v[i];
                if (deq[s] == j - m[i]) s++;
            }
        }
    }

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


Measured memory_bytes: 3380
#include<stdio.h>

#define N 100
#define INFTY (1<<21)

void enqueue(int s);
int dequeue(void);
void bfs(int s);

int M[N][N];
int d[N]; 
int Q[2*N];

int n,i,j;
int head = 1,tail=1;

  
int main(void){
  int k;
  int u,v;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      M[i][j] = 0;
    }
  }

  for(i = 0;i < n;i++){
    scanf("%d %d",&u,&k);
    u--;
      
    for(j = 0;j < k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  
  bfs(0);

  return 0;
}




void enqueue(int s){
  Q[tail++] = s;
}


int dequeue(void){
  return Q[head++];
}


void bfs(int s){
  int u,v;
  
  enqueue(s);
  
  for(i = 0;i < n;i++){
    d[i] = INFTY;
  }
  d[s] = 0;
    
  while(head != tail){
    u = dequeue();
      
    for(v = 0;v < n;v++){
      if(M[u][v] == 0){
	continue;
      }
      if(d[v] != INFTY){
	continue;
      }
	
      d[v] = d[u] + 1;
      enqueue(v);
    }
  }
    
  for(i = 0;i < n;i++){
    printf("%d ",i+1);
      
    if(d[i] == INFTY){
      puts("-1");
    } else {
      printf("%d\n",d[i]);
    }
      
  }
    
}

 



Measured memory_bytes: 2048
#include <stdio.h>

int main(void){
    int a,b,c,i,cnt = 0;
    scanf("%d %d %d",&a,&b,&c);
    for(i = a;i <= b;i++){
        if(c % i == 0) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int N,K,C;

int main()
{
    cin >> N>>K>>C;
    vector<int> workday;
    
    for(int i=0;i<N;i++)
    {
        char s;
        cin >> s;
        
        if(s == 'o')
        {
            workday.push_back(i);
        }
    }
    
    vector<int> af;
    
    int temp = 0;
    int day = 0;
    
    temp = N-1;
    day = K;
    for(int i = (int)workday.size()-1;i>=0;i--)
    {
        if(temp >= workday[i])
        {
            af.push_back(workday[i]);
            temp = workday[i] - C - 1;
            day--;
        }
        if(day == 0)
        {
            break;
        }
    }
    
    temp = 0;
    day = 0;
    
    for(int i = 0;i<workday.size();i++)
    {
        if(temp <= workday[i])
        {
            if(workday[i] == af[K - 1 - day])
            {
                cout << af[K - 1 - day]+1 << endl;
            }
            temp = workday[i] + C + 1;
            day++;
        }
        if(day == K)
        {
            break;
        }
    }
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 3188
using System;
using System.Linq;

namespace D2019PC
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] s = Console.ReadLine().Split(' ');
            int[] n = s.Select(x => int.Parse(x)).ToArray();

            int result = 0;
            int temp = n[3];
            int tempHJ = 0;

            for (int i = 0; i < (n[3] / n[0]) + 1; i++)
            {
                temp -= n[0] * i;
                tempHJ = temp;

                for (int j = 0; j < (temp / n[1]) + 1; j++)
                {
                    tempHJ -= n[1] * j;
                    if (tempHJ % n[2] == 0)
                    {
                        result++;
                    }

                    tempHJ = temp;
                }
                temp = n[3];
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13268
MOD = 1000000007
N = int(input())
d = dict()

for i in range(2, N+1):
    tmp = i
    div = 2
    while tmp > 1:
        if tmp % div == 0:
            if div not in d:
                d[div] = 1
            else:
                d[div] = d[div] + 1
            tmp = tmp // div
        else:
            div += 1
ans = 1
for div in d:
    ans = ans * (d[div] + 1) % MOD

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[500][500],sum[500][500];
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n,x;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        for(int j=0;j<=i;j++)
            sum[j][i] = x;
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            sum[i][j]+=sum[i][j-1];
        }
        if(i<n-1)
            dp[i][i+1] = sum[i][i+1];
    }
    for(int len=2;len<n;len++)
        for(int i=0;i<n-len;i++)
        {
            int j = i+len;
            dp[i][j] = sum[i][i]+sum[i+1][j]+dp[i+1][j];
            for(int k=i+1;k<j;k++)
            {
                dp[i][j] = min(dp[i][j],dp[i][k]+dp[k+1][j]+sum[i][k]+sum[k+1][j]);
            }       
        }
    cout<<dp[0][n-1];
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF MOD
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    Int a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    if (v <= w) {
        cout << "NO" << endl;
        return 0;
    };

    bool ok = false;
    if (abs(a - b) <= (v-w) * t) ok = true;
    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
int main(){
	
	int N;
	std::cin >> N;
	std::vector<int64_t> A(N);
	for(auto&i:A)std::cin>>i;
	std::sort(A.rbegin(),A.rend());
	int64_t ans = 0;
	int64_t a=-1;
	int count = 1;
	for(int i=0;i<N-1;++i){
		if(A[i]==A[i+1])++count;
		else count=1;
		if(count>=2){
			if(a==-1)a=A[i];
			else if(A[i]!=a){
				ans=a*A[i];
				break;
			}
		}
		if(count>=4){
			ans = A[i]*A[i];
			break;
		}
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 1024
from sys import stdin
for num in stdin:
    penalty = [0] * int(num)
    time = [int(i) for i in stdin.readline().split()]
    time.sort()
    penalty[0] = time[0]
    for j in range(1,len(time)):
        penalty[j] += penalty[j-1] + time[j]
    print(sum(penalty))

Measured memory_bytes: 5612
import bisect
A, B, Q = map(int, input().split())
ss = []
for i in range(A):
  s = int(input())
  ss.append(s)
ts = []
for i in range(B):
  t = int(input())
  ts.append(t)
#print(ss, ts)
for i in range(Q):
  x = int(input())
  Is = bisect.bisect_left(ss, x)
  It = bisect.bisect_left(ts, x)
  ss2 = ss[Is-1 if Is > 0 else Is:Is+1]
  ts2 = ts[It-1 if It > 0 else It:It+1]
  #print(x, Is, It, ss2, ts2)
  rs = []
  for s in ss2:
    for t in ts2:
      r = abs(s-x)+abs(t-s)
      rs.append(r)
      r = abs(t-x)+abs(s-t)
      rs.append(r)
  r = min(rs)
  print(r)


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

int main() {
	
	ll x; cin >> x;	
	const ll p = 1000;
	for (ll i = -p; i <= p; i++) {
		for (ll j = -p; j <= p; j++) {
			ll a = i * i * i * i * i;
			ll b = j * j * j * j * j;
			if (a - b == x) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[100],i,r;
int main(){
  for(cin>>n;i<n;i++)cin>>a[i];
  sort(a,a+n);
  for(i=0;i<n-1;i++)r+=(a[i+1]-a[i]);
  cout<<r<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

const ll INF = 1LL<<60;
ll dp[100][100];

int main() {
    int V, E;
    cin >> V >> E;
    rep(i, V) {
        rep(j, V) {
            if(i == j) dp[i][j] = 0;
            else dp[i][j] = INF;
        }
    } 
    rep(i, E) {
        int s, t, d;
        cin >> s >> t >> d;
        dp[s][t] = d;
    }

    rep(k, V) {
        rep(i, V) {
            rep(j, V) {
                if(dp[i][k] == INF || dp[k][j] == INF) continue;
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
            }
        }
    }

    rep(i, V) {
        if(dp[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    rep(i, V) {
        rep(j, V) {
            if(j) cout << " ";
            if(dp[i][j] == INF) cout << "INF";
            else cout << dp[i][j];
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3180
import Control.Applicative
import Control.Monad

merge :: [String] -> [String] -> [String]
merge xs [] = xs
merge [] ys = ys
merge (x:xs) (y:ys)
    | x < y     = x : merge xs (y:ys)
    | otherwise = y : merge (x:xs) ys

msort :: [String] -> [String]
msort [x] = [x]
msort x = merge (msort (take h x)) (msort (drop h x))
    where
        h = length x `div` 2

main = do
  [n, l] <- map read . words <$> getLine
  names <- replicateM n getLine
  putStrLn.concat.msort $ names

Measured memory_bytes: 1404
P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
S = [0]*25

N = int(input())
for i in range(2, N+1):
    num = i
    j = 0
    while num > 1:
        if num%P[j] == 0:
            num //= P[j]
            S[j] += 1
        else:
            j += 1
            if j == 25:
                break

# 74
# 2 24
# 4 14
# 2 4 4

ans = 0
if S[0] >= 74:
    ans += 1
for i in range(3):
    if S[i] >= 24:
        tmp = -1
        for num in S:
            if num >= 2:
                tmp += 1
        ans += tmp
for i in range(4):
    if S[i] >= 14:
        tmp = -1
        for num in S:
            if num >= 4:
                tmp += 1
        ans += tmp
tmp4 = 0
tmp2 = 0
for num in S:
    if num >= 4:
        tmp4 += 1
    if num >= 2 and num < 4:
        tmp2 += 1
ans += tmp4*(tmp4-1)*(tmp4+tmp2-2)//2
print(ans)

Measured memory_bytes: 9272
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {
	double l;
	cin >> l;

	double ans;
	ans = l / 3.0 * l / 3.0 * l / 3.0;
	cout << setprecision(30)<<ans;
}

Measured memory_bytes: 1144
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m, k;
	cin >> n >> m >> k;

	int total = 0;

	vector<vector<char>> v(n, vector<char>(m));
	
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			cin >> v[i][j];
			if(v[i][j] == '#') total++;
		}
	}

	function<int(int, int)> process = [&](int row, int col) {
		int ret = total;

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(v[i][j] == '.') continue;
				bool f = false, g = false;
				if(row >> i & 1) f = true;
				if(col >> j & 1) g = true;

				ret -= (f || g);
			}
		}
		return ret;
	};

	int ans = 0;

	for(int i = 0; i < (1<<n); i++) {
		for(int j = 0; j < (1<<m); j++) {
			if(process(i, j) == k) ans++;
		}
	}

	cout << ans;


	return 0;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            ans += r - l + 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
/*
				" اللهم صلي و سلم علي سيدنا محمد و علي اله وصحبه اجمعين "
*/

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define f for
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define intial(s1,s2,x,dp) f(int i = 0; i < s1; i++)f(int j = 0; j < s2; j++)dp[i][j] = x;
using namespace std;
#define BI  acos(-1)
#define all(a) a.begin(), a.end()
void Open()
{
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
void madesetprobblem()
{
    //$ $
    //less than or equal => $ 1 \leq 100 $
    //  $(1 \le A,B \le 10^5 )$
    // a[i] => $a_i$
    // a[i][j] => $a_{i,j}$
    // double qoutes ''yext''
    /*
    	image
    	\begine{center}
    	\includegraphics{image.jpg}
    	\end{center}
    */
    /*
    	list
    	\begin{itemize}
    		\item first one
    		\item second one
    	\end{itemize}
    */
}
ll const md=7+1e9;
int n,m;
ll dp[1001][1001];
char grid[1001][1001];
ll ans(int i,int j)
{
    if(i==n-1&&j==m-1)return 1;
    if(~dp[i][j])return dp[i][j];
    dp[i][j]=0;
    if(i+1<n&&grid[i+1][j]=='.')
    {
        dp[i][j]=(dp[i][j]%md+ans(i+1,j)%md)%md;
    }
    if(j+1<m&&grid[i][j+1]=='.')
    {
       dp[i][j]=(dp[i][j]%md+ans(i,j+1)%md)%md;
    }
    return dp[i][j]%md;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    f(int i=0;i<n;i++)
    {
        f(int j=0;j<m;j++)
        {
            cin>>grid[i][j];
        }
    }
    intial(1001,1001,-1,dp);
    cout<<ans(0,0);
}


Measured memory_bytes: 9216
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    while True:
        n,m = LI()
        if n == 0:
            break

        a = [I() for _ in range(n)]
        b = [I() for _ in range(m)]
        sa = sum(a)
        sb = sum(b)
        r = -1
        for ai in sorted(a, reverse=True):
            for bi in sorted(b, reverse=True):
                if sa - ai + bi == sb - bi + ai:
                    r = '{} {}'.format(ai, bi)
                    break
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())




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

int main(){
  int n;
  cin >> n;
  vector<pair<string, int>> a(n);
  string s;
  for(int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  cin >> s;
  int ans = 0;
  bool flag = false;
  for(int i = 0; i < n; i++){
    if(flag) ans += a[i].second;
    if(a[i].first == s) flag = true;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e10
#define mod 1000000007
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
#define lcm(x,y)  (x*y)/__gcd(x,y)
void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int  fact(int n)
{
	if (n == 0 || n == 1)
		return 1;
	else
		return n * fact(n - 1);
}
int nCr(int n, int r)
{
	if (r == 0)
		return 1;
	else
		return fact(n) / (fact(n - r) * fact(r));
}
int floorRoot5(int n)
{
	// Base cases
	if (n == 0 || n == 1)
		return n;

	// Initialize result
	int res = 0;

	// Keep incrementing res while res^5 is
	// smaller than or equal to n
	while (res * res * res * res * res <= n)
		res++;

	// Return floor of 5'th root
	return res - 1;
}

int32_t main()
{
	//c_p_c();
	int a, b, k;
	cin >> a >> b >> k;
	int i = 1;
	vi v;
	for (i = min(a, b); i >= 1; i--)
	{
		if (a % i == 0 && b % i == 0)
			v.pb(i);
	}
	// for (auto &it : v)
	// 	cout << it << " ";
	cout << v[k - 1];

}



Measured memory_bytes: 256
import math

a,b,x = input().split()
a = int(a)
b = int(b)
x = int(x)

if x > a * a * b * 0.5:
	c = 2 * b - 2 * x / ( a * a )
	degree = math.degrees(math.atan2(c,a))

else:
	c = 2 * x / (a * b)
	degree = 90 - math.degrees(math.atan2(c,b))

print(degree)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,vis[N],p[N];
int f[N],g[N],dp[N],tong[N];
vector<int> v[N];
void dfs(int x){
	for (int i=0;i<v[x].size();i++) dfs(v[x][i]);
	for (int i=0;i<v[x].size();i++)
		tong[dp[v[x][i]]]++;
	for (;tong[dp[x]];dp[x]++);
	for (int i=0;i<v[x].size();i++)
		tong[dp[v[x][i]]]--;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&p[i]);
		v[p[i]].push_back(i);
	}
	for (int i=1;;i=p[i]){
		vis[i]++;
		if (vis[i]>2) break;
	}
	for (int i=1;i<=n;i++)
		if (vis[i]>=2){
			for (int j=0;j<v[i].size();j++)
				if (vis[v[i][j]]<2)
					dfs(v[i][j]);
			for (int j=0;j<v[i].size();j++)
				if (vis[v[i][j]]<2)
					tong[dp[v[i][j]]]++;
			f[i]=g[i]=-1;
			for (int j=0;;j++)
				if (!tong[j]){
					if (f[i]==-1) f[i]=j;
					else if (g[i]==-1) g[i]=j;
					else break;
				}
			for (int j=0;j<v[i].size();j++)
				if (vis[v[i][j]]<2)
					tong[dp[v[i][j]]]--;
		}
	for (int i=1;i<=n;i++)
		if (vis[i]>=2){
			dp[i]=f[i];
			for (int j=i;;j=p[j]){
				if (p[j]==i){
					if (dp[j]^dp[i])
						return puts("POSSIBLE"),0;
					break;
				}
				dp[p[j]]=(f[p[j]]==dp[j]?g[p[j]]:f[p[j]]);
			}
			dp[i]=g[i];
			for (int j=i;;j=p[j]){
				if (p[j]==i){
					if (dp[j]==f[i])
						return puts("POSSIBLE"),0;
					break;
				}
				dp[p[j]]=(f[p[j]]==dp[j]?g[p[j]]:f[p[j]]);
			}
			return puts("IMPOSSIBLE"),0;
		}
}

Measured memory_bytes: 14848
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

ans = 0
for i, a in enumerate(A):
    b = B[a-1]
    ans+=b
    if a-1 == A[i-1] and i-1>=0:
        ans+=C[a-2]
print(ans)

Measured memory_bytes: 61872
#include <cstdio>

int pi[233333];
long long pp[233333];

int main()
{
	int n; scanf("%d",&n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d",&pi[i]);
		pp[pi[i]]++;
	}
	long long sum=0;
	for(int i=1; i<=n; i++) sum+=pp[i]*(pp[i]-1)/2;
	for(int i=1; i<=n; i++) printf("%lld\n",sum-(pp[pi[i]]*(pp[pi[i]]-1)-(pp[pi[i]]-1)*(pp[pi[i]]-2))/2);
	return 0;
}

Measured memory_bytes: 3840
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
a = RI()

I = []
for i in range(n):
    I.append( a[i] + (i+1) )

J = []
for j in range(n):
    J.append( (j+1) - a[j] )
J.sort()

c = 0
for i in range(n):
    b = I[i]
    c += mycount(J,b)

print(c)

Measured memory_bytes: 124112
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 3e18 + 8;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 1e9;

const int maxn = 1e5 + 7;

int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int r;
    cin >> r;
    double ans = (double)2 * PI * (double)r;
    cout << setprecision(8) << fixed;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3804
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int H,W;
		String work[] = new String[2];

		while(true){

			try {
				work = br.readLine().split("[\\s]+");

				if(work[0].equals("0") && work[1].equals("0"))break;

				H = Integer.parseInt(work[0]);
				W = Integer.parseInt(work[1]);

				for(int col = 0; col < W; col++){
					System.out.printf("#");
				}
				System.out.printf("\n");

				for(int row = 1; row <= H-2; row++){
					System.out.printf("#");
					for(int col = 1; col <= W-2; col++){
						System.out.printf(".");
					}
					System.out.printf("#\n");
				}

				for(int col = 0; col < W; col++){
					System.out.printf("#");
				}
				System.out.printf("\n\n");


			} catch (IOException e) {

				e.printStackTrace();
			}
		}
	}
}





Measured memory_bytes: 58672
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  char a,b;
  a=s[0],b=s[2];
  if(s[1]!=a||s[3]!=b||a==b) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

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

using namespace std;

int main() {

	string s;
	cin >> s;

	deque<char> ss;
	for (long i = 0; i < s.size(); i++) {
		ss.push_back(s[i]);
	}

	long q;
	cin >> q;

	long counter;
	long ti,t1,fi;
	char ci;
	t1 = 0;
	counter = 0;

	for (long i = 0; i < q; i++) {
		cin >> ti;
		if (ti == 1) { t1++; counter++; }
		if (ti == 2) {
			cin >> fi >> ci;
			if ((fi == 1 && t1%2==0) || (fi==2 && t1%2==1)) {
				ss.push_front(ci);
			}
			else {
				ss.push_back(ci);
			}
//			t1 = 0;
		}
	}

	if (counter % 2 == 0) {
		for (long i = 0; i < ss.size(); i++) {
			cout << ss[i];
		}
		cout << endl;
		return 0;
	}
	else {
		for (long i = ss.size()-1; i >=0; i--) {
			cout << ss[i];
		}
		cout << endl;
		return 0;
	}

}

Measured memory_bytes: 1024
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

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

    // input
    ll N, C;
    cin >> N >> C;
    
    ll D[C][C];
    FOR(i, 0, C){
        FOR(j, 0, C){
            cin >> D[i][j];
        }
    }

    ll c[N][N];
    FOR(i, 0, N){
        FOR(j, 0, N){
            cin >> c[i][j];
            c[i][j]--;
        }
    }

    ll sum[3][C];
    FOR(i, 0, 3){
        FOR(j, 0, C){
            sum[i][j] = 0;
        }
    }

    FOR(j, 0, C){
        FOR(y, 0, N){
            FOR(x, 0, N){
                ll a = (x+y)%3;
                ll from_color = c[y][x];
                ll to_color = j;
                ll cost = D[from_color][to_color];
                sum[a][j] += cost;
            }
        }
    }

    ll min_cost = inf;

    FOR(i, 0, C){
        FOR(j, 0, C){
            FOR(k, 0, C){
                if(i!=j && j!=k && i!=k){
                    ll cost = sum[0][i] + sum[1][j] + sum[2][k];
                    min_cost = min(min_cost, cost);
                }
            }
        }
    }

    p(min_cost);
    
    return 0;
}

Measured memory_bytes: 2176
import java.util.*;

public class Main {
	public static void main(String[] args) {

		int o,p,q;
		int a = 0, b = 0;
		
		Scanner sc  = new Scanner(System.in);
//		int[] test  = new int[100000];
//  		int[] test2 = new int[1000];
	  String str1 = sc.next();
	//  String str2 = sc.next();
	for(int i=0; i < str1.length(); i++){
		
		if(i==4)System.out.print(" ");
		
		System.out.print(str1.charAt(i));
		
	
	}
	  
	 /*   
	  int	s = Integer.parseInt(sc.next());
	  int	t = Integer.parseInt(sc.next());
	  int	u = Integer.parseInt(sc.next());
		*/

		
   /*
      int d = 0;
    　　　　while(true){
		
       int	v = Integer.parseInt(sc.next());
       test2[d] = v ;
     	d++;
		}
		
		*/
/*
	  for(int i=0;i<c1.length;i++){
			if(c1[i]!=c2[i]){
				System.out.println("NO");
				return;
			}
		}
		*/

		  System.out.println();
	}
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int yomu = 0;
  bool ans = false;
  if(b < 10){
    yomu = a*10 + b;
  }
  else if(b < 100){
    yomu = a*100 + b;
  }
  else{
    yomu = a*1000 + b;
  }
  rep(i,sqrt(100100)){
    if(yomu == i * i){
      ans = true;
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

    

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n,k;
  cin >> n >> k;
  int a[n];
  for(int i=0;i<n;i++)	cin >> a[i];
  sort(a,a+n);
  int sum=0;
  for(int i=0;i<k;i++)	sum+=a[i];
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Solve
{
    public Solve() { }
    public static int Main()
    {
        new Solve().calc();
        return 0;
    }


    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int M = cin.nextInt();
        int result = 48 - M;
        Console.WriteLine(result.ToString());
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

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

using namespace std;
using ll = long long;

ll dp[105][100005];
ll sums[100005];
const ll MOD_VAL = 1e9+7;

int n, k;
int a[100005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<=a[0];i++){
        dp[0][i] = 1;
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<=k+1;j++){
            sums[j] = dp[i-1][j-1] + sums[j-1];
            sums[j] %= MOD_VAL;
        }
        for(int j=0;j<=k;j++){
            dp[i][j] += (sums[j+1] - sums[max(j-a[i],0)] + MOD_VAL)%MOD_VAL;
        }
    }
    cout<<dp[n-1][k];

    return 0;
}

Measured memory_bytes: 79744
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int h, w;
char c[1000][1000];
vector<int> v1, v2;

int main() {
    cin >> h >> w;
    rep(i,h) rep(j,w) cin >> c[i][j];
    rep(i,h) rep(j,w) {
        if (c[i][j] != '.') v1.push_back(i+j);
        if (c[i][j] != '.') v2.push_back(i-j);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    int ans = max(v1[v1.size()-1] - v1[0], v2[v2.size()-1] - v2[0]);
    cout << ans << endl;
}



Measured memory_bytes: 9976
from operator import itemgetter
N=int(input())
listA=[[] for i in range(N)]
listANS=[]
for i in range(N):
  S,P=input().split()
  listA[i]+=[S,int(P),i+1]
listA.sort()
before=0
if N!=1:
  for i in range(1,N):
    if listA[i-1][0]!=listA[i][0]:
      listN=listA[before:i]
      listN.sort(key=itemgetter(1),reverse=True)
      listANS+=listN
      before=i
 
    if i==N-1:
      listN=listA[before:N]
      listN.sort(key=itemgetter(1),reverse=True)
      listANS+=listN
else:
  listANS=listA
for i in range(N):
  print(listANS[i][2])

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


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

bool dfs(vector<vector<PLL>>& G, int u, VL& dist){
  for(auto& e: G[u]){
	if(dist[e.FF] == INF){
	  dist[e.FF] = dist[u] + e.SS;
	  if(!dfs(G, e.FF, dist))
		return false;
	}
	else if(dist[e.FF] != dist[u] + e.SS)
	  return false;
  }
  return true;
}

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

  int N, M;
  cin >> N >> M;
  vector<vector<PLL>> G(N);
  REP(i,M){
	int l, r, d;
	cin >> l >> r >> d;
	--l;
	--r;
	G[l].EB(r,d);
	G[r].EB(l,-d);
  }

  VL dist(N, INF);
  bool ok = true;
  REP(i,N){
	if(dist[i] != INF) continue;
	dist[i] = 0;
	ok = ok && dfs(G, i, dist);
  }

  cout << (ok? "Yes": "No") << endl;

  return 0;
}

Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,m;cin >> n >>m;
    vl rem(m,0);
    vl dup(m,0);
    map<ll,ll> mp;
    rep(i,n){
        ll a;cin >> a;
        rem[a%m]++;
        mp[a]++;
    }
    for(auto p:mp){
        if(p.se>=2)dup[p.fi%m]+=p.se/2*2;
    }
    ll ans=rem[0]/2;//dup[0]は無視
    repl(i,1,(m+1)/2){
        ll res=min(rem[i],rem[m-i]);
        ans+=res;
        ans+=min(rem[i]-res,dup[i])/2;
        ans+=min(rem[m-i]-res,dup[m-i])/2;
        //cout << ans <<endl;
    }
    if(m%2==0)ans+=rem[m/2]/2;
    cout << ans <<endl;
}

Measured memory_bytes: 8064
#include <type_traits>
#include <algorithm>
#include <iomanip>
#include <list>
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;

namespace EqualCut {
	pair<ll, ll> find_cut(vector<ll> & dist, int start, int end) {
		ll startD = dist[start];
		ll endD = dist[end];

		int cutPointStart = start + 1;
		int cutPointEnd = end - 1;

		while (cutPointStart < cutPointEnd) {
			int pt = cutPointStart + (cutPointEnd - cutPointStart) / 2;

			if (cutPointStart + 1 == cutPointEnd) {
				ll l1 = dist[cutPointStart] - startD;
				ll r1 = endD - dist[cutPointStart];
				ll l2 = dist[cutPointEnd] - startD;
				ll r2 = endD - dist[cutPointEnd];

				if (abs(l1 - r1) < abs(l2 - r2))
					return make_pair(l1, r1);
				else
					return make_pair(l2, r2);
			}

			ll l = dist[pt] - startD;
			ll r = endD - dist[pt];

			if (l < r)
				cutPointStart = pt;
			else if (r < l)
				cutPointEnd = pt;
			else
				return make_pair(l, r);
		}

		return make_pair(dist[cutPointStart] - startD, endD - dist[cutPointStart]);
	}
}


int main()
{
	ifstream ifp("c:\\temp\\small-practice.in");
	ofstream ofp("c:\\temp\\res.out");
	istream & input = cin;
	ostream & output = cout;
	// equal cut
	if (true)
	{
		using namespace EqualCut;
		ll n, v;
		ll d = 0;

		input >> n;
		vector<ll> dist(n + 1);
		for (int i = 0; i < n; i++) {
			input >> v;
			dist[i] = d;
			d += v;
		}

		dist[n] = d;

		ll best = numeric_limits<ll>::max();
		for (int i = 2; i < n - 1; i++) {
			auto v1 = find_cut(dist, 0, i);
			auto v2 = find_cut(dist, i, n);
			ll minV = min(min(min(v1.first, v1.second), v2.first), v2.second);
			ll maxV = max(max(max(v1.first, v1.second), v2.first), v2.second);
			best = min(best, maxV - minV);
		}

		output << best;
	}


    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;

int N,K;
bool dp[100010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N>>K;
  vint a(N);
  repeat(i,N)cin>>a[i];
  repeat(i,K+1){
    for(int j=0;j<N&&a[j]<=i;j++){
      dp[i] |= !dp[i-a[j]];
    }
  }
  cout<<(dp[K]? "First":"Second")<<endl;
  return 0;
}


Measured memory_bytes: 384