akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long n,a,b,min_n,m,sum=0L;
    cin>>n;
    vector<long>e(n+1,0),c(n),ans(n);
    vector<pair<long,long>>ab(n);
    for(long i=1;i<n;i++){
        cin>>a>>b;
        e[a]++;
        e[b]++;
        ab[i]=make_pair(a,b);
    }
    for(long i=0L;i<n;i++)cin>>c[i];
    sort(c.begin(),c.end());
    for(long i=0L;i<n;i++){
        //for(long j=0L;j<n;j++)cout<<e[j]<<(j==n-1?"\n":" ");
        min_n=100000L,m=100000L;
        for(long j=1L;j<=n;j++)if(e[j]<min_n)min_n=e[j],m=j;
        ans[m-1]=c[i];
        e[m]=100000L;
        for(int j=1L;j<n;j++){
            if(ab[j].first==m)e[ab[j].second]--;
            if(ab[j].second==m)e[ab[j].first]--;
        }
    }
    for(long i=1;i<n;i++)sum+=min(ans[ab[i].first-1],ans[ab[i].second-1]);
    cout<<sum<<endl;
    for(long i=0L;i<n;i++)cout<<ans[i]<<(i==n-1?"\n":" ");
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<set>
#include<queue>
#include<algorithm>
#include<climits>
#include<map>
#include<unordered_map>
#define ll long long

bool isPrime(ll n){
    if(n%2==0 || n%3==0) return false;
    if(n<=1)  return false;
    if(n<=3)  return true;
    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0||n%(i+2)==0)
           return false;
    return true;
}

#define w(t) ll t,tt=1;	cin>>t;		while(t--)
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

#define vi vector<int>
#define vll vector<ll>
#define mii map<ll,ll>
#define umii unordered_map<ll,ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>

#define mod 1e9+7
#define inf 1e18

#define lln ll n; cin>>n
#define intn int n; cin>>n
#define YES cout<<"YES"
#define NO cout<<"NO"
#define strr    string str; cin>>str;
#define strn   n=str.length()
#define fr(a,n) for(ll i=a;i<n;i++)
#define loop for(ll i=0;i<n;i++)

using namespace std;

bool possible(int mid,int k,int arr[],int n){
    if(mid==0)  return false;
    int curr=0;
    loop{
        if(arr[i]>mid)   curr+=(arr[i]/mid);
    }
    return curr<=k;
}

void solve (){
    intn;
    int k;
    cin>>k;
    int arr[n];
    loop cin>>arr[i];
    int mid,low=1,high=1e9;
    while(low<high){
        mid=(low+high)/2;
        if(possible(mid,k,arr,n)) high=mid;
        else                low=mid+1;
    }
    cout<<high;
}

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


Measured memory_bytes: 4296
def segfunc(x,y):
  return x+y
ide_ele=0
class SegTree():
  def __init__(self,init_val,segfunc,ide_ele):
    n=len(init_val)
    self.segfunc=segfunc
    self.ide_ele=ide_ele
    self.num=1<<(n-1).bit_length()
    self.tree=[ide_ele]*2*self.num
    for i in range(n):
      self.tree[self.num+i]=init_val[i]
    for i in range(self.num-1,0,-1):
      self.tree[i]=self.segfunc(self.tree[2*i], self.tree[2*i+1])
  def update(self,k,x):
    k+=self.num
    self.tree[k]=x
    while k>1:
      self.tree[k>>1]=self.segfunc(self.tree[k],self.tree[k^1])
      k>>=1
  def query(self,l,r):
    res=self.ide_ele
    l+=self.num
    r+=self.num
    while l<r:
      if l&1:
        res=self.segfunc(res,self.tree[l])
        l+=1
      if r&1:
        res=self.segfunc(res,self.tree[r-1])
      l>>=1
      r>>=1
    return res
n,q=map(int,input().split())
c=list(map(int,input().split()))
st=SegTree([0]*n,segfunc,ide_ele)
lr=[[]for _ in range(n+1)]
for i in range(q):
  l,r=map(int,input().split())
  lr[r]+=[(l,i)]
d={}
for i in range(n):
  if not d.get(c[i]):d[c[i]]=[i]
  else:d[c[i]]+=[i]
for i in d:
  st.update(d[i][-1],1)
ans=[0]*q
r=n
while r>0:
  if lr[r]:
    l,i=lr[r].pop()
    ans[i]=st.query(l-1,r)
  while not lr[r] and r>0:
    if d[c[r-1]]:st.update(d[c[r-1]].pop(),0)
    if d[c[r-1]]:st.update(d[c[r-1]][-1],1)
    r-=1
for i in ans:print(i)

Measured memory_bytes: 263792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    ll N, K, R, S, P;
    string T;
    char cur='a';
    cin>>N>>K>>R>>S>>P>>T;
    ll count=0, curnum=0;
    rep(m, K){
        int i=m;
        while(i<=N-1){
            if(cur!=T[i]){
                if(cur=='r') count+=P*((curnum+1)/2);
                if(cur=='s') count+=R*((curnum+1)/2);
                if(cur=='p') count+=S*((curnum+1)/2);
                cur=T[i];
                curnum=1;
            }
            else{
                curnum++;
            }
            i+=K;
        }
        
        if(cur=='r') count+=P*((curnum+1)/2);
        if(cur=='s') count+=R*((curnum+1)/2);
        if(cur=='p') count+=S*((curnum+1)/2);
        
        cur='a';
        curnum=0;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 512
n = int(input())
h = [int(x) for x in input().split()]
inf = float('inf')
dp = [inf] * n  # initialize dp
dp[0] = 0
for i in range(1, n):
    if i == 1:
        dp[i] = abs(h[i] - h[i-1])
    elif (dp[i-1] + abs(h[i] - h[i-1])) < (dp[i-2] + abs(h[i] - h[i-2])):
        dp[i] = dp[i-1] + abs(h[i] - h[i-1])
    else:
        dp[i] = dp[i-2] + abs(h[i] - h[i-2])
print(dp[-1])

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

struct Card{
  char pic; int val;
};

void bubbleSort(Card A[], int n){
  for(int i = 0; i < n - 1; i++){
    for(int j = n - 1; j > i; j--){
      if(A[j].val < A[j-1].val){
        swap(A[j].val, A[j-1].val);
        swap(A[j].pic, A[j-1].pic);
      }
    }
  }
}

void selectionSort(Card B[], int n){
  for(int i = 0; i < n; i++){
    int min = i;
    for(int j = i; j < n; j++){
      if(B[j].val < B[min].val) min = j;
    }
    swap(B[i].val, B[min].val);
    swap(B[i].pic, B[min].pic);
  }
}

int main(void){
  int n;
  Card A[36], B[36];

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> A[i].pic >> A[i].val;
    B[i].pic = A[i].pic; B[i].val = A[i].val;
  }

  bubbleSort(A, n);
  selectionSort(B, n);

  for(int i = 0; i < n; i++){
    cout << A[i].pic << A[i].val;
    if(i < n - 1) cout << " ";
  }
  cout << "\nStable" << endl;

  bool flag = true;
  for(int i = 0; i < n; i++){
    cout << B[i].pic << B[i].val;
    if(i < n - 1) cout << " ";
    if(B[i].pic != A[i].pic) flag = false;
  }
  if(flag){
    cout << "\nStable" << endl;
  }else{
    cout << "\nNot stable" << endl;
  }

  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

const double EPS=1e-10;
const double INF=1e10;

// 点オブジェクト
// ベクトルを表すのにも使う
struct Point {
    double x, y;
    Point(double x=0, double y=0) : x(x), y(y) {}
    double distance (const Point &o) const {
        return sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y));
    }

    Point operator+(const Point &o) const {
        return Point(x+o.x, y+o.y);
    }

    Point operator-(const Point &o) const {
        return Point(x-o.x, y-o.y);
    }

    Point operator*(const double m) const {
        return Point(x*m, y*m);
    }

    Point operator/(const double d) const {
        return Point(x/d, y/d);
    }

    double cross(const Point &o) const {
        return x * o.y - y * o.x;
    }

    double dot(const Point &o) const {
        return x * o.x + y * o.y;
    }

    double atan() const {
        return atan2(y, x);
    }

    double norm() const {
        return dot(*this);
    }
};

struct Line {
    Point s, e; // start, end(始点,終点)
    Line(Point &s, Point &e) : s(s), e(e) {}
    Line(double sx=0, double sy=0, double ex=0, double ey=0) : s(Point(sx,sy)), e(Point(ex,ey)){}

    // 点Pからの写像
    Point projection(const Point &p) const {
        double t = (p-s).dot(s-e) / (s-e).norm();
        return s + (s-e) * t;
    }

    // 直線に対して点Pと対象な点
    Point reflection(const Point &p) const {
        return p + (projection(p) - p) * 2;
    }

    Point crosspoint(const Line &o) {
        double a = (e-s).cross(o.e-o.s);
        double b = (e-s).cross(e-o.s);
        return o.s + (o.e-o.s)*b/a;
    }
};

int main() {
    Point p1, p2, q;
    string s;
    while (getline(cin, s)) {
        for (int k = s.find(','); k != string::npos; k = s.find(',')) {
            s[k] = ' ';
        }
        istringstream ss(s);
        ss >> p1.x >> p1.y >> p2.x >> p2.y >> q.x >> q.y;
        Line l(p1, p2);
        Point ans = l.reflection(q);
        cout.precision(6);
        cout << fixed << ans.x << ' ' << ans.y << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
#define int long long 
#define MOD 1000000007
 
using namespace std;
 
signed main(){
 
    int n;
    cin >> n;
    vector<int> a;

    int temp;
    for(int i=0;i<n;i++){
        cin >> temp;
        a.push_back(temp);
    }

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

    int z=1;
    int k;
    while(1){
        k=z;
        for(int i=z;i<n;i++){
            
            temp = a[i]%a[k-1];
            if(temp==0){
                z++;
            }
            a[i]=temp;
        }
        sort(a.begin(),a.end());

        if(a[n-2]==0){
            cout <<a[n-1]<<endl;
            return 0;

        }

    }

 
}

Measured memory_bytes: 1400
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	 static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 
	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();		
		String s1 = s.next();
		String t = s.next();
		int c=0;
		for(int i=0;i<s1.length();i++) {
			if(s1.charAt(i)==t.charAt(i))c++;
		}
		System.out.println(s1.length()-c);
}
}

Measured memory_bytes: 37236
import sys
x = []
for line in sys.stdin:
    h,w = line.split()
    h,w = int(h), int(w)
    if h == 0 and w== 0: break
    tmp = (w+1)/2
    s1 = ('.#' * tmp)[:w]
    s2 = ('#.' * tmp)[:w]
    for j in range(h):
        if (j & 1)==0: print s2
        else: print s1
    print
    

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

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

const double PI = acos(-1);
#define MOD 1000000007

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (abs(a*b)/gcd(a,b))
#define sqr(a) (a*a)

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

main()
{
    ///optimize();
    ll n,l;
    while(cin>>n){
        string s;
        map<string,int> mp;
        while(n--){
            cin>>s;
            mp[s]=1;
        }
        cout<<sz(mp) el;
    }






}





///Brainless people are gonna understand this code.




///Brainless_Loco Terminates Here!


Measured memory_bytes: 19264
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		int[] arr2 = arr.clone();
		Arrays.sort(arr2);
		int idx = n / 2 - 1;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			if (arr[i] <= arr2[idx]) {
				sb.append(arr2[idx + 1]);
			} else {
				sb.append(arr2[idx]);
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}


Measured memory_bytes: 95792
let () =
  let (n, k) = Scanf.scanf "%d %d\n" (fun n k -> (n, k)) in
  let a = Array.make n 0 in
  let rec read i =
    if i < n then (Scanf.scanf "%d\n" (fun w -> a.(i) <- w); read (i + 1))
  in
  read 0;
  let check p =
    let rec doit i j s =
      if i = n then n
      else if j >= k then i
      else
        let x = s + a.(i) in
        if x > p then doit i (j + 1) 0
        else doit (i + 1) j x
    in
    doit 0 0 0
  in
  let rec bin_search l r =
    if r < l then l
    else
      let m = (l + r) / 2 in
      let v = check m in
      if v >= n then bin_search l (m - 1)
      else bin_search (m + 1) r
  in
  Printf.printf "%d\n" (bin_search 0 (100000 * 10000))

Measured memory_bytes: 5328
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <unordered_map>
using namespace std;
const int N=1e6+100;
typedef long long ll;
unordered_map<int,int>mp;
inline int read()
{
    int f=1,x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+(ch-'0');
        ch=getchar();
    }
    return x*f;
}
ll a[70];
int tt=1;
void init()
{
    a[1]=1;
    for(int i=2;;i++){
        a[i]=a[i-1]*2;
        if(a[i]>=2e18) break;
        tt++;
    }
}

int main()
{
     string s;cin>>s;
     for(int i=0;i<s.size();i++){
        if(s[i]=='?') s[i]='D';
     }
     cout<<s;
    return 0;
}


Measured memory_bytes: 3724
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] a = new int[m];
    int[] c = new int[m];
    int d = (int)Math.pow(2, n);
    int[][] dp = new int[m][d];
    for(int i = 0; i < m; i++) {
      a[i] = sc.nextInt();
      int b = sc.nextInt();
      int cc = 0;
      for(int j = 0; j < b; j++) {
        int c1 = sc.nextInt();
        cc += (int)(Math.pow(2, c1 - 1));
      }
      c[i] = cc;
    }
    for(int j = 1; j < d; j++) {
      dp[0][j] = (int)Math.pow(10, 7);
    }
    for(int j = 1; j < d; j++) {
      if((j | c[0]) == c[0]) dp[0][j] = a[0];
    }
    for(int i = 0; i < m; i++) {
      dp[i][0] = 0;
    }
    for(int i = 1; i < m; i++) {
      for(int j = 1; j < d; j++) {
        dp[i][j] = Math.min(dp[i - 1][j], dp[i - 1][j - (j & c[i])] + a[i]);
      }
    }
    if(dp[m - 1][d - 1] < (int)Math.pow(10, 7)) {
      System.out.println(dp[m - 1][d - 1]);
    } else {
      System.out.println(-1);
    }
  }
}

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

int main(){
	double n;
	double b[12] = {128,64,32,16,8,4,2,1,0.5,0.25, 0.125,0.0625};
	while( cin >> n , n != -1.0 ){
		string s;
		for(int i=0 ; i < 12 ; i++ ){
			if( n >= b[i] ){
				n -= b[i];
				s += "1";
			}else{
				s += "0";
			}
			if( i == 7 )
				s += ".";
		}
		if( n > 0 )
			cout << "NA" << endl;
		else
			cout << s << endl;
	}
}

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

void solve(long long X){
    ll num =100;
    double r =1.01;
    ll ans =0;
    while(num<X){
        num *= r;
        ans++;
    }
    cout << ans << endl;

}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3764
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 
def main():
    N, M = map(int, readline().split())
    to = [[]  for _ in range(N)]
    for _ in range(M):
        a, b = map(int, readline().split())
        to[a-1].append(b-1)
        to[b-1].append(a-1) 

    dq = deque()
    dq.append(0)
    done = [0 for _ in range(N)]
    done[0] = 1
    ans = [0 for _ in range(N)]
    while len(dq) > 0:
        v = dq.popleft()
        for nx in to[v]:
            if done[nx]:
                continue
            ans[nx] = v
            done[nx] = 1
            dq.append(nx) 
    print('Yes')
    for i in ans[1:]:
        print(i+1)
if __name__ == '__main__':
    main()


Measured memory_bytes: 96892
n = int(input())
t,a = map(int, input().split())
tmp = list(map(int, input().split()))
bst = 100000
p = 0

for i in range(n):
    x = abs(a - float(t - tmp[i]*0.006))
    
    if x < bst:
        p = i+1
        bst = x    
        
print(p)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int a,b,h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
}


Measured memory_bytes: 384
A,B,C,K=input().split(" ")
A=int(A);B=int(B);C=int(C);K=int(K)
SUM=0
if A <= K :#AはK以下であれば
    SUM= 1 * A
    K=K-A
    if B <= K:
        K=K-B
        SUM=SUM + -1*K
        print(SUM)
    else:
        print(SUM)
else:
    print(1*K)

Measured memory_bytes: 61816
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>

#define INF 1e9
#define nmax 200010
#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD 998244353

#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

typedef pair<int, int> pii;
typedef long long int ll;

int n, m, k;
int answer[nmax];

vector <int> g[nmax];

int get_dad(int x, vector <int>& dad)
{
    if (dad[x] == x) return x; else
        return dad[x] = get_dad(dad[x], dad);
}

void unite(int x, int y, vector <int>& dad, vector <int>& sz, vector <int>& r)
{
    x = get_dad(x, dad);
    y = get_dad(y, dad);

    if (x == y) return;

    if (r[x] > r[y]) {

        dad[x] = y; sz[y] += sz[x];
    }
    else {

        dad[y] = x; sz[x] += sz[y];
    }

    if (r[x] == r[y]) r[y]++;
}

int main()
{
    scanf("%d %d %d", &n, &m, &k);

    vector <int> rF(n + 1), szF(n + 1), dadF(n + 1);

    for (int i = 1; i <= n; i++) {

        dadF[i] = i; szF[i] = 1; rF[i] = 0;
    }

    for (int i = 1; i <= m; i++) {

        int x, y;

        scanf("%d %d", &x, &y);

        g[x].pb(y); g[y].pb(x);

        unite(x, y, dadF, szF, rF);
    }

    for (int i = 1; i <= n; i++) answer[i] = szF[get_dad(i, dadF)] - 1;

    for (int i = 1; i <= n; i++) answer[i] -= SZ(g[i]);

    for (int i = 1; i <= k; i++){

        int x, y;

        scanf("%d %d", &x, &y);

        if (get_dad(x, dadF) == get_dad(y, dadF)) answer[x]--, answer[y]--;
    }
         
    for (int i = 1; i <= n; i++) printf("%d ", answer[i]);

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 11256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <iomanip>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define MIN(x, y) ( (x) < (y) ? (x) : (y) )
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define IVFOR(p,a) for(vector<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ILFOR(p,a) for(list<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define CHECK(x)  cout << #x << " = " << (x) << endl
#define FINA(y) cout << (y) << endl

int main(){

  int n, m;
  cin >> n >> m;
  int a[50], b[50], c[50], d[50];

  REP(i,n){
    cin >> a[i] >> b[i];
  }
  REP(i,m){
    cin >> c[i] >> d[i];
  }

  int min, dis, numc;
  REP(i,n){

    REP(j,m){
      dis = abs(c[j] - a[i]) + abs(d[j] - b[i]);
      if(j == 0){
	min = dis;
	numc = j;
      }
      else{
	if(min > dis){
	  min = dis;
	  numc = j;
	}
      }
    }
    cout << numc + 1 << endl;
  }
  
 return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	string s, t;
	cin >> s >> t;
	int ans = 0;
	rep(i, s.size()) {
		if (s[i] != t[i]) {
			ans++;
		}
	}
	cout << ans << endl;
}






Measured memory_bytes: 3852
# -*- coding: utf-8 -*-

def main():
    a = int(input())
    minNum = 3 * 5 * 7
    if a < minNum:
        print(0)
        return
    elif a <= minNum + 1:
        print(1)
        return

    count = 1
    if a % 2 == 1:
        a = a + 1
    for n in range(minNum + 2, a, 2):
        if countDevisor(n) == 8:
            count = count + 1

    print(count)


def factorize(num):
    facts = []
    n = num
    base, expo = 2, 0
    while base * base <= n:
        while n % base == 0:
            n = n // base
            expo = expo + 1
        if expo > 0:
            facts.append((base, expo))
        base = base + 1
        expo = 0

    if n > 1:
        facts.append((n, 1))

    return facts


def countDevisor(num):
    facts = factorize(num)
    count = 1
    for _, expo in facts:
        count = count * (expo + 1)
    return count


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
def main():
    N = int(input())
    S = input()
    MOD = 10**9 + 7
    ans = 1
    from collections import Counter
    c = Counter(S)
    for v in c.values():
        ans *= (v+1)
        ans %= MOD
    print(ans - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_vector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_vector(int n, Ts ... ts){
        return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    void run(){
        ll M, D;
        is >> M >> D;
        if(!is) return;
        ll ans = 0;
        for (int i = 4; i <= M; ++i) {
            for (int j = 22; j <= D; ++j) {
                ll d1 = j % 10;
                ll d10 = j / 10;
                if(d1 < 2 or d10 < 2) continue;
                ans += d1 * d10 == i;
            } // end j
        } // end i
        cout << ans << endl;

    }
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_A.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	while (a > 0 || b > 0) {
	    for (int i = 0; i < a; i++) {
	        for (int o = 0; o < b; o++) {
	            if (i == 0 || i == a - 1 || o == 0 || o == b - 1) cout << "#";
	            else cout << ".";
	        }
	        cout << endl;
	    }
	    cout << endl;
	    cin >> a >> b;
	}
}



Measured memory_bytes: 3084
import sys
input=sys.stdin.readline

def main():
    n, ww = map(int,input().split())
    
    dp = [[0]*(ww+1) for _ in range(n)]
    for i in range(n):
        w, v = map(int,input().split())
        for wgt in range(1,ww+1):
            if wgt - w < 0:
                dp[i][wgt] = dp[i-1][wgt]
                continue
            dp[i][wgt] = max(dp[i-1][wgt], dp[i-1][wgt-w]+v)
            
    print(max(dp[i]))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 151788
import Data.List

solve :: String -> Int -> Int
solve s k
  | all (== head s) s = length s * k `div` 2
  | head s /= last s  = (* k) $ f g
  | otherwise = f [h] + f [h++l] * (k-1) + f m * k + f [l]
  where
    g = group s
    h = head g
    l = last g
    m = (init . tail) g
    f = sum . map ((`div` 2) . length)

main :: IO ()
main = do
    s <- getLine
    k <- readLn :: IO Int
    print $ solve s k

Measured memory_bytes: 508
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        
        long cnt = (long)Math.floor(N/(A+B));
        System.out.println(cnt*A + Math.min(N-cnt*(A+B), A));
    }

}


Measured memory_bytes: 22868
n = int(input())
li_b = list(map(int, input().split()))
li_a = [9999999] * n

for idx, b in enumerate(li_b):
    li_a[idx] = min(li_a[idx], b)
    li_a[idx + 1] = min(li_a[idx + 1], b)

print(sum(li_a))


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

int main(){

    string s;
    cin>>s;

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

    if(s.at(0)==s.at(1)&&s.at(1)!=s.at(2)&&s.at(2)==s.at(3))
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char* argv[]) {

	int a, b, c, x, y;
	int sum = 0;

	scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);

	if(2 * c < a + b) {
		if(x <= y) {
			sum += 2 * x * c;
			if(2 * c < b) {
				sum += 2 * c * (y - x);
			} else
				sum += b * (y - x);
		} else {
			sum += 2 * y * c;
			if(2 * c < a) {
				sum += 2 * c * (x - y);
			} else
				sum += a * (x - y);
		}
	} else {
		sum = a * x + b * y;
	}
	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rkc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
#define vpp vector<pair<ll,ll>>
#define ff first
#define ss second
const ll M = 1e9 + 7;
const double pi  =3.141592653589793238463;
int main()
{
    rkc;
    ll n;
    cin>>n;
    if(n<=9)cout<<n;
    else if(n>=10&&n<=99)cout<<9;
    else if(n>=100&&n<=999)cout<<9+n-99;
    else if(n>=1000&&n<=9999)cout<<909;
    else if(n>=10000&&n<=99999)cout<<909+n-9999;
    else cout<<90909;
}


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

#define lugan "ks2"
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define endl '\n'
#define _io ios_base::sync_with_stdio(0);   cin.tie(NULL); cout.tie(NULL);

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5+7;
const int oo = 1e9+7;

inline void initf()
{
    freopen(lugan".inp", "r", stdin);
    freopen(lugan".out", "w", stdout);
}

int n, m, W;

int main()
{
    _io
    cin >> n >> W;
    vector<int> w(n), v(n);
    for (int i=0; i<n; i++)
    {
        cin >> w[i] >> v[i];
        m += v[i];
    }
    vector<int> dp(m+1, 1e9+7);
    dp[0] = 0;
    for (int i=0; i<n; i++)
        for (int t = m; t>=v[i]; t--)
            dp[t] = min(dp[t], dp[t-v[i]] + w[i]);
    ll res = 0;
    for (int i=0; i<=m; i++)
        if (dp[i] <= W)
            res = i;
    cout << res;
    return 0;
}



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

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

    int ans = N / 111;
    if (N % 111 == 0){
        cout << ans * 111 << endl;
    }else{
        cout << (ans + 1) * 111 << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define max 100
#define infty 1<<21

int n;
int d[max];
int aa[max][max];
int color[max];

void soya() {
	d[0] = 0;
	while (1) {
		int x = infty;
		for (int i = 0; i < n; i++) {
			if (x != infty) {
				if (d[i] < d[x] && color[i] != 2) {
					x = i;
				}
			}
			else {
				if (d[i] < x && color[i] != 2) {
					x = i;
				}
			}
		}

		if (x == infty) break;
		else {
			color[x] = 2;
			for (int i = 0; i < n; i++) {
				if (aa[x][i] != -1 && d[x] + aa[x][i] < d[i]) {
					d[i] = d[x] + aa[x][i];
				}
			}
		}
	}
}

int main() {
	for (int i = 0; i < max; i++) {
		color[i] = 0;
		d[i] = infty;
	}

	for (int i = 0; i < max; i++) {
		for (int j = 0; j < max; j++) {
			aa[i][j] = -1;
		}
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		int id;
		int k;
		cin >> id >> k;
		for (int j = 0; j < k; j++) {
			int num1;
			int kyori;
			cin >> num1 >> kyori;
			aa[id][num1] = kyori;
		}
	}

	soya();

	for (int i = 0; i < n; i++) {
		cout << i << " " << d[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
typedef long  long int ll;
int main(){
    ll k,n;
    cin>>k>>n;
    vector<ll>v(n);
    for(ll i=0;i<n;i++)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        if(i==0)
        {
            ans=max(ans,v[1]-v[0]);
            ans=max(ans,v[0]+k-v[n-1]);
            
        }
        else if(i==n-1)
        {
             ans=max(ans,v[n-1]-v[n-2]);
             
        }
        else
        {
            ans=max(ans,v[i]-v[i-1]);
            ans=max(ans,v[i+1]-v[i]);

        }
        
        
    }
    cout<<k-ans<<"\n";

}

Measured memory_bytes: 1792
import sys

mod = 10**9 + 7

def solve():
    n = int(input())

    if n == 1:
        print(1)
        return

    dp = [0] * (n + 1)
    dp[1] = n % mod
    dp[2] = n**2 % mod

    acc = [0] * (n + 1)
    acc[1] = dp[1] % mod
    acc[2] = (dp[1] + dp[2]) % mod

    for k in range(3, n + 1):
        dp[k] = (dp[k - 1] + (n - 1)**2 + acc[k - 3] + n - k + 2) % mod
        acc[k] = (acc[k - 1] + dp[k]) % mod

    ans = dp[n]
    print(ans)

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Measured memory_bytes: 82144
Scanf.scanf "%s" (fun s ->
  let rec f s n i =
    if i >= n / 2 then true
    else if s.[i] <> s.[n-1-i] then false
    else f s n (i+1)
  and n = String.length s in
  print_endline (if f s n 0 && f s ((n-1) / 2) 0 then "Yes" else "No"))

Measured memory_bytes: 384
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
n,k = map(int,input().split())
MOD = 10**9 + 7
def comb(n, k, mod):
    if n<0 or k<0 or n<k:
        return 0
    if n==0 or k==0:
        return 1
    k=k if k<=n-k else n-k
    x = 1
    y = 1
    for i in range(k):
        x=x*(n-i)%mod
        y=y*(i+1)%mod
    return (x*pow(y,mod-2,mod))%mod
#こっちは計算量O(N)
fac = [1, 1]
inv = [0, 1]
finv = [1, 1]
for i in range(2, 2*n+1):
    fac.append(fac[-1] * i % MOD)
    inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD) 
def comb_mod(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m
if k >= n-1:
    ans = comb_mod(2*n-1,n,MOD)
    print(ans%MOD)
elif k == 1:
    print(n*(n-1)%MOD)
else:
    ans = 0
    for i in range(k+1):
        ans += comb_mod(n-1,i,MOD)*comb_mod(n,i,MOD)
    print(ans%MOD)

Measured memory_bytes: 60924
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll a;
  cin >> a;
  cout << a + a * a + pow(a, 3) << "\n";
}


Measured memory_bytes: 4304
#-*-coding:utf-8-*-

def main():
    #入力
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())

    #全探索してみる
    #カウンタ
    count = 0
    for i in range(A+1):
        for j in range(B+1):
            for k in range(C+1):
                if 500 * i + 100 * j + 50 * k == X:
                    count += 1
    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n, x, m;
    cin >> n >> x >> m;
    int d[100005];
    for(int i = 0; i < m; i++) d[i] = -1;
    ll k;
    ll ans = 0;
    int i;
    for(i = 0; i < n; i++){
        if(d[x] >= 0){
            k = i - d[x];
            break;
        }
        d[x] = i;
        ans += x;
        x = x * x % m;
    }
    if(i == n){
        cout << ans << endl;
        return 0;
    }
    n -= i;
    ll s = 0;
    for(i = 0; i < k; i++){
        s += x;
        x = x * x % m;
    }
    ans += n / k * s;
    n %= k;
    for(int i = 0; i < n; i++){
        ans += x;
        x = x * x % m;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3980
#include<iostream>
#include<vector>
#include<algorithm>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main(){
	int n;
	cin >>n;
	long long int as=0,bs=0;
	int ans=0;
	vector<long long int>a(n),b(n),d(n);
	rep(i,n){cin>>a[i];as+=a[i];}
	rep(i,n){cin>>b[i];bs+=b[i];}
	if(as<bs){
		cout <<"-1"<<endl;
		return 0;
	}
	rep(i,n){d[i]=a[i]-b[i];}
	sort(d.begin(),d.end());
	int l=0,r=n-1;
	bool trg=false;
	while(l<r){
		bool flg=false;
		long long int tmp=min(abs(d[l]),d[r]);
		if (d[l]<0){
			ans++;
			flg=true;
			trg=true;
			d[l]+=tmp;
			d[r]-=tmp;
		}
		if(d[r]==0){
			r--;
		}
		if(d[l]>=0){
			l++;
		}
		if (l>r)
			ans++;
	}
	if(trg)
	cout <<ans+1<<endl;
	else
		cout<<0<<endl;
}

Measured memory_bytes: 2560
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include"stdio.h"
#include"stdlib.h"
#include"assert.h"
#include"ctype.h"
#include"string.h"
#include"math.h"
#include"string"
#include"deque"
#include"iostream"
#include"set"
#include"map"
#include"vector"
#include"algorithm"
#include"bitset"
#include"stack"
#include"queue"
#include"sstream"
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb emplace_back
#define x first
#define y second
#define pii pair<int, int>
#define sz(x) (int)(x).size()

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

	int n;
	cin >> n;

	int a[n];

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

	int ans(0);

	for(int i = 1; i < n-1; ++i)
	{
		vector<int> v{a[i-1], a[i], a[i+1]};
		sort(v.begin(), v.end());

		if(v[1] == a[i])
			ans++;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
int main() {
	while (1) {
		int n;
		std::cin >> n;
		if (n == 0)break;
		std::vector<char>before(n);
		std::vector<char>after(n);
		for (int i = 0; i < n; ++i)std::cin >> before[i] >> after[i];
		int m;
		std::cin >> m;
		std::vector<char>vec(m);
		for (int i = 0; i < m; ++i) {
			std::cin >> vec[i];
			for (int j = 0; j < n; ++j) {
				if (vec[i] == before[j]) { vec[i] = after[j];	break; }
			}
		}
		for (int i = 0; i < m; ++i) {
			if (i == m - 1) { std::cout << vec[i] << std::endl; }
			else std::cout << vec[i];
		}
	}
	return 0;
}

Measured memory_bytes: 3200
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;

namespace ConsoleApp1AtCoder_Beginner_Contest_132
{
    class Program
    {
        //配列にする
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        //Listにする
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var Pn = Sarray();
            var cnt = 0;
            for (var i = 1; i < N - 1; ++i)
            {
                if (
                    (Pn[i - 1] < Pn[i] && Pn[i] <= Pn[i + 1]) ||
                    (Pn[i - 1] >= Pn[i] && Pn[i] > Pn[i + 1])
                    )
                { ++cnt; }
            }
            WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 13268
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n, K; cin >> n >> K;
  vector<ll> a(n); cin >> a;
  vector<ll> S(n+1, 0);
  rep(i, n) S[i+1] = S[i] + a[i];
  vector<ll> v;
  rep(i, n) rep(j, i) {
    v.pb(S[i+1] - S[j]);
  }
  // sort(all(v), greater<ll>());
  ll ans = 0;
  rrep(i, 50) {
    ll cnt = 0;
    each(x, v) {
      if ((ans & x) == ans && (x>>i) & 1) {
        ++cnt;
      }
    }
    if (cnt >= K) {
      ans += 1LL<<i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 6512
while True:
    try:
        a, b, c, d, e, f = map(int, input().split())
    except:
        break
    y = (c*d-f*a) / (b*d-e*a)
    x = (c - b*y) / a
    print("{:.3f} {:.3f}".format(x, y))



Measured memory_bytes: 5612
from collections import deque
from copy import deepcopy

H, W, K = map(int, input().split())

mod = int(1e9+7)

## 一列の中で可能な置換を全て保持しておく
perm_lst = []
def bfs():
    dq = deque() ## ((post permutation), next_line)
    dq.append(([],0))
    while dq:
        post, line = dq.popleft()
        if line < W: ## 何も繋がない
          post_tmp = deepcopy(post) ## もっといい書き方ありそう
          post_tmp.append((line,line))
          dq.append( (post_tmp,line+1) )
        if line < W-1: ## 隣とつなぐ
          post_tmp = deepcopy(post) ## もっといい書き方ありそう
          post_tmp.append((line,line+1))
          dq.append( (post_tmp,line+2) )
        if line == W:
          perm_lst.append(post)
bfs()
#print(perm_lst)

## dp[i][j]: i列目まで線を引いてjにいる場合の数の総数
dp = [[0 for j in range(W)] for i in range(H+1)]
dp[0][0] = 1
for i in range(1,H+1):
  for perm in perm_lst:
    for j in range(len(perm)):
      if perm[j][0] != perm[j][1]:
        dp[i][perm[j][0]] += dp[i-1][perm[j][1]]
        dp[i][perm[j][1]] += dp[i-1][perm[j][0]]
      else:
        dp[i][perm[j][0]] += dp[i-1][perm[j][0]]
      
#print(dp)

print(dp[H][K-1] % mod)

Measured memory_bytes: 3572
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
template<class Abel> struct UF {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UF(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

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

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;cin>>n>>m;
UF<int>  uf(n);
for(int i=0;i<m;i++){
    int a,b,c;
    cin>>a>>b>>c;
  if(!uf.merge(--a,--b,c)){
      if(uf.diff(a,b)!=c)cout<<"No"<<endl;
      else continue;
      return 0;
  }
}
cout<<"Yes"<<endl;
}


Measured memory_bytes: 1408
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <float.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a>=c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(LL &a,LL &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(LL &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int index=0 ; index<b ; index++)scanf("%d",&a[index])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	int n,k,a[200][200],b,c;
	scd(n);
	forin(i,0,n)
	{
		scd(c);
		scd(k);
		forin(j,0,k)
		{
			scd(b);
			a[c-1][b-1]=1;
		}
	}
	forin(i,0,n)
	{
		forin(j,0,n-1)
		printf("%d ",a[i][j]);
		printf("%d\n",a[i][n-1]);
	}
	return 0;
}

Measured memory_bytes: 3256