akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1ll << 60;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

#ifdef WIN32
#define dump(x) cout << #x << " = " << (x) << "\n"
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n"
#else
#define dump(x)
#define debug(x)
#endif

int N;
int info[ 50 ][ 9 ];
string name[ 50 ];

void solve() {
  vector<pair<double, string> > v( N );
  for ( int i = 0; i < N; i++ ) {
    v[ i ] = MP( info[ i ][ 0 ], name[ i ] );
    int cnt = 0;
    for ( int j = 1; j < 4; j++ ) {
      cnt += info[ i ][ j ];
    }
    for ( int k = 4; k < 6; k++ ) {
      cnt += info[ i ][ k ] * info[ i ][ 8 ];
    }
    v[ i ].first -= info[ i ][ 6 ] * info[ i ][ 7 ] * info[i][ 8 ];
    v[ i ].first /= cnt;
  }
  sort( v.begin(), v.end() );
  for ( int i = 0; i < N; i++ ) {
    cout << v[ i ].second << "\n";
  }
  cout << "#\n";
}

int main() {
	ios::sync_with_stdio( false );
	cin.tie( 0 );
  while ( cin >> N && N ) {
    for ( int i = 0; i < N; i++ ) {
      cin >> name[ i ];
      for ( int j = 0; j < 9; j++ ) {
        cin >> info[ i ][ j ];
      }
    }
    solve();
  }
	return 0;
}

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

int main() {
    string s;
    int m, h;
    
    while (true) {
        cin >> s;
        if (s == "-") break;
        cin >> m;

        for (int i = 0; i < m; i++) {
            cin >> h;
            string sub = s.substr(0, h);
            s.erase(0, h);
            s += sub;
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
using namespace std;

int main(){
  string s;
  cin >> s;
  string t;
  cin >> t;
  string res;
  for(int i = 0; i < s.size() + t.size(); i++){
    if(i % 2 == 0){
      res.push_back(s[i / 2]);
    }
    else{
      res.push_back(t[i / 2]);
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
from itertools import accumulate
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
Ac = list(accumulate(A))

ans = 0
for i in range(N):
  ans += A[i]*(Ac[-1]-Ac[i])
  ans = ans%MOD
print(ans)

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 H, W;
  cin >> H >> W;
  if (H > W) swap(H, W);
  if (H == 1) {
    cout << 1 << endl;
  } else {
    cout << (H * W + 1) / 2 << endl;
  }
}


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

int main() {
  string S;
  cin >> S;

  int count_first_1 = 0;
  int count_first_0 =0;
  
  for(int i = 0; i < S.size(); i++) {
    if(i % 2 == 0) {
      if(S[i] == '1') {
        count_first_0++;
      }else{
        count_first_1++;
      }
    }else{
      if(S[i] == '1') {
        count_first_1++;
      }else{
        count_first_0++;
      }
    }
  }

  cout << min(count_first_0, count_first_1) << endl;

  return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
	int N, K;
	cin >> N >> K;
	vector <int> h_vec;
	for (int i = 0; i < N; i++) {
		int h;
		cin >> h;
		h_vec.push_back(h);
	}
	std::sort(h_vec.begin(), h_vec.end(), [](const int& x, const int& y) {return x > y;});

	int ans = h_vec.at(0);
	for (int i = 0; i <= (N-K); i++) {
		ans = std::min(ans, h_vec.at(i) - h_vec.at(i+K-1));
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 892
n,k,q=map(int,input().split())
a=[int(input()) for _ in range(q)]
nman=[]
for i in range(n):
    nman.append(k-q)
for j in a:
    nman[j-1]+=1
for l in range(n):
    if(nman[l]<=0):
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 11776
#内積0の場合直行している
#外積0の場合平行
def main():
  q = int(input())
  for i in range(q):
    print(parallel_orthogonal())

def parallel_orthogonal():
  xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(int, input().split())
  l1_start = complex(xp0, yp0)
  l1_end = complex(xp1, yp1)
  l2_start = complex(xp2, yp2)
  l2_end = complex(xp3, yp3)

  if 0 == dot(l1_end - l1_start, l2_end - l2_start):
    return 1
  if 0 == cross(l1_end - l1_start, l2_end - l2_start):
    return 2
  return 0

# p0..p3がそれぞれ座標になっている

#内積
def dot(a, b):
  return a.real * b.real + a.imag * b.imag

#外積
def cross(a, b):
  return a.real * b.imag - a.imag * b.real

main()


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  vector<int> c(n);
  rep(i,n) cin >> c[i];
  vector<int> a(n,0);
  rep(i,n) a[i] = v[i] - c[i];
  int ans = 0;
  rep(i,n){
      if(a[i] > 0)ans += a[i];
  }
  cout << ans << endl;
    return 0;    
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    for (int i = 0; i < N; ++i) {
        cin >> C[i];
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
        }
    }
    int ans = numeric_limits<int>::max();
    for (int i = 0; i < (1 << N); ++i) {
        int cost = 0;
        vector<int> sum(M, 0);
        for (int j = 0; j < N; ++j) {
            if (i & (1 << j)) {
                cost += C[j];
                for (int k = 0; k < M; ++k) {
                    sum[k] += A[j][k];
                }
            }
        }
        bool OK = true;
        for (int k = 0; k < M && OK; ++k) {
            if (sum[k] < X) {
                OK = false;
            }
        }
        if (OK) {
            ans = min(ans, cost);
        }
    }
    if (ans == numeric_limits<int>::max()) {
        cout << "-1\n";
    } else {
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int x[100000], y[100000], n, mx, my; bool unused[100000];
int solve(int lx, int ly, int rx, int ry) {
	for (int i = 0; i < n; i++)unused[i] = false;
	for (int i = 0; i < n; i++) {
		if (lx <= x[i] && x[i] <= rx && ly <= y[i] && y[i] <= ry)unused[i] = true;
	}
	int ex = 1000000, ey = 1000000, sx = 0, sy = 0;
	for (int i = 0; i < n; i++) { if (unused[i] == false) { ex = min(ex, x[i]); ey = min(ey, y[i]); sx = max(sx, x[i]); sy = max(sy, y[i]); } }
	return max(sx - ex, sy - ey);
}
bool solve(int r) {
	return (solve(0, 0, r, r) <= r || solve(0, my - r, r, my) <= r || solve(mx - r, 0, mx, r) <= r || solve(mx - r, my - r, mx, my) <= r);
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i]; int r1 = x[i] - y[i], r2 = x[i] + y[i]; x[i] = r1; y[i] = r2; mx = min(mx, x[i]); my = min(my, y[i]);
	}
	for (int i = 0; i < n; i++) { x[i] -= mx; y[i] -= my; }mx = 0; my = 0;
	for (int i = 0; i < n; i++) { mx = max(mx, x[i]); my = max(my, y[i]); }
	int L = 0, R = 1000000, M;
	while (true) {
		M = (L + R) / 2; bool U1 = solve(M - 1), U2 = solve(M);
		if (U1 == false && U2 == true) { cout << M << endl; break; }
		if (U1 == true)R = M;
		if (U2 == false)L = M;
	}
	return 0;
}

Measured memory_bytes: 3968
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String s=scan.next();
		String t=scan.next();

        MinorChange a=new MinorChange(s,t);
        System.out.println(a.toString());
	}

}

class MinorChange{
	char [] s;
	char [] t;
	private int count;
	
	MinorChange(String s,String t){
		this.s=s.toCharArray();
		this.t=t.toCharArray();
		
		count(this.s,this.t,s);
		
	}
	void count(char []s,char[]t,String str) {
		
		for(int i=0;i<str.length();i++) {
			if(s[i]!=t[i]) count++;
		}
		
	}
	public String toString() {
		return count+"";
	}
}

Measured memory_bytes: 43212
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N, M;
	cin >> N >> M;
	vector<vector<char>> data_N(N, vector<char>(N));
	vector<vector<char>> data_M(M, vector<char>(M));

	for (int i = 0; i < N * N; i++)
	{
		char tmp;
		cin >> tmp;
		data_N[i / N][i % N] = tmp;
	}

	for (int i = 0; i < M * M; i++)
	{
		char tmp;
		cin >> tmp;
		data_M[i / M][i % M] = tmp;
	}

	for (int i = 0; i < N - M + 1; i++)
	{
		for (int j = 0; j < N - M + 1; j++)
		{
			bool flag = true;
			for (int k = 0; k < M; k++)
			{
				for (int l = 0; l < M; l++)
				{
					if (data_N[i + k][j + l] != data_M[k][l])
						flag = false;
				}
			}
			if (flag)
			{
				cout << "Yes" << endl;
				return;
			}
		}
	}
	cout << "No" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

#define int long long

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

	int a[3][3];
	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cin >> a[i][j];
		}
	}

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

		for (int j = 0; j < 3; ++j)
		{
			for (int l = 0; l < 3; ++l)
			{
				if (a[j][l] == b[i])
					a[j][l] = 0;
			}  
		}
	}

	int f = 0;
	for (int i = 0; i < 3; ++i)
	{
		int c = 0;
		for (int j = 0; j < 3; ++j)
		{
			if (a[i][j])
				c = 1;
		}

		if (c == 0)
		{
			f = 1;
		}
	}

	// for (int i = 0; i < 3; ++i)
	// {
	// 	for (int j = 0; j < 3; ++j)
	// 	{
	// 		cout << a[i][j] << " \n"[j == 2];
	// 	}
	// }
	for (int i = 0; i < 3; ++i)
	{
		int c = 0;
		for (int j = 0; j < 3; ++j)
		{
			if (a[j][i])
				c = 1;
		}

		if (c == 0)
		{
			f = 1;
		}
	}

	if (a[0][0] == 0 && a[0][0] == a[1][1] && a[1][1] == a[2][2])
		f = 1;


	if (a[2][0] == 0 && a[2][0] == a[1][1] && a[1][1] == a[0][2])
		f = 1;

	if (f)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0; 
 }

Measured memory_bytes: 256
# -*- coding:utf-8 -*-
import math
N, M = map(int, input().split())
if abs(N-M) == 0:
    print((2*math.factorial(N)*math.factorial(M))%((10**9)+7))
elif abs(N-M) == 1:
    print((math.factorial(N)*math.factorial(M))%((10**9)+7))
else:
    print(0)

Measured memory_bytes: 5172
#include<bits/stdc++.h>
 
using namespace std;
 
#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void sb()
{	
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
//int dp[3001][3001];
ll dp[3001][3001];
ll a[3005];
ll winner( int i,int j){
//int dp[n+1][n+1];
//memset(dp,-1,sizeof dp);
   if(i>j){
       return 0 ;
   }
   if(dp[i][j]!=-1){
     return dp[i][j];
   }
   if(i==j){
     return dp[i][j]=a[i]; 
   }
   
   dp[i][j]=max(a[i]-winner(i+1,j),a[j]-winner(i,j-1));     
 
 
   return dp[i][j];
 
  
 
}
 
//int winner(int a[],int n){
    //int dp[n+1][n+1];
    //memset(dp,0,sizeof dp);
    //dp[0]=0;
    //int X,Y;
    //dp[0][0]=0
    //for(int i=n;i>0;i--){
        //for(int j=i;j<n+1;j++){
            //if(i==0&&j==0){
                //dp[i][j]=0;
            //}
            //if(i==j){
                //dp[i][j]=a[i];
            //}
            //if(i>j){
               // dp[i][j]=0;
           // }
            //if(i<j){
              //  dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
           // }
        //}
   // }
//return dp[1][n];
    
    
//}
int main() {
ll n;
    cin>>n;
   //long long  int a[n];
   memset(dp,-1,sizeof(dp));
    
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    cout<<winner(0,n-1);
}

Measured memory_bytes: 74128
# C - Lower
N = int(input())
H = list(map(int, input().split()))

count = 0
maxCount = 0

for i in range(len(H) - 1):
    if H[i] >= H[i + 1]:
        count += 1
    else:
        if maxCount < count:
            maxCount = count
        count = 0

if maxCount < count:
    maxCount = count

print(maxCount)


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

struct node{
  int key;
  struct node *parent, *left, *right;
};

struct node *root, *NIL;

void insert(int);
struct node *find(struct node *, int);
void inorder(struct node *);
void preorder(struct node *);

int main(){
  int n, i, x;
  char array[10];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s",&array[0]);
    if(!strcmp(array, "find")){
      scanf("%d", &x);
      if(find(root, x) != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(!strcmp(array, "insert")){
      scanf("%d", &x);
      insert(x);
    }
    else {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  
  return 0;
}
void insert(int k){
  struct node *y = NIL;
  struct node *x = root;
  struct node *z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;  
  z->right = NIL;

  while(x != NIL){ 
    y = x; 
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else {
    if(z->key < y->key) y->left = z; 
    else y->right = z;
  }
}
void inorder(struct node *u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(struct node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}
struct node *find(struct node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}



Measured memory_bytes: 20516
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int NICO = 100000 + 10;
typedef long long Long;
Long a[NICO], b[NICO], n;
int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i] >> b[i];
    }
    Long tmp = 0;
    for(int i=n;i>=1;i--)
    {
        a[i] += tmp;
        tmp += (b[i] - a[i]%b[i]) % b[i];
    }
    cout << tmp << endl;
}

Measured memory_bytes: 1792
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())

rem = pow(10,9)+7

#n = ip()                                     #入力整数1つ
#x,y= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[input() for i in range(x)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
s = []
for i in range(len(a)):
    if a[i] == 'B' :
        if len(s) : s.pop(len(s)-1)
    else : s.append(a[i])
print(''.join(s))

Measured memory_bytes: 13896
num=int(input())
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
x=num2alpha(num)
print(x.lower())

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

int main(void) {
  int a, b ,c, d;
  scanf("%d %d %d %d", &a, &b ,&c, &d);
  float f_t = (float) a / (float) d, f_a = (float) c / (float) b;
  int count_t, count_a;
  if (f_t == (int) f_t) count_t = f_t;
  else count_t = (int) f_t + 1;
  if (f_a == (int) f_a) count_a = f_a;
  else count_a = (int) f_a + 1;
  if (count_t < count_a) printf("No\n");
  else printf("Yes\n");

  return 0;
}


Measured memory_bytes: 1648
#include<iostream>
#include<string>
using namespace std;
int main(){
  int a,b;
  string s,t,u;
  cin>>s>>t;cin>>a>>b;cin>>u;
  if(s==u)cout<<a-1<<" "<<b;
  else if(t==u)cout<<a<<" "<<b-1;
}

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

using ll=long long;
using namespace std;

#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

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

const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

char BigAlphaToSmall(char a){
    if (a >= 65 && a <= 90){
        return a + 32;
    }
    return a;
}

char SmallAlphaToBig(char a){
    if (a >= 97 && a <= 122){
        return a - 32;
    }
    return a;
}

double Distance(double x1, double y1, double x2, double y2){
    return pow(pow(x1 - x2, 2.0) + pow(y1 - y2, 2.0), 0.5);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    double a, b, C;
    cin >> a >> b >> C;
    double S = a*b*sin(C*(M_PI/180))/2;
    double l = pow(pow(a, 2.0) + pow(b, 2.0) - 2*a*b*cos(C*(M_PI/180)), 0.5);
    double h = 2*S/a;

    cout << fixed << setprecision(10);
    cout << S << " " << a + b + l << " " << h << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
using namespace std;

int main() {
  int n, l;
  cin >> n >> l;
  int flag = 0;
  int sum = 0;
  for (int i=1;i<n+1;i++){
    sum = sum + (l+i-1);
    if(l+i-1 == 0) flag = 1;
  }
  
  int min = l;
  int max = l+n-1;
  
  if (flag == 1) cout << sum << endl;
  else if (min>0) cout << sum - min << endl;
  else if (max<0) cout << sum - max << endl;
}

Measured memory_bytes: 256
use proconio::fastout;
use proconio::input;

#[fastout]
fn main() {
    input! { a: u64, b: u64, n: u64, }
    let x = n.min(b - 1);
    let ans = (a * x / b) - (a * (x / b));
    println!("{}", ans);
}


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

int main()
{
    int H, W;
    char mas[105][105];
    bool rowCheck[105], colCheck[105];

    cin >> H >> W;

    fill_n(rowCheck, 105, true);
    fill_n(colCheck, 105, true);

    for ( int i = 0; i < H; i++ ) {
        for ( int j = 0; j < W; j++ ) {
            cin >> mas[i][j];
            rowCheck[i] &= (mas[i][j] == '.');
            colCheck[j] &= (mas[i][j] == '.');
        }
    }

    for ( int i = 0; i < H; i++ ) {
        if ( !rowCheck[i] ) {
            for ( int j = 0; j < W; j++ ) {
                if ( !colCheck[j] ) {
                    cout << mas[i][j];
                }
            }
            cout << endl;
        }
    }

    return ( 0 );
}


Measured memory_bytes: 256
def bubbleSort(A, N):
    ret = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                ret += 1
    return ret


n = int(input())
a = list(map(int, input().split()))
count = bubbleSort(a, n)
print(" ".join(map(str, a)))
print(count)

Measured memory_bytes: 7800
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int H,W;
    cin >> H >> W;
    vector<bool> row(H,false),col(W,false);
    string a[H];

    for (int i = 0; i < H; i++){
        cin >> a[i];
    }
    for (int i = 0; i < H; i++){
        for (int k = 0; k < W; k++){
            if (a[i][k] == '#'){
                row[i] = true;
                col[k] = true;
            }
        }
    }

    for (int i = 0; i < H; i++){
        if (row[i]){
            for (int k = 0; k < W; k++){
                if (col[k]){
                    cout << a[i][k];
                }
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long int lli;
const lli mod = 1e9+7;

lli ExGCD(lli a, lli b, lli &x, lli &y){
	lli d=a;
	x=1; y=0;
	if(b!=0){ d=ExGCD(b, a%b, y, x); y-=a/b*x; }
	return d;
}
lli inverse(lli a){
	lli x,y;
	ExGCD(a, mod, x, y);
	return x>0? x: mod+x;
}

lli modpow(lli a, lli p){
	lli ret = 1;
	for(int i=63; i>=0; i--){
		ret *= ret;
		ret %= mod;
		if((1LL<<i & p) != 0){
			ret *= a;
			ret %= mod;
		}
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	vector<lli> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	vector<map<lli, lli>> factors(n);
	for(int i=0; i<n; i++){
		int b = a[i];
		for(int j=2; j*j<=b; j++){
			while(b%j == 0){
				factors[i][j]++;
				b /= j;
			}
		}
		if(b != 1){
			factors[i][b]++;
		}
	}

	map<lli, lli> maxfactor;
	for(int i=0; i<n; i++){
		for(auto &p: factors[i]){
			maxfactor[p.first] = max(maxfactor[p.first], p.second);
		}
	}
	lli lcm = 1;
	for(auto &p: maxfactor){
		lcm *= modpow(p.first, p.second);
		lcm %= mod;
	}
	int ans = 0;
	for(int i=0; i<n; i++){
		ans += lcm *inverse(a[i]) %mod;
		ans %= mod;
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3968
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, mod):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % mod)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], mod - 2, mod)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % mod
        self.mod = mod

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.mod

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.mod

    def combination_large(self, k, r):
        """kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用"""
        if k < r:
            return 0
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.mod
        return (res * self.inv_fact[r]) % self.mod

n,k = map(int,input().split())
mod = 10**9+7
comb = Combination(n,mod)

k = min(k,n-1)
ans = 0
for i in range(k+1):
    ans += comb.combination(n,i)*comb.combination(n-1,i)
    ans %= mod
print(ans)

Measured memory_bytes: 90420
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 102;

short f[N][N][N][N] , s1[N][N] , s2[N][N];
char s[N][N];
int n , m;

int main(){
	cin >> n >> m;
	for(int i = 1 ; i <= n ; ++ i)
		cin >> (s[i] + 1);
	int px , py;
	for(int i = 1 ; i <= n ; ++ i)
		for(int j = 1 ; j <= m ; ++ j)
			if(s[i][j] == 'E'){
				px = i;
				py = j;
				break;
			}
	for(int i = 1 ; i <= n ; ++ i)
		for(int j = 1 ; j <= m ; ++ j)
			s1[i][j] = s1[i][j - 1] + (short)(s[i][j] == 'o');
	for(int i = 1 ; i <= n ; ++ i)
		for(int j = 1 ; j <= m ; ++ j)
			s2[i][j] = s2[i - 1][j] + (short)(s[i][j] == 'o');
	memset(f , -1 , sizeof f);
	f[px][px][py][py] = 0;
	short ans = 0;
	for(int i = px ; i >= 1 ; -- i)
		for(int j = px ; j <= n ; ++ j)
			for(int k = py ; k >= 1 ; -- k)
				for(int t = py ; t <= m ; ++ t){
					if(f[i][j][k][t] == -1) continue;	
					if(i > 1 && i > j - px + 1) f[i - 1][j][k][t] = max(f[i - 1][j][k][t] , (short)(f[i][j][k][t] + s1[i - 1][min(m - py + k , t)] - s1[i - 1][max(k - 1 , t - py)]));
					if(j < n && j < n - (px - i)) f[i][j + 1][k][t] = max(f[i][j + 1][k][t] , (short)(f[i][j][k][t] + s1[j + 1][min(m - py + k , t)] - s1[j + 1][max(k - 1 , t - py)]));
					if(k > 1 && k > t - py + 1) f[i][j][k - 1][t] = max(f[i][j][k - 1][t] , (short)(f[i][j][k][t] + s2[min(n - px + i , j)][k - 1] - s2[max(i - 1 , j - px)][k - 1]));
					if(t < m && t < m - (py - k)) f[i][j][k][t + 1] = max(f[i][j][k][t + 1] , (short)(f[i][j][k][t] + s2[min(n - px + i , j)][t + 1] - s2[max(i - 1 , j - px)][t + 1]));
					ans = max(ans , f[i][j][k][t]);
				}
	cout << ans << endl;				
	return 0;
}

Measured memory_bytes: 211712
import sys

s = input()
t = input()
difl = []

for i in range(len(s)-len(t)+1):
    if s[i:i+len(t)] == t:
        print(0)
        sys.exit()
    else:
        dif = 0
        for j in range(len(t)):
            if s[j+i] != t[j]:
                dif += 1
    difl.append(dif)

print(min(difl))


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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int W = sc.nextInt();
    int[] w = new int[N];
    int[] v = new int[N];
    for (int i = 0; i < N; i++) {
      w[i] = sc.nextInt();
      v[i] = sc.nextInt();
    }
    sc.close();

    long[][] dp = new long[N + 1][W + 1];
    for (long[] a : dp) Arrays.fill(a, -1);
    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < W + 1; j++) {
        long val = dp[i][j];
        if (val < 0) continue;

        long no_select = Math.max(
            dp[i + 1][j], val);
        dp[i + 1][j] = no_select;

        int wi = w[i];
        if (W < j + wi) continue;
        long select = Math.max(
            dp[i + 1][j + wi], val + v[i]);
        dp[i + 1][j + wi] = select;
      }
    }

//    Arrays.stream(dp).forEach(a ->
//      System.out.println(Arrays.toString(a)));

    long ans = 0;
    for (long val : dp[N]) ans = Math.max(ans, val);
    System.out.println(ans);
  }
}

Measured memory_bytes: 127700
from collections import deque
n, e = [int(item) for item in input().split()]
edge = [[] for _ in range(n)]
source_num = [0] * n
distance = [0] * n
for i in range(e):
    f, t = map(int, input().split())
    f -= 1
    t -= 1
    source_num[t] += 1
    edge[f].append(t)

dq = deque()
for i, item in enumerate(source_num):
    if item == 0:
        dq.append(i)
        source_num[i] = -1
while(dq):
    i = dq.pop()
    source_num[i] = -1
    for v in edge[i]:
        distance[v] = max(distance[v], distance[i] + 1)
        source_num[v] -= 1
        if source_num[v] == 0:
            dq.append(v)
print(max(distance))

Measured memory_bytes: 23012
#include <iostream>

using namespace std;

const int INF = 1000000000;

int abs(int t){ return t>0?t:-t; }

int main(){
	int n;
	static int DP[3][40];
	int p[40], t[40];
	while(cin >> n, n){
		for(int i=0;i<3;i++)
			for(int j=0;j<n;j++) DP[i][j] = INF;
		cin >> p[0] >> t[0];
		if(t[0] >= p[0]) DP[0][0] = p[0];
		for(int i=1;i<n;i++){
			cin >> p[i] >> t[i];
			for(int j=0;j<3;j++){
				if(DP[j][i-1] == INF) continue;
				if(t[i]-t[i-1] >= p[i]+(j+2)*p[i-1])
					DP[0][i] = min(DP[0][i], DP[j][i-1]+p[i]+p[i-1]);
				if(j!=2 && t[i]-t[i-1] >= (j+2)*abs(p[i]-p[i-1]))
					DP[j+1][i] = min(DP[j+1][i], DP[j][i-1]+abs(p[i]-p[i-1]));
			}
		}
		int res = INF;
		for(int i=0;i<3;i++)
			res = min(res, DP[i][n-1]+p[n-1]);
		if(res < INF) { cout << "OK " << res << endl; }
		else {
			res = 1;
			for(int i=0;i<n;i++)
				for(int j=0;j<3;j++)
					if(DP[j][i] < INF) res = i+2;
			cout << "NG " << res << endl;
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <list>
#include <math.h>
#include <vector>
#include <algorithm>
#include<iomanip>
#include <unordered_map> 
#include <queue>
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
 
#define MOD 1000000007
 
 
int main() {
  int A1, A2, A3;
  
  cin >> A1 >> A2 >> A3;
  
  if (A1+A2+A3 >= 22) {
    cout << "bust";
  }
  else {
    cout << "win"; 
  }
 
  //for float, double precision
  //cout << std::fixed << setprecision(15);
  return 0;
 
}


Measured memory_bytes: 256
def main():
	H1, M1, H2, M2, K = map(int, input().split())
	if H2 < H1:
		H2 += 24
	totalTime = (H2 - H1) * 60 + (M2 - M1)
	print(totalTime - K)

if __name__ == '__main__':
	main()

Measured memory_bytes: 9164
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

modN = 2019

pow :: Num a => a -> Int -> a
pow base 0 = 1
pow base 1 = base
pow base time
    | odd time = let 
        a = pow base (div time 2)
        in
        a * a * base
    | otherwise = let
        a = pow base (div time 2)
        in
        a * a

inv :: ModNum -> ModNum
inv a = pow a $ modN - 2

newtype ModNum = ModNum {getInt :: Int} deriving (Show, Eq, Ord)
instance Num ModNum where
    (+) (ModNum a) (ModNum b) = ModNum $ mod (a + b) modN
    (-) (ModNum a) (ModNum b)
            | a < b = (ModNum $ a + modN) - ModNum b
            | otherwise = ModNum $ mod (a - b) modN
    (*) (ModNum a) (ModNum b) = ModNum $ mod (a * b) modN
    abs (ModNum a)
        | a < 0 = abs . ModNum $ a + modN
        | otherwise = ModNum a
    signum (ModNum a) = ModNum $ signum a
    fromInteger i = abs . ModNum . fromIntegral $ mod i (fromIntegral modN)

mDiv :: ModNum -> ModNum -> ModNum
mDiv a b = a * inv b

chooseTwo :: Int -> Int
chooseTwo 0 = 0
chooseTwo 1 = 0
chooseTwo a = a * (a - 1) `div` 2

counter :: (Ord a, Num b) => [a] -> [(a, b)]
counter = M.toList . foldl' (flip $ M.alter (Just . maybe 1 (+1))) M.empty 

solve :: BC.ByteString -> Int
solve s = sum $ chooseTwo <$> intCount where
    intList :: [ModNum]
    intList = zipWith (\time base -> base * pow 10 time) [0..] $ fromIntegral . digitToInt <$> (BC.unpack . BC.reverse $ s)
    sumacc = scanl' (+) 0 intList
    intCount :: [Int]
    intCount = fmap snd $ counter sumacc

main = do
    n <- BC.getLine
    print $ solve n


Measured memory_bytes: 6076
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

void dfs(int cur, int precolor, vector<vector<pair<int, int>>> &G, vector<int> &ans) {
    int color = (precolor == 1) ? 2 : 1;
    for (auto next : G.at(cur)) {
        if (ans.at(next.second) != 0) continue;
        ans.at(next.second) = color;
        dfs(next.first, color, G, ans);
        color++;
        if (color == precolor) color++;
    }
}
 
int main() {
    int n = 0;
    cin >> n;
    vector<pair<int, int>> edge(n-1);
    vector<vector<pair<int, int>>> G(n);
    for (int i=0; i<n-1; i++) {
        cin >> edge.at(i).first >> edge.at(i).second;
        edge.at(i).first--; edge.at(i).second--;
        G.at(edge.at(i).first).push_back(make_pair(edge.at(i).second, i));
        G.at(edge.at(i).second).push_back(make_pair(edge.at(i).first, i));
    }
    vector<int> cnt(n);
    for (auto e : edge) {
        cnt.at(e.first)++;
        cnt.at(e.second)++;
    }
    int color = 0;
    for (int x : cnt) {
        color = max(color, x);
    }
    cout << color << endl;
    vector<int> ans(n-1);
    dfs(0, 0, G, ans);
    for (int x : ans) {
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define mp make_pair
#define x first
#define y second
using namespace std;
char board[1005][1005];
bool chk[1005][1005];
typedef pair<int,int> ii;
typedef pair<int,ii> ti;
int main()
{
    int h,w;
    cin >> h >> w;
    for(int i=1;i<=h;i++) scanf("%s",board[i]+1);
    int ans=0;
    queue<ti> q;
    int di[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            if(board[i][j]=='#') q.emplace(0,mp(i,j));
    while(!q.empty())
    {
        auto fr=q.front(); q.pop();
        int d=fr.x,r=fr.y.x,c=fr.y.y;
        if(chk[r][c]) continue;
        chk[r][c]=1; ans=max(ans,d);
        for(int i=0;i<4;i++) {
            int r2=r+di[i][0],c2=c+di[i][1];
            if(r2<1||c2<1||r2>h||c2>w) continue;
            if(!chk[r2][c2]) q.emplace(d+1,mp(r2,c2));
        }
    }
    printf("%d",ans);
}


Measured memory_bytes: 26420
# coding: utf-8
import sys
sysread = sys.stdin.readline

def run():
    N = int(input())
    A = list(map(int, sysread().split()))


    A = [(idx, val) for idx, val in enumerate(A, 1) if val < N]

    ret = 0
    store = [0] * N
    for idx, val in A:
        if idx - val > 0:
            ret += store[idx - val]
        try:
            store[idx + val] += 1
        except:
            continue
    print(ret)

if __name__ == "__main__":
    run()

Measured memory_bytes: 37420
package main

import(
	"fmt"
)

func isCenter(w,h,x,y int)bool{
	return w==2*x && h==2*y
}

func main(){
	var w,h,x,y int
	fmt.Scanln(&w,&h,&x,&y)
	fmt.Print(float64(w*h)/2.0)
	if isCenter(w,h,x,y){
		fmt.Println(" 1")
	}else{
		fmt.Println(" 0")
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
    int a;
    cin >> a;
    cout << "ABC" << a << endl;

    return 0;
}

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

typedef std::pair<int, int> ii;

ii merge(ii a, ii b) {
	int val[4];
	val[0] = a.first, val[1] = a.second;
	val[2] = b.first, val[3] = b.second;
	std::sort(val, val + 4);
	//std::cout << "for (" << a.first << ", " << a.second << "), (" << b.first << ", " << b.second << ") got (" << val[3] << ", " << val[2] << ")\n";
	return ii(val[3], val[2]);
}

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int k;
	std::cin >> k;
	int n = 1 << k;
	std::vector<ii> submask(n, ii(0, 0));
	for(int i = 0; i < n; i++) {
		std::cin >> submask[i].first;
	}
	for(int len = 1; len < n; len += len) {
		for(int i = 0; i < n; i += 2 * len) {
			for(int j = 0; j < len; j++) {
				submask[i + j + len] = merge(submask[i + j], submask[i + j + len]);
			}
		}
	}
	std::vector<int> ans(n, 0);
	for(int i = 0; i < n; i++) {
		ans[i] = submask[i].first + submask[i].second;
		//std::cout << ans[i] << std::endl;
	}
	/*for(int len = 1; len < n; len += len) {
		for(int i = 0; i < n; i += 2 * len) {
			for(int j = 0; j < len; j++) {
				ans[i + j + len] = std::max(ans[i + j], ans[i + j + len]);
			}
		}
	}*/
	for(int i = 1; i < n; i++) {
		ans[i] = std::max(ans[i], ans[i - 1]);
	}
	for(int i = 1; i < n; i++) {
		std::cout << ans[i] << '\n';
	}
}

Measured memory_bytes: 6144
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N);
    rep(i, N) cin >> a[i] >> b[i] >> c[i];

    vv<int> dp = vvec(N + 1, 3, 0);
    rep(i, N) {
        dp[i + 1][0] = max(dp[i][1] + a[i], dp[i][2] + a[i]);
        dp[i + 1][1] = max(dp[i][2] + b[i], dp[i][0] + b[i]);
        dp[i + 1][2] = max(dp[i][0] + c[i], dp[i][1] + c[i]);
    }

    write(max({ dp[N][0], dp[N][1], dp[N][2] }));
}

Measured memory_bytes: 6912
#!/usr/bin/env python3
import sys
import copy
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    H,W = MAP()
    S = [input() for _ in range(H)]
    answerLabel = [[S[i][j]=="#" for j in range(W)] for i in range(H)]

    def dfs(cur,isVisited):
        i,j = cur
        isVisited[i][j] = True
        v = copy.deepcopy(isVisited)
        v2 = copy.deepcopy(isVisited)
        
        if i == H-1 and j == W-1:
            if isVisited == answerLabel:
                print("Possible")
                sys.exit()
            return
        if i+1<H:
            dfs((i+1,j),v)
        
        if j+1<W:
            dfs((i,j+1),v2)
    
    dfs((0,0),[[False]*W for _ in range(H)])

    print("Impossible")
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 52952
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define MAX_V 210
#define INF 2147483647

struct edge{
	int to, cap, rev;
	
	edge(int t, int c, int r)
	: to(t), cap(c), rev(r)
	{}
};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int f, int t, int c){
	G[f].push_back(edge(t, c, G[t].size()));
	G[t].push_back(edge(f, 0, G[f].size() - 1));
}

int dfs(int v, int t, int f){
	if(v == t){ return f; }
	used[v] = true;

	for(int i = 0; i < G[v].size(); ++i){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t, int lim = INF){
	int flow = 0;
	for(; lim > 0;){
		memset(used, 0, sizeof used);
		int f = dfs(s, t, lim);
		if(f == 0){ break; }
		flow += f;
		lim -= f;
	}

	return flow;
}

int main(){
	int n, m, a, b;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i){
		add_edge(i * 2, i * 2 + 1, 1);
	}
	for(int i = 0; i < m; ++i){
		scanf("%d%d", &a, &b);
		if(max_flow(3, 2 * a + 1, 1) && max_flow(3, 2 * b + 1, 1)){
			puts("Yes");
		}
		else{
			puts("No");
		}
		
		for(int i = 2; i <= 2 * n + 1; ++i){
			int c = i % 2;
			for(int j = 0; j < G[i].size(); ++j){
				G[i][j].cap = j ? c : 1 - c;
			}
		}

		add_edge(2 * a + 1, 2 * b, 1);
		add_edge(2 * b + 1, 2 * a, 1);
	}
}

Measured memory_bytes: 1304
#include <algorithm>
#include <iostream>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

//  -d
int main() {
    int n, m;
    cin >> n >> m;

    typedef pair<int, int> tour;  // (height, idx);
    vector<tour> tours(n);
    rep(i, 0, n) {
        int height;
        cin >> height;
        tours[i] = {height, i};
    }

    vector<vector<int>> loads(n, vector<int>());
    rep(i, 0, m) {
        int from, to;
        cin >> from >> to;
        from--;
        to--;
        loads[from].push_back(to);
        loads[to].push_back(from);
    }

    // Searching
    int sumcnt = 0;
    for (tour corr : tours) {
        int chgt         = corr.first;
        int cidx         = corr.second;
        vector<int> load = loads[cidx];
        if (load.size() == 0) {
            sumcnt++;
            continue;
        }

        int overcnt = 0;
        for (int toidx : load) {
            tour toTour = tours[toidx];
            int tohgt   = toTour.first;
            if (tohgt < chgt) {
                overcnt++;
            } else {
                break;
            }
        }
        if (overcnt >= load.size()) { sumcnt++; }
    }

    cout << sumcnt << endl;

    return 0;
}



Measured memory_bytes: 9196
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
#define BLACK 0
#define WHITE 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    ll N, K;
    cin >> N >> K;
    ll n, m;
    
    n=N/K;
    m=N/(K/2)-n;
    
    ll ans=0;
    if(K%2==0) {
        ans+=m*m*m;
    }
    
    ans+=n*n*n;
    prin(ans);
}

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

typedef long long int ll;

int main(){
  ll x,y,a,b,c,i;
  cin>>x>>y>>a>>b>>c;
  vector <ll> p(a),q(b),r(c);
  for(i=0;i<a;i++){
    cin>>p[i];
  }
  for(i=0;i<b;i++){
    cin>>q[i];
  }
  for(i=0;i<c;i++){
    cin>>r[i];
  }
  vector <ll> ans;
  sort(p.rbegin(),p.rend());
  sort(q.rbegin(),q.rend());
  sort(r.rbegin(),r.rend());
  for(i=0;i<x;i++){
    ans.push_back(p[i]);
  }
  for(i=0;i<y;i++){
    ans.push_back(q[i]);
  }

  for(i=0;i<min(c,x+y);i++){
    ans.push_back(r[i]);
  }


  sort(ans.rbegin(),ans.rend());
  ll finalAns=0;
  for(i=0;i<x+y;i++){
    finalAns+=ans[i];
  }
  cout<<finalAns<<endl;
  return 0;
}


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

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define memo(a,b) memset(a,b,sizeof(a))
#define INF 1e9
#define EPS 1e-8
#define PI 3.14159265358979323846

typedef long  long  ll;

ll ar[200005];
ll tree[800005];
bool Notprime[100005];
int cnt[100005];
void f(){
Notprime[0]=Notprime[1]=true;
int limit=sqrt(100005*1.0)+2;
	//for(int i=4;i<100005;i+=2) Notprime[i]=true;
    for(int i=2;i<=limit;i++){

		if(!Notprime[i]){

			for(int j=i*i;j<100005;j+=i){

				Notprime[j]=true;

			}

		}

    }
    for(int i=3;i<100005;i++){

		if(!Notprime[i] && !Notprime[(i+1)/2]) cnt[i]=1;

    }
    //for(int i=0;i<1000;i++) cout<<i<<" "<<prime[i]<<endl;
}
struct segtree
{
    long long s;
};
segtree node[400005],zero;

segtree merge(segtree leftchild,segtree rightchild)
{
    segtree res;
	res.s=leftchild.s+rightchild.s;

    return res;
}
void build(ll pos,ll low,ll high)
{

    if(low==high)
    {
        node[pos].s=cnt[low];
        return;
    }
    ll mid=(low+high)/2;

    build(2*pos+1,low,mid);
    build(2*pos+2,mid+1,high);
    node[pos]=merge(node[pos*2+1],node[pos*2+2]);
}
segtree query(ll pos,ll low,ll high,ll qlow,ll qhigh)
{
    if(low>high || low>qhigh || high<qlow)
        {
        return  zero;
        }
    if(qlow<=low && high<=qhigh)
        return node[pos];
    ll mid=(low+high)/2;

    return merge(query(pos*2+1,low,mid,qlow,qhigh),query(pos*2+2,mid+1,high,qlow,qhigh));
}
int  main()
{
f();
    //freopen("in.txt","r",stdin);
    zero.s=0;
    int  Q,l,r;
    cin>>Q;
    build(0,0,100000);
    for(int i=0;i<Q;i++){
    cin>>l>>r;
    cout<<query(0,0,100000,l,r).s<<endl;
    }
return 0;

}


Measured memory_bytes: 4736