akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
 	lli n,n1=0;
 	cin>>n;
 	lli a[n];
 	for(lli i=0;i<n;i++){lli x;cin>>x;if(x<0)n1++;a[i]=abs(x);}
 	lli mini=a[0],sum=0;
 	for(lli i=0;i<n;i++){sum+=a[i];mini=min(a[i],mini);}
 		if(n1%2==0)cout<<sum;
 	else cout<<sum-2*mini;


   	return 0;
 }

Measured memory_bytes: 1024
import java.util.*;

class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		
		int x=Math.abs(Integer.parseInt(s.substring(0, 3))-753);
		for(int i=1;i<s.length()-2;++i) {
			if(Math.abs(Integer.parseInt(s.substring(i,i+3))-753)<x) {
				x=Math.abs(Integer.parseInt(s.substring(i,i+3))-753);
			}
		}
			
		

		System.out.println(x);
	}
}


Measured memory_bytes: 25300
def main():

    from collections import Counter
    import sys

    n = int(input())
    a = list(map(int, sys.stdin.readline().split()))

    d = Counter(a)

    base = sum(v * (v - 1) // 2 for v in d.values())
    e = {k: base - (v >= 2) * (v - 1) for k, v in d.items()}
    p = [str(e[x]) for x in a]
    q = '\n'.join(p)
    print(q)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44276
import java.util.Scanner;

/**
 * @author : Ritchie Zhang
 * @date : 2020/5/10
 * @description： TODO
 * @modifiedBy：
 * @version: 1.0
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int h = scanner.nextInt();
        int m = scanner.nextInt();

        double degree = Math.abs(30*h-5.5*m);
        if (degree>180)
        {
            degree = 360 -degree;
        }
        double hudu = degree*(Math.PI/180);
        double c = Math.sqrt(b*b+a*a-2*a*b*Math.cos(hudu));
        System.out.println(c);
    }
}


Measured memory_bytes: 36112
import sys

import math
import itertools

n=int(input())
a=list(map(int,input().split()))
q=int(input())
all=0
li=[0]*10**5
for i in a:
    all+=i
    li[i-1]+=1
ans=[]*q

for i in range(q):
    b,c=map(int,(input().split()))
    ans.append((all+(c-b)*li[b-1]))
    all=(all+(c-b)*li[b-1])
    li[c-1]+=li[b-1]
    li[b-1]=0
for i in ans:
    print(i)


Measured memory_bytes: 20840
def i1str():
    return input()


def istrs(n=None):
    if n is None:
        return input().split()
    a = []
    for _ in range(n):
        a.append(istrs())
    return a


def i1num():
    return int(input())


def inums(n=None):
    if n is None:
        return list(map(int, input().split()))
    a = []
    for _ in range(n):
        a.append(inums())
    return a


def ostrs(l, sp=" "):
    print(sp.join(l))


def onums(l, sp=" "):
    print(sp.join(map(str, l)))


def solve(n):
    pi = 3.14159
    return 2*pi*n


if __name__ == "__main__":
    n = i1num()
    print(solve(n))


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


void cc_env() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	//
#endif
}



int main() {
	// cc_env();
	// input part
	int H, W;
	cin >> H >> W;
	vector<vector<char> > inputArr(H, vector<char>(W));

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)
			cin >> inputArr[i][j];
	}

	// processing
	// dp[i][j] -> no of ways to reach at (i, j)
	vector<vector<int> > dp(H, vector<int>(W, 0));
	dp[0][0] = 1;

	// Base Cases
	for (int i = 1; i < H; i++) {
		if (inputArr[i][0] == '#')
			dp[i][0] = 0;
		else
			dp[i][0] = dp[i - 1][0];
	}

	// Base Case 2
	for (int j = 1; j < W; j++) {
		if (inputArr[0][j] == '#')
			dp[0][j] = 0;
		else
			dp[0][j] = dp[0][j - 1];
	}

	// Solution building
	for (int i = 1; i < H; i++) {
		for (int j = 1; j < W; j++) {
			if (inputArr[i][j] == '#')
				dp[i][j] = 0;
			else
				dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod;
			// cout << dp[i][j] << " ";
		}
		// cout << endl;
	}

	cout << dp[H - 1][W - 1] << endl;

}


Measured memory_bytes: 8572
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<set>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

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 int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
static const int N=114514;

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=1e9+7;
#define ll long long

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
  string s;
  cin>>s;
  if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
def main():
    N, M, X, Y = map(int, input().split())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))

    if max(x) < min(y):
        if min(y) <= X or max(x) >= Y:
            print("War")
        else:
            print("No War")
    else:
        print("War")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<stdio.h>

#define MAX 100000

int A[MAX];

int partition(int p, int r){
    int max = A[r];
    int i = p-1;
    int j, k, tmp;

    for(j=p; j<r; j++){

        if(A[j] <= max){
            i++;
            
            tmp = A[i];
            A[i] = A[j];
            A[j] = tmp;
        }   
    }

    tmp = A[i+1];
    A[i+1] = A[r];
    A[r] = tmp;

    return i+1;
}

int main(){
    int n, i, mark;

    scanf("%d", &n);

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

    mark = partition(0, n-1);

    for(i=0; i<n; i++){
        if(i == mark){
            printf("[%d]", A[i]);
        }else{
            printf("%d", A[i]);
        }
        if(i != n-1) printf(" ");
    }
    printf("\n");

    return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll fuc(ll tmp){
	return tmp*tmp*tmp*tmp*tmp;
}
ll x;

int main(){
	cin>>x;
	ll i,j;
	for(i=200;i>=0;--i){
		for(j=i-1;j>=-200;--j){
			if(fuc(i)-fuc(j)==x){
				cout<<i<<" "<<j;
				return 0;
			}
		}
	}
	
	
	
	return 0;
}

Measured memory_bytes: 3624
def DP_E() :
    N, W = map(int, input().split())
    w = []
    v = []
    for i in range(N) :
        wi, vi = map(int, input().split())
        w.append(wi)
        v.append(vi)

    dp = [[10**10]*(max(v)*(N+1)) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(1, N+1):
        for j in range(max(v)*(N+1)) :
            # i番目の品物を選ぶ場合
            if j >= v[i-1] :
                dp[i][j] = min(dp[i][j], dp[i-1][j-v[i-1]]+w[i-1])
            # i番目の品物を選ばない場合
            dp[i][j] = min(dp[i][j], dp[i-1][j])
    ans = 0
    for i in range(max(v)*(N+1)) :
        if dp[N][i] <= W :
            ans = i

    return ans

print(DP_E())


Measured memory_bytes: 119408
#[allow(dead_code)]
const MOD: usize = 1_000000000 + 7;

fn main() {
    let mut cin = Scanner::new();
    let n = cin.next_isize();

    for i in 0..1<<3 {
        let mut v = n / 1000;
        let mut k = 100;
        for j in 0..3 {
            let sign = (i>>j&1)*2-1;
            v += sign * (n / k % 10);
            k /= 10
        }
        let mut k = 100;
        if v == 7 {
            print!("{}", n / 1000);
            for j in 0..3 {
                let sign = if (i>>j&1) == 0 { '-' } else { '+' };
                print!("{}{}", sign, n / k % 10);
                k /= 10
            }
            println!("=7");
            return;
        }
    }
}


struct Scanner {
    reader: std::io::Stdin,
    tokens: std::collections::VecDeque<String>,
}

impl Scanner {
    fn new() -> Self {
        Scanner {
            reader: std::io::stdin(),
            tokens: std::collections::VecDeque::new(),
        }
    }

    fn next(&mut self) -> String {
        if self.tokens.is_empty() {
            let mut s = String::new();
            loop {
                self.reader.read_line(&mut s).ok();
                let s = s.trim();
                if s.len() != 0 {
                    for it in s.split_whitespace() {
                        self.tokens.push_back(it.into())
                    }
                    break;
                }
            }
        }
        self.tokens.pop_front().unwrap()
    }

    fn next_generics<T>(&mut self) -> T where
        T: std::str::FromStr + std::marker::Copy,
        <T as std::str::FromStr>::Err: std::fmt::Debug
    {
        self.next().parse().unwrap()
    }
    
    #[allow(dead_code)] fn next_i32(&mut self) -> i32 { self.next_generics::<i32>() }
    #[allow(dead_code)] fn next_i64(&mut self) -> i64 { self.next_generics::<i64>() }
    #[allow(dead_code)] fn next_u64(&mut self) -> u64 { self.next_generics::<u64>() }
    #[allow(dead_code)] fn next_usize(&mut self) -> usize { self.next_generics::<usize>() }
    #[allow(dead_code)] fn next_isize(&mut self) -> isize { self.next_generics::<isize>() }
}



Measured memory_bytes: 4352
#include <stdio.h>

int main() 
{
	int i, n, g[10] = { 1,2,4,8,16,32,64,128,256,512 };
	while (scanf("%d", &n)!=EOF) 
	{
		i = 0;
		while (1) 
		{
			if (n % 2 == 1)
			{
				printf("%d", g[i]);
				if (n / 2 != 0)
				{
					printf(" ");
				}
			}
			n /= 2;
			if (n == 0)
			{
				break;
			}
			i++;
		}
		putchar('\n');
	}

	return 0;
}


Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int ans = max(0, c-(a-b));

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int x,c=0;
    cin>>x;
    for (int i=1;i<=x;i++){
        int m=log10(i)+1;
        if (m&1)
            c++;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 768
N = gets.to_i
q = gets.split.map(&:to_i)

if q == q.sort
  puts 'YES'
  exit
end

N.times do |i|
  (i+1).upto(N-1) do |j|
    q[i], q[j] = q[j], q[i]
    sorted = true
    1.upto(N-1) do |k|
      if q[k-1] > q[k]
        sorted = false
        break
      end
    end

    if sorted
      puts 'YES'
      exit
    end

    q[i], q[j] = q[j], q[i]
  end
end

puts 'NO'


Measured memory_bytes: 3836
n,k=map(int, input().split())
arr=[0]*n
ans=0
for i in range(k):
    d=int(input())
    a=list(map(int, input().split()))
    for j in range(d):
        arr[a[j]-1]+=1
for i in range(n):
    if arr[i]==0:
        ans+=1
print(ans)

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <cstdlib>
typedef long long ll;
#define fi first
#define se second

using namespace std;

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

int main(){

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

    int ans;
    cin >> ans;
    int mx = ans;
    if (ans == k){
        cout << "POSSIBLE";
        return 0;
    }
    for(int i=1;i<n;i++){
        int x;
        cin >> x;
        mx = max(mx,x);
        if(x == k){
            cout << "POSSIBLE";
            return 0;
        }
        ans = gcd(ans,x);
    }

    if(k%ans == 0 && k <= mx) cout << "POSSIBLE";
    else cout << "IMPOSSIBLE";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, x, t;
    cin >> n >> x >> t;
    cout << ((n - 1) / x + 1) * t;
}


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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   int n,m,a,b,cnt=0;
   cin>>n>>m;
   vector<int> x;
   x.resize(n,-1);

   rep(i,0,m){
      cin>>a>>b;
      if(x[a-1] == -1 || x[a-1] == b){
         x[a-1] = b;
      }else{
         cout<<-1<<'\n';
         return 0;
      }
   }

   if(n >= 2 && x[0] == 0){
      cout<<-1<<'\n';
      return 0;
   }else if(n == 1 && x[0] == 0){
      cout<<0<<'\n';
      return 0;
   }else if(n == 1 && m == 0){
      cout<<0<<'\n';
      return 0;
   }

   rep(i,0,n){
      if(i != 0){
         cnt *= 10;
      }
      if(x[0] == -1){
         x[0] = 1;
      }else if(x[i] == -1){
         x[i] = 0;
      }

      cnt += x[i];
   }

   cout<<cnt<<'\n';
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 5e5+10;

int h[N];
ll dp[N];
int main(){
fast;
int n,k;
cin>>n>>k;
for(int i=0;i<n;i++) {
    cin>>h[i];
}

dp[0]=0;
for(int i=1;i<n;i++) {
    dp[i]=INF;
    for(int j=1;j<=k && i-j>=0;j++) {
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    }
}

cout<<dp[n-1]<<endl;
return 0;
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main(){
    string s;
    cin>>s;
    int n=sz(s);
    rep(i,n){
        char c=s[i];
        if(i%2==0){
            if(c=='L'){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else{
            if(c=='R'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,s=0,sum=0;
            boolean end=false;
            while ((line = br.readLine()) != null) {
            	if(line.equals("0 0"))break;
            	String[] str=line.split(" ");
            	sum=0;
            	n=Integer.parseInt(str[0]);
            	s=Integer.parseInt(str[1]);
            	for(int i=n;i>0;i--){
            		for(int j=i-1;j>0;j--){
            			end=true;
            			for(int k=j-1;k>0;k--){
                    		if(i+j+k==s){
                    			sum++;
                    		}
                    		/*if(i+j+k>=s){
                    			end=false;
                    		}*/
                    	}
            			if(end){
                			end=false;
                		}
                	}
            		if(end){
            			break;
            		}
            	}
            	System.out.println(sum);
            }
        }
    }

}

Measured memory_bytes: 25128
// #pragma GCC optimize("no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC diagnostic ignored "-W"

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>
#include<functional>
#include<complex>
#include<climits>
#include<random>
#include<thread>

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>
#endif

// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/rope>

using namespace std;
// using namespace __gnu_pbds;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vint vector<int>
#define vpii vector<pair<int,int>>
#define SS stringstream
#define PQ priority_queue
#define MS(x,v) memset((x),(v),sizeof(x))
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)
#define CPPinput ios_base::sync_with_stdio(0); cin.tie(0)
#define FIN(fname) freopen(fname,"r",stdin)
#define FOUT(fname) freopen(fname,"w",stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#include"/home/edison/Coding/cpp/template/debug.cpp"
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define DEBUG 1
#define exit(x) cout<<"exit code "<<x<<endl, exit(0)
#else
#define PDE(...) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

void JIZZ(string output=""){cout<<output; exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-10;
const ll mod=1e9+7;

set<string> st;

int main(){
    CPPinput;
    int n; cin>>n;
    char la=0;
    while(n--){
        string s; cin>>s;
        if(st.find(s)!=st.end()){ No; exit(0); }
        st.insert(s);
        if(la && s[0]!=la){ No; exit(0); }
        la=s.back();
    }
    Yes;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define M (long long)3e5 + 10

using namespace std;

long long cnt[M], a[M], sum[M];

int main()
{
	long long n, tot = 0;

	cin >> n;

	for (long long i = 1; i <= n; i++)
	{
		long long tmp;
		cin >> tmp;
		cnt[tmp]++;
	}

	for (long long i = 1; i <= n; i++)
	{
		if (cnt[i] != 0)
			a[++tot] = cnt[i];
	}

	sort(a + 1, a + tot + 1);

	sum[1] = a[1];

	for (long long i = 2; i <= tot; i++)
		sum[i] = sum[i - 1] + a[i];								//前缀和

	for (long long k = 1; k <= n; k++)
	{
		long long l = 1, r = n;
		while (l <= r)
		{
			long long mid = (l + r) >> 1;
			long long pos = upper_bound(a + 1, a + tot + 1, mid) - a;		//返回数组中第一个大于或等于被查数的值的下标
			pos--;											//小于等于mid的数的个数

			if (sum[pos] + (tot - pos) * mid < k * mid)
				r = mid - 1;
			else
				l = mid + 1;
		}
		cout << r << endl;
	}

	return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N;
int prime[1005],tot;
bool nonprime[1005];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int f(int n,int p) {
    if(n < p) return 0;
    return f(n / p ,p) + n / p;
}
void Solve() {
    read(N);
    for(int i = 2 ; i <= N ; ++i) {
        if(!nonprime[i]) {prime[++tot] = i;}
        for(int j = 1 ; j <= tot ; ++j) {
            if(i * prime[j] > N) break;
            nonprime[i * prime[j]] = 1;
            if(i % prime[j] == 0) break;
        }
    }
    int ans = 1;
    for(int i = 1 ; i <= tot ; ++i) {
        ans = mul(ans,f(N,prime[i]) + 1);
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int K;
  cin >> K;
  string S;
  cin >> S;
  int N = S.size();
  if(N<=K)
  {
    cout << S << endl;
  }
  else
  {
    for(int i=0;i<K;i++)
    {
      cout << S[i];
    }
    cout << "...";
  }

  
  return 0;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define FOR(i, a, n, step) for (int (i) = (a); (i) < (int)(n); (i) += (step))
#define ROF(i, a, n, step) for (int (i) = (a); (i) >= (int)(n); (i) -= (step))
#define FOREACH(it, v) for (auto (it) : (v))

using namespace std;

typedef unsigned long long ull;
typedef long long ll ;
typedef long double ld;
typedef pair <int, int> pii;

template <class T>
const bool is_impar(const T &x) {return (bool) (x & 1);}

int a, b;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> a >> b;
    cout << a * b - a - b + 1;
}

Measured memory_bytes: 384
#C - : (Colon)
import numpy as np
a,b,h,m = list(map(int, input().split()))
pi = np.pi

hx = a*np.cos(-h*pi/6 + pi/2 - pi*m/360)
hy = a*np.sin(-h*pi/6 + pi/2 - pi*m/360)

mx = b*np.cos(-m*pi/30 + pi/2)
my = b*np.sin(-m*pi/30 + pi/2)

l = np.sqrt((hx-mx)**2+(hy-my)**2)

print(l)

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

int main() {
	unsigned long long x, ans, result, remain;
	cin >> x;
	if(x <= 11){
		if(x <= 6){
			ans = 1;
		}else{
			ans = 2;
		}
	}else{
		result = x/11;
		remain = x % 11;
		if(remain == 0){
			ans = result * 2;
		}else if( remain <= 6){
			ans =  result * 2 + 1;
		}else{
			ans = result * 2 + 2;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr ll MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

template <typename T>
T mypow(T a, T b)
{
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

vector<ll> fact(200020, 1), inv(200020, 1);

ll comb(int n, int k)
{
    if (k < 0 || n < k)
        return 0;
    ll ret = fact[n] * inv[k] % MOD;
    return ret * inv[n - k] % MOD;
}

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

    ll n, m, k;
    cin >> n >> m >> k;
    for (int i = 2; i <= 200000; i++)
    {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = mypow(fact[i], MOD - 2);
    }
    ll ret = 0;
    for (int d = 1; d <= n - 1; d++)
    {
        ll sum = comb(n * m - 2, k - 2) * (n - d) % MOD;
        sum *= m * m % MOD;
        sum %= MOD;
        sum = sum * d % MOD;
        ret = (ret + sum) % MOD;
    }
    for (int d = 1; d <= m - 1; d++)
    {
        ll sum = comb(n * m - 2, k - 2) * (m - d) % MOD;
        sum *= n * n % MOD;
        sum %= MOD;
        sum = sum * d % MOD;
        ret = (ret + sum) % MOD;
    }
    cout << ret << endl;
}


Measured memory_bytes: 3328
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		solve();
	}

	private static void solve() {
		String[] btn = new String[10];
		btn[1]=".,!? ";
		btn[2]="abc";
		btn[3]="def";
		btn[4]="ghi";
		btn[5]="jkl";
		btn[6]="mno";
		btn[7]="pqrs";
		btn[8]="tuv";
		btn[9]="wxyz";
		Scanner scn = new Scanner(System.in);
		PrintWriter pr = new PrintWriter(System.out);
		int n = scn.nextInt();
		int[] b = new int[10];
		for(int k=1;k<=n;k++){
			String tmp = scn.next();
			for(int s=0;s<tmp.length();s++){
				b[tmp.charAt(s)-'0']++;
				if(b[0]!=0){
					b[0]=0;
					for(int t=1;t<=9;t++){
						if(b[t]!=0){
							pr.print(btn[t].charAt((b[t]-1)%btn[t].length()));
							b[t]=0;
						}
					}
				}
			}
			pr.println();
		}
		pr.flush();
		scn.close();
	}

}

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

class Test
{
    static void Main()
    {
        string ss;
        while ( (ss = Console.ReadLine()) != "0 0")
        {
            int H = int.Parse(ss.Split()[0]);
            int W = int.Parse(ss.Split()[1]);

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    Console.Write("#");
                }
                Console.Write("\n");
            }
            Console.WriteLine();
        }
    }
}


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

int main() {
    int a,b,n;
    string s;
    cin>>a>>b>>s;
    n=count(s.begin(),s.end(),'-');
    if(s[a]=='-'&&n==1)  cout<<"Yes\n";
    else  cout<<"No\n";
    return 0;
}

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

pos = 0
# スタートを一文字ずつずらして全探索
for i in range(N):
    c = 0
    for j in range(N-i):
        # print('::', i, j)
        # print('!!', s[i+j], t[j])
        if s[i+j] == t[j]:
            c += 1
        else:
            break
    else:
        pos = max(pos, c)

# print(pos)
ans = 2 * N - pos
print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20191201
{
    static class C
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int a = (int)(n / 100);
            int b = n % 100;
            int ans;
            if ((b+4)/5<=a) { ans = 1; }
            else { ans = 0; }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
const ll mod=998244353;
inline ll pw(ll x,ll y)
{
    ll ans=1;
    while(y>0)
    {
        if(y%2==1)
            ans=ans*x%mod;
        x=x*x%mod;
        y/=2;
    }
    return ans;
}
int dp1[3010][3010],dp2[3010][3010];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    //위에걸 칠한다
    //중복해서 세지 않도록, 경로를 오른쪽에서 위쪽으로 꺾을 때는 반드시 가장 오른쪽을 칠한다
    dp1[a][b]=1;
    for(int i=a;i<=c;i++)
    {
        for(int j=b;j<=d;j++)
        {
            dp2[i][j]=(ll)j*(dp2[i-1][j]+dp1[i-1][j])%mod;
            if(i==a)
            {
                if(j!=b)
                    dp1[i][j]=(ll)i*dp1[i][j-1]%mod;
            }
            else if(j!=b)
            {
                dp1[i][j]=(ll)i*dp1[i][j-1]%mod;
                dp1[i][j]+=dp2[i][j-1];
                dp1[i][j]%=mod;
            }
            //cout<<i<<' '<<j<<' '<<dp1[i][j]<<' '<<dp2[i][j]<<endl;
        }
    }
    cout<<(dp1[c][d]+dp2[c][d])%mod<<endl;
    return 0;
}

Measured memory_bytes: 74172
#include <stdio.h>
int main(void){
    int N;
    int d[50];
    
    //標準入力
    scanf("%d", &N);
    for(int i = 0;i < N; i++) {
       scanf("%d", &d[i]);
    }
  
    //計算
    int sum = 0;
    for(int i = 1; i < N; i++) {
       for(int j = 0; j < i; j++) {
          sum += d[j] * d[i];
       }
    }
    
    //出力
    printf("%d\n", sum);
  
    return 0;
}


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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
s = input()
t = input()
ans = 0
for i in range(len(s)):
    if s[i] != t[i]:
        ans += 1
print(ans)


Measured memory_bytes: 9216
#include <algorithm>
using namespace std;

int a[10000];
int main(){
  int n,i;
  long long int z,r;
  for(;scanf("%d",&n),n;printf("%lld\n",r)){
    for(i=0;i<n;i++)scanf("%d",a+i);
    sort(a,a+n);
    for(z=r=i=0;i<n-1;i++)z+=a[i],r+=z;
  }
}

Measured memory_bytes: 0
# input
R, G, B, N = map(int, input().split())

rmax = N // R

count = 0
for r in range(rmax+1):
    rem = N - r * R
    gmax = rem // G
    for g in range(gmax+1):
        remm = rem - g * G
        if remm % B == 0:
            count += 1

print(count)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int n, int m) {
    using type = pair<int, pair<int, string>>;
    vector<type> gen(n);
    for_each(ALL(gen), [](type &e) {
        string s;int a, b;
        cin >> s >> a >> b;
        e = MP(b, MP(a, s));
    });
    SORT(gen);
    VI ids(n);
    REP(i, n) ids[i] = gen[i].first;
    REP(i, m) {
        int num; cin >> num;
        int idx = distance(begin(ids), lower_bound(ALL(ids), num));
        //DEBUG(idx)
        if (!(0 <= idx && idx < n)) {
            cout << "Unknown" << endl;
            continue;
        }
        auto e = gen[idx];
        int buf = e.second.first - (e.first - num);
        if (buf > 0 && e.second.first >= buf) {
            cout << e.second.second << " " << buf << endl;
        } else {
            cout << "Unknown" << endl;
        }
    }
    return;
}

signed main(void) {
    LL n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n >> m, n) {
        solve(n, m);
        //return 0;
    }
}

Measured memory_bytes: 3176
using System;
using System.Linq;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var NX = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
            var N = NX[0];
            var X = NX[1];
            var an = Console.ReadLine().Split(' ').Select(s=> int.Parse(s)).ToArray();
            long result = 0;
            if(X<an[0])
            {
                result = an[0]-X;
                an[0] = X;
            }
            for(var i =1;i<N;i++)
            {
                var sum = an[i] + an[i - 1];
                if (sum <= X) continue;
                var diff = sum - X;
                result += diff;
                an[i] -= diff;
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 30300
#include <bits/stdc++.h>
using namespace std;
int ha,ma,hb,mb,k;
int main() {
  scanf("%d%d%d%d%d",&ha,&ma,&hb,&mb,&k);
  ma+=ha*60;
  mb+=hb*60;
  printf("%d\n",mb-k-ma);
  return 0;
}


Measured memory_bytes: 3816
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
using namespace std;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define inf mod1
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
	fast;
	ll h = 1;
	//scanf("%lld", &h);
    while(h--){ 
          ll n;
          cin >> n;
          ll a[10][10] = {};
          for(int i  =1; i <= n; i++){
            vector<ll> v;
            ll x = i;
            while(x != 0){
                v.pb(x % 10);
                x /= 10;
            }
            a[v[v.size()-1]][v[0]]++;
          }
          ll out = 0;
          for(int i = 1; i <= n; i++){
            vector<ll> v;
            ll x = i;
            while(x != 0){
                v.pb(x % 10);
                x /= 10;
            }
            out += a[v[0]][v[v.size()-1]];
          }
          cout << out << endl;
        }   
    }       

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds;  
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
    
//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k;

ll t=1;

void solve()
{
    string s,ss;
    cin>>s>>ss;
    n=s.size(),m=ss.size();
    c=0;
    ll ans=INT_MAX;
    for(ll i=0;i<=n-m;i++)
    {
        c=0;
        b=i;
        for(auto p:ss)
        c+=((p!=s[b])?1:0),b++;
        
        ans=min(ans,c);
    }
    cout<<ans;
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 3648
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, m = ns()
    expected = 2**m

    ans = (100*(n-m)+1900*m)*expected
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5332
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include <iostream>
using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N], B[N], C[N-1];

    int total =0;

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

    for(int i=0; i<N; i++){
        cin >> B[i];
        total += B[i];
        // cout << total;
    }

    for(int i=0; i<N-1;i++){
        cin >> C[i];
    }

    for(int i=0; i<N-1; i++){
        if(A[i+1] - A[i] == 1){
            total += C[A[i] - 1];
            //cout << C[A[i] - 1] << endl;
        }
    }

    cout << total;

}

Measured memory_bytes: 256
from heapq import*
def dijkstra(n,s,edge):
    g=10**6
    d=[10**18]*n
    used=[True]*n
    d[s]=0
    used[s]=False
    edgelist=[]
    for a,b in edge[s]:heappush(edgelist,a*g+b)
    while edgelist:
        minedge=heappop(edgelist)
        if not used[minedge%g]:continue
        v1=minedge%g
        c1=d[v1]=minedge//g
        used[v1]=False
        for c2,v2 in edge[v1]:
            if used[v2]:heappush(edgelist,(c1+c2)*g+v2)
    return d
def main():
    n,m,s,t,*z=map(int,open(0).read().split())
    e1,e2=[[[]for _ in range(n)]for _ in range(2)]
    for u,v,a,b in zip(*[iter(z)]*4):
        u-=1
        v-=1
        e1[u]+=(a,v),
        e1[v]+=(a,u),
        e2[u]+=(b,v),
        e2[v]+=(b,u),
    c1=dijkstra(n,s-1,e1)
    c2=dijkstra(n,t-1,e2)
    a=[]
    m=0
    for y,s in zip(c1[::-1],c2[::-1]):
        t=10**15-y-s
        if t>m:m=t
        a+=m,
    print(*a[::-1],sep='\n')
main()

Measured memory_bytes: 92464
from itertools import product
import numpy as np
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for _ in range(n)]
a,c=np.array([i[1:] for i in ca]).T,np.array([i[0] for i in ca])
ans=pow(10,9)
for i in product([0,1],repeat=n):
  i=np.array(i)
  if all(np.dot(a,i)>=x):
    s=np.dot(i,c)
    ans=s if s<ans else ans
print(ans if ans<pow(10,9) else -1)

Measured memory_bytes: 27224
import std.stdio, std.conv, std.string, std.algorithm, std.range;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.to!(int[]);
    if (N % 2) A ~= 0;
    A.sort!((a,b) => a > b).chunks(2).map!(a => a[0] - a[1]).sum.writeln;
}


Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int t,n,s,e;
	while(cin>>t,t){
		cin>>n;
		int res=t;
		rep(i,n){
			cin>>s>>e;
			res-=(e-s);
		}
		if(res<=0)cout<<"OK"<<endl;
		else cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

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



Measured memory_bytes: 1928
class Node:
    '''
    p: parent node
    l: child node
    r: sibling node
    '''
    def __init__(self, p=-1, l=-1, r=-1):
        self._p = p
        self._l = l
        self._r = r

Depth = []
T = []

def rec(node, depth):
    global Depth
    global T
    Depth[node] = depth

    child = T[node]._l
    while child != -1:
        rec(child, depth + 1)
        child = T[child]._r


    # if T[node]._r != -1:
    #     rec(T[node]._r, depth)

    # if T[node]._l != -1:
    #     rec(T[node]._l, depth + 1)

def print_node(index):
    global Depth
    global T
    print('node %d: parent = %d, depth = %d, '%(index, T[index]._p, Depth[index]), end='')

    if T[index]._p == -1:
        print('root, [', end='')
    elif T[index]._l == -1:
        print('leaf, [', end='')
    else:
        print('internal node, [', end='')

    i = 0
    node = T[index]._l
    while node != -1:
        if i:
            print(', ', end='')
        print(node, end='')

        i += 1
        node = T[node]._r
    print(']')
    


if __name__ == '__main__':
    n = int(input())

    for i in range(n):
        T.append(Node())
    Depth = [-1]*n
    for i in range(n):
        parent_node, child_cnt, *child_node = map(int, input().split())
        for j in range(child_cnt):
            if j == 0:
                T[parent_node]._l = child_node[j]
            else:
                T[child_node[j - 1]]._r = child_node[j]
            T[child_node[j]]._p = parent_node

    root = 0
    for i in range(n):
        if T[i]._p == -1:
            root = i
            break
    
    rec(root, 0)

    for i in range(n):
        print_node(i)



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

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[][] graph = new int[n][n];
      String[] vInfo;
      int degree;

      for(int i=0,v=0; i<n; i++) {
        vInfo = br.readLine().split(" ");
        degree = Integer.parseInt(vInfo[1]);
        for(int j=0,k=2; j<degree; j++) {
          v = Integer.parseInt(vInfo[k++]);
          graph[i][v-1] = 1;
        }
      }

      StringBuilder buf = new StringBuilder(n*n);
      for (int[] vertex : graph) {
        for (int v : vertex) {
          buf.append(v).append(" ");
        }
        buf.setLength(buf.length()-1);
        buf.append("\n");
      }

      System.out.print(buf);
    }
    catch (IOException e) {
      System.out.println("IOException!");
    }
  }
}


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

#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;
mt19937 rnd(time(0));
#define ioss ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("avia.in", "r", stdin); freopen("avia.out", "w", stdout);
#define _GLIBCXX_DEBUG
//#define s second
//#define f first
#define pb push_back
#define add insert
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pii pair<int,int>
#define res resize
#define NO cout<<"NO"<<'\n'; return;
#define YES cout<<"YES"<<'\n'; return;
#define PI acos(-1)
#define gggg cout << "NO";return;
const ll INF = 1e9;//9223372036854775807L; //LONG_MAX;
constexpr ll mod = 1e9 + 7;


void solve() {
    int n;
    cin >> n;
    vector<int> arr(62);
    for (ll i = 0, x; i < n; i++) {
        cin >> x;
        for (int j = 0; j < 62; j++)if (x & (1LL << j))arr[j]++;
    }
    ll ans = 0;
    for (int i = 0; i < 62; i++) {
        ll upd = (((((1LL << i) % mod) * arr[i]) % mod) * (n - arr[i])) % mod;
        ans = (ans + upd) % mod;
    }
    cout << ans;
}

signed main() {
    ioss
    //file
    //id.resize(3e5);
    int t = 1;                                                                                                                                                                        //ll
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}




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

using namespace std;


int main()
{
	int x,n;
	cin >> x >> n;
	map<int,int> arr;
	for(int i = 0; i < n; i++){
		int m; cin >> m;
		arr[m] = 1;
	}
	int ans, mn1;
	for(int i = x; i <= 1000; i++){
		if(!arr[i]){
			ans = i;
			mn1 = abs(i-x);
			break;
		}
	}
	int ans2, mn2;
	for(int i = x; i > -1000; i--){
		if(!arr[i]){
			ans2 = i;
			mn2 = abs(x-i);
			break;
		}
	}
	if(mn1 > mn2) cout << ans2;
	else if(mn1 < mn2) cout << ans;
	else cout << min(ans2, ans);
}


Measured memory_bytes: 3636