akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

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

void reverse(vector<vint>& board, int x, int y)
{
	rep(i, 5)
	{
		int nx = x + dx[i], ny = y + dy[i];
		
		if(0 <= nx && nx < 10 && 0 <= ny && ny < 10)
			board[nx][ny] = !board[nx][ny];
	}
}


void bitinitialize(vector<vint>& board, vector<vint>& ans, int bit)
{
	rep(i, 10) if(bit & 1 << i)
	{
		reverse(board, i, 0);
		ans[i][0] = 1;
	}
}


void fill(vector<vint>& board, vector<vint>& ans)
{
	REP(y, 1, 10) rep(x, 10)
	{
		if(board[x][y-1])
		{
			reverse(board, x, y);
			ans[x][y] = 1;
		}
	}
}


bool check(vector<vint>& board)
{
	rep(i, 10) rep(j, 10)
		if(board[i][j]) return false;
	
	return true;
}


int main()
{
    int n;
	cin >> n;
	
	while(n--)
	{
		vector<vint> answer(10, vint(10));
		
		rep(y, 10) rep(x, 10)
			cin >> answer[x][y];
		
		rep(bit, 1 << 10)
		{
			vector<vint> board(answer);
			vector<vint> ans(10, vint(10, 0));
			
			bitinitialize(board, ans, bit);
			
			fill(board, ans);
						
			if(check(board))
			{
				rep(y, 10) rep(x, 10)
					cout << ans[x][y] << (x == 9 ? "\n" : " ");
				
				break;
			}
		}
	}
}

Measured memory_bytes: 908
"""
author : halo2halo
date : 12, Jan, 2020
"""

import sys

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

a, b, c, d = readline().decode('utf8').rstrip()
print('Bad' if a == b or b == c or c == d else 'Good')


Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std; 
  
typedef long long int ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
  
double EPS = 1e-9; 
long long INF = 1000000000000000005ll; 
double PI = acos(-1); 
#define M 1000000007ll
#define D 998244353ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound  
#define SQR(x) ((LL)(x) * (x)) 
#define RESET(a, b) memset(a, b, sizeof(a))
#define GCD(a,b) __gcd(a,b)
#define setbits(x)   __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x) 
#define ps(x,y)  fixed<<setprecision(y)<<x
#define endl '\n'
#define ff first 
#define ss second 
#define mp make_pair  
#define ALL(v) v.begin(), v.end() 
#define ALLA(arr, sz) arr, arr + sz 
#define SIZE(v) (int)v.size() 
#define SORT(v) sort(ALL(v)) 
#define REVERSE(v) reverse(ALL(v)) 
#define SORTA(arr, sz) sort(ALLA(arr, sz)) 
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) 
#define PERMUTE next_permutation 
  
inline string IntToString(ll a) 
{ 
    char x[100]; 
    sprintf(x, "%lld", a); 
    string s = x; 
    return s; 
} 
  
inline ll StringToInt(string a) 
{ 
    char x[100]; 
    ll res; 
    strcpy(x, a.c_str()); 
    sscanf(x, "%lld", &res); 
    return res; 
} 
  

inline string uppercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'a' && s[i] <= 'z') 
        s[i] = s[i] - 'a' + 'A'; 
    return s; 
} 
  
inline string lowercase(string s) 
{ 
    int n = SIZE(s); 
    for(ll i=0;i<n;i++) 
    if (s[i] >= 'A' && s[i] <= 'Z') 
        s[i] = s[i] - 'A' + 'a'; 
    return s; 
}

bool sortcol( const vector<ll>& v1, 
               const vector<ll>& v2 ) { 
 return v1[0] > v2[0]; 
} 

bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}

int main() {
    FAST
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll x,n;
    cin>>x>>n;
    ll a[n];
    map <ll,ll> m;
    ll mi=INT_MAX;
    ll val=0;
    for(ll i=0;i<n;i++){
    	cin>>a[i];
    	m[a[i]]++;
    }
    //cout<<m[9]<<endl;
    for(ll i=-1;i<=101;i++){
    	if(abs(i-x)<mi && m[i]==0){
    		mi=abs(i-x);
    		val=i;
    	}
    }
    cout<<val<<endl;
    return 0;
}

Measured memory_bytes: 3568
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	long long N;
	cin >> N;
	int n = N;

	string s = "";


	while(n != 0) {
		int r = n % 2;
		if (r < 0)r += 2;

		n = (n - r) / (-2);

		s += r + 0x30;
	}

	reverse(s.begin(), s.end());
	if (s == "")s = '0';

	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as np

H,W =map(int,input().split())
a = [list(map(int,input().split())) for _ in range(H)]

odd_points = []
odd_mat = [[False] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if a[i][j]%2 == 1:
            odd_mat[i][j] = True
            odd_points.append([i,j])

odd_points = np.array(odd_points)            
if len(odd_points)%2 == 1:
    L = len(odd_points) - 1
else:
    L = len(odd_points)
    
#center_point = [0,0]
#center_point[0] = int(sum(odd_points[:,0])/len(odd_points))
#center_point[1] = int(sum(odd_points[:,1])/len(odd_points))

cnt = 0
Wi = W
ans = []
M = 0
for i in range(H):
    opi = 0
    if i%2 == 0:
        Wloop = range(Wi)
        opj = 1 
    else:
        Wloop = reversed(range(Wi))
        opj = -1
        
    if i == H-1:
        if i%2 == 0:
            Wloop = range(Wi-1)
            opj = 1 
        else:
            Wloop = reversed(range(1,Wi))
            opj = -1
        
        
    for j in Wloop:
        
        if j==0 and opj == -1:
            opj = 0
            opi = +1
        elif j==W-1 and opj == 1:
            opj = 0
            opi = +1
        
        if odd_mat[i][j]:
            cnt += 1
        if cnt%2 == 1:
            ans.append([i+1,j+1,i+1+opi,j+1+opj])
            M += 1
        opi = 0
W += 1        
print(M)    
for i in range(M):
    print(' '.join(map(str,ans[i])))


Measured memory_bytes: 49568
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 5223372036854775807
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=200105;
const int NN=200005;
const ll md=1e9+7;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;
    ll k;
    cin >> k;
    ll m=0;

    for (ll i=k;i<=n+1;i++){
        ll mn,mx;
        mn=(i)*(i+1)/2;
        mx=(i)*(n+1+n+1-i+1)/2;
        m+=max((mx-mn+1),0ll);
        m%=md;
    }
    cout << m << E;
    r0;
}
/*











*/





Measured memory_bytes: 3648
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define int             long long
 
 
int32_t main() {
 
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
 
 
  int n;
  cin >> n;
  int a[n];
  int dp[n];
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  dp[1] = abs(a[1] - a[0]);
  //cout << dp[0];
  //cout << dp[1];
  for (int i = 2; i < n; i++) {
    // cout << dp[i];
    dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
 
  }
 
  cout << dp[n - 1];
 
 
 
  return 0;
}

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

int  main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> vec(H, vector<char>(W));
   for(int i=0; i<H; i++){
     for(int j=0; j<W; j++){
       cin >> vec.at(i).at(j);
     }
   }
  
  for(int k=0; k<H; k++){
    for(int l=0; l<W; l++){
      cout << vec.at(k).at(l);
    }
    cout << endl;
    for(int m=0; m<W; m++){
      cout << vec.at(k).at(m);
    }
    cout << endl;
  }
    
}
   

Measured memory_bytes: 256
H, W = map(int, input().split())
a = []
b = []
for i in range(H):
        a.append(list(input()))

for i in range(H):
        all_white = True
        for j in range(W):
                if a[i][j] == '#':
                        all_white = False
        if all_white == False:
                b.append(a[i])
H = len(b)

for j in range(W):
        all_white = True
        for i in range(H):
                if b[i][j] == '#':
                        all_white = False
        if all_white == True:
                for i in range(H):
                        b[i][j] = ' '    

for i in range(H):
        for j in range(W):
                if b[i][j] != ' ':
                        print(b[i][j], end = '')
        print(end = '\n')

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

public class Main {

    public static void main (String[] args) {

        Scanner input = new Scanner(System.in);

        int a = input.nextInt();
        int b = input.nextInt();

        a = a * b;

        b = a;
        a = a/2;
        a = a*2;

        if(a == b){ System.out.println("Even"); }
        else{ System.out.println("Odd"); }

    }
}

Measured memory_bytes: 21716
require 'prime'
k = gets.to_i
k_to_s = k.to_s
k_size = k_to_s.size
if k.even? || k_to_s[k_size - 1] == '5' || k_to_s[k_size - 1] == '0'
  puts -1
  exit
end
tmp = 0
ans = -1
mods = [7 % k]
k.times do |i|
  mods[i + 1] = mods[i] * 10 % k
end
1.upto(k) do |i|
  tmp += mods[i]
  tmp %= k
  if tmp == 0
    ans = i
    break
  end
end
puts ans


Measured memory_bytes: 22500
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int d, c[30], l[30], s[400][30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d)for1(j, 26)cin >> s[i][j];
	for1(i, d) {
		int p = 0, k = -mod;
		for1(j, 26) {
			int kj = s[i][j] + c[j] * (i - l[j]);
			if (kj > k) { p = j; k = kj; }
			else if (kj == k && c[j] > c[p])p = j;
		}
		puts(p); l[p] = i;
	}
}

Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29

int main(){
	int n, k, h[100100], dp[100100];
	cin >> n >> k;
	rep(i, n) dp[i] = INF;
	dp[0] = 0;
	rep(i, n) cin >> h[i];
	rep(i, n) {
		for(int j = 1; j <= k; j++) {
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}
	cout << dp[n - 1] << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = 2e18;

template< class T >
struct CumulativeSum2D {
    vector< vector< T > > data;

    CumulativeSum2D(int W, int H) : data(W + 1, vector< int >(H + 1, 0)) {}

    void add(int x, int y, T z) {
        ++x, ++y;
        if(x >= data.size() || y >= data[0].size()) return;
        data[x][y] += z;
    }

    void build() {
        for(int i = 1; i < data.size(); i++) {
            for(int j = 1; j < data[i].size(); j++) {
                data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
            }
        }
    }

    T query(int sx, int sy, int gx, int gy) {
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }
};

signed main() {
    int N, K;
    cin >> N >> K;
    int baseK = 2 * K;
    auto B = CumulativeSum2D<int>(baseK * 2, baseK * 2);
    auto W = CumulativeSum2D<int>(baseK * 2, baseK * 2);
    for (int i = 0; i < N; i++) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        if (c == 'W') {
            W.add(x % baseK, y % baseK, 1);
            W.add((x % baseK) + baseK, y % baseK, 1);
            W.add(x % baseK, (y % baseK) + baseK, 1);
            W.add((x % baseK) + baseK, (y % baseK) + baseK, 1);
        } else {
            B.add(x % baseK, y % baseK, 1);
            B.add((x % baseK) + baseK, y % baseK, 1);
            B.add(x % baseK, (y % baseK) + baseK, 1);
            B.add((x % baseK) + baseK, (y % baseK) + baseK, 1);
        }
    }
    B.build();
    W.build();
    int ans = -1;
    int blackBase = B.query(0, 0, baseK, baseK);
    for (int i = 0; i < baseK; i++) {
        for (int j = 0; j < baseK; j++) {
            int white = 0, black = blackBase;
            white += W.query(i, j, i + K, j + K);
            black -= B.query(i, j, i + K, j + K);
            white += W.query(i + K, j + K, i + 2 * K, j + 2 * K);
            black -= B.query(i + K, j + K, i + 2 * K, j + 2 * K);
            ans = max(ans, white + black);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 250624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC085C
{
    class Program
    {
        static string searchCombination(int n, int y)
        {
            foreach (var i in Enumerable.Range(0, n + 1))
            {
                foreach (var j in Enumerable.Range(0, n + 1 - i))
                {
                    var k = n - (i + j);
                    var sum = 10000 * i + 5000 * j + 1000 * k;

                    if (sum == y)
                    {
                        return string.Format("{0} {1} {2}", i, j, k);
                    }
                }
            }

            return "-1 -1 -1";
        }

        static void Main(string[] args)
        {
            var nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
            var n = nums[0];
            var y = nums[1];

            Console.WriteLine(searchCombination(n, y));
        }
    }
}


Measured memory_bytes: 13396
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, A, B = MAP()

if (A-B-1)%2:
	print((B-A)//2)

else:
	print(min(A-1, N-B) - (A-B)//2 )


Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
#include<cstdlib>
#define ll long long int
#define ar array
int main() 
{
	int n,temp;
	ll sum=0;
	cin>>n;
	int a[100000],dp[100000];
	for(int i=0;i<n;i++)
		cin>>a[i];
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);

	for(int i=2;i<n;i++)	
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	printf("%d",dp[n-1]);
}


Measured memory_bytes: 4524
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
#define For(i,x) for (int i=h[x],k; i; i=nxt[i])
typedef long long ll;
using namespace std;

const int N=5010;
int n,cnt,u,v,ans,a[N],g[N],sz[N],h[N],to[N<<1],nxt[N<<1];
ll f[N][N];
void add(int u,int v){ to[++cnt]=v; nxt[cnt]=h[u]; h[u]=cnt; }

void dfs(int x,int fa){
	For(i,x) if ((k=to[i])!=fa) dfs(k,x);
	if (a[x]>0){
		g[x]=0;
		For(i,x) if ((k=to[i])!=fa){
			int s=g[k];
			rep(j,0,n) if (f[k][j]<0){ s=min(s,j+1); break; }
			g[x]+=s;
		}
	}
	f[x][0]=a[x]; sz[x]=1;
	For(i,x) if ((k=to[i])!=fa){
		for (int j=sz[x]+sz[k]; ~j; j--){
			f[x][j]+=f[k][0];
			if (j-g[k]-1>=0) f[x][j]=min(f[x][j],f[x][j-g[k]-1]);
			rep(s,max(0,j-sz[x]),min(j,sz[k])){
				if (s) f[x][j]=min(f[x][j],f[x][j-s]+f[k][s]);
				if (s<j && f[k][s]<0) f[x][j]=min(f[x][j],f[x][j-s-1]);
			}
		}
		sz[x]+=sz[k];
	}
}

int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,2,n) scanf("%d%d",&u,&v),add(u,v),add(v,u);
	memset(g,42,sizeof(g)); memset(f,42,sizeof(f));
	dfs(1,1); ans=g[1];
	rep(i,0,n) if (f[1][i]<0){ ans=min(ans,i); break; }
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 196736
n = int(input())
m, a, r, c, h = 0, 0, 0, 0, 0
for i in range(n):
    s = input()
    if s[0]=='M':
        m += 1
    elif s[0]=='A':
        a += 1
    elif s[0]=='R':
        r += 1
    elif s[0]=='C':
        c += 1
    elif s[0]=='H':
        h += 1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+ a*r*c+a*r*h+a*c*h+r*c*h)


Measured memory_bytes: 3064
import math
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * N

for i in range(1, N):
    m = math.inf
    for j in range(1, K+1):
        k = i - j
        if k < 0:
            break
        m = min(m, abs(h[i] - h[k]) + dp[k])
    dp[i] = m
print(dp[N-1])
    

Measured memory_bytes: 84140
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>

 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

int N;
int P[200004];
int A[200004];
signed main(){
    scanf("%lld",&N);
    int ans=N;
    rep(i,N){
        scanf("%lld",&P[i]);
        A[P[i]]=i+1;//A[i]はi番目にある
    }
    int sub=0;
    int subnow=1;
    rep(i,N){
        if(i>0&&A[i+1]>A[i]){
            subnow++;
            if(i==N-1)sub=max(subnow,sub);
        }else{
            sub=max(subnow,sub);subnow=1;
        }
    }
    printf("%lld",ans-sub);
}




Measured memory_bytes: 3328
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	ll n, w, ans = 0;
	cin >> n >> w;
	vector<ll> dp(w+1);
	for(int i = 0, a, b; i < n; i++) {
		cin >> a >> b;
		for(int j = w; j; j--) {
			if(j<a)
				break;
			dp[j]=max(dp[j], dp[j-a]+b);
			ans=max(ans, dp[j]);
		}
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
int abs(int x) { return x > 0 ? x : -x; }
int main() {
	int n;
	int x, y, px=0, py=0, pt=0, t;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d%d", &t, &x, &y);
		int d = abs(x - px) + abs(y - py);
		if (t - pt < d || (t - pt - d) % 2 != 0) {
			printf("No\n");
			return 0;
		}
		pt = t; px = x; py = y;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
// ABC123_A
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18（const int inf   = 1<<29;）

int main() {
    // input(sunippets: inpv, inpn, inps)
    vector<ll> vec(5);
    REP(i, 5) cin >> vec[i];
    ll k;
    cin >> k;
    sort(vec.begin(), vec.end());
    
    // calculation
    REP(i, 5) {
        REP(j, 5) {
            if (!(i == j)) {
                if (!(abs(vec[i] - vec[j]) <= k)) {
                    cout << ":(" << "\n";
                    return 0;
                }
            }
        }
    }
    cout << "Yay!" << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
using namespace std;

typedef pair<long long, int> P;
#define INF (1L<<50)

int N, M, C;
vector<int> edges[100100];
map<P, long long> L;
P D[100100];
bool dead[100100];
long long e;

int main() {
  cin >> N >> M >> C;
  for (int i=0; i<M; i++) {
    int a, b, d;
    cin >> a >> b >> d;
    edges[a-1].push_back(b-1);
    edges[b-1].push_back(a-1);
    L[P(a-1, b-1)] = L[P(b-1, a-1)] = d;
    e += d;
  }

  for (int i=0; i<N; i++) D[i] = P(INF, -1);

  priority_queue< P, vector<P>, greater<P> > q;
  D[0] = P(0, 0);
  q.push(D[0]);

  while (!q.empty()) {
    P p = q.top(); q.pop();
    int s = p.second;
    for (int t : edges[s]) {
      if (D[s].first + L[P(s, t)] < D[t].first) {
        D[t] = P(D[s].first + L[P(s, t)], t);
        q.push(D[t]);
      }
    }
  }

  sort(D, D+N);
  long long ans = INF;
  for (int i=0; i<N; i++) {
    P p = D[i];
    long X = p.first, s = p.second;
    for (int t : edges[s]) {
      if (dead[t]) e -= L[P(s, t)];
    }
    dead[s] = true;
    if (D[i+1].first == X) continue;
    ans = min(ans, C*X + e);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 37188
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static List<List<Integer>> ans;
	static int num = 0;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		for (int i = 2; i < n + 2; i++) {
			int val = i * (i - 1) / 2;
			if (val == n) {
				System.out.println("Yes");
				System.out.println(i);
				ans = new ArrayList<>(i);
				int[] target = new int[i];
				for (int j = 0; j < i; j++) {
					ans.add(new ArrayList<>());
					target[j] = j;
				}
				combination(target, 2, new ArrayList<Integer>());
				for (int j = 0; j < i; j++) {
					StringBuilder sb = new StringBuilder();
					sb.append(ans.get(j).size()).append(' ');
					for (int s : ans.get(j)) {
						sb.append(s).append(' ');
					}
					sb.deleteCharAt(sb.length() - 1);
					System.out.println(sb.toString());
				}
				return;
			} else if (val > n) {
				System.out.println("No");
				return;
			}
		}
	}

	static void combination(int[] target, int k, List<Integer> list) {
		if (list.size() == k) {
			num++;
			for (int i : list) {
				ans.get(target[i]).add(num);
			}
			return;
		}

		int i = 0;
		if (!list.isEmpty()) {
			i = list.get(list.size() - 1) + 1;
			if (list.size() + target.length - i < k) {
				return;
			}
		}
		for ( ; i < target.length; i++) {
			list.add(i);
			combination(target, k, list);
			list.remove(list.size() - 1);
		}
	}
}


Measured memory_bytes: 43676
def main():
    a, b, c = map(int,input().split())
 
    _set = set()
    if a <= c and b >= c: _set.add(c)
    if c // 2 < b:
        b = c // 2
    if c % 2 == 0:
        _set = _set | set(range(a, b+1))
    else:
        if a % 2 == 0:
            _set = _set | set(range(a+1, b+1, 2))
        else:
            _set = _set | set(range(a, b+1, 2))
             
    print(sum(map(lambda x: c % x == 0, _set)))
 
main()

Measured memory_bytes: 8168
// WARNING: Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#define REP(i, N) for(int i=0; i<(int)N; i++)
#define REPR(i, N) for(int i=(int)N-1; i>=0; i--)
#define mp make_pair
#define pb push_back

// Type
using ll = long long;
template <typename T = int> using P = pair<T, T>;

// Constants
const ll MOD = 1000000007;

/**
  型に合わせたINFを返す
  int: 214,748,364 (2.14 * 1e8)
  ll : 922,337,203,685,477,580 (9.22 * 1e17)
*/
template <typename T = int>
T getINF() {
  // NOTE: INF同士を足してもオーバーフロー起こさないように、10で割っている
  return numeric_limits<T>::max() / 10;
}

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

int main() {
  int n, m;
  cin >> n >> m;

  ll a[n];
  REP(i, n) cin >> a[i];
  sort(a, a + n, greater<int>());
  // REP(i, n) cout << a[i] << endl;

  P<ll> _bc[m];
  REP(i, m) {
    ll b, c;
    cin >> b >> c;
    _bc[i] = mp(c, b);
  }
  sort(_bc, _bc + m, greater<P<ll>>());
  // REP(i, m) cout << "(" << bc[i].first << ", " << bc[i].second << ")" << endl;

  ll bc[n];
  int p = 0;
  REP(i, n) {
    bool isBreak = false;
    REP(j, _bc[i].second) {
      if(p == n) {
        isBreak = true;
        break;
      }
      bc[p++] = _bc[i].first;
    }
    if(isBreak) break;
  }

  ll _sum = 0;
  int ai = 0, bci = 0;
  REP(i, n) {
    if(a[ai] >= bc[bci]) _sum += a[ai++];
    else _sum += bc[bci++];
  }
  cout << _sum << endl;

  return 0;
}


Measured memory_bytes: 3328
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

template<class Monoid>
struct SegTree {

  static int32_t nextPow2(int32_t n) {
    --n; n |= (n>>1); n |= (n>>2); n |= (n>>4); n |= (n>>8); n |= (n>>16);
    return ++n;
  }

  using Func = function<Monoid(Monoid, Monoid)>;
  const int sz;
  const Func fn;
  const Monoid unity;
  vector<Monoid> dat;

  SegTree(int n, const Monoid &u, Func f)
    : sz(nextPow2(n+1)), fn(f), unity(u), dat(sz*2, unity) {}

  void set(int k, const Monoid &v) {
    dat[k + sz] = v;
  }

  void build() {
    for (int k = sz-1; k > 0; --k) dat[k] = fn(dat[2*k], dat[2*k+1]);
  }

  void update(int k, const Monoid &v) {
    dat[ k += sz ] = v;
    while(k >>= 1) dat[k] = fn(dat[2*k], dat[2*k+1]);
  }

  Monoid query(int a, int b) const {
    Monoid L = unity,  R = unity;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = fn(L, dat[a++]);
      if (b & 1) R = fn(dat[--b], R);
    }
    return fn(L, R);
  }

  Monoid& operator[] (int k) {
    return dat[k + sz];
  }
};


signed main()
{
  int N;

  cin >> N;
  SegTree<int> seg(N+5, 0, [](int a, int b){ return __gcd(a,b); });

  for (int i = 1; i <= N; ++i) {
    int a; cin >> a;
    seg.set(i, a);
  }

  seg.build();

  int maxv = 0;
  for (int i = 1; i <= N; ++i) {
    chmax(maxv, __gcd(seg.query(0, i), seg.query(i+1, N+1)));
  }

  cout << maxv << endl;

  return 0;
}



Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <map>
#include <cmath>

using namespace std;

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

    int N;scanf("%d",&N);
    vector<vector<int>> map;
    map.resize(2);
    for(int i=0;i<2;i++){
        map[i].resize(N);
    }
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++){
            scanf("%d",&map[i][j]);
        }
    }

    int max=0;
    for(int i=0;i<N;i++){
        int tmp=0;
        for(int j=0;j<=i;j++){
            tmp+=map[0][j];
        }
        tmp+=map[1][i];
        for(int j=i+1;j<N;j++){
            tmp+=map[1][j];
        }
        if(max<tmp){
            max=tmp;
        }
    }
    printf("%d",max);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
//	freopen("1.txt","r",stdin);
//	freopen("1.out","w",stdout);
	string a,b;
	cin>>a;
	b=a;
	reverse(b.begin(),b.end());
	for (int i=0;i<b.length();i++)
	{
		if (b[i]=='b')b[i]='d';
		else if (b[i]=='d')b[i]='b';
		else if (b[i]=='p')b[i]='q';
		else  if (b[i]=='q')b[i]='p';
	}
	for (int i=0;i<b.length();i++)
	{
		if (b[i]!=a[i])
		{
			cout<<"No"<<'\n';
			return 0;
		}
	}
	cout<<"Yes"<<'\n';
}

Measured memory_bytes: 512
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
x = int(input())
#n, m = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))


if 400 <= x < 600:
    print(8)
elif 600 <= x < 800:
    print(7)
elif 800 <= x < 1000:
    print(6)
elif 1000 <= x < 1200:
    print(5)
elif 1200 <= x < 1400:
    print(4)
elif 1400 <= x < 1600:
    print(3)
elif 1600 <= x < 1800:
    print(2)
else:
    print(1)
 
    


        


Measured memory_bytes: 10060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
using namespace std;
const int NN = 11000;
typedef long long ll;

int n;
vector<string> vec1;

int main(){
	//freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);
	
	scanf("%d", &n);
	vec1.push_back("a");
	
	for (int i=1; i<=n-1; i++){
		int t1 = vec1.size();
		int add1 = 0;
		for (int j=0; j<t1; j++){
			string s = vec1[j];
			int l = s.length();
			int sum = 0;
			for (int k=0; k<l; k++) sum = max(sum, s[k] - 'a' + 1);
			//cout << s << " " << sum << endl; 
			for (int k=1; k<=sum+1; k++){
				add1++;
				char ch = 'a' + k - 1;
				string s1 = s + ch; 
				vec1.push_back(s1);
			} 
		}
		
		vec1.erase(vec1.begin(), vec1.begin()+t1);
	}
	
	for(vector<string>::iterator it=vec1.begin(); it<vec1.end();++it)
	{
		cout << *it << endl;
	}

	return 0;
} 

Measured memory_bytes: 11120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,n,a,i,s=0;
    cin>>h>>n;
    for(i=0;i<n;i++)
    {
        cin>>a;
        s+=a;
    }
    cout<<(s>=h?"Yes":"No")<<endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
  if (b == 0){
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> L(N + 1, 0);
  for (int i = 0; i < N; i++){
    L[i + 1] = gcd(L[i], A[i]);
  }
  vector<int> R(N + 1, 0);
  for (int i = N - 1; i >= 0; i--){
    R[i] = gcd(R[i + 1], A[i]);
  }
  int M = 0;
  for (int i = 0; i < N; i++){
    M = max(M, gcd(L[i], R[i + 1]));
  }
  cout << M;
}

Measured memory_bytes: 1408
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MX = 610;

int n, m;
int a[MX][MX];
string tmps[310];
int sm[MX][MX];

int get(int x1, int y1, int x2, int y2) {
	x1 = max(x1, 0);
	y1 = max(y1, 0);
	x2 = min(x2, n);
	y2 = min(y2, n);
	if (x1 >= x2 || y1 >= y2)
		return 0;
	return sm[x2][y2] - sm[x2][y1] - sm[x1][y2] + sm[x1][y1];
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		cin >> tmps[i];
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j) {
			if (tmps[i][j] == '#')
				a[i - j + m][i + j] = 1;
		}
	n = m = n + m;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) {
			sm[i][j] = sm[i - 1][j] + sm[i][j - 1] - sm[i - 1][j - 1] + a[i - 1][j - 1];
		}
	ll ans = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j) {
			if (!a[i][j])
				continue;
			for (int k = j + 2; k < n; k += 2) {
				if (a[i][k]) {
					ans += get(i + (k - j), j, i + (k - j) + 1, k + 1);
					ans += get(i - (k - j), j, i - (k - j) + 1, k + 1);
				}
			}
			for (int k = i + 2; k < n; k += 2) {
				if (a[k][j]) {
					ans += get(i + 1, j + (k - i), k, j + (k - i) + 1);
					ans += get(i + 1, j - (k - i), k, j - (k - i) + 1);
				}
			}
		}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
    int minn = Math.min((a+b),(a+c));
    int m = Math.min(minn,(b+c));
        System.out.println(m);
    }
    

}


Measured memory_bytes: 20692
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	string s;
	cin >> s;
	
	set<int>ss;
	for(auto i : s) ss.insert(i);
		ss.size() == 2 ? cout << "Yes" : cout << "No";
}

Measured memory_bytes: 3612
// Problem : C - Sum of product of pairs
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

///Astalavista Code........~boy_with_no_gf
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << ' ' ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}

// <=================================================================================================================================
// <=================================================================================================================================

void fun(){
	int n;cin>>n;
	vi arr(n);
	for(int i=0;i<n;i++)cin>>arr[i];
	vi pre(n+1,0);
	for(int i=n-1;i>=0;i--){
		pre[i]=pre[i+1]+arr[i];
	}
	int ans=0;
	for(int i=0;i<n;i++){
		ans=(ans+(arr[i]*(pre[i+1]%M))%M)%M;	
	}
	cout<<ans;
}

signed  main() {
    lets_go

    int t;
    t=1;
//    cin >> t;
    while (t--) {

    fun();

    }



    return 0;

}


Measured memory_bytes: 6276
def combinationUtil(arr, n, r, index, data, i):
    global a
    if(index == r):
        tmp = []
        for j in range(r):
            tmp.append(data[j])
            # print(data[j], end = " ")
        a.append(tmp)
        # print(" ") 
        return
    if(i >= n): 
        return
    data[index] = arr[i] 
    combinationUtil(arr, n, r, index + 1, data, i + 1) 
    combinationUtil(arr, n, r, index, data, i + 1) 

def printcombination(arr, n, r):
    data = list(range(r)) 
    combinationUtil(arr, n, r, 0, data, 0)

h, w, k = map(int, input().split())
l = []
for i in range(h):
    s = list(input())
    l.append(s)
ans = 0
ro, col = [], []
for i in range(h): ro.append(i)
for i in range(w): col.append(i)


t1 = []
t2 = []
for i in range(h + 1):
    a = []
    printcombination(ro, h, i)
    for j in a: t1.append(j)

for i in range(w + 1):
    a = []
    printcombination(col, w, i)
    for j in a: t2.append(j)

# print(t1)
# print(t2)


for i in t1:
    for j in t2:
        cnt = 0
        for a in range(h):
            for b in range(w):
                if a in i or b in j: continue
                if l[a][b] == '#': cnt -= -1
        if cnt == k: ans -= -1
print(ans)

Measured memory_bytes: 68256
n = int(input())
a = list(map(int, input().split()))
MOD = int(1e9+7)
k = (MOD + 1) // 2

ans = sum(a)**2 % MOD
for ai in a:
    ans -= ai**2
    ans %= MOD
ans *= k
ans %= MOD
print(ans)

Measured memory_bytes: 94352
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
	int n;
	char str[1024];

	scanf("%d ", &n);

	for (int i = 0; i < n; i++){
		fgets(str, sizeof(str), stdin);

		int len = strlen(str);
		for (int j = 0; j < len - 6; j++){
			if (strncmp(str + j, "Hoshino", 7) == 0){
				str[j + 6] = 'a';
			}
		}

		cout << str;
	}

	return (0);
}

Measured memory_bytes: 1168
#include <iostream>

int main(){
    int n, k, x, y;
    std::cin >> n >> k >> x >> y;

    int fee = 0;
    if(n > k){
        fee += k*x;
        fee += (n - k)*y;
    }else{
        fee += n*x;
    }
    std::cout << fee << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    string s; cin>>s;
    int num=s.length()-2;
    vector<int> li(num);
    for(int i=0;i<num;i++){
        int a=(s[i]-'0');
        int b=(s[i+1]-'0');
        int c=(s[i+2]-'0');
        li[i]=a*100+b*10+c;
    }
    int mina=800;
    for(int i=0;i<num;i++){
        if(abs(li[i]-753)<mina) mina=abs(li[i]-753);
    }
    cout<<mina<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

long long A[100001] ={};

int main() {
    long long N;
    std::cin >> N;
    long long sum = 0;
    for (int i=0; i<N; i++) {
        long long tmp;
        std::cin >> tmp;
        A[tmp]++;
        sum += tmp;
    }
    long long Q;
    std::cin >> Q;
    for (int i=0; i<Q; i++) {
        long long B, C;
        std::cin >> B >> C;
        sum += A[B] * (C-B);
        A[C] += A[B];
        A[B] = 0;
        std::cout << sum << std::endl;
    }
}

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


int main()
{
	int dp[100001] ={};
	int i, j, k, l, m,N;
	cin >> N;
	k = 0;
	for (i = 0; i <= 5; i++) {
		dp[i] = i;
	}
	for (i = 0; i <= N; i++) {
		k = 6;
		while (i + k <= N) {
			j = 1;
			while (i + k * j <= N && j < 6) {
				if (dp[i + k * j] == 0)
					dp[i + k * j] = dp[i] + j;
				j++;
			}
			k *= 6;
		}
	}
	for(i=0;i<=N;i++){
			k = 9;
			while (i + k <= N) {
				j = 1;
				while (i + k * j <= N && j < 9) {
						dp[i + k * j] = min(dp[i] + j,dp[i+k*j]);
					
					j++;
				}
				k *= 9;
			}
		}
	cout << dp[N] << endl;
	
	
    return 0;
}



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

int main(){
  char a;
  cin >>a;
  if(a=='A')
    cout<<'T'<<endl;
  if(a=='T')
    cout<<'A'<<endl;
  if(a=='G')
    cout<<'C'<<endl;
  if(a=='C')
    cout<<'G'<<endl;
}


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

int swap(int *a,int *b){
  *a^=*b;
  *b^=*a;
  *a^=*b;
  return;
}

int main(){
  int A,B;
  int C,D,E;
  scanf("%d %d",&A,&B);
  C=A+B;
  D=A-B;
  E=A*B;
  if(D<E) swap(&D,&E);
  if(C<D) swap(&C,&D);
  printf("%d\n",C);
  return 0;
}

Measured memory_bytes: 1720
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

vector<ll> all_divs(ll n){
    vector<ll> ret;
    for(ll i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long A,B,K;
    cin >> A >> B >> K;
    vector<ll> divs_a = all_divs(A);
    sort(divs_a.rbegin(), divs_a.rend());
    vector<ll> divs_b = all_divs(B);
    sort(divs_b.rbegin(), divs_b.rend());
    ll count=0;
    ll common;
    for(auto a : divs_a)
    {
        for(auto b: divs_b)
        {
            if(a == b)
            {
                count++;
                if(count==K) common=a;
                break;
            }
        }
    }
    cout << common << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>

int main() {
	int N;
	int A;
	int B;
	scanf("%d", &N);
	scanf("%d", &A);
	scanf("%d", &B);
	int i;
	if (N * A > B) {
		i = B;
	} else {
		i = N * A;
	}
	printf("%d\n", i);
	return 0;
}


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

using namespace std;

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

    long int n,ans=0;
    cin>>n;

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

    cout<<ans<<"\n";

    return 0;
}


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

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

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

int N, C;
int d[35][35], c[505][505];
vector<int> color[3];
int ans = INF;

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

    cin >> N >> C;
    REP(i, C) REP(j, C) cin >> d[i][j];
    REP(i, N) REP(j, N) cin >> c[i][j], c[i][j]--;
    REP(i, N) REP(j, N) color[(i+j)%3].pb(c[i][j]);

    if(N == 1){
        ans = 0;
    }else{
        int color_sum[30][3];
        REP(i, 30) REP(j, 3) color_sum[i][j] = 0;
        REP(i, C) for(auto x: color[0]) color_sum[i][0] += d[x][i];
        REP(i, C) for(auto x: color[1]) color_sum[i][1] += d[x][i];
        REP(i, C) for(auto x: color[2]) color_sum[i][2] += d[x][i];
        REP(i, C) REP(j, C) REP(k, C){
            if(i == j || i == k || j == k) continue;
            int sum = color_sum[i][0] + color_sum[j][1] + color_sum[k][2];
            ans = min(ans, sum);
        }
    }
    cout << ans << endl;
}


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

const ll MOD = 1000000007;

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

struct Combination
{
    int maxn;
    vector<ll> fact;
    vector<ll> ifact;
    
    Combination(int maxn) : maxn(maxn){
        fact.resize(maxn + 1);
        ifact.resize(maxn + 1);
        fact[0] = 1;
        for(int i = 1; i <= maxn; i++) fact[i] = fact[i - 1] * i % MOD;
        ifact[maxn] = modpow(fact[maxn], MOD - 2);
        for(int i = maxn - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1) % MOD;
    }

    ll com(ll n, ll k){
        if(k > n || k < 0) return 0;
        if(k == n || k == 0) return 1;
        return (fact[n] * ifact[k] % MOD) * ifact[n - k] % MOD;
    }
};

int main()
{
    int n;
    cin >> n;
    int a[100005];
    int b[100005];
    for(int i = 1; i <= n; i++) b[i] = -1;
    int l, r;
    for(int i = 0; i < n + 1; i++){
        cin >> a[i];
        if(b[a[i]] != -1){
            l = b[a[i]];
            r = i;
        }
        else b[a[i]] = i;
    }
    Combination com(n + 1);
    for(int i = 1; i <= n + 1; i++){
        cout <<
            (com.com(n, i) + com.com(n - 1, i - 1) - com.com(n - (r - l), i - 1) + com.com(n - 1, i - 2) + MOD) % MOD <<
            endl;
    }
}


Measured memory_bytes: 5632