akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int a[100005];
pair<int,int> b[100005];
int cmp(pair<int,int> p,pair<int,int> q)
{
    return p.first>q.first;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&b[i].second,&b[i].first);
    }
    sort(b+1,b+1+m,cmp);
    int pos=1;
    int flag=0;
    a[n+1]=1e9+10;
    for(int i=1;i<=m;i++)
    {
        while(b[i].second)
        {
            if(b[i].first>a[pos])
            {
                a[pos]=b[i].first;
                pos++;
                b[i].second--;
            }
            else
            {
                flag=1;
                break;
            }
        }
        if(flag==1) break;
    }
    long long sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=a[i];
    }
    printf("%lld\n",sum);
}


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

#include <bits/stdc++.h>
using namespace std;

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef long long ll;


int main(){
    int x;
    cin >> x;
    int ans = 8;
    for(int i=400;i<=2000;i+=200){
        if(x>=i&&x<i+200){
            cout << ans << endl;
            break;
        } 
        ans--;
    }
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();

    	TreeSet[] segs = new TreeSet[26];
    	char[] d = sc.next().toCharArray();
    	for (int i = 0; i < 26; i++){
    		segs[i] = new TreeSet();
    		segs[i].add(510000);
    	}
    	for (int i = 0; i < n; i++) {
    		segs[(int) d[i] - 'a'].add(i);
    	}
    	int q = sc.nextInt();
    	for (int i = 0; i < q; i++) {
    		int a = sc.nextInt();
    		if (a==1) {
    			int index = sc.nextInt()-1;
    			char oldc = d[index];
    			char newc = sc.next().toCharArray()[0];
    			if (oldc == newc) continue;
    			d[index]=newc;
    			segs[(int)oldc-'a'].remove(index);
    			segs[(int)newc-'a'].add(index);
    			continue;
    		}
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            int ans = 0;
            for (int j = 0; j < 26; j++) {
                if ((int)segs[j].ceiling(l) <= r) ans += 1;
            }
            System.out.println(ans);
    	}
    }
} 



Measured memory_bytes: 106380
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

const long long INF = 1LL << 60;
const int MAX_N = 110;
const int MAX_V = 100010;

int N;
long long W;
long long w[MAX_N];
long long v[MAX_N];
long long dp[MAX_N][MAX_V];

int main() {
  cin >> N >> W;
  for (int i = 0; i < N; ++i) cin >> w[i] >> v[i];
  for (int i = 0; i < MAX_N; ++i) for (int j = 0; j <= MAX_V; ++j) dp[0][j] = INF;

  dp[0][0] = 0;

  for (int i = 0; i < N; ++i) {
    for (int sum_v = 0; sum_v <= MAX_V; ++sum_v) {
      if (v[i] <= sum_v) {
        dp[i + 1][sum_v] = min(dp[i][sum_v - v[i]] + w[i], dp[i][sum_v]);
      } else dp[i + 1][sum_v] = dp[i][sum_v];
    }
  }

  long long res = 0;
  for (long long sum_v = 0; sum_v < MAX_V; ++sum_v) {
    if (dp[N][sum_v] <= W) {
      res = max(res, sum_v);
    }
  }

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


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

int main() {
	int n, cnt = 0; cin>>n;
	for(int i = 0; i <n; i++){
		int a, b; cin>>a>>b;
		if(a == b){
			cnt++;
			if(cnt == 3){
				puts("Yes");
				return 0;
			}
		}
		else{
			cnt = 0;
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N = sc.nextInt();
	static int h[] = new int[N];
	static int ans = 0;

	public static void main(String[] args) {
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		while(true) {
			for(int i = 0; i < N; i++) {
				if(h[i] > 0) {
					solv(i);
					break;
				}
				if(i == N - 1) {
					System.out.println(ans);
					return;
				}
			}
		}
	}

	public static void solv(int st) {
		ans++;
		for(int i = st; i < N; i++) {
			if(h[i] == 0)
				return;
			else
				h[i]--;
		}
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const double eps=1e-8;
const double pi=acos(-1);
int n,m;
template<class T>
inline void read(T &x)
{
    char c;
    x=1;
    while((c=getchar())<'0'||c>'9')
        if(c=='-')
            x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9')
        res=res*10+c-'0';
    x*=res;
}
int main()
{
    int k;
    r(n); r(m);
    set<int> s;
    map<int,int> mm;
    int ans1=0,ans2=0;
    FOR(i,1,m){
        int a; r(a);
        string ss;
        cin>>ss;
        if(ss=="WA"){
            if(!s.count(a)) mm[a]++;
        }
        else if(ss=="AC"){
            if(!s.count(a)){
                ans1++;
                ans2+=mm[a];
                s.insert(a);
            }
        }
    }
    cout<<ans1<<' '<<ans2<<endl;
    return 0;
}


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

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int
main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++)
  {
    cin >> p[i];
  }
  int count = 0;
  for (int i = 0; i < n - 2; i++)
  {
    if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2])
        || (p[i] > p[i + 1] && p[i + 1] > p[i + 2]))
    {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
//コメント付き。
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
static void Main(string[] args){
  var NY = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
  int N=NY[0];
  int Y=NY[1]/1000;
  //最初に-1,-1,-1を入れておけば、値が見つかれば更新され、なければ-1のまま。
  int[] ans=new int[]{-1,-1,-1};
  //indexがN+1まで必要ということに注意
  for(int i=0;i<N+1;i++){
  	for(int j=0;j<N-i+1;j++){
      for(int k=0;k<N-i-j+1;k++){
        if(i+j+k==N){
      		if(i*10+j*5+k*1==Y){
              //
          　　ans=new int[]{i,j,k};
              Console.WriteLine("{0} {1} {2}",ans[0],ans[1],ans[2]);
              //一個だけ見つければいいので、ここで抜けないと実行時間がかなり長くなる。
              return;
              //もしくは、
              //goto end;
            }
        }
      }
    }
  }
  Console.WriteLine("{0} {1} {2}",ans[0],ans[1],ans[2]);
  //end:;
}
}


Measured memory_bytes: 13268
N=int(input())
s=[]
t=[]
for i in range(N):
  s.append(input())
M=int(input())
for i in range(M):
  t.append(input())
max = 0
for a in s:
  cnt = s.count(a) - t.count(a)
  if cnt > max:
    max = cnt
print(max * (max > 0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >> s;
  int k;  cin >> k;
  vector<string> v;
  for(int i=0 ; i<s.size() ; i++){
    for(int j=1 ; j<=k ; j++){
        string tmp = s.substr(i,j);
        v.push_back(tmp);
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(),v.end()), v.end());
  cout << v[k-1] << endl;
  return 0;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=200005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T> inline void read(T &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
template<class T> inline void print(T x){
	if(!x){puts("0");return;}
	if(x<0){putchar('-');x=-x;}
	int a[20],m=0;
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');puts("");
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,k,cnt,ans[N];
char s[N];
deque<int> q;

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
	srand(time(0));
#endif
	ios::sync_with_stdio(0);
	scanf("%d%d",&n,&k);
	scanf("%s",s+1);
	if(s[1]=='A') s[1]='B',k--;
	s[++n]='B';
	for(int i=1;i<=n;i++){
		int r=i;
		while(r<n&&s[r+1]==s[i]) r++;
		q.push_back(r-i+1);i=r;
		cnt++;
	}
//	debug(q.front());
	for(int i=1;i<=k&&cnt<n;i++){
		int x=q.front();
		if(x==1){
			q.pop_front();q.push_back(1);
			continue;
		}
		q.pop_front();cnt++;
		q.push_front(x-1);q.push_back(1);
		if(i==k) break;
		if(x==2){
			if(cnt==n){
				if((k-i)&1){q.pop_front();q.pop_front();q.push_front(2);cnt--;}
				break;
			}
			int y;
			q.pop_front();y=q.front();
			q.pop_front();q.push_front(y+1);
			cnt--;i++;
			continue;
		}
		i++;cnt++;
		q.pop_front();
		q.push_front(x-2);q.push_front(1);
	}
	int p=n,now=1;
	while(!q.empty()){
		for(int i=1;i<=q.back();i++)
			ans[p--]=now;
		q.pop_back();now^=1;
	}
	for(int i=1;i<n;i++)
		if(ans[i]) putchar('B'); else putchar('A');puts("");
#ifdef rqgao2014
	time_tester(1);
#endif
	return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, a, b;
        n = Integer.parseInt(sc.next());
        a = Integer.parseInt(sc.next());
        b = Integer.parseInt(sc.next());
        
        int num = n * a;
        if(num < b) System.out.println(num);
        else if(num == b) System.out.println(num);
        else System.out.println(b);

        sc.close();
    }
}

Measured memory_bytes: 21716
#include<iostream>    
#include<cstdio>  
#include<stdio.h>  
#include<cstring>    
#include<cstdio>    
#include<climits>    
#include<cmath>   
#include<vector>  
#include <bitset>  
#include<algorithm>    
#include <queue>  
#include<map>  
#include<stack>
using namespace std;
 
long long int ans1, ans2, sum1, sum2;
int n, i;
long long int a[100005];
int main()
{
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	if (a[1] >0)
	{
		sum1 = a[1];
		ans2= a[1] + 1;
		sum2 = -1;
	}
	else if (a[1] == 0)
	{
		sum1 = 1;
		ans1 = ans2 = 1;
		sum2 = -1;
	}
	else 
	{
		sum1 = 1;
		ans1 = abs(a[1]) + 1;
		sum2 = a[1];
	}
	for (i = 2; i <= n; i++)
	{	
		if (sum1 > 0)
		{
			if (a[i] + sum1 >= 0)
			{
				ans1 += a[i] + sum1 + 1;
				sum1 = -1;
			}
			else
			{
				sum1 += a[i];
			}
		}
		else
		{
			if (a[i] + sum1 <= 0)
			{
				ans1 += abs(sum1 + a[i]) + 1;
				sum1 = 1;
			}
			else
			{
				sum1 += a[i];
			}
		}
	}
	if (sum1 == 0)
	{
		ans1++;
	}
	for (i = 2; i <= n; i++)
	{
		if (sum2 > 0)
		{
			if (a[i] + sum2 >= 0)
			{
				ans2 += a[i] + sum2 + 1;
				sum2 = -1;
			}
			else
			{
				sum2 += a[i];
			}
		}
		else
		{
			if (a[i] + sum2 <= 0)
			{
				ans2 += abs(sum2 + a[i]) + 1;
				sum2 = 1;
			}
			else
				sum2 += a[i];
		}
	}
	if (sum2 == 0)
	{
		ans2++;
	}
	cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 1024
/*  CREATED BY
    Stream_Cipher
    13-sep-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define debug2(a,b) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<"\n"
#define debug3(a,b,c) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<","<<#c<<"="<<(c)<<"\n"
#define fix_precision(n) cout<<fixed<<setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int mx=5*1000000;//5*64M bit ->5*8M byte ->40MB size for long long int (64 bit)
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int ans=-inf;
        ans=max(ans,max(a*c,max(a*d,max(b*c,b*d))));
        cout<<ans<<endl;
}

Measured memory_bytes: 3648
until (s = gets.chomp) == "0 0" do
    n, x = s.split.map(&:to_i)
    arr = Array.new
    1.upto(n) do |i|
        arr.push(i)
    end
    res = 0
    arr.combination(3) do |item|
        res += 1 if item.inject(:+) == x
    end
    p res
end

Measured memory_bytes: 8776
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// Range
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	ary := strings.Split(strings.TrimSpace(sc.Text()), " ")
	a, _ := strconv.Atoi(ary[0])
	b, _ := strconv.Atoi(ary[1])
	c, _ := strconv.Atoi(ary[2])
	if a < b && b < c {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}



Measured memory_bytes: 1124
# AOJ ITP1_9_B

def main():
    while True:
        string = input()
        if string == "-": break
        n = int(input())  # シャッフル回数
        for i in range(n):
            h = int(input())
            front = string[0 : h]  # 0番からh-1番まで
            back = string[h : len(string)]  # h番からlen-1番まで
            string = back + front
        print(string)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5596
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;


int main() {
    ll N, K, min;
    cin >> N >> K;
    min = N % K;
    ll x = K - min;
    cout << (min > x ? x : min) << endl;

    return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	x := getNextInt(scanner)
	y := getNextInt(scanner)
	for i := 0; i < 100; i++ {
		for j := 0; j < 100; j++ {
			if i+j == x && 2*i+4*j == y {
				fmt.Fprintln(writer, "Yes")
				return
			}
		}
	}
	fmt.Fprintln(writer, "No")
}


Measured memory_bytes: 1800
from itertools import product
n,m = map(int,(input().split()))
sw =[list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for bit in product([0, 1], repeat=n):
    ele = True
    for i in range(m):
        cnt = 0
        for j in sw[i][1:]:
            cnt += bit[j-1]
        if cnt % 2 != p[i]:
            ele = False
            break
    if ele:
        ans += 1        
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int A,B,C;
int m[555][555];
int dp[555];
int ans[555][555];
vector<int>X,Y;
int main(){
    cin>>A>>B>>C;
    for(int i=0;i<B;i++){
        int x,y;
        cin>>x>>y;
        m[x][y]++;
    }
    for(int i=1;i<555;i++){
        for(int j=1;j<555;j++){
            dp[i] += m[j][i];
        }
    }
    for(int i=1;i<555;i++){
        for(int j=1;j<555;j++){
            ans[i][j] += ans[i][j-1] + dp[j];
        }
        for(int j=1;j<555;j++){
            dp[j]-=m[i][j];
        }
    }
    while(C--){
        int x,y;
        cin>>x>>y;
        cout<<ans[x][y]<<'\n';


    }
    return 0;
}


Measured memory_bytes: 3200
import java.util.*;
import java.util.Map.Entry;
 
 

class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
   public static void main(String[] args) {
	   
       Scanner sc = new Scanner(System.in);
       String S = "0" + sc.next();
       char[] c = S.toCharArray();
       
       int N =c.length;
       int[][] dp =new int[N+1][2];
       dp[N][0]=Character.getNumericValue(c[0]);
       dp[N][1]=10-Character.getNumericValue(c[0]);
       for(int i=N-1;i>=0;i--) {
           Arrays.fill(dp[i], Integer.MAX_VALUE);
    	   for(int j=0;j<2;j++) {
    		   for(int k=0;k<10;k++) {
    			   int tmp=Character.getNumericValue(c[i])+j;
    			   tmp=k-tmp;
    			   if(tmp<0) {
    				   dp[i][1]=Math.min(dp[i][1], dp[i+1][j]+tmp+10+k);
    			   } else {
    				   dp[i][0]=Math.min(dp[i][0], dp[i+1][j]+tmp+k);
    			   }
    		   }
    	   }
       }
       

       System.out.println(dp[0][0]);
   }

}

Measured memory_bytes: 69688
from collections import deque


def bfs(s, m, n):
    d = []
    for _ in range(n):
        d.append(1 << 21)
    queue = deque()
    queue.append(s)
    d[s] = 0

    while len(queue) != 0:
        u = queue.popleft()
        for v in range(n):
            if m[u][v] == 0:
                continue
            if d[v] != 1 << 21:
                continue
            d[v] = d[u] + 1
            queue.append(v)

    for i, v in enumerate(d):
        ans_v = v
        if v == 1 << 21:
            ans_v = -1

        print(i + 1, ans_v)


n = int(input())
m = list()
for i in range(n):
    tmp = list()
    for j in range(n):
        tmp.append(0)
    m.append(tmp)

for _ in range(n):
    l = [int(i) for i in input().split()]
    u = l[0]
    for li in l[2:]:
        m[u - 1][li - 1] = 1

bfs(0, m, n)



Measured memory_bytes: 6104
s1=input()
s2=input()
a=[[0]*(len(s2)+1) for i in range(len(s1)+1)]
res=''
for i in range(1,len(s1)+1):
  for j in range(1,len(s2)+1):
    if s1[i-1] == s2[j-1]:
      a[i][j] = a[i-1][j-1] + 1
    elif a[i-1][j] >= a[i][j-1]:
      a[i][j] = a[i-1][j]
    else:
      a[i][j] = a[i][j-1]
i=len(s1)
j=len(s2)
while i>0 and j>0:
  if a[i][j] == a[i-1][j]:
    i -= 1
  elif a[i][j] == a[i][j-1]:
    j -= 1
  else:
    res = s1[i-1] + res
    i -= 1
    j -= 1   
print(res)

Measured memory_bytes: 112092
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e15+4;
const int Nmax=2e5+1;
const int Nd=61;
ll dfs[3003][3003][4];
ll  v[3003][3003];


int main(){
  int r,c,k;
  cin>>r>>c>>k;
  //vector<P> rc(k);
  rep(i,r+2){// dfsの初期化
    rep(j,c+2){
      v[i][j]=0;
      rep(l,4){
        dfs[i][j][l]=0;
      }
    }
  }


  rep(i,k){
    int x,y;
    cin>>x>>y;
    cin>>v[x][y];
  }
  int n=r+c-1;


  dfs[1][1][0]=0;
  for(int in=2; in<=n; in++){// step n回
    int imax=min(in,r);
    for(int i=1; i<=imax;i++){//
      int j=in-i;
      /// 拾わないケース///
      dfs[i+1][j][0]=max(dfs[i+1][j][0],dfs[i][j][0]);
      dfs[i+1][j][0]=max(dfs[i+1][j][0],dfs[i][j][1]);
      dfs[i+1][j][0]=max(dfs[i+1][j][0],dfs[i][j][2]);
      dfs[i+1][j][0]=max(dfs[i+1][j][0],dfs[i][j][3]);
      dfs[i][j+1][0]=max(dfs[i][j+1][0],dfs[i][j][0]);
      dfs[i][j+1][1]=max(dfs[i][j+1][1],dfs[i][j][1]);
      dfs[i][j+1][2]=max(dfs[i][j+1][2],dfs[i][j][2]);
      dfs[i][j+1][3]=max(dfs[i][j+1][3],dfs[i][j][3]);
      if(v[i][j]!=0){//v[i][j]!=0;
        ///ひろうケース
        dfs[i+1][j][0]=max(dfs[i+1][j][0],dfs[i][j][0]+v[i][j]);
        dfs[i+1][j][0]=max(dfs[i+1][j][0],dfs[i][j][1]+v[i][j]);
        dfs[i+1][j][0]=max(dfs[i+1][j][0],dfs[i][j][2]+v[i][j]);
        dfs[i][j+1][1]=max(dfs[i][j+1][1],dfs[i][j][0]+v[i][j]);
        dfs[i][j+1][2]=max(dfs[i][j+1][2],dfs[i][j][1]+v[i][j]);
        dfs[i][j+1][3]=max(dfs[i][j+1][3],dfs[i][j][2]+v[i][j]);
      }
    }
  }
  ll ans=max(dfs[r][c][0]+v[r][c],max(dfs[r][c][1]+v[r][c],max(dfs[r][c][2]+v[r][c],dfs[r][c][3])));
  cout<<ans<<endl;

}


Measured memory_bytes: 355708
#include <iostream>
#include <vector>
#include <string>

using namespace std;

void search(int w, int h, const vector< vector<int> >& area_map, vector< vector<int> >& visited, int W, int H) {
    visited[h][w] = 1;
    int dw[] = {1, 1, 0, -1, -1, -1, 0, 1}, dh[] = {0, 1, 1, 1, 0, -1, -1, -1};
    for(int i = 0; i < 8; i++) {
        int nw = w + dw[i], nh = h + dh[i];
        if(0 <= nw && nw < W && 0 <= nh && nh < H && visited[nh][nw] != 1 && area_map[nh][nw] == 1) {
            search(nw, nh, area_map, visited, W, H);
        }
    }
}

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

        vector< vector<int> > area_map, visited;
        for(int i = 0; i < h; i++) {
            vector<int> temp;
            for(int j = 0; j < w; j++) {
                int e; cin >> e;
                temp.push_back(e);
            }
            area_map.push_back(temp);
            visited.push_back(vector<int>(w));
        }
        int ans = 0;
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                if(area_map[i][j] == 1 && visited[i][j] != 1) {
                    search(j, i, area_map, visited, w, h);
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3432
program main
    implicit none
    integer i, flag
    character s*6
    read(*,*) s

    flag = 0
    if (s(3:3) == s(4:4)) then
        flag = 0
    else 
        flag = 1
    end if

    if (flag == 0) then
        if(s(5:5) == s(6:6)) then
            flag = 0
        else 
            flag = 1
        end if
    end if

    if (flag == 0) then
        write(*,*) "Yes"
    else if (flag == 1) then
        write(*,*) "No"
    end if

end program

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

string s;
int k;

signed main() {
	cin >> s >> k;
	for (int i = 0; i < k; i++) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
	}
	cout << 1 << endl;
	getchar(); getchar();
	return 0;
}

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

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

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
even = {}
odd = {}

for i in range(n):
  if i % 2 == 0:
    if a[i] in even:
      even[a[i]] += 1
    else:
      even[a[i]] = 1
  else:
    if a[i] in odd:
      odd[a[i]] += 1
    else:
      odd[a[i]] = 1
      
#print(even)
#print(odd)
emode = max(even, key=even.get)
omode = max(odd, key=odd.get)
emax = max(even.values())
omax = max(odd.values())

if emode != omode:
  print(n-emax-omax)
else:
  even[emode]=0
  odd[omode]=0
  emax2 = max(even.values())
  omax2 = max(odd.values())
  print(min(n-emax-omax2, n-emax2-omax))
  

Measured memory_bytes: 17656
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

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

#define DEBUG
#undef DEBUG

using ll  = long long;
using ull = unsigned long long;

ll X;

/**
 * ひたすら右へ飛び続けた場合を考える
 * ちょうどXに着ければそれでよい
 * 着けない場合、時刻Aで1回飛び越した状態を考える
 * 飛び越した距離はAより少ないので、どこかの時点で何もしなければピッタリ合う
 * よって時刻Aで着ける
 *
 * A回右へ飛び続けると (A(A+1))/2 へ移動する
 * 方程式 A(A+1)/2 = X を解くと A = (-1+sqrt(1+8X))/2
 * これの小数点以下を切り上げるとXを高々1回飛び越した状態になる
 */
void solve()
{
    ll A = static_cast<ll>(ceil((-1.0 + sqrt(1 + 8*X)) / 2.0));

    cout << A << "\n";
}

int main()
{
    cin >> X;

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

ll l_max = 0, r_min = 1e9+5;

struct problem {
    ll l;
    ll r;
    ll a;
    ll b;

    bool operator<(const problem& other) const {
        if (a < other.a ) return true;
        else if(a > other.a ) return false;
        else return b > other.b;
    }
};

int main() {
    int N, l_arg, r_arg;
    cin >> N;
    
    vector<ll> L(N), R(N);
    vector<problem> problems(N);
    REP(i, N) {
        ll l, r;
        cin >> l >> r;
        L[i] = l;
        R[i] = r+1;
        if(l_max < l) {
            l_max = l;
            l_arg = i;
        }
        if(r_min > r + 1) {
            r_min = r + 1;
            r_arg = i;
        }
    }

    ll length_max = 0;
    REP(i, N) {
        problems[i].l = L[i];
        problems[i].r = R[i];
        problems[i].a = max(R[i] - l_max, ll(0));
        problems[i].b = max(r_min - L[i], ll(0));
        if(R[i] - L[i] > length_max) length_max = R[i] - L[i];
    }

    sort(ALL(problems));

    set<ll> tset;
    ll ans = 0, min1, min2;
    min1 = problems[0].a;
    min2 = 0;
    ans = min1 + min2;

    FOR(i, 1, N-1) {
        min1 = problems[i].a;
        tset.insert(problems[i-1].b);
        min2 = *tset.begin();
        if(ans < min1 + min2) ans = min1 + min2;
    }

    tset.insert(problems[N-1].b);
    if(ans < *tset.begin()) {
        ans = *tset.begin();
    }

    if(ans < length_max + max(min(R[l_arg], R[r_arg]) - max(L[l_arg], L[r_arg]), ll(0)))
        ans = length_max + max(min(R[l_arg], R[r_arg]) - max(L[l_arg], L[r_arg]), ll(0));

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

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define LL long long

#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))

const int maxn = 2e5 + 20;
const int MOD = (int) 1e9 + 7;

int n, m;
int L[maxn], R[maxn];
int Qx[maxn];
int ans[maxn];
pair<int, int> pr[maxn];

struct Node
{
    vector<int> v;
    Node *ch[2];
};

void ins(int idx, int pos, int l, int r, int id, Node *&rt)
{
    if(rt == NULL)
    {
        rt = new Node;
        rt->ch[0] = rt->ch[1] = NULL;
    }

    if(l == r)
    {
        rt->v.push_back(idx);
        return ;
    }

    int mid = MID(l, r);

    if(pos <= mid) ins(idx, pos, lson, rt->ch[0]);
    else ins(idx, pos, rson, rt->ch[1]);
}

void dfs(int x, int l, int r, int id, Node *&rt)
{
    if(rt == NULL) return ;

    if(l == r)
    {
        for(auto y : rt->v) ans[y] = x;
        rt = NULL;
        return ;
    }

    int mid = MID(l, r);
    dfs(x, lson, rt->ch[0]);
    dfs(x, rson, rt->ch[1]);

    rt = NULL;
}

void query(int x, int L, int R, int l, int r, int id, Node *&rt)
{
    if(rt == NULL) return ;

    if(L <= l && r <= R)
    {
//        cout <<l <<" " <<r <<endl;
        dfs(x, l, r, id, rt);
        return ;
    }

    int mid = MID(l, r);

    if(L <= mid) query(x, L, R, lson, rt->ch[0]);
    if(mid < R)  query(x, L, R, rson, rt->ch[1]);
}

void work()
{
    cin >>n >>m;
    for(int i = 0; i < n; i++)
    {
        cin >>L[i] >>R[i];
        R[i]--;
        cin >>pr[i].first;
        pr[i].second = i;
    }

    int inf = 1e9;
    Node *rt = NULL;
    for(int i = 0; i < m; i++)
    {
        ans[i] = -1;
        cin >>Qx[i];
        ins(i, -Qx[i], -inf, inf, 1, rt);
    }

    sort(pr, pr + n);

    for(int i = 0; i < n; i++)
    {
        int x = pr[i].first, idx = pr[i].second;
        int s = L[idx], t = R[idx];

//        cout <<s <<" " <<t <<" " <<x <<" interval : " <<x - R[idx] <<" " <<x - L[idx] <<endl;
        query(x, x - R[idx], x - L[idx], -inf, inf, 1, rt);
//
//        cout <<"ans : ";
//        for(int i = 0; i < m; i++) cout <<ans[i] <<" "; cout <<endl;
    }

    for(int i = 0; i < m; i++)
        cout <<ans[i] <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
    int tc = 1;
//    cin >>tc;
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 137728
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n;cin>>n;
    vector<int> ans(100005);
    for(int i =1;i<100;i++){
        for(int j =1;j<100;j++){
            for(int k =1;k<100;k++){
                int sum =i*i+j*j+k*k+i*j+j*k+k*i;
                ans[sum]++;

            }
        }
    }
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }

}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i,n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i,m) {
    int a = q.top(); q.pop();
    q.push(a/2);
  }
  ll ans = 0;
  rep(i,n) {
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;

const int Maxn = 1005;
const int Maxb = 40;

int n;
ll X[Maxn], Y[Maxn];
ll pw[Maxb];
ll my[Maxb];
int b = 32;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld %lld", &X[i], &Y[i]);
        if (bool((X[i] + Y[i]) % 2) != bool((X[0] + Y[0]) % 2)) { printf("-1\n"); return 0; }
    }
    pw[0] = 1;
    for (int i = 1; i < b; i++)
        pw[i] = 2ll * pw[i - 1];
    for (int i = 0; i < b; i++)
        my[i] = pw[b - 1 - i];
    if ((X[0] + Y[0]) % 2 == 0)
        my[b++] = 1;
    printf("%d\n", b);
    for (int i = 0; i < b; i++)
        printf("%lld%c", my[i], i + 1 < b? ' ': '\n');
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < b; j++)
            if (abs(X[i]) >= abs(Y[i]))
                if (X[i] < 0) { printf("L"); X[i] += my[j]; }
                else { printf("R"); X[i] -= my[j]; }
            else if (Y[i] < 0) { printf("D"); Y[i] += my[j]; }
                 else { printf("U"); Y[i] -= my[j]; }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		int count = Integer.parseInt(in);
		int sum = 0;
		for (int i = 0; i < count; i++) {
			String line = sc.nextLine();
			String[] lineArray = line.split(" ");
			int start = Integer.parseInt(lineArray[0]);
			int end = Integer.parseInt(lineArray[1]);
			int lineSum = (end + 1) - start;
			sum += lineSum;
		}
		System.out.println(sum);
	}



}

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s; cin >> s;

  int one = 0, zer0 = 0;
  rep(i, s.size()) {
    s[i]-'0' ? ++one : ++zer0;
  }
  cout << min(one, zer0) * 2;
}


Measured memory_bytes: 512
N, L = list(int(el) for el in input().split())

sum = 0
min_val = 100000

for i in range(1,N+1):
  sum += L+i-1
  if abs(L+i-1) < abs(min_val):
    min_val = L+i-1
    
print(sum-min_val)

Measured memory_bytes: 3060
import sys
N = int(input())
MOD = 10**9+7
ACGT = ['A', 'C', 'G', 'T']
# ?AGC
# ?GAC
# ?ACG
# A?GC
# AG?C

def ok(l4):
  l3 = l4[1:4]
  if l3 == 'AGC' or l3 =='GAC' or l3 == 'ACG':
    return False
  if l4[0] == 'A' and l4[2:4] == 'GC':
    return False
  if l4[0:2] == 'AG' and l4[3] == 'C':
    return False
  return True

# dp[i][l4] = i文字かつ末尾4文字がlast4な数
dp = [{} for _ in range(N+1)]

for c1 in ACGT:
  for c2 in ACGT:
    for c3 in ACGT:
      l4 = 'X' + c1 + c2 + c3
      if ok(l4):
        dp[3][l4] = 1
      else:
        dp[3][l4] = 0

for i in range(4, N+1):
  for l4 in dp[i-1].keys():
    for c in ACGT:
      next_l4 = l4[1:4] + c
      if not next_l4 in dp[i]:
        dp[i][next_l4] = 0
      if ok(next_l4):
        dp[i][next_l4] += dp[i-1][l4]

print(sum(dp[N].values())%MOD)

Measured memory_bytes: 6488
S=input()
Q=int(input())

X=[]
Y=[]
f=1
for _ in range(Q):
    A=list(input().split())
    if A[0]=="1":
        f*=-1
    if A[0]=="2":
        if A[1]=="1":
            if f==1:
                X.append(A[2])
            if f==-1:
                Y.append(A[2])
        if A[1]=="2":
            if f==-1:
                X.append(A[2])
            if f==1:
                Y.append(A[2])

x="".join(X)
x="".join(list(reversed(x)))
y="".join(Y)

a=[x,S,y]
b="".join(a)

if f==-1:
    b="".join(list(reversed(b)))

print(b)


Measured memory_bytes: 70232
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#define ll long long
using namespace std;

int main()
{
  string S;
  cin >> S;
  int n = S.size();
  string str = "";
  for (int i = 0; i < n / 2; i++)
  {
    str += "hi";
  }
  if (str == S)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int v[60];
int main(){
	int n;cin>>n;
	priority_queue<double,vector<double>,greater<double>>que;
	rep(i,n){
		cin>>v[i];
		que.push(v[i]);
	}
	while(que.size()>1){
		double a=que.top();que.pop();
		double b=que.top();que.pop();
		que.push((a+b)/2);
	}
	double ans=que.top();
	printf("%.12lf\n",ans);
}

Measured memory_bytes: 256
// Problem : F - Strivore
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rep2(i,a,b) for(int i = a; i >= b; i--)
#define die return 0;

using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;

const int MOD=1e9+7;
const int MAX=2e6+7;

ll modulo(ll a,ll b, ll n){
    ll x=1, y=a; 
    while (b > 0) {
        if (b%2 == 1) {
            x = (x*y) % n; // multiplying with base
        }
        y = (y*y) % n; // squaring the base
        b /= 2;
    }
    return x % n;
}

vector<int> fact(MAX+1),finv(MAX+1);

void pre()
{
	fact[0]=1,finv[0]=1;
	for(int i=1; i<=MAX; i++)
	{
		fact[i]=(fact[i-1]*i)%MOD;
	}
	for(int i=1; i<=MAX; i++)
	{
		finv[i]=modulo(fact[i],MOD-2,MOD);
	}
}

int nCr(int n, int r)
{
	if(n<r)
		return 0;
	if (n < 0 || r < 0) return 0;
    if (r == 0 || r == n) return 1;
		return ((((fact[n]*finv[r])%MOD)*finv[n-r])%MOD);
}

int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int testcases;
testcases=1;
//cin>>testcases;

while(testcases--)
{
pre();
int k;
string str;
cin>>k;
cin>>str;
int ans=0;
int len=str.length();
int fin=len+k;
for(int i=len; i<=fin; i++)
{
	int last=fin-i;
	int temp=modulo(26,last,MOD);
	temp=(temp*modulo(25,fin-last-len,MOD))%MOD;
	temp=(temp*nCr(i-1,len-1))%MOD;
	ans=(ans+temp)%MOD;
}

cout<<ans<<'\n';
}

return 0;
}


Measured memory_bytes: 35520
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	const double pi = acos(0)*2;
	double n;
	cin >> n;
	cout << 2 * n * pi << '\n';
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    ll N, M;
    cin >> N >> M;

    if (M % N == 0) {
        cout << M / N << endl;
        return;
    }

    for (int i = M/N; i >= 1; i--) {
        if (M % i == 0) {
            cout << i << endl;
            return;
        }
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
// =====================================================================
// macros
// =====================================================================

/// input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        #[allow(unused_mut)]
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            #[allow(unused_mut)]
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        #[allow(unused_mut)]
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/// yet another input macro from https://qiita.com/hatoo@github/items/fa14ad36a1b568d14f3e
#[allow(unused_macros)]
macro_rules! inputln {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

// =====================================================================
// functions
// =====================================================================

fn main() {
    input!{
        h: usize,
    }
    let mut sum:usize= 0;
    while h > 1{
        sum += 1;
        h/=2;
    }
    let result = 2i64.pow((sum+1) as u32) - 1;
    println!("{}",result.to_string());
}


Measured memory_bytes: 4352
import java.util.Scanner;

class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int ts = sc.nextInt();
		int h = ts/3600;
		int m = ts%3600/60;
		int s = ts%3600%60;
		System.out.println(h + ":" + m +":" + s);
	}
}


Measured memory_bytes: 26268
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


#define rep(i,r,l) for(int i = r; i < l; i++)
#define elif else if
#define ll long long

ll nextint(void){ll n;scanf("%lld",&n);return n;}
void printint(ll d){printf("%lld\n",d);}


int main(void){ 

    ll sum=0;
    int n = nextint();
    ll max = nextint();
    rep(i,1,n){
        ll a = nextint();
        //printint(a);
        (max>a)?(sum+=(max-a)):(max = a);
    }
    printint(sum);
    return 0;
}



Measured memory_bytes: 1708
import numpy as np
N = int(input())
S = []
for i in range(N):
    S.append(list(map(int,input().split())))
now = [0,0]
time = 0
flag = True
for i in range(N):
    dis = abs(S[i][1]-now[0])+abs(S[i][2]-now[1])
    if(dis > S[i][0] or (S[i][0]-time)%2 != dis%2):
        flag = False
        break
    now[0] = S[i][1]
    now[1] = S[i][2]
    time = S[i][0]
    
if flag:
    print("Yes")
else:
    print("No")

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

using namespace std;
using ll = long long;

#pragma GCC optimize("O3")
static const auto __ = [] {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  return nullptr;
}();

ll solve(int N, int M) {
  pair<ll, int> A[N];
  for (pair<ll, int>& a : A) {
    cin >> a.first >> a.second;
  }
  sort(A, A + N);
  ll ans {0};
  for (int i {0}; M; ++i) {
    int amt {min(A[i].second, M)};
    ans += amt * A[i].first;
    M -= amt;
  }
  return ans;
}

int main(int argc, char* argv[]) {
  int N, M;
  cin >> N >> M;
  cout << solve(N, M) << '\n';
  return 0;
}

Measured memory_bytes: 1792
#coding: UTF-8
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))
ans = 0
def linsearch(v,S):
  for w in S:
    if v == w:
      return True
  return False
  
for v in T:
  if linsearch(v,S):
    ans += 1
  
print(ans)


Measured memory_bytes: 6548
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

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

ll lcm(ll a, ll b)
{
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}

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

int solve(vector<vector<int>> &a, int n, bool x, bool y, bool z, vector<vector<int>> &dp)
{
    if (n == 1)
    {
        if (x)
        {
            return dp[n][0] = max(a[n - 1][1], a[n - 1][2]);
        }
        if (y)
        {
            return dp[n][1] = max(a[n - 1][0], a[n - 1][2]);
        }
        return dp[n][2] = max(a[n - 1][0], a[n - 1][1]);
    }
    int b = 0, c = 0, d = 0;
    if (!x)
    {
        if (dp[n][0] != -1)
        {
            b = dp[n][0];
        }
        else
        {
            b = a[n - 1][0] + solve(a, n - 1, 1, 0, 0, dp);
            dp[n][0] = b;
        }
    }
    if (!y)
    {
        if (dp[n][1] != -1)
        {
            c = dp[n][1];
        }
        else
        {
            c = a[n - 1][1] + solve(a, n - 1, 0, 1, 0, dp);
            dp[n][1] = c;
        }
    }
    if (!z)
    {
        if (dp[n][2] != -1)
        {
            d = dp[n][2];
        }
        else
        {
            d = a[n - 1][2] + solve(a, n - 1, 0, 0, 1, dp);
            dp[n][2] = d;
        }
    }
    return max({b, c, d});
}

int main()
{
    start();
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(3, 0));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> dp(n + 1, vector<int>(3, -1));
    cout << solve(a, n, 0, 0, 0, dp);
    return 0;
}

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

int main(){
  long long N,ans,g,u;
cin>>N;
  ans=(N/11)*2;
  g=N%11;
 if(g>6){
   ans+=2;
 }
  else if(g>0){
    ans++;
  }
    cout<<ans<<endl;
}


Measured memory_bytes: 256