akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

template <class T>
T abs(T a) { return a < 0 ? -a : a; }

int main() {
    long long n, j = 0;
    std::cin >> n;

    if (n == 0) {
        std::cout << 0 << std::endl;
        return 0;
    }
    
    long long di;
    if (n > 0) {
        j = 1;
        di = 0;
        while (n > j) {
            j = (j << 2ll) + 1ll;
            di += 2;
        }
    } else {
        n = -n;
        j = 2;
        di = 1;
        while (n > j) {
            j = (j << 2ll) + 2ll;
            di += 2;
        }
        n = -n;
    }
    std::vector<int> v(di + 10);

    j = -1;
    while (n != 0) {
        //std::cout << "n: " << n << std::endl;
        long long k, d = 0ll;
        if (n > 0) {
            k = 1;
            d = 0;
            while (n > k) {
                k = (k << 2ll) + 1ll;
                d += 2;
            }
        } else {
            n = -n;
            k = 2;
            d = 1;
            while (n > k) {
                k = (k << 2ll) + 2ll;
                d += 2;
            }
            n = -n;
        }
        //std::cout << "d: " << d << std::endl;
        v[d] = 1;
        n -= (d % 2 == 0 ? 1 : -1) * (1ll << d);
        if (j == -1) j = d;
    }

    for (auto i = j; i >= 0; i--) {
        std::cout << v[i];
    }
    std::cout << std::endl;

    return 0;
}


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

int main(void){
    long long int n;
    std::cin >> n;
    std::vector<long long int> a(n);
    std::map<long long int, long long int> cnt_map;
    for(long long int i=0; i<n; i++){
        std::cin >> a[i];
    }
    for(int i=0; i<n; i++){
        if(cnt_map.find(a[i]) == cnt_map.end()){
            cnt_map[a[i]] = 1;
        }else{
            cnt_map[a[i]]++;
        }
    }
    

    long long int sum = 0;
    long long int before, after;
    for(auto i=cnt_map.begin(); i!=cnt_map.end(); i++){
        sum += i->second * (i->second - 1) / 2;
    }
    

    for(int i = 0; i < n; i++){
        if(cnt_map[a[i]]>1){
            before = cnt_map[a[i]] * (cnt_map[a[i]] - 1) / 2;
            after = (cnt_map[a[i]] - 2) * (cnt_map[a[i]] - 1) / 2;
            std::cout << sum - before + after << std::endl; 
        }else{
            std::cout << sum << std::endl;
        }
        
    }
    return 0;
    
}

Measured memory_bytes: 12544
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i = 0;i < (n); ++i)

int main() {
	long double a, b, x, pi;
	cin >> a >> b >> x;
	pi = acos(-1);
	long double ans;
	if (a *a* b >= 2 * x) {
		ans = atan(a * b * b / (2 * x));
		ans *= 180;
		ans /= pi;
			printf("%2.10llf\n", ans);
	}
	else {
		ans = atan((2 * a * a * b - 2 * x) / (a * a * a));
		ans *= 180;
		ans /= pi;
		printf("%2.10llf\n", ans);
	}

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
cb = [[-c,b] for b,c in bc]
from heapq import heappush, heappop, heapify
ret = 0
heapify(a)
heapify(cb)
flg = True
while flg and len(cb)>0:
    c,j = heappop(cb)
    for _ in range(j):
        if len(a)==0:
            flg=False
            break
        min_a = heappop(a)
        if min_a < -c:
            ret+=(-c)
        else:
            ret+=min_a
            flg=False
            break
ret+=sum(a)
print(ret)



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

int main() {
    string s;
    cin >> s;
    if(s[0] == s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>


using namespace std;

int main() {
    int n,k,i,count = 0;
    cin >> n >> k;
    int h[n];
    
    for(i = 0; i < n; i++) {
        cin >> h[i];
    }
    
    for(i = 0; i < n; i++) {
        if(h[i] >= k) {
            count += 1;
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 640
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String s = in.next();
		// char[] s = in.next().toCharArray();

		HashSet<String> set = new HashSet<>();

		int len = 1;
		int lenMax = 0;
		for ( int st = 0; st + len - 1 < n; st++ ) {
			String temp = s.substring(st, st + len);

			while ( s.indexOf(temp, st + len) > st ) {
				len++;
				temp = s.substring(st, st + len);
			}
			lenMax = Math.max(lenMax, len - 1);
		}

		System.out.println(lenMax);
		in.close();
	}
}

Measured memory_bytes: 39032
#include<iostream>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  double a = 0;
  double ans = 0;
  for(int i = 1;i <= n;i++){
    if(i % 2 == 1){
      a++;
    }
  }
  ans = a / n;
  cout << ans <<endl;
}

Measured memory_bytes: 3788
import java.util.*;
import java.util.Map.Entry;
 
class Main {
//	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
   public static void main(String[] args) {
	   
       Scanner sc = new Scanner(System.in);
       int X = sc.nextInt();
       int Y = sc.nextInt();
       int Z = sc.nextInt();
       int K = sc.nextInt();
//       int B = sc.nextInt();
//       String S = sc.next();
//       String T = sc.next();
//       char[] s = S.toCharArray();
//       char[] t = T.toCharArray();
       
       long[] a = new long[(int)X];
       for (int i=0 ; i<X; i++) {
           a[i] = sc.nextLong();
       } 
       long[] ab=new long[X*Y];
       long b = 0;
       for (int i=0 ; i<Y; i++) {
           b = sc.nextLong();
           for(int j=0;j<X;j++) {
        	   ab[i*Y+j]=a[j]+b;
           }
       }
       Arrays.sort(ab);
       long[] c = new long[(int)Z];
       for (int i=0 ; i<Z; i++) {
           c[i] = sc.nextLong();
       } 
       Arrays.sort(c);
	   long right=30000000001l;
	   long left=-1;
	   int[] okcnt=new int[X*Y];
	   while(right-left>1) {
		   long mid=left+(right-left)/2;
		   long cnt=0;

		   int zcnt=0;
		   boolean flg=false;
		   for(int i=X*Y-1;i>=0;i--) {
			   while(ab[i]+c[zcnt]<=mid) {
				  if(flg==true) {
					  okcnt[i]=-1;
					  break;
				  }
				  if(zcnt==Z-1) {
					  flg=true;
					  okcnt[i]=-1;
					  break;
				  }
				  zcnt++;
			   }
			   if(flg==false) {
				   okcnt[i]=zcnt;
				   cnt=cnt+Z-zcnt;				   
			   }
		   }
		   if(cnt<K) right=mid;
		   else left=mid;
	   }
       
	   long[] max=new long[3005];
	   Arrays.fill(max, right);
	   int cnt=0;
	   for(int i=0;i<X*Y;i++) {
		   if(okcnt[i]==-1)continue;
		   for(int k=okcnt[i];k<Z;k++) {
			   max[cnt]=ab[i]+c[k];
			   cnt++;
		   }
	   }
       
	   Arrays.sort(max);
	   StringBuffer ans = new StringBuffer();
	   for(int i=0;i<K;i++) {
		   ans.append(max[3004-i]);
		   ans.append("\n");
	   }
	   System.out.println(ans);
   }
      
}

Measured memory_bytes: 46912
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	cout << (h2 - h1) * 60 + m2 - m1 - k << "\n";

	return 0;
}



Measured memory_bytes: 3552
i = list(map(int, input().split()))
j = list(map(int, input().split()))
t = int(input())
ans = "NO"
if i[0] > j[0]: # 鬼が右側にいるとき
  i[1] = i[0] - t * i[1]
  j[1] = j[0] - t * j[1]
  if i[1] <= j[1]:
    ans = "YES"
elif i[0] < j[0]: # 鬼が左側にいるとき
  i[1] = i[0] + t * i[1]
  j[1] = j[0] + t * j[1]
  if i[1] >= j[1]:
    ans = "YES"
else:
    ans = "YES"

print(ans)

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

class UnionFind{
public:
  vector<int> p;		// 親
  vector<int> rank;	// サイズ・各集合の根のみ有効
  UnionFind(int n){
    p.resize(n, -1);
    rank.resize(n, 1);
  }
  int root(int x){
    if(p[x] == -1)return x;
    else return p[x] = root(p[x]); // 深さを 1 にしている
  }
  void unite(int x, int y){
    x = root(x); y = root(y);
    if(x == y)return;
    if(rank[x] > rank[y]) swap(x, y); // rankの小さいものを下につける
    rank[y] += rank[x];
    p[x] = y;
  }
  //xが属すグループのサイズ
  int size(int x){ return rank[root(x)]; }
  bool same(int x, int y){ return (root(x) == root(y)); }
};

void solve()
{
  ll n, m, a, b;
  cin >> n >> m;
  vector<P> br(m);
  for(int i = 0; i < m; ++i)
  {
    cin >> a >> b;
    a--; b--;
    br[i] = P(a, b);
  }

  reverse(br.begin(), br.end());
  UnionFind uf(n);

  stack<ll> ans;
  ll e_cnt = n * (n - 1) / 2;
  for(const auto& p : br)
  {
    ans.push(e_cnt);
    if (!uf.same(p.first, p.second))
    {
      e_cnt -= uf.size(p.first) * uf.size(p.second);
      uf.unite(p.first, p.second);
      if (uf.size(p.first) == n) e_cnt = 0;
    }
  }

  while(!ans.empty())
  {
    cout << ans.top() << endl;
    ans.pop();
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 5508
N = int(input())
d = map(int, input().split())

d = sorted(d)
l = len(d)

if l%2 == 0:
    if d[int(l/2)]-d[int((l/2)-1)]==0:
        print(0)
    else:
        print(d[int(l/2)]-d[int((l/2)-1)])

else:
    print(0)


Measured memory_bytes: 14396
#include<cstdio>
#include<cstring>

#define MAXN 100
int N[3];
char S[3][MAXN+5];

int main(){
    scanf("%s%s%s",S[0]+1,S[1]+1,S[2]+1);
    N[0]=strlen(S[0]+1),N[1]=strlen(S[1]+1),N[2]=strlen(S[2]+1);
    int i[3]={1,1,1},who=0;
    while(i[who]<=N[who]){
        char c=S[who][i[who]++];
        if(c=='a') who=0;
        else if(c=='b') who=1;
        else who=2;
    }
    if(who==0) puts("A");
    else if(who==1) puts("B");
    else puts("C");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n,m; cin >> n >> m; int a[n]; ll s = 0; ll cnt = 1;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++)
    {
        s += a[i];
        if(s <= m) cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		char[] ac = a.toCharArray();
		int count = 0;
		if (ac[0] == '1') count++;
		if (ac[1] == '1') count++;
		if (ac[2] == '1') count++;
		System.out.println(count);
	}	
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

int main()
{
    ll s;
    cin >> s;
    bool mm1 = false,mm2 = false;

    if(s / 100 <= 12 && s / 100 > 0)mm1 = true;
    if(s % 100 <= 12 && s % 100 > 0)mm2 = true;

    if(mm1 && mm2)cout << "AMBIGUOUS" << endl;
    else if(mm1)cout << "MMYY" << endl;
    else if(mm2)cout << "YYMM" << endl;
    else cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	// test 3 C
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int k = sc.nextInt();
		int n = sc.nextInt();
		
		int ary[] = new int[n];

		for(int i =0; i<n; i++) {
			ary[i] = sc.nextInt();
		}

		// 隣同士の距離を調査しつつ、最大の距離を求める。
		// 最大 > (K/2) の場合、それは K-最大 に adjust する
		int maxLen = 0;
		for(int i=0; i< (n-1); i++) {
			int j = i+1;
			int dist1;
			dist1 = ary[j]-ary[i];

//			if ( dist1 > (k/2) ) {
//				dist1 = k - dist1;
//			}
			if(maxLen<dist1)
				maxLen = dist1;
		}
		
		// end を調査
		int lastDist = k + ary[0] - ary[n-1];
		if (maxLen < lastDist)
			maxLen = lastDist;
		
		int tripLen = k - maxLen;
		
		log( tripLen );
		sc.close();
		
	}
	
	static void log(String s) {
		System.out.println(s);
	}

	static void log(int i) {
		System.out.println(i);
	}

	static void log(double d) {
		System.out.printf("%.12f\n",d);
	}

	
	
}


Measured memory_bytes: 82696
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );

vector<ll> dp;

/*
ll f(string s){
  char c=s[0];
  if(s.size()==1){
    if(c=='0') return dp[0];
    else return dp[1];
  }
  else{
    if(c=='0') return ( dp[s.size()-1 ] + f(s.substr(1)) )%mod;
    else return ( dp[ s.size()-1 ] + 2LL*f(s.substr(1)) )%mod;
  }
}
*/

int main(void){

  string l;
  cin>>l;

  string l_r=l;
  reverse(begin(l_r),end(l_r));

  dp.resize(100002,0);
  dp[0]=1;
  dp[1]=3;

  for(ll i=2;i<100002;i++){
    dp[i]=dp[i-1]*3LL % mod;
  }
  ll ans=0;
  for(ll i=0;i<l_r.size();i++){
    auto c=l_r[i];
    if(i==0){
      if(c=='0') ans=1;
      else ans=3;
    }
    else{
      if(c=='0') ans=(ans)%mod;
      else ans=(2LL*ans+dp[ i ])%mod;
    }
  }  

  cout << ans << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T> void dbg(T x) { cout << x << "\n"; }
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }


int main() {
    int n; cin >> n;
    set<int> S;
    rep(i, n) {
        int a; cin >> a;
        S.insert(a);
    }
    cout << S.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main(){
  int n, p[N+1], m[N+1][N+1], i, j, l, k;

  scanf("%d",&n);

  for( i = 1 ; i <= n ; i++ ) scanf("%d%d", &p[i-1], &p[i]);

  for( i = 1 ; i <= n ; i++ ) m[i][i] = 0;
  for( l = 2 ; l <= n ; l++ ){
    for( i = 1 ; i <= n-l+1 ; i++ ){
      j = i + l - 1;
      m[i][j] = (1<<21);
      for( k = i ; k <= j-1 ; k++ ){
	if( m[i][j] > m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j] ) m[i][j] =  m[i][k]+m[k+
1][j]+p[i-1]*p[k]*p[j];
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}



Measured memory_bytes: 2100
#include <stdio.h>
#include <string.h>
#define N 14
#define MAX 1000000
 
char G[MAX][N];
int top=0;
 
 
int getChar(char c){
  if(c=='A') return 1;
  else if(c == 'C') return 2;
  else if(c=='G') return 3;
  else if(c=='T') return 4;
  else return 0;
}
 
int get(char a[]){
  int sum=0;
  int p=1,i;
  for( i = 0; i < strlen(a); i++){
    sum += p*(getChar(a[i]));
    p *= 5;
  }
  return sum;
}
 
int g1(int data){return data % MAX;}
int g2(int data){return 1 + (data % (MAX-1));}
 
int find(char a[]){
  int key,i,g;
  key = get(a);
  i=0;
  while(1){
    g = (g1(key)+ i * g2(key)) % MAX;
    if(strcmp(G[g],a)==0) return 1;
    else if(strlen(G[g])==0) return 0;
    i++;
  }
  return 0;
}
 
int insert(char a[]){
  int key,i,g;
  key = get(a);
  i=0;
  while(1){
    g = (g1(key) + i * g2(key)) % MAX;
    if(strcmp(G[g],a)==0)return 1;
    else if(strlen(G[g])==0){
      strcpy(G[g],a);
      return 0;
    }
    i++;
  }
  return 0;
}
 
 
int main(){
  int i,j=0,b,k;
  char a[MAX][3],c[MAX],d[MAX];
 
  for(i=0;i<MAX;i++){
    G[i][0] = '\0';
  }
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%s%s",a[i],c);
  if(a[i][0] == 'i'){
    insert(c);
  }
  else{
    if(find(c)){
      printf("yes\n");
      
    }
    else{
      printf("no\n");
      
    }
  }
}
return 0;
}

Measured memory_bytes: 18160
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))

heapq.heapify(A)
for i in range(M):
    a = -heapq.heappop(A)
    heapq.heappush(A, -(a // 2))
print(-sum(A))


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

typedef long long ll;

ll N, K;
deque<ll> V;
ll R;

int main() {
  cin >> N >> K;
  V.resize(N);
  for (ll i = 0; i < N; ++i) cin >> V[i];
  for (ll i = 0; i <= N; ++i)
    for (ll j = 0; j <= N - i; ++j) {
      ll rest = K - i - j;
      if (rest < 0) continue;
      deque<ll> v = V;
      vector<ll> w;
      for (ll k = 0; k < i; ++k) {
        w.push_back(v.front());
        v.pop_front();
      }
      for (ll k = 0; k < j; ++k) {
        w.push_back(v.back());
        v.pop_back();
      }
      sort(w.begin(), w.end(), greater<ll>());
      while (w.size() > 0 && w.back() < 0 && rest > 0) {
        w.pop_back();
        --rest;
      }
      ll sum = 0;
      for (ll x : w) sum += x;
      R = max(R, sum);
    }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 256
/*  ex3_4
    B30095    */
#include <stdio.h>

int main(void){
    int num;
    int condition = 0; // is num a product of integers between 1 and 9
    scanf("%d", &num);
    
    if(1 <= num && num <= 81){  // num should be between 1(1*1) and 81(9*9) 
        for (int i = 1; i <= 9; i++){
            int quotient = num / i;
            int remainder = num % i;
            if((1 <= quotient && quotient <= 9) && (remainder == 0))
                condition = 1;
        }
    }

    if(condition) 
        printf("Yes");
    else 
        printf("No");

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm> /*sort()を使用するのに必要*/

using namespace std;

int main(){
    int N;
    vector<int> L;

    cin >> N;
    for(int i=0; i<N; i++){
        int j;
        cin >> j;
        L.push_back(j);
    }

    sort(L.begin(), L.end());

    int count = 0;
    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){

            //二分探索で3つめを絞る
            /*nt start = j + 1;
            int end = N - 1;
            int middle = (start + end) / 2;
            int k;
            while(start != end){
                if(L[middle] >= L[i] + L[j]){
                    end = middle - 1;
                }else{
                    continue;
                }
            }
            */

            for(int k = j+1; k<N; k++){
                if(L[i] >= L[j] + L[k]) continue;
                if(L[j] >= L[i] + L[k]) continue;
                if(L[k] >= L[i] + L[j]) continue; //すでにやっている
                count ++;
            }
        }
    }

    cout << count;

    return 0;

}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, T int
	fmt.Scan(&n, &T)
	
	t := make([]int, n)
	
	for i := range t {
		fmt.Scan(&t[i])
	}
	
	sum := 0
	for i  := 0; i < n-1; i++ {
		if t[i] + T > t[i+1] {
			sum += t[i+1] - t[i]
		} else {
			sum += T
		}
		
	}
	sum += T
	fmt.Println(sum)
}

Measured memory_bytes: 6488
class Panel(object):
    def __init__(self, name, depth, child, x1, y1, x2, y2):
        self.name = name
        self.depth = depth
        self.child = child
        self.x1 = x1
        self.y1 = y1
        self.x2 = x2
        self.y2 = y2

    def touch(self, x, y, depth):
        if depth < self.depth and self.x1 <= x <= self.x2 and self.y1 <= y <= self.y2:
            return self
        else:
            return None

    def __repr__(self):
        return f"{self.name} {self.child}"


def solve():
    import re
    while True:
        N = int(input())
        if N == 0:
            break

        S = input()
        panels = [Panel("OUT OF MAIN PANEL", 0, 1, 0, 0, 10000, 10000)]

        def rec(s, depth):
            child = 0
            while s:
                child += 1
                tag_name = re.match(r"<([^>]+)>", s).group(1)
                result = re.match(r"<%s>(\d+),(\d+),(\d+),(\d+)(.*?)</%s>" % (tag_name, tag_name), s)
                panels.append(Panel(tag_name, depth, rec(result.group(5), depth + 1), *(map(int, result.groups()[:4]))))
                s = s[result.span()[1]:]
            return child

        rec(S, 1)

        for _ in [0]*N:
            x, y = map(int, input().split())
            result = panels[0]
            for panel in panels[1:]:
                result = panel.touch(x, y, result.depth) or result
            print(result)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 6632
import sys
sys.setrecursionlimit(100000000)
n = int(input())
nodes = [[] for _ in range(n+1)]
done = [1 for _ in range(n+1)]
mod = int(1e9+7)
def dfs(next,pre):
    w=1
    b=1
    for v in nodes[next]:
        if v!=pre:
            white,black= dfs(v,next)
            w *= (white+black)
            b *= white
            w%=mod
            b%=mod
    return (w,b)

for i in range(n-1):
    a,b = map(int,input().split())
    nodes[a].append(b)
    nodes[b].append(a)
done[1]=0

ans = dfs(1,-1)
print(sum(ans)%mod)


Measured memory_bytes: 100528
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n;
  cin>>n;
  vector<ll> a(n),b(n);
  REP(i,n) cin>>a[i]>>b[i];

  ll v=0;
  for(int i=n-1;i>=0;i--){
    a[i]+=v;
    v+=(a[i]%b[i])? b[i]-a[i]%b[i]:0;
  }
  cout<<v<<endl;

  return 0;
}

Measured memory_bytes: 1792
n = int(input())
S = input()
s = list(S)
alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
al = list(alph)
for i in range(len(s)):
    s[i] = al[al.index(s[i])+n]
print(''.join(s))

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(){
  char ch,a;
  scanf("%c",&ch);
  a='\n';
  while(a!=ch){
    if(islower(ch)){
      printf("%c",toupper(ch));}
    else if(isupper(ch)){
      printf("%c",tolower(ch));}
    else printf("%c",ch);
    scanf("%c",&ch);
    }
  printf("%c",a);
  return 0;}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

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

ll n,a,b;

int main(){
	
	read(n);
	read(a);
	read(b);

	if(a%2==b%2){
		cout<<(b-a)/2<<endl;
	}
	else{
		ll x=(a+b-1)/2;
		ll y=(n-a+n-b+1)/2;
		cout<<min(x,y)<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

veci B(20);
int N,M,C;

int main() {
    int ans = 0;
    cin >> N >> M >> C;
    REP(i,M) cin >> B.at(i);
    REP(i,N) {
        int val = 0;
        REP(j,M) {
            int A;
            cin >> A;
            val += A*B.at(j);
        }
        val += C;
        if(val > 0) ans++;
    }
    cout << ans << endl;
}


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}


   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
const ll MAX_N = 21;
ll N;
ll a[MAX_N][MAX_N];
ll dp[MAX_N + 1][1ll << MAX_N] = {};

/* next combination */
ll next_combination(ll sub) {
    ll x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

int main(){
  cin >> N;
  REP(i, N){
    REP(j, N){
      cin >> a[i][j];
    }
  }
  dp[0][0] = 1;
  REP(i, N){
    ll s = (1 << (i + 1)) - 1;
    for (; s < (1 << N); s = next_combination(s)){
      REP(k, N){
        if ((s >> k) && 1){
          dp[i + 1][s] += dp[i][s &  ~(1ll << k)] * a[i][k];
          dp[i + 1][s] %= MOD;
//          printf("i + 1 = %lld, s = %lld, k = %lld, s and not 1<<k = %lld\n", i + 1, s, k, (s & ~ (1ll << k)));
        }
      }
//    printf("dp[%lld][%lld] = %lld\n", i+1, s, dp[i + 1][s]);
    }
  }
  cout << (dp[N][(1ll << N) - 1] % MOD) << endl;
}


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

int main() {
    int n, c; cin >> n >> c;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    long long v[401][c+1];
    long long sum[c+1][410];
    for (int i = 1; i <= 400; i++) {
        v[i][0] = 1;
        for (int j = 1; j <= c; j++) {
            v[i][j] = v[i][j-1] * i % mod;
        }
    }
    for (int i = 0; i <= c; i++) {
        sum[i][0] = 0;
        for (int j = 1; j <= 400; j++) {
            sum[i][j] = (sum[i][j-1] + v[j][i]) % mod;
        }
    }
    long long dp[n+1][c+1];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= c; j++) {
            // dp[i+1][j]
            for (int k = 0; k <= j; k++) {
                long long add = dp[i][k] * ((mod + sum[j-k][b[i]] - sum[j-k][a[i]-1]) % mod);
                dp[i+1][j] += add % mod;
                dp[i+1][j] %= mod;
            }
        }
    }
    cout << dp[n][c] << endl;
    return 0;
}

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

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true)
		{
			int H=sc.nextInt();
			int W=sc.nextInt();
			if(H==0)break;
			for(int i=0;i<H;i++)
			{
				for(int j=0;j<W;j++)
				{
					System.out.print('#');
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 39000
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define eps 1e-9
#define mp make_pair

int n,x,a[100005];
LL ans;

int main () {
	scanf("%d%d",&n,&x);
	a[0]=0;
	FOE(i,1,n) {
		scanf("%d",&a[i]);
		if (a[i]>x) {
			ans=(LL)ans+a[i]-x;	
			a[i]=x;
		}
		if (a[i]+a[i-1]>x) {
			ans=(LL)ans+a[i]+a[i-1]-x;
			a[i]-=(a[i]+a[i-1]-x);
		}
		//printf("%lld %lld\n",ans,a[i]);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 512
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<std::string> g(n);
	rep(i,n) std::cin >> g[i];
	// check if all white
	bool allwhite = true;
	rep(i,n) {
		bool check = true;
		rep(j,n) {
			if(g[j][i]=='#') check = false;
		}
		if(!check) {
			allwhite = false;
			break;
		}
	}
	if(allwhite) {
		print(-1); return 0;
	}
	// check black in row
	std::vector<int> brow(n,0);
	rep(i,n) {
		int count = 0;
		rep(j,n) {
			if(g[i][j]=='#') count++;
		}
		brow[i] = count;
	}
	// choose which row to make black
	int min = n;
	rep(i,n) {
		if(g[i][i]=='.' && brow[i]>0) {
			min = std::min(min, n-brow[i]+1);
		}
		rep(j,n) {
			if(g[i][j]=='#') {
				min = std::min(min,n-brow[j]);
			}
		}
	}
	// check if white exists for each column
	int whitecount = 0;
	rep(i,n) {
		bool exists = false;
		rep(j,n) {
			if(g[j][i]=='.') exists = true;
		}
		whitecount += (int)exists;
	}
	print(min+whitecount);
	return 0;
}


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

#include <algorithm>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)
signed main() {
    int n;
    cin >> n;
    vector<long long> as(n);
    vector<long long> bs(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
        if (as[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    long long ans = as[0];
    REP(i, n - 1) {
        if (ans <= (1000000000000000000LL / as[i + 1])) {
            ans *= as[i + 1];
            // cout << ans << endl;
            if (ans > 1e18) {
                cout << -1 << endl;
                return 0;
            }
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4760
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<stack>
#include<iterator>
#include<functional>
#include<string.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//namespace mp = boost::multiprecision;


int main() {
	int n; cin >> n;
	int sum = 0;
	int tmp = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		sum += a;
		if (a > tmp) {
			tmp = a;
		}
	}
	cout << sum - tmp / 2 << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)
 
int main() {
  long double L, a;
  cin >> L;

  a = L*L*L/27.0;
  //cout << a << endl;
  cout << fixed << setprecision(15) << a << endl;
  
}

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

vector<vector<int>> g;
vector<ll> f, ans;

void dfs(int v, int p) {
	for (auto nv : g[v]) {
		if (nv == p) continue;
		ans[nv] += ans[v];
		dfs(nv, v);
	}
}

int main() {
	int n, q;
	cin >> n >> q;
	g.assign(n, vector<int>());
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	ans.assign(n, 0);
	rep(i, q) {
		int p, x;
		cin >> p >> x;
		p--;
		ans[p] += x;
	}
	dfs(0, -1);
	rep(i, n) {
		cout << ans[i];
		if (i == n - 1) cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 25080
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>

#define INF 200000000
#define MOD 1000000007

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a;
    int tmp;
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        a.push_back(tmp);
    }
    int m;
    cin >> m;
    int tmp2;
    vector<pair<int, int>> p;
    for (int i = 0; i < m; i++)
    {
        cin >> tmp >> tmp2;
        p.push_back(make_pair(tmp, tmp2));
    }
    int sum;
    for (int i = 0; i < m; i++)
    {
        sum = 0;
        for (int j = 0; j < n; j++)
        {
            if (j == p[i].first - 1)
            {
                sum += p[i].second;
                continue;
            }
            sum += a[j];
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = list(map(int, input().split()))

# 2* x_0 = A[0] + A[N-1] + (A[2] + A[4] + ... (偶数項) ) - (A[1] + A[3] + ... (奇数項))
# あとは順次x_1, x_2, を求めていけば良い

even = 0
odd = 0
for i in range(N):
    if i % 2:
        odd += A[i]
    else:
        even += A[i]

X = [0] * N
X[0] = even - odd

for i in range(1, N):
    X[i] = 2*(A[i-1] - X[i-1]//2)

X = [str(x) for x in X]
print(" ".join(X))




Measured memory_bytes: 23868
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int s = 0; 
    for (int i = 0; i < n; i++) {
        s ^= a[i];
    }
    for (int i = 0; i < n; i++) {
        a[i] ^= s;
    }
    for (int i = 0; i < n; i++) {
        cout << a[i] << endl;
    }
    return 0;
}


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

int main() {
int A,B,c=0;
  cin>>A>>B;
if(B==1){
  cout<<0<<endl;
}
  else if(A>=B){
  cout<<1<<endl;
}
else{
  for(int i=2;i<7000*B;i++){
    if(((A-1)*i+1)>=B){
      cout<<i<<endl;
      break;
    }
    }
} 
}


Measured memory_bytes: 256
// 

// g++ -std=c++11 abc145_c.cc && ./a.out 
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n, m, i, j;
    cin >> n >> m;
    int c[m];
    rep(i, m) {
        cin >> c[i];
    }

    // dp[i]: i円払う場合の、コインの最小枚数
    // dp[0],..., dp[k-1]が確定した状態で、dp[k]を導くことは可能か？
    // dp[k] = min{dp[k-c0], dp[k-c1], ... , dp[k-cm]} + 1
    int dp[n+1];
    dp[0] = 0;
    dp[1] = 1;
    for (i = 2; i <= n; i++) {

        int tmp_min = 2147483647;
        rep(j, m) {
            if (i >= c[j]) {
                if (dp[i - c[j]] < tmp_min) {
                    tmp_min = dp[i - c[j]];
                }
            }
        }
        dp[i] = tmp_min + 1;
    }

    cout << dp[n] << endl;

    return 0;
}



Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, l; cin >> n >> l;
  V<> a(n);
  iota(begin(a), end(a), l);
  int s = accumulate(begin(a), end(a), 0);
  int mn = 1e9, res = -1;
  for (int i = 0; i < n; ++i) {
    int t = s - a[i];
    if (abs(t - s) < mn) {
      mn = abs(t - s);
      res = t;
    }
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
def chk(arr):
  if arr[0][1] and arr[1][1] and arr[2][1]:
    return True
  if arr[3][1] and arr[4][1] and arr[5][1]:
    return True
  if arr[6][1] and arr[7][1] and arr[8][1]:
    return True
  if arr[0][1] and arr[3][1] and arr[6][1]:
    return True
  if arr[1][1] and arr[4][1] and arr[7][1]:
    return True
  if arr[2][1] and arr[5][1] and arr[8][1]:
    return True
  if arr[0][1] and arr[4][1] and arr[8][1]:
    return True
  if arr[2][1] and arr[4][1] and arr[6][1]:
    return True
  return False

arr = [(int(_), False) for _ in input().split()]
arr.extend([(int(_), False) for _ in input().split()])
arr.extend([(int(_), False) for _ in input().split()])

n = int(input())

for _ in range(n):
  i = int(input())
  if arr.count((i, False)) == 1:
    index = arr.index((i, False))
    arr[index] = (i, True)

if chk(arr):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------


int main()
{
	
	int n, m;
	string s[111];
	string t[111];

	cin >> n;
	for (int i = 0;i < n;i++) cin >> s[i];

	cin >> m;
	for (int i = 0;i < m;i++) cin >> t[i];

	int ans = -INF;

	for (int i = 0;i < n;i++) {
		int tmp = 0;
		for (int j = 0;j < n;j++) {
			if (s[i] == s[j]) tmp++;
		}

		for (int j = 0;j < m;j++) {
			if (s[i] == t[j]) tmp--;
		}

		ans = max(ans, tmp);
	}

	cout << max(ans,0) << endl;

	return 0;
}



Measured memory_bytes: 256
n,m = map(int,input().split())
if n%2 == 1:
  for i in range(1,m+1):
    print(i,n+1-i)
else:
  c = 0
  for i in range(1,(n//4)+1):
    print(i,n+1-i)
    c += 1
    if c == m:
      exit()
  j = n//2
  while True:
    print(j,n+2-j)
    c += 1
    if c == m:
      exit()
    j -= 1
  
                 
    

Measured memory_bytes: 69628
S = input()

odd_list = ['R', 'U', 'D']
even_list = ['L', 'U', 'D']

answer = 'Yes'
for i in range(0, len(S)):
    if (i+1) % 2 == 0:
        if S[i] not in even_list:
            answer = 'No'
            break
    else:
        if S[i] not in odd_list:
            answer = 'No'
            break

print(answer)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define N 2019
using namespace std;
int main() {
  long long L, R, answer = N;
  cin >> L >> R;
  if (R-L+1 >= N) {
    cout << 0;
  } else {
    for (long long i = L; i < R; i++) {
      for (int j = i+1; j <= R; j++) {
        answer = min(answer,i*j%N);
      }
    }
    cout << answer;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
// typedef vector<int,vector<int>> vvec;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
// inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
// inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
const int MOD=1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#define here  cout<<"Here"<<endl;


//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;


int N,M;
string S;

signed main(){
  int X,Y,Z;cin>>X>>Y>>Z;
  cout<<Z<<" "<<X<<" "<<Y<<"\n";

}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];

    int ans=gcd(a[0],a[1]);

    for(int i=2;i<n;i++){
        ans=gcd(ans,a[i]);
    }

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

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

int main() {
  int N, K, n=1;
  cin >> N >> K;
  for (int i=0; i<N; i++) {
    if (2*n >= n+K) {
      n += K;
    }
    else {
      n *= 2;
    }
  }
  cout << n <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

vector<vector<pair<int, int>>> tree(100100);
vector<int> ans(100100);
vector<bool> visited(100100, false);

void search(int sear, int len)
{
  if (visited.at(sear)) return;
  visited.at(sear) = true;
  ans.at(sear) += len;
  ans.at(sear) %= 2;
  for (int i = 0; i < tree.at(sear).size(); i++)
  {
    search(tree.at(sear).at(i).first, 
           (len + tree.at(sear).at(i).second) % 2);
  }
  return;
}

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

  for (int i = 0; i < N - 1; i++)
  {
    int u, v, w;
    cin >> u >> v >> w;
    w %= 2;
    pair<int, int> p;
    p.second = w;
    p.first = v;
    tree.at(u).push_back(p);
    p.first = u;
    tree.at(v).push_back(p);
  }

  search(1, 0);

  for (int i = 1; i <= N; i++) cout << ans.at(i) << endl;
}

Measured memory_bytes: 8448
use proconio::{fastout, input};

const M: i128 = 1e+9 as i128 + 7;

#[fastout]
fn main() {
    input! {in_n: usize, in_k: usize};
    let mut cnt = vec![0i128; in_k + 1];

    let mut n = in_n;
    let mut mul = Vec::new();

    while n != 0 {
        if n % 2 == 1 {
            mul.push(true);
            n -= 1;
        } else {
            mul.push(false);
        }

        n /= 2;
    }

    for k in 1..=in_k {
        let mut p = (in_k / k) as i128;
        let mut v = 1i128;

        for m in &mul {
            if *m {
                v = (v * p) % M;
            }
            p = (p * p) % M;
        }

        cnt[k] = v;
    }

    for k in (1..=in_k).rev() {
        for j in ((k * 2)..=in_k).step_by(k) {
            cnt[k] = (cnt[k] - cnt[j] + M) % M;
        }
    }

    let mut count = 0i128;

    for k in 1..=in_k {
        count = (count + cnt[k] * k as i128) % M;
    }

    println!("{}", count);
}


Measured memory_bytes: 3652