akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<vector>
#include<queue>
#include<iostream>
#include<fstream>
#include<string>
#include<cassert>
#include<algorithm>
#include<random>
#include<map>
#include<set>
#include <bitset>
#include<ctime>

using namespace std;

//int mod = 998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int>vi;
typedef vector<ll>vl;
typedef vector<char>vc;
typedef vector<string>vs;
typedef vector<vector<int>>vii;
typedef vector<vector<char>>vvc;
typedef vector<vector<ll>>vll;
typedef vector< pair<ll, ll>>vpll;
typedef vector< pair<ld, ld>>vpld;
typedef vector< pair<int, int>>vpi;
typedef pair<ld, ld>pld;
#define mp make_pair
#define pb push_back

const int mod = 998244353;
int add(int a, int b)
{
	int c = a + b;
	if (c >= mod)
	{
		c -= mod;
	}
	return c;
}
int dif(int a, int b)
{
	int c = a - b;
	if (c < 0)
	{
		c += mod;
	}
	return c;
}
int mlt(int a, int b)
{
ll c = a * 1LL * b;
return c % mod;
}
int ibit(int n, int i)
{
	return ((n >> i) & 1);
}
void outp(vii &ou)
{
	for (int i = 0; i < ou.size(); i++)
	{
		for (int j = 0; j < ou[i].size(); j++)
		{
			cout << ou[i][j] << ' ';
		}
		cout << '\n';
	}
}
int bp(int x, int y)
{
	if (y == 0)
	{
		return 1;
	}
	int a = 0;
	if (!(y % 2))
	{
		a = bp(x, y / 2);
	}
	return (y % 2) ? mlt(bp(x, y - 1), x) : mlt(a, a);
}
int obr(int x)
{
	return bp(x, mod - 2);
}
const int maxn = 2000007;
int fact[2000007], ofact[2000007];
void prec()
{
	fact[0] = 1;
	ofact[0] = 1;
	for (int i = 1; i < maxn; i++)
	{
		fact[i] = mlt(fact[i - 1], i);
	}
	//cerr << "sdsds" << endl;
	ofact[maxn - 1] = obr(fact[maxn - 1]);
	for (int i = maxn - 2; i > 0; i--)
	{
		ofact[i] = mlt(ofact[i + 1], i + 1);
	}
}
int c(int a, int b)
{
	if (a == 0)return 1;
	return ((a <= b) && (a >= 0)) ? mlt(fact[b], mlt(ofact[a], ofact[b - a])) : 0;
}
ll gcd(ll x, ll y)
{
	//cerr << x << y << endl;
	if (x == 0)return y;
	return(x > y) ? gcd(y, x) : gcd(y%x, x);
}
int obr2(int n)
{
	int x = fact[n - 1];
	x = mlt(x, ofact[n]);
	return x;
}
int me(vi &v)
{
	sort(v.begin(), v.end());
	v.pb(9999999);
	if (v[0] > 0)return 0;
	for (int i = 0; i < v.size(); i++)
		if (v[i + 1] - v[i] > 1)return v[i] + 1;
}
vector<int>gran(const vii &gr)
{
	vi grn(gr.size());
	int n = gr.size();
	for (int i = n - 1; i >= 0; i--)
	{
		vi v;
		for (int j = 0; j < gr[i].size(); j++)v.pb(grn[gr[i][j]]);
		grn[i] = me(v);
	}
	vi sums(1<<10);
	int md = bp(10, 18), cur = md;
	for (int i = 0; i < n; i++)
	{
		sums[grn[i]] = add(sums[grn[i]], cur);
		cur = mlt(cur, md);
	}
	return sums;
}
vi grr(int n)
{
	vii gr(n);
	int m;
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >>a >> b;
		if (a > b) gr[b - 1].pb(a - 1);
		else gr[a - 1].pb(b - 1);
	}
	return gran(gr);
}
void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n, an=0;
	cin >> n;
	vi v1 = grr(n), v3 = grr(n), v4 = grr(n);
	for (int i = 0; i < v1.size(); i++)
		for (int j = 0; j < v3.size(); j++)
			an = add(an, mlt(v1[i], mlt(v3[j], v4[i^j])));
	cout << an << endl;

}
int main()
{
	solve();
	int n;
	cin >> n;
}

	


Measured memory_bytes: 4816
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,vl>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=998244353;



int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> a(M,0);
    vector<ll> canopen(M,0);
    for(ll i=0;i<M;i++){
        cin>>a[i];
        ll b;
        cin >> b;
        for(ll j=0;j<b;j++){
            ll c;
            cin >> c;
            canopen[i]+=1<<(c-1);
        ;}
    ;}
    vector<ll> dp(1<<N,INF);
    for(ll i=0;i<M;i++){
        if(i==0){
            dp[0]=0;
            dp[canopen[i]]=a[i];
        }
        else for(ll j=0;j<(1<<N);j++){
            dp[j|canopen[i]]=min(dp[j|canopen[i]],dp[j]+a[i])
        ;}
    ;}
    if(dp[(1<<N)-1]==INF){
        cout<<-1<<endl;return 0;
    }
    cout<<dp[(1<<N)-1]<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const long long MOD = 1000000007;

void solve(long long N, std::vector<long long> T, std::vector<long long> A) {
  vector<bool> fixed(N);
  vl num(N);

  ll maxHeight = 0;
  rep(n, N) {
    if (maxHeight < T[n]) {
      maxHeight = T[n];
      fixed[n] = true;
      num[n] = T[n];
    } else {
      num[n] = num[n - 1];
    }
  }

  maxHeight = 0;
  rrep(n, N) {
    // 矛盾チェック
    if (fixed[n] && num[n] > A[n]) {
      print(0);
      return;
    }

    if (maxHeight < A[n]) {
      maxHeight = A[n];

      // 矛盾チェック
      if (fixed[n] && num[n] != A[n]) {
        print(0);
        return;
      }

      fixed[n] = true;
      num[n] = A[n];
    } else {
      if (!fixed[n]) {
        num[n] = min(num[n], num[n + 1]);
      }
    }
  }

  ll ans = 1;
  rep(n, N) {
    if (!fixed[n]) {
      ans *= num[n];
      ans %= MOD;
    }
  }
  print(ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> T(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &T[i]);
  }
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(T), std::move(A));
  return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int K, N, ans = 0;
	scanf("%d %d", &K, &N);
	int A[N];
	for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
	for (int i = 0; i < N; ++i) ans = max(ans, (A[(i + 1) % N] - A[i] + K) % K);
	printf("%d", K - ans);
	return 0;
}

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

int C[102][102];

void meiro(int W,int H,int c){
  if(C[W][H]!=c){
    return;
  }

  C[W][H] = -1;

  meiro(W-1,H  ,c);
  meiro(W  ,H+1,c);
  meiro(W+1,H  ,c);
  meiro(W  ,H-1,c);
}

int main(){
  while(1){
    int w,h;
    cin >> w >> h;
    if(w==0 && h==0){
      break;
    }

    for(int i=0;i<102;i++){
      for(int j=0;j<102;j++){
        C[i][j] = 10;
      }
    }

    int xs,ys,xg,yg;
    cin >> xs >> ys >> xg >> yg;

    int n;
    cin >> n;

    int c,d,x,y;
    for(int i=0;i<n;i++){
      cin >> c >> d >> x >> y;

      if(d==0){
        for(int j=x;j<x+4;j++){
          for(int k=y;k<y+2;k++){
            C[j][k]=c;
          }
        }
      }else{
        for(int j=x;j<x+2;j++){
          for(int k=y;k<y+4;k++){
            C[j][k]=c;
          }
        }
      }
    }

    meiro(xs,ys,C[xs][ys]);

    if(C[xg][yg] == -1){
      cout << "OK" << endl;
    }else{
      cout << "NG" << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3756
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main()
        {
            int k = int.Parse(Console.ReadLine());
            string ab = Console.ReadLine();
            int a = int.Parse(ab.Split(" ")[0]);
            int b = int.Parse(ab.Split(" ")[1]);

            bool exist = false;

            for (int i = a; i <= b; i++)
            {
                if(i % k == 0)
                {
                    exist = true;
                    break;
                }
            }

            string result = "NG";
            if(exist)
            {
                result = "OK";
            }

            Console.WriteLine(result);
        }

    }
}


Measured memory_bytes: 27324
/*
	Name: A-简单的计算器 
	Author: RoseKey
	Date: 14/02/19 16:51
	Description: 模拟 
*/

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
#define LL long long
#define Rg register
#define RI register int
#define RC register char
#define ed puts("") 
#define pair pair<LL,LL>
#define space putchar(' ')
using namespace std;
    
template <typename tp> inline void read(tp & x)
{	
    x=0;
    RI f=1;
    RC c=getchar();
    while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar(); }
    while(c>='0' && c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();} 
 	x*=f;
} 	
    
template <typename Tp> inline void print(Tp x)
{		
    if(x<0) x=-x,putchar('-');
    if(x>9) print(x/10);
    putchar(x%10+'0');
}	

LL x,y;
LL tempa,tempb;
const LL inf=0x3f3f3f3f;
LL Ans1,Ans2,Ans3,Ans4;
LL Ans;

inline LL Min(LL a,LL b)
{
	if(a<b)
		return a;
	return b;
}

inline LL ans1()//y由x+a组成
{
	LL c=tempb-tempa;
	if(c>0)
		return c;
	else 
		return inf;	
} 


inline LL ans2()//y由x-a组成
{
	LL c=tempb-tempa;
	if(c<0)
	{
		LL hh=-c+2;
		return hh;
	}
	else
		return inf;
} 
	
inline LL ans3()//y由-x+a组成 先按下B再按a次A 
{
	LL c=y+x;
	if(c>=0)	
	{
		LL hh=c+1;	
		return hh;
	}
	return inf;
}	
	
inline LL ans4()//y由-x-a组成 先按a次A 再按1次B 
{
	LL c=y+x;
	if(c<=0)
	{
		LL hh=-c+1;
		return hh; 
	}
	return inf; 
}	

	
int main()
{
	read(x);
	read(y);
	tempa=x;
	tempb=y;
	Ans1=ans1();
	Ans2=ans2();
	Ans3=ans3();
	Ans4=ans4();
	Ans=Min(Ans1,Ans2);
	Ans=Min(Ans,Ans3);
	Ans=Min(Ans,Ans4);
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <string>
using namespace std;

int main()
{
	//char s[100], f[100], l[100];
	//memset(s, '\0', 100);
	//memset(f, '\0', 100);
	//memset(l, '\0', 100);
	string str;
	int cnt = 0, i = 0;
	int fi = 0, li = 0;
	cin >> cnt;
	for(; i != cnt; i++){
		//cin >> s[i];
		char s;
		cin >> s;
		str.push_back(s);
	}
	//str += '\0';
	i = 0;
	int flag = 0;
	/*
	while (s[i] != '\0') {
		if (s[i] == ')') {
			if (flag != 0) {
				li--;
				flag--;
			}
			else {
				fi++;
			}
		}
		else {
			li++;
			flag++;
		}
		i++;
	}
	*/
	while (i != str.length())
	{
		if (*(str.begin() + i) == ')') {
			if (flag != 0) {
				li--;
				flag--;
			}
			else {
				fi++;
			}

		}
		else {
			li++;
			flag++;
		}
		i++;
	}
	i = 0;
	/*
	for (int c = 0; c < fi; c++) {
		f[c] = '(';
	}
	for (int c = 0; c < li; c++) {
		l[c] = ')';
	}
	strcat(f, s);
	*/
	while (i != fi) {
		str = '(' + str;
		i++;
	}
	i = 0;
	while (i != li) {
		str.push_back(')');
		i++;
	}
	//strcat(f, l);

	cout << str << endl;
    return 0;
}

Measured memory_bytes: 256
using System;


namespace hello_world
{class Program
	{
		static void Main(string[] args)
		{
			
			 string[] input= Console.ReadLine().Split(" ");
			int n = int.Parse(input[0]);
			int k = int.Parse(input[1]);
			int cnt = 0;
			bool[] s = new bool[n];
			for(int i = 0; i < k; i++)
			{
				int d = int.Parse(Console.ReadLine());
				string[] input2 = Console.ReadLine().Split(" ");
				for(int j = 0; j < d; j++)
				{
					
					s[int.Parse(input2[j])-1] = true;
				}
			}
			for(int aa = 0; aa < n; aa++)
			{
				if (s[aa] == false)
					cnt++;
			}
			Console.WriteLine(cnt);
			
		}

		
	}

}

	

Measured memory_bytes: 27560
N=int(input())
A=list(map(int,input().split()))
def count_two(num):
    flag=0
    count=0
    while flag==0:
        if num%2==0:
            count+=1
            num=int(num/2)
        else:
            flag=1
    return count

ans=0
for temp in A:
    ans+=count_two(temp)
print(ans)


Measured memory_bytes: 4148
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

ll a[200010];

int main() {
  int n;cin>>n;
  rep(i,n) cin>>a[i];
  ll ans = 0;
  ll sum = 0;
  int r = 0;
  rep(l,n) {
    while(r<n&&sum+a[r]==(sum^a[r])){
      sum+=a[r];
      r++;
    }
    ans += r-l;
    if(l==r) r++;
    else sum-=a[l];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5164
#include<stdio.h>

int main(){
  int x=1;
  int n=0;
  int p[101]={0};
  int q[102]={0};
  scanf("%d %d",&x,&n);
  if(n==0){
    printf("%d",x);
    return 0;
  }
  
  int i;
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
    q[p[i]]=1;
  }

  if(q[x]==0){
    printf("%d",x);
    return 0;
  }
  i=1;
  while(1){
    if(q[x-i]==0){
      printf("%d",x-i);
      return 0;
    }else if(q[x+i]==0){
      printf("%d",x+i);
      return 0;
    }
    i++;
  }
  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int main(){
    string S,T;
    int A,B;
    string U;
    cin >> S >> T >> A >> B >> U;
    if(S==U) cout << --A << " " << B << endl;
    else cout << A << " " << --B << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define debug(var) std::cout << #var << " : " << var << std::endl;
using ll = long long;
using ull = unsigned long long;
ll mod = 1e9 + 7;


int main(){


	std::array<int, 3> arr;
	std::cin >> arr[0] >> arr[1] >> arr[2];
	int K; std::cin >> K;
	std::sort(arr.begin(), arr.end());

	rep(i, K){
		arr[2] *= 2;
	}

	std::cout << arr[0] + arr[1] + arr[2];

	
	return 0;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

# define fr(a,b) for(int i = a; i < b; i++)
# define rep(i,a,b) for(int i = a; i < b; i++)

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;


void solve(){
    int n;
    cin >> n;
    unordered_map<string,int> mp;
    fr(0,n) {
        string s; cin >> s;
        mp[s]++;
    }

    cout << "AC x " << mp["AC"];line
    cout << "WA x " << mp["WA"];line
    cout << "TLE x " << mp["TLE"];line
    cout << "RE x " << mp["RE"];line



    return;
}
int main(){
	fast
	int t=1;
	//cin >> t;
	while(t--){
             solve();
    }

	R 0;
}


Measured memory_bytes: 3636
import std.stdio, std.range,std.array, std.algorithm, std.algorithm, std.conv;

int[] furui(long max)
{
  int[] vs = 1.repeat().take(max).array;
  vs[0] = 0; vs[1] = 0;
  for (long i = 3; i < max; i+=2) {
    if (vs[i] == 0) {
      continue;
    }
    long j = i+i;
    while (j < max) {
      vs[j] = 0;
      j += i;
    }
  }
  return vs;
}


void main()
{
  long N;
  readf("%d\n", &N);
  int[] ps = furui(55555);
  long[] vs = [];
  long i = 3;
  for (;vs.length != N;i+=2) {
    if (ps[i] == 1 && i%5 == 1) {
      vs ~= i;
    }
  }
  vs.map!(to!string).join(" ").writeln();

}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true){
            final int n = Integer.parseInt(br.readLine());
            if (n == 0) { break; }
             
            Map<String, Long> data = new HashMap<>(n);
            List<String> out = new ArrayList<>();
            for (int i=1; i <= n; i++) {
                String[] st = br.readLine().split(" ");
                String e = st[0];
                long p = Long.parseLong(st[1]);
                long q = Long.parseLong(st[2]);
                long total = data.getOrDefault(e, 0L) + p * q;
                data.put(e, total);
                if (total >= 1_000_000L) {
                    if (out.contains(e) == false) {
                        System.out.println(e);
                        out.add(e);
                    }
                }
            }
            if (out.isEmpty()) {
                System.out.println("NA");
            }
        }
    }
}

Measured memory_bytes: 27196
#include<iostream>
#include<cstdio>
using namespace std;
struct A
{
	bool in;
	int cnt;
};
A box[100001];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	box[1].in=true;
	for(int i=1;i<=n;i++)
		box[i].cnt=1;
	int a,b;
	while(m--)
	{
		scanf("%d%d",&a,&b);
		box[a].cnt--;
		if(box[a].in)
			box[b].in=true;
		if(box[a].cnt==0)
			box[a].in=false;
		box[b].cnt++;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(box[i].in)
			ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=1e5+5;
int n,m,p,a[N],b[N],ans=1e9;

signed main(){
	read(n,m,p);
	for(int i=1;i<=n;i++) read(a[i]);
	for(int i=1;i<=m;i++) read(b[i]);
	ans=*min_element(a+1,a+1+n)+*min_element(b+1,b+1+n);
	while(p--){
		int x,y,z;
		read(x,y,z);
		ans=min(ans,a[x]+b[y]-z);
	}
	write(ans);
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;

  vector<ll> A(a),B(b),C(c),V;

  for(int i=0;i<a;i++)cin>>A[i];
  for(int i=0;i<b;i++)cin>>B[i];
  for(int i=0;i<c;i++)cin>>C[i];

  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());
  sort(C.begin(), C.end());

  ll ans=0;
  for(int i=0;i<x;i++){V.push_back(A[i]);ans+=A[i];}
  for(int i=0;i<y;i++){V.push_back(B[i]);ans+=B[i];}
  sort(V.begin(), V.end());

  for(int i=0;i<x+y;i++){
    if(C.back()<=V[i]){break;}
    ans -= V[i];ans += C.back();C.pop_back();
    if(C.size()==0)break;
  }
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 4852
n = int(input())
cnt = 0
a = 0
b = 0
ba = 0
for i in range(n):
    s = input()
    cnt += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        ba += 1
    elif s[0] == "B":
        b += 1
    elif s[-1] == "A":
        a += 1

if ba == 0:
    cnt += min(a, b)
else:
    if a == 0 and b == 0:
        cnt += ba - 1
    else:
        cnt += ba + min(a, b)
print(cnt)

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

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define debug(x) cerr << (#x) << "is "<< x << "\n"

using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;

int32_t main(){
	ios::sync_with_stdio(NULL);
	cin.tie(NULL);
	int n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;
	s+=".";
	a--,b--,c--,d--;
	int ma=0,cc=0;
	f(i,a,c+1){
		cc = (s[i]=='#')?++cc:0;
		ma = max(cc,ma);
	}
	if(ma>=2){
		cout << "No\n";
		return 0;
	}
	ma=0,cc=0;
	f(i,b,d+1){
		cc = (s[i]=='#')?++cc:0;
		ma = max(cc,ma);
	}
	if(ma>=2){
		cout << "No\n";
		return 0;
	}
	int posb=-1;
	f(i,b,d+1){
		if(i==0){
			continue;
		}
		if(s[i]=='.'){
			if(s[i+1]=='.' and s[i-1]=='.'){
				posb=i+1;
			}
		}
	}
	if(c<d){
		cout << "Yes\n";
		return 0;
	}
	else{
		if(posb==-1){
			cout << "No\n";
		}
		else{
			cout << "Yes\n";
		}
	}
	// if(posb==-1){
	// 	cout << "No\n";
	// 	return 0;
	// }
	// bool chk1=false,chk2=false;
	// s[d] == '#';
	// ma=0,cc=0;
	// f(i,a,c+1){
	// 	cc = (s[i]=='#')?++cc:0;
	// 	ma = max(cc,ma);
	// }
	// s[d]='.';
	// if(ma<2){
	// 	chk1=true;
	// }
	// s[c]='#';
	// ma=0,cc=0;
	// f(i,a,c+1){
	// 	cc = (s[i]=='#')?++cc:0;
	// 	ma = max(cc,ma);
	// }
	// if(ma<2){
	// 	chk2=true;
	// }
	// if(chk1 or chk2) cout << "Yes\n";
	// else cout << "No\n";
	return 0;
}

Measured memory_bytes: 592
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

int a,b;
int main(){
 
cin>>a>>b;
    if((a%3==0)||(b%3==0)||((a+b)%3==0)){
        cout<<"Possible"<<endl;
    }
    else{
        cout<<"Impossible"<<endl;
        
    }




}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int p=100000;
    for(int i=0;i<n;i++){
       p=p*1.05;
       if(p%1000!=0){
         p=p/1000*1000+1000;
       }
    }
    cout<<p<<endl;
    return 0;
}


Measured memory_bytes: 3084
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
long long a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(a+b+1>=c)
	    cout<<b+c;
    else
        cout<<b+(a+b+1);
	return 0;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}

	inline int ts(char *s)
	{
		int a=0,c=fetch();
		while(c<=32 && c!=EOF)c=fetch();
		while(c>32 && c!=EOF)s[a++]=c,c=fetch();
		s[a]=0;
		return a;
	}
}
using ae86::ty;
using ae86::ts;

const int _ = 200007;

int n;char s[_];
int stk[_]={0},top=0;

int main()
{
	n=ts(s+1);
	for(int i=2,las=s[1],cnt=1;i<=n+1;i++)
	{
		if(s[i]!=las)stk[++top]=cnt,cnt=1,las=s[i];
		else cnt++;
	}

	int ans=0;
	for(int i=1;i<=top;i++)
	{
		if(!stk[i])continue;
		if(stk[i]%3==1 || stk[i]%3==0)ans+=stk[i]/3*2+stk[i]%3;
		else if(stk[i+1])ans+=(stk[i]+1)/3*2,stk[i+1]--;
		else ans+=(stk[i]+1)/3*2-1;
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 1280
#include <cstdio>
typedef long long LL;
const int N=1000005,mo=998244353;
LL fac[N],inv[N];
LL ksm(LL x,int y){
	LL i=1;
	for (;y;y>>=1,x=x*x%mo)
		if (y&1) i=i*x%mo;
	return i;
}
void Pre(int n){
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mo;
	inv[n]=ksm(fac[n],mo-2);
	for (int i=n;i>=1;i--) inv[i-1]=inv[i]*i%mo;
}
LL C(int n,int m){
	return n<m||m<0?0:fac[n]*inv[m]%mo*inv[n-m]%mo;
}
LL INV(int n){
	return inv[n]*fac[n-1]%mo;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	Pre(n+m);
	int ans=0,sum=0,s=C(n+m,n);
	for (int i=1;i<=n+m;i++){
		if (i&1)
			s=(s+C(i-2,i/2)*C(n+m-i+1,n-i/2))%mo;
		else
			s=(s-C(i-2,i/2-1)*C(n+m-i,n-i/2)*2)%mo;
		sum=(sum+s)%mo;
		ans=(ans+sum*INV(i))%mo;
	}
	ans=ans*ksm(C(n+m,n),mo-2)%mo;
	printf("%d\n",(ans+mo)%mo);
}

Measured memory_bytes: 15744
def solve(n, s, t):
    count = 0
    for i in range(n):
        if s[i:] == t[:n - i]:
            return 2 * n - (n - i)
    return 2 * n

_n = int(input())
_s = input()
_t = input()
print(solve(_n, _s, _t))


Measured memory_bytes: 38384
xretu = []
xtasi = []

while True:
  retu = int(input())
  if retu == 0:
    break
  xretu.append(retu)
#print(xretu)
for a in xretu:
  xtasi.append(str(a))
#print(xtasi)
for b in xtasi:
  kei = 0
  bnaga = len(b)
  for c in range(bnaga):
    kei += int(b[c])
  print(kei)


Measured memory_bytes: 5616
import sys
write = sys.stdout.write

a = list(map(int,input().split()))
x1 = a[0]
y1 = a[1]
x2 = a[2]
y2 = a[3]

x4 = x1 + y1 - y2
y4 = x2 + y1 - x1
x3 = x4 + y4 - y1
y3 = x1 + y4 - x4

write(str(x3) + " " + str(y3) + " " + str(x4) + " " + str(y4) + "\n")

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[s.size()-1] == 's') s += "es";
    else s += 's';
    cout << s << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define LL long long
#define INF 0x7FFFFFFF//or 0x3f3f3f3f ?
using namespace std;

template<class T> inline
void read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;

LL n, A, B, T;
LL a[N], c[N];

int check(LL k) {
    for (int i = 1; i <= n; i++) c[i] = a[i] - k * B;
    LL cnt = 0;
    for (int i = 1; i <= n; i++)
        if (c[i] > 0) cnt += (c[i] / T) + (c[i] % T ? 1 : 0);
    return cnt <= k;
}

int main() {
    read(n), read(A), read(B); T = A - B;
    for (int i = 1; i <= n; i++) read(a[i]);
    int l = 0, r = 1000000000, ans = 0;
    while (l <= r) {
        int m = (l + r) >> 1;
        if (check(m)) {
            ans = m;
            r = m - 1;
        } else l = m + 1;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI a(n);
    vector<double> b(n);
    REP(i,0,n) cin >> a[i];
    sort(all(a));
    int maxv = a[n-1];
    REP(i,0,n) {
        b[i] = 1.0 * maxv / 2 - a[i];
    }
    sort(all(b), [](auto &l, auto &r) {
        return abs(l) < abs(r);
    });
    cerr << b[0] << endl;
    cout << maxv << " " << int(1.0 * maxv / 2 - b[0]) << endl;
}

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


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int tag[2000005];
int main()
{
    int n;
    cin>>n;
    int maxs=-1000000005,mins=1000000005;
    //cout<<mins<<endl;
    for(int i=0;i<n;i++)
    {
        cin>>tag[i];
        if(i&&tag[i]-mins>maxs) maxs=tag[i]-mins;
        if(tag[i]<mins) mins=tag[i];
    }
    cout<<maxs<<endl;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int N, K; cin >> N >> K;

  ll ans = 0;
  for (int b=K+1; b<=N; ++b) {
    ans += (b-K) * (N/b) + max(0, N%b - (K-1));
  }

  if (K == 0) ans -= N;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_C
 */
#include <iostream>
#include <vector>
#include <map>

using namespace std;

class Die
{
    enum fname {
        top, front, right, left, back, bottom,
    };

    vector<int> faces;
    map<fname, int> f2i;

    bool
    check_rest(Die &x)
    {
        if (faces[f2i[right] ] != x.Right() ) { return false; }
        if (faces[f2i[left]  ] != x.Left()  ) { return false; }
        if (faces[f2i[back]  ] != x.Back()  ) { return false; }
        if (faces[f2i[bottom]] != x.Bottom()) { return false; }
        return true;
    }

    bool
    check_top(Die &x)
    {
        turn_s();
        const string roll = "EEEE";
        bool ret = false;
        for (auto it : roll) {
            if (faces[f2i[top]] == x.Top()) {
                ret |= check_rest(x);
            }
            turn(it);
        }
        return ret;
    }

    void
    turn_e() {
        int tmp = f2i[top];
        f2i[top] = f2i[left];
        f2i[left] = f2i[bottom];
        f2i[bottom] = f2i[right];
        f2i[right] = tmp;
    }

    void
    turn_n() {
        int tmp = f2i[top];
        f2i[top] = f2i[front];
        f2i[front] = f2i[bottom];
        f2i[bottom] = f2i[back];
        f2i[back] = tmp;
    }

    void
    turn_s() {
        int tmp = f2i[top];
        f2i[top] = f2i[back];
        f2i[back] = f2i[bottom];
        f2i[bottom] = f2i[front];
        f2i[front] = tmp;
    }

    void
    turn_w() {
        int tmp = f2i[top];
        f2i[top] = f2i[right];
        f2i[right] = f2i[bottom];
        f2i[bottom] = f2i[left];
        f2i[left] = tmp;
    }

public:
    Die()
    {
        faces.reserve(6);

        f2i.emplace(top, 0);
        f2i.emplace(front, 1);
        f2i.emplace(right, 2);
        f2i.emplace(left, 3);
        f2i.emplace(back, 4);
        f2i.emplace(bottom, 5);
    }

    ~Die()
    {
        faces.clear();
        f2i.clear();
    }

    void
    read_faces(istream &is) {
        for (int i = 0; i < 6; i++) {
            is >> faces[i]; is.ignore();
        }
    }

    bool
    operator==(Die &x) {
        const string aface = "NENENE";
        bool ret = false;
        for (auto it : aface) {
            if (faces[f2i[top]] == x.Front()) {
                ret |= check_top(x);
            }
            turn(it);
        }
        return ret;
    }

    void
    turn(const char c) {
        switch (c) {
          case 'N':
            turn_n();
            break;
          case 'E':
            turn_e();
            break;
          case 'S':
            turn_s();
            break;
          case 'W':
            turn_w();
            break;
        }
    }

    int Top()    { return faces[f2i[top]   ]; }
    int Front()  { return faces[f2i[front] ]; }
    int Right()  { return faces[f2i[right] ]; }
    int Left()   { return faces[f2i[left]  ]; }
    int Back()   { return faces[f2i[back]  ]; }
    int Bottom() { return faces[f2i[bottom]]; }
};

int
main()
{
    ios::sync_with_stdio(false);

    Die d1, d2;
    d1.read_faces(cin);
    d2.read_faces(cin);

    cout << (d1 == d2 ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#include <vector>

void print(std::vector<int> &vec){
    for(int i = 0; i < vec.size(); ++i){
        std::cout << vec.at(i);
        if(vec.size() - 1 != i){
            std::cout << " ";
        }else{
            std::cout << std::endl;
        }
    }
}

void insertionSort(std::vector<int> &vec){
    int n = vec.size();
    // This function sorts the partial array from the index "0" to "i" at each step.
    // In the loop where the "i + 1" th value is considered, the value will be inserted in a proper place in the "0-i" array or its end.
    for(int i = 1; i < vec.size(); ++i){
        auto v = vec.at(i), j = i - 1;
        while(0 <= j && v < vec.at(j)){
            vec.at(j + 1) = vec.at(j);
            --j;
        }
        // Because of "--j" at the end of the while loop, j indicate the index prior to the target place by 1.
        // Hence, j has to be incremented before the "v" is inserted in the proper place.
        vec.at(j + 1) = v;

        print(vec);
    }
}

int main(){
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for(int i = 0; i < n; ++i){
        std::cin >> a.at(i);
    }

    print(a);
    insertionSort(a);
    
    return 0;
}


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

#define int long long

auto check(string s) -> bool {
    for(int i=0; i<s.size()-1; ++i) if(s[i]!=s[i+1]) return false;
    return true;
}

auto solve(string s, char target) -> int {
    int res = 0;
    while(true) {
        if(check(s)) return res;
        string t = "";
        for(int i=0; i<s.size()-1; ++i) {
            if(s[i]==target) t += s[i];
            else t += s[i+1];
        }
        s = t;
        res++;
    }
}

auto main() -> signed {
    string s;
    cin >> s;
    int ans = 1e+9;
    for(int k=s.size()-1; k>=0; --k) {
        char target = s[k];
        ans = min(ans, solve(s, target));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;i++)
#define fs first
#define sc second
#define MAXN 1000005
#define LIMIT 1500
#define LOGN 22
#define MOD 1000000009
#define pb push_back
#define ll long long
#define lc 2*pos
#define rc 2*pos+1
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    int n;
    ll l,r,ans=0;
    priority_queue<ll>lo;
    priority_queue<ll,vector<ll>,greater<ll>>hi;
    ll lazyLo=0,lazyHi=0;
    cin>>n;
    n--;
    cin>>l>>r;
    hi.push(l),lo.push(l);
    while(n){
        n--;
        lazyHi+=r-l;
        cin>>l>>r;
        lazyLo-=r-l;
        if(l>=hi.top()+lazyHi){
            ll shifted=hi.top()+lazyHi;
            ans+=l-shifted;
            hi.push(l-lazyHi);
            hi.push(l-lazyHi);
            hi.pop();
            lo.push(shifted-lazyLo);
        }else if(l<=lo.top()+lazyLo){
            ll shifted=lo.top()+lazyLo;
            ans+=shifted-l;
            lo.push(l-lazyLo);
            lo.push(l-lazyLo);
            lo.pop();
            hi.push(shifted-lazyHi);
        }else{
            hi.push(l-lazyHi);
            lo.push(l-lazyLo);
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2036
import java.io.*;
class Main{
	public static void main(String[] args) throws IOException {
		int[] n = new int[2];
		String[] str = new String[2];
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		str = in.readLine().split(" ");
		n[0] = Integer.parseInt(str[0]);
		n[1] = Integer.parseInt(str[1]);
		System.out.println(n[0]*n[1]+ " "+(2*n[0]+2*n[1]));
	}
}

Measured memory_bytes: 24044
n, l = map(int, input().split())

tastes = [l + i - 1 for i in range(1, n + 1)]

tmp = [sum(tastes) - tastes[i] for i in range(n)]
tmp2 = [abs(sum(tastes)-v) for v in tmp]
print(tmp[tmp2.index(min(tmp2))])


Measured memory_bytes: 3060
#include <iostream>


using namespace std;

int n = 16;

struct obstacles {
  bool above;
  bool left;
  int value;
};



int main() {

  int input;
  cin >> input;

  for (int j = 0; j < input; j++) {
    obstacles grid[n][n];

    for (int rowi = 0; rowi < n; rowi++) {
      for (int coli = 0; coli < n; coli ++) {
	if (coli == 0) {
	  grid[rowi][coli].above = true;
	} else {
	  grid[rowi][coli].above = false;
	}
	if (rowi == 0) {
	  grid[rowi][coli].left =  true;
	} else {
	  grid[rowi][coli].left = false;
	}
	grid[rowi][coli].value = 0;
      }
    }

    int goalx, goaly;

    cin >> goalx >> goaly;
    int n_matatabi;
    
    cin >> n_matatabi;
    
     for (int m = 0; m < n_matatabi; m++) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      if (x1 == x2) { // vertical link |
	if (y1 > y2) {
	  grid[x1][y1].above = true;
	} else {
	  grid[x1][y2].above = true;
	} 
      }
      if (y1 == y2) { //horizontal link -
	if (x1 > x2) {
	  grid[x1][y1].left = true;
	} else {
	  grid[x2][y1].left = true;
	}
      }
      }

  
    
    for (int x = 0; x <= goalx; ++x) {
      for (int y = 0; y <= goaly; ++y) {
	if (x == 0 && y == 0) {
	  grid[0][0].value = 1;
	  continue;
	}
	int above = 0, left = 0;
	if (grid[x][y].above == false) {
	  above = grid[x][y-1].value;
	}
	if (grid[x][y].left == false) {
	  left = grid[x - 1][y].value;
	}
	grid[x][y].value = above + left;
      }
    }
    
    if (grid[goalx][goaly].value == 0) {
      cout << "Miserable Hokusai!" << endl;
    } else {
      cout << grid[goalx][goaly].value << endl;
    }
  }
}
  
 


  
  
  
 

Measured memory_bytes: 1160
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: u32 = read();
    let b: u32 = read();
    let c: u32 = read();

    let ans = if a < b && b < c { "Yes" } else { "No" };
    println!("{}", ans);
}



Measured memory_bytes: 5020
n = gets.to_i
cards = gets.chomp.split(" ").map(&:to_i)

puts cards.join(" ")

for i in 1..n - 1
    card = cards[i]
    j = i - 1
    while (j >= 0) && cards[j] > card
        cards[j + 1] = cards[j]
        j -= 1
        cards[j + 1] = card

    end
    puts cards.join(" ")
end


Measured memory_bytes: 6896
#include <stdio.h>                                            
#include <math.h>
 
int i, t;
int n;
int flag = 0;
long long ans = 1;
int a[100000];
 
int main(){
  scanf("%d", &n);
  if(n%2) flag = 1;
  for(i = 0; i < (flag?(n+1):n)/2; i++)a[i] = 2;
  if(flag) a[0]--;
  for(i = 0; i < n; i++){
    scanf("%d", &t);
    if(!flag) t--;
    a[t/2]--;
  }
  for(i = 0; i < (flag?(n+1):n)/2; i++){
    if(a[i] != 0){ 
      printf("0\n");
      return 0;
    }   
  }
  for(i = 0; i < (flag?(n-1):n)/2; i++){
    ans*=2;
    ans%=1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,m,sl[605][605],sc[605][605],N;
bool g[605][605];
LL res;
bool readch(){
	char c=getchar();
	while(c==' '||c=='\n') c=getchar();
	return (c=='#');
}
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    int i,j,k;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;++i){
		for(j=0;j<m;++j){
			g[i+j][i-j+m-1]=readch();
		}
	}
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
	N=n+m-1;
	for(i=0;i<N;++i){
		for(j=0;j<N;++j){
			sl[i][j]=sc[i][j]=g[i][j];
			if(j) sl[i][j]+=sl[i][j-1];
			if(i) sc[i][j]+=sc[i-1][j];
		}
	}
    for(i=0;i<N;++i){
		for(j=0;j<N;++j){
			if(g[i][j]) for(k=j+1;k<N;++k){
				if(g[i][k]){
					int d=k-j;
					if(i+d<N) res+=(LL)sl[i+d][k];
					if(i+d<N && j) res-=(LL)sl[i+d][j-1];
					if(i>=d) res+=(LL)sl[i-d][k];
					if(i>=d && j) res-=(LL)sl[i-d][j-1];
				}
			}
		}
	}
	for(i=0;i<N;++i){
		for(j=0;j<N;++j){
			if(g[j][i]) for(k=j+1;k<N;++k){
				if(g[k][i]){
					int d=k-j;
					if(i+d<N) res+=(LL)sc[k-1][i+d];
					if(i+d<N) res-=(LL)sc[j][i+d];
					if(i>=d) res+=(LL)sc[k-1][i-d];
					if(i>=d) res-=(LL)sc[j][i-d];
				}
			}
		}
	}
	printf("%lld\n",res);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

Measured memory_bytes: 3456
a,b=[int(x) for x in input().split(" ")]
if a*2==b or a*4==b:
    print("Yes")
else:
    f=0
    for i in range(1,a):
        if (i*2+(a-i)*4)==b:
            f=1
            break
    if f==1:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 9176
#include <stdio.h>

int main(void)
{
   int n, i, f, s;

   scanf("%d",&n);

   f=0;s=0;
   for(i=1;i<10;i++){
     if((n % i == 0) && (n / i <= 9))
         f=1;
   }

   if(f==1) printf("Yes\n");
   else     printf("No\n");

   return 0;
}


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

int main() {
    ll K,N;cin >> K >> N;
    ll A[N] = {};
    for (int i = 0;i < N;i++) cin >> A[i];
    ll B[N] = {};ll sum = 0;
    for (int i = 0;i < N - 1;i++){
        B[i] = A[i + 1] - A[i];
        sum += B[i];
    }
    B[N - 1] = K - A[N - 1] + A[0];
    ll res = K;
    for (int i = 0;i < N;i++){
        res = min(res,K - B[i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 3328
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
      
      if(c>=a && c<=b){
      	System.out.println("Yes");
      }else{
      	System.out.println("No");
      }
          
	}
}

Measured memory_bytes: 35488
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

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

	int ans = 0;
	for(int i = 0; i < s.size() / 2; i++) {
		if(s[i] == s[(int)s.size() - i - 1]) continue;
		ans++;
	}
	
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

int calc(char c){
	if(c=='I')return 1;
	if(c=='V')return 5;
	if(c=='X')return 10;
	if(c=='L')return 50;
	if(c=='C')return 100;
	if(c=='D')return 500;
	if(c=='M')return 1000;
	return 0;
}

int main(){
	string s;
	//vector<int> n;
	//int ans;
	while(cin>>s){
		int ans=0;
		vector<int> n;

		for(int i=0; i<s.size(); i++){
			n.push_back(calc(s.at(i)));
		}
		for(int i=0; i<n.size(); i++){
			if(i<n.size()-1){
				if(n[i]<n[i+1])ans-=n[i];
				else ans+=n[i];
			}
			else{
				ans+=n[i];
			}
			//cout<<n[i]<<" "<<ans<<endl;
		}
		cout<<ans<<endl;
	}


}

Measured memory_bytes: 1208
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2==0:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7000
#include<iostream>
#include<map>
#include<vector>
#include<array>

const int DiceSizeFace = 6;

using namespace std;
using DiceSides = map<int, array<int, 4>>;
using Labels = map<int, int>;

int main() {
  DiceSides sides = {
    {1, {5, 3, 2, 4}},
    {2, {1, 3, 6, 4}},
    {3, {1, 5, 6, 2}},
    {4, {1, 2, 6, 5}},
    {5, {1, 4, 6, 3}},
    {6, {5, 4, 2, 3}},
  };
  Labels label_to_value_list;
  Labels value_to_label_list;

  for(int i = 1; i <= DiceSizeFace; i++) {
    cin >> label_to_value_list[i];
    value_to_label_list[label_to_value_list[i]] = i;
  }

  int question_size;
  cin >> question_size;

  for(int i = 0; i < question_size; i++) {
    int top_label, face_label;
    int top_value, face_value;
    cin >> top_value >> face_value;
    top_label = value_to_label_list[top_value];
    face_label = value_to_label_list[face_value];

    int right_label;
    for(int j = 0; j < sides[top_label].size(); j++) {
      if(sides[top_label][j] == face_label) {
        int right_labe_index = (j - 1 + sides[top_label].size()) % sides[top_label].size();
        right_label = sides[top_label][right_labe_index];
        break;
      }
    }

    cout << label_to_value_list[right_label] << endl;
  }
}



Measured memory_bytes: 3104