akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
/*子を持たない節点は外部節点(external node)または葉(leaf)と呼ばれる。葉でない節点は内部接点(internal node)と呼ぶ。
*/
const int MAX_N =100010;
int n;//頂点数
int parent[MAX_N];//親のノード番号
int child[MAX_N];//子供
int brother[MAX_N];

void rec(){
	for(int i =0;i < n;i++){
		cout << "node " << i << ": parent = " << parent[i] << ", depth = " << flush;
		int cnt = 0;
		for(int j =i;parent[j]!=-1;j =parent[j]) cnt++;
		cout << cnt << ", " << flush;

		if(parent[i]==-1)cout << "root, " << flush;
		else if(child[i]==-1)cout << "leaf, " << flush;
		else cout << "internal node, " << flush;

		cout << "[";
		for(int j =child[i];j !=-1;j =brother[j]){
			if(j!=child[i]){
				cout <<", ";
			}
			cout <<j;
		}
		cout <<"]"<<endl;;
	}
}

int main(){
	cin>>n;
	fill(parent,parent+MAX_N,-1);
	fill(child,child+MAX_N,-1);
	fill(brother,brother+MAX_N,-1);
	for(int i =0;i < n;i++){
		int node,k,prev;
		cin>>node>>k;
		for(int j =0;j < k;j++){
			int x;
			cin>>x;
			parent[x]=node;
			if(j==0)child[node] =x;
			else brother[prev] =x;
			prev = x;
		}
	}
	rec();
	return 0;
}

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

		int N = sc.nextInt();
		long K = sc.nextLong();
		long[] count = new long[100001];
		for( int i=0; i<N; i++ ){
			int a = sc.nextInt();
			long b = sc.nextLong();
			count[a] += b;
		}
		long ans = 0;
		for( int i=1; i<=100000; i++ ){
			ans += count[i];
			if( ans>=K ){
				System.out.println(i);
				break;
			}
		}
	}
}


Measured memory_bytes: 64708
from collections import deque

H, W = map(int, input().split())
Maze = [list(input()) for _ in range(H)]
ans = 0
sy = 0
while sy < H:
  sx = 0
  while sx < W:
    if Maze[sy][sx] == ".":
      M_cnt = 0
      q = deque()
      memo = [[-1]*(W) for _ in range((H))]
      memo[sy][sx] = 0
      q.append([sy, sx])
      while q:
        cy, cx = q.popleft()
        for ny, nx in zip((cy, cy, cy+1, cy-1) , (cx+1, cx-1, cx, cx)):
          if ny >= 0 and ny < H and nx >= 0 and nx < W and Maze[ny][nx] == "." and memo[ny][nx] < 0:
            q.append([ny, nx])
            memo[ny][nx] = memo[cy][cx] + 1
      ans = max(ans, max([max(m)  for m in memo]))
    sx += 1
  sy += 1
print(ans)

Measured memory_bytes: 47196
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

n,m,k = map(int,readline().split())
a = list(map(int,readline().split()))
b = list(map(int,readline().split()))

csuma = [0]
csumb = [0]
for ai in a:
    csuma.append(csuma[-1]+ai)
for bi in b:
    csumb.append(csumb[-1]+bi)


ans = 0
for i,csumai in enumerate(csuma):
    ng = m+1
    ok = -1
    while ng - ok > 1:
        mid = (ok + ng)//2
        if csumb[mid] <= k-csumai:
            ok = mid
        else:
            ng = mid
    if ok >= 0:
        ans = max(ans,i+ok)
print(ans)


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

int main() {
    int N = 0;
    int K = 0;
    
    cin >> N >> K;
    
    vector<int> vec(N, 0);
    vector<int> box(N + 1, 0);
    
    for (int i = 0; i < N; ++i) {
        cin >> vec[i];
    }
    
    for (int i = 0; i < N; ++i) {
        box[vec[i]]++;
    }
    sort(box.begin(), box.end());
    
    int ans = 0;
    
    for (int i = 0; i < N + 1; ++i) {
        if (box[i] != 0) {
            int variation = N + 1 - i;
            for (int j = i; j < N + 1; ++j) {
                if (variation <= K)
                    break;
                else {
                    variation--;
                    ans += box[j];
                }
            }
            break;
        }
    }
    
    cout << ans;
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)

using namespace std;
typedef long long int ll;
typedef pair<int,int> PI;

int P,Q,R;
int main(void){
    cin >> P >> Q >> R;
    cout << P+Q+R-max(P,max(Q,R)) << endl;
    return 0;
}



Measured memory_bytes: 256
N = gets.to_i
Se = []
So = []
(N + 1).times{|i| So << []; Se << []}
(N - 1).times{|i|
  u, v, w = gets.chomp.split(" ").map(&:to_i);
  w.even? ? (Se[u] << v; Se[v] << u) : (So[u] << v; So[v] << u)
}

vtx = Array.new(N + 1){ -1 } 
vtx[1] = 1
q = [1]
while q.size > 0
  v = q.shift
  Se[v].select{|i| -1 == vtx[i] }.each{|j| vtx[j] =   vtx[v]; q.push(j)}
  So[v].select{|i| -1 == vtx[i] }.each{|j| vtx[j] = 1-vtx[v]; q.push(j)}
end

puts vtx[1, N]

Measured memory_bytes: 18428
package main

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

func main() {
	sc := NewScanner()

	_ = sc.NextLine()
	s := sc.NextLine()
	cnt := make([]int, len(s))
	num := 0

	// for W
	for i := 0; i < len(s); i++ {
		if i == 0 {
			cnt[0] = num
			if string(s[i]) == "W" {
				num++
			}
			continue
		}
		cnt[i] = num
		if string(s[i]) == "W" {
			num++
		}
	}
	//	fmt.Printf("%+v\n", cnt) // output for debug
	num = 0
	for i := len(s) - 1; i >= 0; i-- {
		if i == len(s)-1 {
			cnt[len(s)-1] += num
			if string(s[i]) == "E" {
				num++
			}
			continue
		}
		cnt[i] += num
		if string(s[i]) == "E" {
			num++
		}
	}
	//	fmt.Printf("%+v\n", cnt) // output for debug

	min := 3000000
	for i := 0; i < len(cnt); i++ {
		if min > cnt[i] {
			min = cnt[i]
		}
	}
	fmt.Printf("%+v\n", min) // output for debug
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

long long int dp[3001][3001][2];

long long int play(long int a[],int start,int end,int chance,long long int x,long long int y)
{
    if(start==end)
    {
        if(chance)
        {
            y+=a[start];
        }else
        {
            x+=a[start];
        }
        return x-y;
    }
    long long int t1,t2;
    if(chance)
    {
        if(!dp[start+1][end][0])
        {
            dp[start+1][end][0]=play(a,start+1,end,0,x,y+a[start])-x+y+a[start];
        }
        if(!dp[start][end-1][0])
        {
            dp[start][end-1][0]=play(a,start,end-1,0,x,y+a[end])-x+y+a[end];
        }
        t1=dp[start+1][end][0]+x-y-a[start];
        t2=dp[start][end-1][0]+x-y-a[end];
        return min(t1,t2);
    }
    if(!dp[start+1][end][1])
    {
        dp[start+1][end][1]=play(a,start+1,end,1,x+a[start],y)-x-a[start]+y;
    }
    if(!dp[start][end-1][1])
    {
        dp[start][end-1][1]=play(a,start,end-1,1,x+a[end],y)-x-a[end]+y;
    }
    t1=dp[start+1][end][1]+x+a[start]-y;
    t2=dp[start][end-1][1]+x+a[end]-y;
    return max(t1,t2);
}

int main()
{
    int n;
    cin>>n;
    long int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cout<<play(a,0,n-1,0,0,0);
}


Measured memory_bytes: 139904
#define r return
#define a (int dx,int dy,int x,int y,char m,int c)
i,j,n,f[6];w[8]={1,1,0,-1,-1,-1,0,1};h[8]={0,1,1,1,0,-1,-1,-1};char t[10][10],mark[2]={'o','x'};l a{if(t[x][y]=='.'||t[x][y]=='0')r 0;if(t[x][y]==m)r c;r l(dx,dy,x+dx,y+dy,m,c+1);}s a{int k,d;d=0;if(t[x][y]!='.')r 0;for(k=0;k<8;k++)d+=l(w[k],h[k],x+w[k],y+h[k],m,0);r d;}p a{if(t[x][y]=='0'||t[x][y]=='.')r 0;if(t[x][y]==m)r 1;if(p(dx,dy,x+dx,y+dy,m,0)){t[x][y]=m;r 1;}else r 0;}o a{int k;t[x][y]=m;for(k=0;k<8;k++)p(w[k],h[k],x+w[k],y+h[k],m,0);r 0;}main(){for(i=0;i<10;i++)t[0][i]=t[9][i]='0';for(i=1;i<9;i++){scanf("%s",&t[i][1]);t[i][0]='0';t[i][9]='0';}f[1]=-1;for(n=0;;n=(n+1)%2){f[n]=-1;for(i=n?8:1;n?i>-1:i<9;n?i--:i++)for(j=n?8:1;n?j>-1:j<9;n?j--:j++)f[n]<s(0,0,i,j,mark[n],0)?f[2+n]=i,f[4+n]=j,f[n]=s(0,0,i,j,mark[n],0):0;f[n]!=0?o(0,0,f[2+n],f[4+n],mark[n],0):0;if(f[0]==0&&f[1]==0)break;}for(i=1;i<9;i++){for(j=1;j<9;j++)printf("%c",t[i][j]);puts("");}r 0;}

Measured memory_bytes: 524
def run(A, B):
    ans = None
    if 1 not in [A, B]:
        ans = 1
    if 2 not in [A, B]:
        ans = 2
    if 3 not in [A, B]:
        ans = 3
    return ans


def main():
    A = int(input())
    B = int(input())
    print(run(A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int x,y,z;
  cin>>x>>y>>z;
  int width=y+z;
  int person=x/width;
  x-=(person*width);
  if(x<z)person--;
  cout<<person<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch DisjointSetOfCommonDivisors | diff DisjointSetOfCommonDivisors.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address DisjointSetOfCommonDivisors.cpp && ./a.out

/*
 
 9/28/2019
 
 5:12-
 
 */

LL A,B;

LL gcd(LL a, LL b) { return b==0?a:gcd(b,a%b); }

vector<LL> distinctPrimeFactors(LL n) {
  assert(n>=1);
  vector<LL> res;
  for(LL p=2; p*p<=n; ++p) if(n%p==0) {
    res.push_back(p);
    while(n%p==0) n/=p;
  }
  if(n>1) res.push_back(n);
  return res;
}

void solve() {
  vector<LL> X=distinctPrimeFactors(A),Y=distinctPrimeFactors(B);
  set<LL> P1(ALL(X)),P2(ALL(Y));
  int res=1;
  FORR(p,P1) if(P2.count(p)) ++res;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>A>>B;
  solve();
  
  return 0;
}


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

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

struct UF
{
	int par[SIZE],rank[SIZE];

	void init(int n)
	{
		for(int i=0;i<n;i++)
		{
			par[i]=i;
			rank[i]=0;
		}
	}
	int find(int x)
	{
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y)
	{
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]) par[x]=y;
		else
		{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
	bool same(int x,int y)
	{
		return find(x)==find(y);
	}
};
UF uf;
int A[SIZE];
vector <int> vec[SIZE];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	uf.init(n+2);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
	}
	for(int i=0;i<m;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		uf.unite(x,y);
	}
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(uf.find(i)==i) cnt++;
		int p=uf.find(i);
		vec[p].push_back(A[i]);
	}
	if((cnt-1)*2>n)
	{
		printf("Impossible");
		return 0;
	}
	if(cnt==1)
	{
		printf("0");
		return 0;
	}
	ll ret=0;
	vector <int> vt;
	for(int i=0;i<n;i++)
	{
		if(uf.find(i)==i)
		{
			sort(vec[i].begin(),vec[i].end());
			ret+=vec[i][0];
			for(int j=1;j<vec[i].size();j++) vt.push_back(vec[i][j]);
		}
	}
	sort(vt.begin(),vt.end());
	for(int i=0;i<cnt-2;i++) ret+=vt[i];
	printf("%lld\n",ret);
	return 0;
}


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

int main(void){
    int h = 0, w = 0, n = 0;
    int ans = 0, cnt = 0;

    scanf("%d%d%d", &h, &w, &n);

    if(h >= w){
        while(cnt < n){
            cnt += h;
            ans++;
        }
    }else{
        while(cnt < n){
            cnt += w;
            ans++;
        }
    }

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

    return 0;

} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
template<typename T>
inline T read(T&x){
	x=0;int f=0;char ch=getchar();
	while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x=f?-x:x;
}
const int N=10000+10;
int n;
int main(){
	cin>>n;
	puts(n<=999?"ABC":"ABD");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
   int  n,i,x,temp;
   x=0;
   temp=0;
   scanf("%d ",&n);
   char ar[n+1];
   for(i=0;i<n;i++)
        scanf("%c",&ar[i]);
   for(i=0;i<n;i++)
   {
       if(ar[i]=='I'){
        x++;
       }
       if(ar[i]=='D'){
        x--;
       }
       if(x>temp){
        temp=x;
       }
       
   }
       printf("%d",temp);
       return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int idx = s.find("ABC");
    int cnt = 0;
    while(idx != string::npos)
    {
        cnt++;
        idx = s.find("ABC", idx+3);
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    int count = scan.nextInt();

    while(count>0) {
      int[][] arr = new int[count][2];
      for(int i = 0; i < count; i++) {
        char[] input = scan.next().toCharArray();
        //System.out.println(input);
        arr[i][0] = input.length;
        arr[i][1] = input[input.length-1];
      }

      Func.ite = 0;
      Func.arr = arr;

      System.out.println(new Func().calc());

      count = scan.nextInt();
    }
  }
}

class Func{
  static int ite;
  static int[][] arr;
  char mark;
  ArrayList<Func> list;

  Func() {
    mark = (char)arr[ite][1];
    switch(arr[ite][1]) {
      case '+':
      case '*':
        int deep = arr[ite][0];
        ite++;
        list = new ArrayList<>();
        while(ite<arr.length&&arr[ite][0]>deep) {
          list.add(new Func());
        }
        break;
      default:
        ite++;
        break;
    }
  }

  int calc() {
    int sum = 0;
    switch(mark) {
      case '+':
        for(Func _f : list) {
          sum += _f.calc();
        }
        return sum;
      case '*':
        sum = 1;
        for(Func _f : list) {
          sum *= _f.calc();
        }
        return sum;
      default:
        return (int)(mark-'0');
    }
  }
}

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

using namespace std;
#define pb push_back
#define db(x) cerr << #x << " = " << x << endl;
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define vi vector<int>
#define vll vector<ll>
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define ll long long
#define ull unsigned long long
typedef long double ld;

const int MAXN = 3000;

int n;
double p[MAXN];
int vis[MAXN][MAXN];
double dp[MAXN][MAXN];

double solve(int idx, int heads)
{
    if (idx == n)
    {
        int tails = idx - heads;
        return heads > tails;
    }

    if (vis[idx][heads])
        return dp[idx][heads];
    vis[idx][heads] = 1;

    return dp[idx][heads] = p[idx] * solve(idx + 1, heads + 1) + (1.0 - p[idx]) * solve(idx + 1, heads);
}

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

    printf("%.10lf\n", solve(0, 0));
    
}

Measured memory_bytes: 104320
r,c = tuple(map(int,input().split()))

a = [[int(t)for t in input().split()]for _ in [0]*r]

r_sum = []

for i in range(r):
    r_sum.append(sum(a[i]))

c_sum = []

for i in range(c):
    s_ = 0
    for j in range(r):
        s_+=a[j][i]
    c_sum.append(s_)

for i in range(r):
    for j in range(c):
        print(a[i][j],end=' ')
    print(r_sum[i])

for t in range(c):
    print(c_sum[t],end=' ')

print(sum(c_sum))
  


Measured memory_bytes: 6248
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll SORT(int n, vector<pair<ll, ll>> &v, int start){
  sort(v.begin()+start, v.end());
  return v[n-1].first;
}


int main(void){
  
  double a,b,h;
  cin>>a>>b>>h;
  cout<<(a+b)*h/2.0<<endl;
  return 0;


}

Measured memory_bytes: 256
// Problem : A - Multiplication 1
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define T() int tt; cin >> tt; rep1(qq,1,tt)
#define rep(i,start,lim) for(int i=start;i<lim;i++)
#define rep1(i,start,lim) for(int i=start; i<=lim; ++i)
#define repd(i,start,lim) for(int i=start;i>=lim;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define br cout<<"\n"
#define MOD (1000000007LL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eps (1e-6)
#define what_is(x) cerr << #x << " is " << x << "\n";
#define int long long int
#define infll 9e18
#define inf 1e12

#define lnode (2 * node + 1)
#define rnode (2 * node + 2)

using namespace std;

typedef pair<int, int> pii;

const int N = 3 * 1e6 + 2;

int n, k;

int32_t main(){

  FIO
  //cout << fixed << setprecision(10);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  cin >> n >> k;
  cout << n * k << '\n';

	return 0;
}






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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; i++)
    cin >> l[i];
  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = 0; i < n-2; i++) {
    for (int j = i+1; j < n-1; j++) {
      for (int k = j+1; k < n; k++) {
        if (l[i] + l[j] > l[k]) ans++;
        else break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    ll L,R;
    cin >> L >> R;
    if(R-L>=2018){
        cout << 0 << endl;
        return 0;
    }
    ll ans=MOD;
    for(ll i=L; i<=R; i++){
        for(ll j=L; j<i; j++){
            ans=min(ans,(i*j)%2019);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LINE_BUFSIZ 1024

int main(int argc, char **argv)
{
  char buf[LINE_BUFSIZ];
  if (!fgets(buf, LINE_BUFSIZ, stdin)) {
    perror("fgets");
    exit(1);
  }

  int a, b;
  char *p = strchr(buf, ' ');
  int space_index = p - buf;

  buf[space_index] = 0;

  a = atoi(buf);
  b = atoi(p + 1);

  int tower_index = b - a;
  int tower_height = tower_index * (tower_index + 1) / 2;

  printf("%d\n", tower_height - b);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  string s;

  cin >> s;

  int ans;
  int cnt1 = 0;
  int cnt2 = 0;

  for(int i = 0; i < s.size(); i++){
    //変える色が101010の場合
    if(i % 2 == 0){
      //偶数番目
      if(s[i] == '0'){
        cnt1++;
      }
    }else{
      //奇数番目
      if(s[i] == '1'){
        cnt1++;
      }
    }
    //変える色が010101の場合
    if(i % 2 == 0){
      //偶数番目
      if(s[i] == '1'){
        cnt2++;
      }
    }else{
      //奇数番目
      if(s[i] == '0'){
        cnt2++;
      }
    }  
  }
  ans = min(cnt1, cnt2);
  cout << ans << endl;
}


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

using namespace std;

int main() {
    int N,tot,L,i,mx;

    scanf("%d",&N);

    mx = 0;
    tot = 0;
    for (i = 0;i < N;i++) {
        scanf("%d",&L);
        tot += L;
        mx = max(mx,L);
    }

    if (tot - mx > mx)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<stack>
#include <cstring>
#include <climits>
using namespace std;
#define rep(i,n) for(int (i)=0;(i) < (n); (i)++)
#define rrep(f,i,n) for(int (i)=0;(i) < (f); (i)++)
#define FIND(v, k) find((v).begin(), (v).end(), k)
#define MAX 101
#define MAX_V 15
#define mset(a,x) memset(a,x,sizeof(a))
int t[100000];
int main() {
	int n, c, k;
	cin >> n >> c >> k;
	rep(i, n) {
		cin >> t[i];
	}
	sort(t, t + n);
	int res = 0;
	int i = 0;
	while (i < n) {
		int nu = 0;
		int j = i;
		while (nu + 1 <= c && t[j] - t[i] <= k && j < n) {
			nu++;
			j++;
		}
		res++;
		i = j;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>

using namespace std;

void out() {
     cout.flush();
    int n;
    cin >> n;
    exit(0);
}

void solve() {
     int n, m;
     cin >> n >> m;
     int kol = 0;
     int num = 0;
     int k;
     cin >> k;
     vector<vector<int> > a(n, vector<int>(m, 0));
     for (int i = 0; i < n; ++i) {
         int st, fin, dd;
         if (i&1)
            st = 0, fin = m, dd = 1;
         else
            st = m-1, fin = -1, dd = -1;
         for (int j = st; j != fin; j += dd) {
             if (kol == 0) {
                cin >> kol;
                ++num;
             }
             --kol;
             a[i][j] = num;
         }
     }
     for (int i = 0; i < n; ++i) {
         for (int j = 0; j < m; ++j)
             cout << a[i][j] << ' ';
         cout << "\n";
     }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    solve();
    out();
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  string S; cin >> S;
  // SA-IS O(n)
  vector<int> sa(N + 1); rep(i, N + 1) sa[i] = i;
  sort(range(sa), [&](int i, int j) {
    return S.substr(i) < S.substr(j);
  });
  // LCP O(n)
  vector<int> lcp(N + 1);
  rep(i, N) {
    int h = 0;
    while (sa[i] + h < N && sa[i + 1] + h < N && S[sa[i] + h] == S[sa[i + 1] + h]) h++;
    lcp[i] = h;
  }

  vector<int> ord(N);
  rep(i, N) ord[i] = i;
  // counting sort O(n)
  sort(range(ord), [&](int i, int j) { return lcp[i] > lcp[j]; });

  vector<int> par(N + 1); rep(i, N + 1) par[i] = i;
  vector<int> mn(N + 1), mx(N + 1);
  rep(i, N + 1) mn[i] = mx[i] = sa[i];
  auto find = [&](int x) -> int {
    while (x != par[x]) x = par[x];
    return x;
  };
  auto unite = [&](int x, int y) {
    x = find(x);
    y = find(y);
    mn[x] = min(mn[x], mn[y]);
    mx[x] = max(mx[x], mx[y]);
    par[y] = x;
  };

  // O(n*a(n))
  int ans = 0;
  for (int i : ord) {
    unite(i, i + 1);
    int r = find(i);
    ans = max(ans, min(lcp[i], mx[r] - mn[r]));
  }
  cout << ans << endl;
}


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

int main() {
	int x;
	for (int i = 0; i < 10000; i++) {
		cin>>x;
		if (x == 0) {
			break;}

	cout << "Case" <<" " <<i+1 << ": " << x << endl;
		
	}
	
}


Measured memory_bytes: 3004
#include <iostream>

int main(){
    
    int H,W;
    
    while(1){
    std::cin >> H >> W;
    
    if(H == 0 && W == 0)return 0;
    
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            std::cout << "#";
        }
        std::cout << "\n";
    }
    
    std::cout << "\n";
    }
    
    return 0;
}



Measured memory_bytes: 3016
N=int(input())
s=input()
a=[0]*N
for i in range(1,N):
    if s[i]=="E": a[0]+=1

for j in range(1,N):
    tmp=a[j-1]
    if s[j-1]=="W": tmp+=1
    if s[j]=="E": tmp-=1
    a[j]=tmp

print(min(a))

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

int main()
{
  int n;
  int arr[100];
  int i, j, k;
  cin >> n;

  for(i=0;i<n;i++)
  {
    cin >> arr[i];
  }

  int cnt = 0;


  for(i=0;i<n;i++)
  {
    for(j = i+1;j<n;j++)
    {
      for(k = j+1; k<n;k++)
      {
        if(arr[i]!= arr[j] && arr[i]!= arr[k] && arr[j] != arr[k]){
          if( (arr[i] + arr[j] > arr[k]) && (arr[j] + arr[k] > arr[i]) && ((arr[i] + arr[k] > arr[j])) )
          {
            cnt++;
          //  cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
          }
        }
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}


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

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}

#[fastout]
fn main() {
  input!{
    n: usize,
    xl: [(i32, i32);n]
  };

  // let mut xl = xl;
  // xl.sort_by_cached_key(|t| t.0 + t.1); // -> 32ms
  // xl.sort_by_key(|t| t.0 + t.1);        // -> 36ms
  // xl.sort_unstable_by_key(|t| t.0 + t.1);  // -> 28ms ただし最長ケースが異なる。
  // let mut idx = std::i64::MIN;
  // let mut ans = 0;
  // for (x, l) in xl {
  //   if idx <= x - l {
  //     idx = x+l;
  //     ans += 1;
  //   }
  // }
  let mut xl = xl.iter().map(|t| (t.0+t.1, t.0-t.1)).collect::<Vec<(i32, i32)>>();
  xl.sort_unstable();
  let mut idx = std::i32::MIN;
  let mut ans = 0;
  for (end, start) in xl {
    if idx <= start {
      idx = end;
      ans += 1;
    }
  }
  echo!(ans);
}


Measured memory_bytes: 5408
#include <iostream>

using namespace std;

int main ()
{
	for (int u = 0; u < 100; u++)
	{
		int n,a[100];
		cin >> n;
		if (n == 0)
		{
			break;
		}

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

		int co = 0;

		for (int i = 0; i < n / 4; i++)
		{
			co += a[i];
		}
		cout << co << endl;
	}
	return 0;
}



Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args)  {
       Scanner sc = new Scanner(System.in);
       
       int n = sc.nextInt();
       int a[] = new int[n];
       for(int i=0;i<n;i++){
           a[i] = sc.nextInt();
       }
       int count = 0;
       boolean flag = true;
       while(flag){
           flag = false;
           for(int i=n-1;i>0;i--){
               if(a[i]<a[i-1]){
                   int tmp = a[i];
                   a[i] = a[i-1];
                   a[i-1] = tmp;
                   count++;
                   flag = true;
               }
           }
       }
       System.out.print(a[0]);
       for(int i=1;i<n;i++){
           System.out.printf(" %d",a[i]);
       }
       System.out.println();
       System.out.println(count);
    }
}



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

using namespace std;

string s;

int stoi(string str) {
	int len = (int)str.size();
	if (len==0) return 0;
	return (str[len - 1] - '0') + 10 * ( stoi(str.substr(0, len - 1)) );
}

int parse(int l, int r) {
	int k = 0;
	
	// +, -
	for (int i=r-1; i>=l; i--) {
		if (s[i]=='(') k++;
		if (s[i]==')') k--;
		if (k==0 && s[i]=='+') return parse(l, i) + parse(i+1, r);
		if (k==0 && s[i]=='-') return parse(l, i) - parse(i+1, r);
	}
	
	// *,/
	for (int i=r-1; i>=l; i--) {
		if (s[i]=='(') k++;
		if (s[i]==')') k--;
		if (k==0 && s[i]=='*') return parse(l, i) * parse(i+1, r);
		if (k==0 && s[i]=='/') return parse(l, i) / parse(i+1, r);
	}
	
	if (s[l] == '(' && s[r-1] == ')') return parse(l+1, r-1);
	
	return stoi(s.substr(l, r-l));
}

int main() {
	int n; cin >> n;
	
	for (int i=0; i<n; i++) {
		cin >> s;
		cout << parse(0, (int)s.size()-1) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1212
import java.util.*;
 
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] cnt = new int[100];
		
		for(int i=1;i<=n;i++){
			if(i<10)
				cnt[i*10+i]++;
			else{
				int q = i;
				while(q>=10){
					q/=10;
				}
				int r = i%10;
				
				cnt[q*10+r]++;
			}
		}
		
		int ans = 0;
		for(int i=11;i<=99;i++){
			int q = i/10;
			int r = i%10;
			
			if(q!=0 && r!=0){
				ans += cnt[q*10+r]*cnt[r*10+q];
			}
		}
		
		System.out.println(ans);
	}
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    string s = to_string(n);
    bool ans = false;
    for(char c: s){
        if(c == '7') ans = true;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3720
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

// 二分探索
// llrep(i,N){
//     b = B[i];
//     auto cntA = lower_bound(A.begin(), A.end(), b);//イテレータなのでそのままllに変換とかはできない
//     auto cntC = upper_bound(C.begin(), C.end(), b);
//     ll cntA_ll = distance(A.begin(), cntA);
//     ll cntC_ll = C.size() - distance(C.begin(), cntC);
//     cnt += (cntA_ll * cntC_ll);
// }

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    cout << min(C, B/A) << endl;

    return 0;
}


Measured memory_bytes: 256
l = gets.chomp.split
s = []

l.each do |x|
  case x
  when '+', '-', '*', '/'
    b = s.pop
    a = s.pop
    case x
    when '+'
      s.push(a + b)
    when '-'
      s.push(a - b)
    when '*'
      s.push(a * b)
    when '/'
      s.push(a / b)      
    end
  else
    s.push(x.to_i)
  end
end

puts s

Measured memory_bytes: 6104
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,j=0;
  cin>>N;
  vector<int> A(N);
  for(int &i:A){
    cin>>i;
    if(i<0){
      j++;
    }
  }
  int k=0,mi=1000000000;
  for(int i:A){
    k+=abs(i);
    mi=min(mi,abs(i));
  }
  if(j%2==0)
    cout<<k<<endl;
  else
    cout<<k-mi*2<<endl;
}

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

using namespace std;

int main()
{
    int h, w, num = 0;
    long ans = 0;
    cin >> h >> w;

    vector<vector<int>> l(h, vector<int>(w, 0));
    vector<vector<int>> r(h, vector<int>(w, 0));
    vector<vector<int>> u(h, vector<int>(w, 0));
    vector<vector<int>> d(h, vector<int>(w, 0));
    vector<vector<char>> s(h, vector<char>(w, '.'));

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> s[i][j];
        }
    }
    for (int i = 0; i < h; ++i) {
        num = 0;
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '.') ++num;
            else break;
        }
        r[i][0] = num;
    }
    for (int j = 0; j < w; ++j) {
        num = 0;
        for (int i = 0; i < h; ++i) {
            if (s[i][j] == '.') ++num;
            else break;
        }
        d[0][j] = num;
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#') l[i][j] = 0;
            else if (j == 0) l[i][j] = 1;
            else l[i][j] = l[i][j - 1] + 1; 

            if (s[i][j] == '#') u[i][j] = 0;
            else if (i == 0) u[i][j] = 1;
            else u[i][j] = u[i-1][j] + 1;

        }
    }
    
    for (int i = h-1; i >= 0; --i) {
        for (int j = w-1; j >= 0; --j) {
            if (s[i][j] == '#') r[i][j] = 0;
            else if (j == w-1) r[i][j] = 1;
            else r[i][j] = r[i][j+1] + 1; 

            if (s[i][j] == '#') d[i][j] = 0;
            else if (i == h-1) d[i][j] = 1;
            else d[i][j] = d[i+1][j] + 1;

            long tmp = l[i][j] + u[i][j] + r[i][j] + d[i][j] - 3;
            if (tmp > ans) ans = tmp;
        }
    }
    
    cout << ans << endl;
}

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


int main(){

    int N,M;
    cin >> N >> M;

    int vsum = 0;

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

    int minv = vsum/(4*M);
    int flag = vsum%(4*M);

    int count = 0;
    for(size_t i=0;i<N;i++){
        if(!flag){
            if(A[i]>=minv) count++;
        }else{
            if(A[i]>minv) count++;
        }
    }
    //cout << minv << ' '<< count << endl;

    if(count>=M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
num = []
for ch in input().rstrip().split():
    if ch.isdigit():
        num.append(int(ch))
    else:
        a = num.pop()
        b = num.pop()
        if ch == "+":
            num.append(b + a)
        elif ch == "-":
            num.append(b - a)
        elif ch == "*":
            num.append(b * a)
        else:
            num.append(b / a)
print(num[0])


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  //input
  int r,d,x;cin>>r>>d>>x;llint y=x;
  //caricurate
  for(int i=2000;i<2010;i++){
    y=r*y-d;cout<<y<<endl;
  }
  //output
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void){
	int k, a, b, ok = 0;
	scanf("%d", &k);
	scanf("%d", &a);
	scanf("%d", &b);
	
	for(; a <= b; a++){
		if(a % k == 0){
			printf("OK");
			ok = 1;
			break;
		}
	}
	if(ok==0)
		printf("NG");
	
	return 0;
}

Measured memory_bytes: 1732
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''D Redistribution'''
mod=10**9+7
n = r()
ans = [0]*(n+1)
dp = [0]*(n+1)
ans[0]=1
dp[0]=1
if n>=1:
    dp[1]=1
if n>=2:
    dp[2]=1
for i in range(3,n+1):
    ans[i]=dp[i-3]
    dp[i]=(dp[i-1]+ans[i])%mod
print(ans[-1])

Measured memory_bytes: 77596
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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

  

  cin >> n;
  vector<pair<string, pll>> v;
  rep(i, n) {
    cin >> s >> m;
    v.pb(make_pair(s, pll(-m, i + 1)));
  }
  sort(all(v));
  rep(i, n) cout << v[i].second.second << endl;




  return 0;
}

Measured memory_bytes: 256
"""

https://atcoder.jp/contests/agc023/tasks/agc023_c

完全に無駄になる(すべて塗られている後に動く)マシンの数を数えればいい
つまり、取り除いていくことを考える
→取り除くと、その両側は取り除けない

マシンの総数は (N-1)! * (N-1)
1,N-1のマシンは取り除かれることはない

N-1 の順列のうち、隣り合う数字が選ばれる or 1,N-1が選ばれるまでに登場した数字の総数を求めよ
となる

答え = ΣΣt個取ったうえでxを取る場合
        t x
        
隣り合わないでa個取る場合にはすべてが等しい確率で含まれる…？
1234から2こ取る場合
1 3
1  4
 2 4
→違うわ　でも問題ない…？
t番目にxを取るの数を数え上げられればいい

→隣り合わないで x個取る方法 * x! * (N-1-x)!
→隣り合わないで x個取る通り数がわかればおk

dp[i][x] = i番目まで見てx個取る通り数
dp[i][x] = Σdp[j][x-1]
           j <= i-2

1つづつ置いていくことを考える
置くと置ける場所が2減る場合と1減る場合がある

最初はXこどこにでも置ける
そのうち、1減るのは2とおり、2減るのはN-2通り
次のおける集合を考える
1減るのは

=====答えを見た=====

愚直に考えればいい
各Kについて、K回目ですべて塗られているような順列の個数がわかればいい→f(K)
K回目に初めて塗られるのは f(K) - f(K-1) - f(K-2) - … - f(1)

f(K)を導出する
まず、K個のマシンを選びたい → g(K)とする
f(K) = g(K) * K! * (N-1-K)! である

g(K)を導出する
選ばれないマスはN-1-K個
隙間に選ばれないマスを入れていくことを考える

隙間はK-1個ある
ここにN-1-K個のあまりものを入れていく
nCr(K-1,N-1-K)

"""

def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)
    if n < r:
        return 0
    return fac[n] * inv[n-r] * inv[r] % mod

N = int(input())
mod = 10**9+7

fac,inv = modfac(N+10,mod)
fsum = 0
ans = 0

for K in range(1,N):
    f = modnCr(K-1,N-1-K,mod,fac,inv) * fac[K] * fac[N-1-K]
    ans += (f - fsum) * K % mod
    fsum = f
    fsum %= mod
    ans %= mod
print (ans)








Measured memory_bytes: 157000
#include <iostream>
#include <map>
using namespace std;
typedef pair<int,int> P;

int nukopos[100]={};
int W;

int cansleep(int w){
     int space=0;
     int tmp=-1;
     for(int i=0;i<W;i++){
	  if(nukopos[i]==0)
	       space++;
	  else
	       space=0;
	  if(space==w){
	       tmp=i-w+1;
	       break;
	  }
     }
     return tmp;
}
void wakenuko(int id){
     id++;
     for(int i=0;i<W;i++){
	  if(nukopos[i]==id)nukopos[i]=0;
     }
}

int main(){
     int Q;
     while(cin>>W>>Q,W||Q){
	  for(int i=0;i<W;i++)nukopos[i]=0;
	  map<int,int> nuko;
	  for(int i=0;i<Q;i++){
	       char a;
	       cin>>a;
	       int id,w,p;
	       switch(a){
	       case 's':
		    cin>>id>>w;
		    p=cansleep(w);
		    if(p==-1){
			 cout<<"impossible"<<endl;
			 break;
		    }
		    nuko.insert(P(id,w));
		    cout<<p<<endl;
		    for(int i=p;i<p+w;i++)nukopos[i]=id+1;
		    break;
	       case 'w':
		    cin>>id;
		    wakenuko(id);
		    break;
	       }
	  }
	  cout<<"END"<<endl;
	  //for(int i=0;i<W;i++)cout<<nukopos[i]<<" ";
     }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> vec(W);
  
  //文字列を読み込んで配列に格納する
  
  //最初の列#
  for (int i = 0; i < W + 2; i++){
    cout << '#';
  }
  cout << endl;
  
  //文字列の最初と最後に#をつける
  for (int i = 0; i < H; i++){
    cout << '#';
    for (int j = 0; j < 1; j++){
      cin >> vec.at(j);
      cout << vec.at(j);
    }
    cout << '#' << endl;
  }
  //最後の列#
  for (int i = 0; i < W + 2; i++){
    cout << '#';
  }
  cout << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,d,c=0;
    cin>>n>>d;
    double x,y,dis;
    while(n--)
    {
        cin>>x>>y;
        dis=sqrt((x*x)+(y*y));
        if(dis<=d)
            c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
  
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   
   ll i,n,t,a,b,c,d,ans;
 
    
   cin>>a>>b>>c>>d;
    
   ans=max(a*c,max(a*d,max(b*c,b*d)));
    
   cout<<ans<<endl;
   
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main() {

    while(true) {
        string s;
        cin >> s;
        if (s == "0")
            break;

        int sum = 0;

        for (char& c : s) {
            sum += stoi(string{c});
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
// set<int>st{ 3,1,4,1,5,9,2,6,5,3,5 };
//     for (auto itr = st.begin(); itr != st.end(); ++itr) {
//         cout << *itr;
//     }
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
  int n;
  cin>>n;
  int cnt =0;
  int a;
  rep(i,n){
    cin>>a;
    if(a==cnt+1){
      cnt+=1;
    }
  }
  if(cnt==0){
    cout<<-1<<endl;
    return 0;
  }
  cout<<n-cnt<<endl;
  }

Measured memory_bytes: 3628
#coding:utf-8

n, k = input().split()
A_raw = input().split()

A = sorted(A_raw) 
N = int(n)
K = int(k)

lef = N - K 

if lef%(K-1) > 0:
    ans = lef // (K-1) + 2

elif lef%(K-1) == 0:
    ans = lef // (K-1) + 1

print(ans)

Measured memory_bytes: 10612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7, A = 5e5 + 2;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    vector<pair<int, int>> v;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        v.pb({y, x});
    }
    sort(v.rbegin(), v.rend());
    int ptr = 0;
    for (int i = 0; i < m; i++) {
        ll num = v[i].S, val = v[i].F;
        for (int i = 0; i < num; i++) {
            if (a[ptr] < val)
                a[ptr] = val, ptr++;
            else break;
            if (ptr == n) break;
        }
        if (ptr == n) break;
    }
    ll sum = 0;
    for (int i = 0; i < n; i++) sum += a[i];
    cout << sum;
    return 0;
}

Measured memory_bytes: 4568
#include <bits/stdc++.h>
using namespace std;
int ar[100000+10];
int main(){
	long long n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int t;cin>>t;
		ar[t]++;
	}
	int ans = INT_MIN;
	for(int i=1;i<100000+10;i++){
		ans = max(ans,ar[i-1]+ar[i]+ar[i+1]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640