akhauriyash/Code-Regression huggingface dataset:
from copy import deepcopy

class Dice():

    def __init__(self):
        self.E = [4,2,1,6,5,3]
        self.N = [2,6,3,4,1,5]
        self.S = [5,1,3,4,6,2]
        self.W = [3,2,6,1,5,4]
        self.order = "NNNNWNNNWNNNENNNENNNWNNN"

    def num_input(self):
        self.number = list(map(int,input().split()))

    def rotate(self,order):
        tmp = deepcopy(self.number)
        if order == "E":
            for i in range(6):
                self.number[i] = tmp[self.E[i]-1]
        elif order == "N":
            for i in range(6):
                self.number[i] = tmp[self.N[i]-1]
        elif order == "S":
            for i in range(6):
                self.number[i] = tmp[self.S[i]-1]
        elif order == "W":
            for i in range(6):
                self.number[i] = tmp[self.W[i]-1]
    
    def sidenum(self,x,y):
        for i in self.order:
            if self.number[1] == y and self.number[0] == x:
                print(self.number[2])
                break
            else:
                self.rotate(i)

if __name__ == "__main__":
    dice = Dice()
    dice.num_input()
    q = int(input())
    for i in range(q):
        x,y = map(int,input().split())
        dice.sidenum(x,y)


Measured memory_bytes: 6344
require 'matrix'

n, m = gets.split(/\s+/).map(&:to_i)

ar = []
br = []

n.times.each do 
  ar.push gets.split(/\s+/).map(&:to_i).to_a
end

m.times.each do 
  br.push gets.to_i
end

puts (Matrix[*ar] * Vector[*br]).to_a.join("\n")


Measured memory_bytes: 7328
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
struct edge {
    ll from;
    ll to;   //到達点
    ll cost; //移動コスト
};

int main() {
    ll n,m,p;
    std::cin >> n>>m>>p;
    vector<edge> edges;
    for (int i = 0; i < m; i++) {
        ll a,b,c;
        std::cin >> a>>b>>c;
        a--;
        b--;
        edges.push_back({a,b,p-c});
    }
    // infってどんなもん。
    vector<ll> d(n,1e18);
    d[0] = 0;
    
    bool has_loop = false;
    ll val = -1;
    
    for (int i = 0; i < n*2; i++) {
        for (auto e : edges) {
            if (d[e.from] != 1e18 && d[e.to] > d[e.from] + e.cost) {  //移動した後のコストが小さいと、頂点のコストを更新
                d[e.to] = d[e.from] + e.cost;
                if (i >= n) {         //頂点の数と同じ回数ループすると、負の閉路があるのでループをぬける
                    if(!has_loop){
                        val = d[n-1];
                        has_loop = true;
                    }else{
                        if(val != d[n-1]){
                            std::cout << -1 << std::endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    
    std::cout << max((ll)0,-d[n-1]) << std::endl;
    
}
 


Measured memory_bytes: 512
#include <iostream>
#define fast ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	int n,final=0;
	cin>>n;
	int arr[n];
	int sat[n];
	int add[n];
	for(auto i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(auto i=0;i<n;i++)
	{
		cin>>sat[i];
		final+=sat[i];
		//cout<<"final=="<<final<<"\n";
	}
	for(auto i=0;i<n-1;i++)
	{
		cin>>add[i];
	}
	//cout<<final<<"\n";
	for(auto i=0;i<n;i++)
	{
		if(arr[i+1]==arr[i]+1)
		{
			//cout<<i<<"\n";
			int z = add[arr[i]-1];
			final+=z;
		}
	}
	cout<<final<<"\n";
	
	
}

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

int main() {
  int n;
  cin >> n;
  bool f = false;
  for (int i = 1; i <= 9; ++i) {
    if (n%i == 0 && n/i <= 9) {
      f = true;
      break;
    }
  }
  cout << (f ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn count(s: &String, c: &mut [usize; 26]) {
	let v: Vec<char> = s.chars().collect();
	for i in 0..v.len() {
		c[v[i] as usize - 'a' as usize] += 1;
	}
}

fn main() {
	input!(n: usize);
	input!(s: [String; n]);

	let mut c: [usize; 26] = [0; 26];
	count(&s[0], &mut c);
	for i in 1..n {
		let mut ctmp: [usize; 26] = [0; 26];
		count(&s[i], &mut ctmp);
		for j in 0..26 {
			if ctmp[j] < c[j] {
				c[j] = ctmp[j];
			}
		}
	}
	for i in 0u8..26 {
		for _j in 0..c[i as usize] {
			print!("{}", ('a' as u8 + i) as char);
		}
	}
	println!("");
}



Measured memory_bytes: 2148
(x, y, A, B, C) = map(int, raw_input().split())

ps = sorted(map(int, raw_input().split()), reverse=True)[:x]
qs = sorted(map(int, raw_input().split()), reverse=True)[:y]
cs = sorted(map(int, raw_input().split()))

res = sorted(ps + qs, reverse=True)
tot = sum(res)

while cs and res and cs[-1] >= res[-1]:
    tot -= res.pop()
    tot += cs.pop()

print tot




Measured memory_bytes: 17060
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

s = rs()
counter = collections.Counter(s)
n = len(s)
res = 0
for i, c in enumerate(s):
    if c == 'W':
        counter['W'] -= 1
    else:
        res += counter['W']
print(res)

Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
using ll = int64_t;

int main(){
    int n; cin >> n;
    ll a[n]; rep(i, n) cin >> a[i];

    set<ll> s;
    rep(i, n){
        auto it = s.find(a[i]);
        if(it != s.end()){
            cout << "NO" << endl;
            return 0;
        } else {
            s.insert(a[i]);
        }
    }
    cout << "YES" << endl;
    return 0;
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int N;
    scanf("%d", &N);

    int m = -1;
    int point = -1;
    for (int i = 0; i < N; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        if (m < x) {
            m = x;
            point = y;
        }
    }

    cout << m + point << endl;

    return 0;
}

Measured memory_bytes: 256
[N, M] = list(map(int, input().split()))
H = list(map(int, input().split()))
T = [1]*N
for i in range(M):
    [A, B] = list(map(int, input().split()))
    if H[A-1] == H[B-1]:
        T[A-1] = 0
        T[B-1] = 0
    elif H[A-1] > H[B-1]:
        T[B-1] = 0
    else:
        T[A-1] = 0
answer = 0
for i in range(N):
    if T[i] == 1:
        answer += 1
print(answer)

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;

const int mod = 1e9+7;
const int inf = (1<<28);
const ll infl = (1LL<<60);

int main() {
  ll h; cin >> h;
  ll ans = 0, num = 1;
  while (h > 0) {
    ans += num;
    num <<= 1;
    h >>= 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
     
using namespace std;
     
int main() {
    ll n;
    cin >> n;
    queue<pair<ll, ll>> monsters;
    monsters.push({1, n});
    ll atk = 0;
    while (!monsters.empty()) {
        pair<ll, ll> hp = monsters.front();
        monsters.pop();
        atk += hp.first;
        if (hp.second / 2 > 0) {
            monsters.push({hp.first * 2, hp.second / 2});
        }
    }
    cout << atk;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    int N; cin >> N;
    vector<map<char, int>> M(N);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 26; j++){
            //cout << (char)(j+97) << endl;
            M[i][(char)(j+97)] = 0;
        }
    }
    for(int i = 0; i < N; i++){
        string S; cin >> S;
        for(auto c : S)M[i][c]++;
    }

    vector<int> Min(26);
    for(int i = 0; i < 26; i++) Min[i] = INF;
    for(int i = 0; i < N; i++){
        for(auto m : M[i]){
            char ch = m.first;
            int num = m.second;
            Min[(int)ch-97] = min(num, Min[(int)ch-97]);
        }
    }

    string ans = "";
    for(int i = 0; i < 26; i++){
        if(Min[i] == INF) continue;
        for(int j = 0; j < Min[i]; j++){
            ans += (char)(i + 97);
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long

#define fast ios_base::sync_with_stdio(false)
#define itt cin.tie(0)
#define now cout.tie(0)

using namespace std;

ll n,m,h[200005],ans,t;
bool g[200005];

int main()
{
	cin>>n>>m;
	memset(g,1,sizeof(g));
	for(int i=1;i<=n;i++)
		cin>>h[i];
	for(int i=0;i<m;i++)
	{
		ll a,b;
		cin>>a>>b;
		if(h[a]<=h[b])
			g[a]=false;
		if(h[b]<=h[a])
			g[b]=false;
	}
	ans=0;
	for(int i=1;i<=n;i++)
	{
		if(g[i])
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    char c;
    cin >> c;
    c++;
    cout << c << endl;

}



Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log, atan,pi #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    a,b,x = MI()
    x /= a
    if x > a*b/2:
        x = a*b-x
        y = 2*x/a
        ans = (atan(y/a)*1/(2*pi)*360)
        # print(y,a)
    else:
        y = 2*x/b
        ans = 90 - (atan(y/b)*1/(2*pi)*360)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
#define QWQ puts("successfully enter.")
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define FILL(a,val) memset(a,val,sizeof(a))
const int MAXN=100000+5;
int n,k,r,s,p,ans;
string S; char las[MAXN],winit[MAXN];
void display(initializer_list<int> out)
{
	cout<<"DISPLAY:";
	for(auto x:out) cout<<x<<' ';
	puts("");
}
int main()
{
	winit['r']='p',winit['s']='r',winit['p']='s';
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin>>n>>k>>r>>s>>p;
	cin>>S; S="0"+S;
	for(int i=1;i<=k;i++)
	{
		if(S[i]=='r') ans+=p,las[i]='p';
		if(S[i]=='s') ans+=r,las[i]='r';
		if(S[i]=='p') ans+=s,las[i]='s';
	}
	for(int i=k+1;i<=n;i++)
	{
		if(las[i-k]!=winit[S[i]])
		{
			if(S[i]=='r') ans+=p,las[i]='p';
			if(S[i]=='s') ans+=r,las[i]='r';
			if(S[i]=='p') ans+=s,las[i]='s';
			continue;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    let n = parseInt(lines[0])
    /* let l = lines[1].split(' ').map(function (_) { return parseInt(_); }) */

    if(n >= 30) {
        console.log('Yes')
    } else {
        console.log('No')
    }
});

Measured memory_bytes: 29896
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGraphPartition solver = new BGraphPartition();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGraphPartition {
        int n;
        boolean[][] a;
        int[] ind;

        int bfs(int u) {
            ind[u] = 1;
            int[] q = new int[n];
            int h = 0, t = 1;
            q[h] = u;
            int ans = 1;
            while (h < t) {
                u = q[h++];
                for (int v = 0; v < n; v++) {
                    if (a[u][v]) {
                        if (ind[v] != 0 && ind[v] != ind[u] - 1 && ind[v] != ind[u] + 1) {
                            return -1;
                        }
                        if (ind[v] == 0) {
                            q[t++] = v;
                            ind[v] = ind[u] + 1;
                            ans = ind[v];
                        }
                    }
                }
            }
            return ans;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            n = in.nextInt();
            a = new boolean[n][n];
            for (int i = 0; i < n; i++) {
                String s = in.next();
                for (int j = 0; j < n; j++) {
                    a[i][j] = s.charAt(j) == '1';
                }
            }

            int ans = -1;
            for (int i = 0; i < n; i++) {
                ind = new int[n];
                int k = bfs(i);
                if (k > ans) {
                    ans = k;
                }
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 27172
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{

  public static void main
  (
    String[] args
  )
  {
    BufferedReader in_stream;
    String         in_str;
    String[]       in_str_split;

    int   in_N;

    int      cnt;
    double[] ans;

    try
    {
      in_stream = new BufferedReader(new InputStreamReader(System.in));

      /*----------------
       * 引数
       *----------------*/
      in_str = new String(in_stream.readLine());
      in_N   = Integer.parseInt(in_str);

      System.out.println("" + (in_N / 3));
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)

int main(void)
{
    string s ,t;
    cin >> s >> t ;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s<t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int N, A, B;

		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = sc.nextInt();
		B = sc.nextInt();

		sc.close();

		System.out.println(Math.min(N*A, B));
	}

}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return 
#define endl         "\n" 

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(l,r)     ((l)+((r)-(l))/2) 

#define fo(i,a,b)    for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***




void solve()
{
    int n;rd(n);
    int a[n+1],b[n+1],c[n+1];
    fo(i,1,n)rd(a[i]);
    fo(i,1,n)rd(b[i]);   
    fo(i,1,n-1)rd(c[i]);   
    int pre = -2;
    ll tot = 0;
    fo(i,1,n){
        int cu = a[i];
        tot += b[cu];
        if(cu-pre==1)tot+=c[cu-1];
        pre = cu;
    }
    cout<<tot<<endl;


    
}


void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

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

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

    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, q;
    cin >> n >> q;

    vector< vs32 > g(n);
    int a, b;
    rep (i, n - 1)
    {
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vs32 ans(n, 0);
    rep (i, q)
    {
        cin >> a >> b;
        --a;
        ans[a] += b;
    }

    vector< bool > reached(n, false);
    queue<int> que;
    que.push(0);
    while (!que.empty())
    {
        int u = que.front(); que.pop();
        if (reached[u]) continue;
        reached[u] = true;

        for (auto v : g[u])
        {
            if (reached[v]) continue;
            ans[v] += ans[u];
            que.push(v);
        }
    }

    rep (i, n)
    {
        if (i > 0) cout << " ";
        cout << ans[i];
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 15604
x,k,d=(int(i) for i in input().split())
c=(abs(x)//d)
if(x<0):
    x+=(min(k,c)*d)
else:
    x-=(min(k,c)*d)
k=max(0,k-c)
if(k%2==1 and x<0):
    print(abs(x+d))
elif(k%2==1 and x>0):
    print(abs(x-d))
elif(k%2==1 and x==0):
    print(x+d)
else:
    print(abs(x))

Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    int n; cin >> n;
    vector<ll> s(5,0);
    int p[10]={0,0,0,0,0,0,1,1,1,2};
    int q[10]={1,1,1,2,2,3,2,2,3,3};
    int r[10]={2,3,4,3,4,4,3,4,4,4};
    rep(i,n) {
        string tmp; cin >> tmp;
        if (tmp[0] == 'M') {
            s[0]++;
        }
        if (tmp[0] == 'A') {
            s[1]++;
        }
        if (tmp[0] == 'R') {
            s[2]++;
        }
        if (tmp[0] == 'C') {
            s[3]++;
        }
        if (tmp[0] == 'H') {
            s[4]++;
        }
    }

    ll ans = 0;
    rep(i,10) {
        ans += s[p[i]] * s[q[i]] * s[r[i]];
    }
    printf ("% lld\n",ans);
    return 0;
}


Measured memory_bytes: 3688
#include <cstdio>
#include <set>

int main()
{
  std::set<long long> set[100000];
  
  int n;
  scanf("%d", &n);
  if (n & 1)
  {
    const int m = n / 2;
    for (int i = 0; i < n; ++i)
    {
      long long a;
      scanf("%lld", &a);
      if (a & 1)
      {
        puts("0");
        return 0;
      }
      set[m + a / 2].insert(i);
      set[m - a / 2].insert(i);
    }
    if (set[m].size() != 1)
    {
      puts("0");
      return 0;
    }
  }
  else
  {
    for (int i = 0; i < n; ++i)
    {
      long long a;
      scanf("%lld", &a);
      if (!(a & 1))
      {
        puts("0");
        return 0;
      }
      set[n / 2 + a / 2].insert(i);
      set[n / 2 - 1 - a / 2].insert(i);
    }
  }
  
  long long ans = 1;
  for (long long i = 0; i <= (n - 1) / 2; ++i)
  {
    if (n & 1 && i == (n - 1) / 2) break;
    if (set[i].size() != 2)
    {
      puts("0");
      return 0;
    }
    ans = ans * 2 % 1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll T = 26;
ll L[T];

ll D;
vector<ll> C;
vector< vector<ll> > S;

vector<ll> R;

//------------------------------------------------------------------------------
// 乱数生成
//------------------------------------------------------------------------------
template<typename T = unsigned long> T xorshift()
{
    static T x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    T t=(x^(x<<11));x=y;y=z;z=w;
    return (w=(w^(w>>19))^(t^(t>>8)));
}

//------------------------------------------------------------------------------
// 入力
//------------------------------------------------------------------------------
void input()
{
    cin >> D;

    C.assign(D, 0);
    rep (t, T) { cin >> C[t]; }

    S.assign(D, vector<ll>(T, 0));
    rep (d, D) { rep (t, T) { cin >> S[d][t]; } }

    R.assign(D, 0);
    rep (d, D) { R[d] = xorshift() % T; }
}

//------------------------------------------------------------------------------
// 出力
//------------------------------------------------------------------------------
void output()
{
    rep (d, D) { cout << R[d] + 1 << endl; }
}

//------------------------------------------------------------------------------
// スコア計算
//------------------------------------------------------------------------------
ll calcScore(const vector<ll>& contests)
{
    fill(L, L + T, 0);

    ll res = 0;

    rep (d, D)
    {
        res += S[d][contests[d]];

        L[contests[d]] = d + 1;
        rep (t, T) { res -= C[t] * (d + 1 - L[t]); }
    }

    return res;
}

//------------------------------------------------------------------------------
// 現状の最適解を改変してみる
//------------------------------------------------------------------------------
void solve()
{
    ll highScore = calcScore(R);

    fill(L, L + T, 0);

    rep (k, 100000)
    {
        const ll dd = xorshift() % D;
        const ll tt = xorshift() % T;

        const ll origin = R[dd];
        R[dd] = tt;

        const ll score = calcScore(R);

        if (highScore < score) { highScore = score; } else { R[dd] = origin; }
    }
}

int main()
{
    input();

    solve();

    output();

    return 0;
}


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

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

    vector<int> numbers(N);
    for(int i=0; i<N; i++){
        cin >> numbers.at(i);
    }

   int ans = 0;
   for(int i=0; i<N; i++){
       while(numbers.at(i) > 0 && numbers.at(i)%2 == 0){
           ans += 1;
           numbers.at(i) /= 2;
       }
   }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;

int main()
{
    int n;
    cin >> n;
    V<ll> a(n);
    rep(i,n) cin >> a[i];
    V<ll> dp(2, 0); //i番目まで足したとき、i+1番目の正負はa[i]と一致しているか(i+1番目がflipされているか)
    dp[0] = a[0];
    dp[1] = -a[0];
    rep(i,n-1)
    {
        V<ll> dp2(2, 0);
        int ni = i+1;
        chmax(dp2[0], dp[0] + a[ni]); //a[i+1]はそのままで、+a[i] -> a[i+2]の正負はそのまま
        chmax(dp2[0], dp[1] - a[ni]); //a[i+1]に-1をかけて、-a[i] -> a[i+2]の正負は逆転
        chmax(dp2[1], dp[0] - a[ni]); //a[i+1]はそのままで、-a[i] -> a[i+2]の正負はそのまま
        chmax(dp2[1], dp[1] + a[ni]); //a[i+1]に-1をかけて、+a[i] -> a[i+2]の正負は逆転
        swap(dp2, dp);
        // cout << dp << endl;
    }
    cout << dp[0] << endl; //n番目はflip出来ない

    return 0;
}

Measured memory_bytes: 3988
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;



int64_t f(int64_t a, int64_t b) {
  cerr << "\033[93m" << a << " " << b << "\033[m" << endl;
  int64_t n  = std::max(a, b);
  int result = 1;
  while (n >= 10) {
    result++;
    n /= 10;
  }
  return result;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int64_t n;
  cin >> n;
  int64_t result = f(n, 1);
  for (int64_t a = 1; a <= std::pow(n, 0.5) + 1; a++) {
    if (n % a == 0) {
      int64_t b = n / a;
      result    = std::min(result, f(a, b));
    }
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}
 
void solve(){
 
 
}


vi a;
ll c[200009];

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();

    int n;cin>>n;
    a.resize(n,0);
    rep(i,n) cin>>a[i], c[a[i]]++;

    ll ans=0;
    rep(i,200009) ans+=c[i]*(c[i]-1)/2;

    rep(i,n) cout<<ans-c[a[i]]+1<<'\n';


	return 0;
}
 



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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

int N;
vi A;

void solve() {
    ll mx = -1e10;
    ll odd = 0, even = 0;
    REP (i, N) {
        mx = max(mx, A[i]);
        if (i&1) odd += max(0ll, A[i]);
        else even += max(0ll, A[i]);
    }

    if (mx <= 0) {
        cout << mx << "\n" << N-1 << "\n";
        int idx = 0;
        while (A[idx] != mx) {
            cout << 1 << "\n";
            idx++;
        }
        while (idx < N-1) {
            cout << N-idx << "\n";
            idx++;
        }
        assert(N-idx == 1);
        return;
    }

    vi op;
    if (odd > even) {
        op.PB(1);
        A.erase(A.begin());
        N--;
    }
    if (A.size()%2 == 0) {
        op.PB(A.size());
        A.erase(--A.end());
    }

    while (A[0] <= 0) {
        op.PB(1); op.PB(1);
        A.erase(A.begin());
        A.erase(A.begin());
    }
    while (A[A.size()-1] <= 0) {
        op.PB(A.size()); A.erase(--A.end());
        op.PB(A.size()); A.erase(--A.end());
    }
    while (A.size() > 1) {
        assert(A.size() >= 3);
        assert(A.size()%2 == 1);
        if (A[2] > 0) {
            op.PB(2);
            A[0] += A[2];
        }
        else op.PB(3);
        A.erase(++A.begin());
        A.erase(++A.begin());
    }
    assert(A.size() == 1);
    assert(A[0] == max(odd, even));

    cout << A[0] << "\n" << op.size() << "\n";
    FORE (x, op) cout << x << "\n";
}

int main() {
    cin >> N; A = vi(N);
    REP (i, N) cin >> A[i];
    solve();
}

Measured memory_bytes: 256
#1~xまでの整数の組*2の最大マッチングを考える
#基本はx//2と(x+1)//2のマッチングが最大値，a==bに注意

Q=int(input())
for _ in range(Q):
    a,b=map(int,input().split())
    if a>b:
        a,b=b,a
    
    if a==b:
        print(2*a-2)
    else:
        ab=a*b
        ok=1
        ng=a*b
        while (ng-ok)>1:
            med=(ok+ng)//2
            if ((med+1)//2) * ((med+2)//2) >=ab:
                ng=med
            else:
                ok=med
        print(ok-1)
            
        





Measured memory_bytes: 39024
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define range(i, a, b, s) for (int i = (a), __##i = (b); i < __##i; i += (s))
#define down(i, a, b, s) for (int i = (a), __##i = (b); __##i < i; i += (s))

const int maxn = 2e3 + 2;
const int mod = 1e9 + 7;

ll n, m, a[maxn], b[maxn], dp[maxn][maxn];

ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }

int main(int argc, char const *argv[]) {
  // freopen("E.txt", "r", stdin);

  while (cin >> n >> m) {
    range(i, 0, n, 1) cin >> a[i];
    range(i, 0, m, 1) cin >> b[i];

    memset(dp, 0, sizeof(dp));
    range(i, 0, n, 1) {
      range(j, 0, m, 1) {
        if (a[i] == b[j]) {
          dp[i][j] = 1;
          if (i >= 1 && j >= 1) dp[i][j] = add(dp[i][j], dp[i - 1][j - 1]);
        }
        if (i >= 1) dp[i][j] = add(dp[i][j], dp[i - 1][j]);
        if (j >= 1) dp[i][j] = add(dp[i][j], dp[i][j - 1]);
        if (i >= 1 && j >= 1) dp[i][j] = sub(dp[i][j], dp[i - 1][j - 1]);
      }
    }
    cout << dp[n - 1][m - 1] + 1 << endl;
  }
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> g(n, true);
  for(int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if(h.at(a-1) <= h.at(b-1)) {
      g.at(a-1) = false;
    }
    if(h.at(b-1) <= h.at(a-1)) {
      g.at(b-1) = false;
    }
  }
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(g.at(i)) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3788
#include <stdio.h>
int main(){
	int n,i;
	scanf("%d",&n);
	int a=n/4,b=n/7,count=0;
	for(i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			if(4*i+7*j==n){
				count++;
				}
		}
	}
	if(count>0){
		printf("Yes");
		}
	else{
		printf("No");
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> d(N);
  for( int i = 0; i < N; ++i ){
    cin >> d.at(i);
  }
  
  int sum = 0;
  for( int i = 0; i < N-1; ++i ){
    for( int j = i+1; j < N; ++j ){
      sum += d.at(i) * d.at(j);
    }
  }
  
  cout << sum;
}


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

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

  int64_t t, a;
  cin >> t >> a;

  for (int i = 1; i < N; ++i) {
    int64_t T, A;
    cin >> T >> A;

    if (T * a != A * t) {
      int64_t d = max((t + T - 1) / T, (a + A - 1) / A);
      t = d * T;
      a = d * A;
    }
  }

  cout << t + a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, M, K;
	cin >> N >> M >> K;
	
	vector<int> A(N), B(M);
	REP(i, N) scanf("%d", &A[i]);
	REP(i, M) scanf("%d", &B[i]);
	
	vector<ll> sum(M + 1);
	REP(i, M) sum[i + 1] += sum[i] + B[i];
	
	int ans = 0;
	ll s = 0;
	REP(i, N + 1) {
		ll dif = K - s;
		if (dif < 0) continue;
		auto it = upper_bound(ALL(sum), dif);
		chmax(ans, i + (it - sum.begin() - 1));
		
		if (i < N) s += A[i];
	}
	
	cout << ans << endl;
	
	return 0;
}


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

#define ll  long long int
#define ld  long double
#define MAX 1000001
#define MOD 1000000007
#define pi  3.14159265358979323846264338
#define mp  make_pair
#define pb  push_back
#define pll pair<ll,ll>
#define vl  vector<ll>
#define vi  vector<int>
#define vs  vector<string>
#define vc  vector<char>
#define fst first
#define sec second
#define foi(i, a, b)   for(ll i = a; i<b;i++)
#define fod(i, a, b)   for(ll i = a;i>=b;i--)
#define all(v)         (v).begin(), (v).end()
#define max3(a, b, c)  max(max(a,b), c)
#define min3(a, b, c)  min(min(a,b), c)
#define ump  unordered_map<ll,ll>
#define us   unordered_set<ll>
#define nl  "\n"
#define INF  (ll)1e18
#define s(v) (ll)(v).size()
#define e(v) (v).empty

using namespace std;

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


void solve(){
    ll h,w;
    cin>>h>>w;

    vector<vector<ll>> a(h,vector<ll>(w));

    char c;
    foi(i,0,h){
        foi(j,0,w){
            cin>>c;
            if(c=='.'){
                a[i][j] = 1;
            }else{
                a[i][j] = 0;
            }
        }
    }
    
    foi(i,0,w){
        if(a[0][i]==0){
            while(i<w){
                a[0][i] = 0;
                i++;
            }
        }
    }

    foi(i,0,h){
        if(a[i][0]==0){
            while(i<h){
                a[i][0] = 0;
                i++;
            }
        }
    }

    foi(i,1,h){
        foi(j,1,w){
            if(a[i][j]==0){
                continue;
            }else{
                a[i][j] = (a[i-1][j] + a[i][j-1])%MOD;
            }
            
        }
    }

    cout<<a[h-1][w-1]<<"\n";
}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
    }

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 11092
#include <stdio.h>
#include<iostream>
#include<string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <map>
using namespace std;
int a[105];
bool cmp(int a,int b){
    return a<b;
}
int main() {
    long long x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    if(x/d>=k) printf("%lld\n",x-d*k);
    else{
        k-=x/d;
        x%=d;
        if(k%2) printf("%lld\n",d-x);
        else printf("%lld\n",x);
    }
    return 0;
}

Measured memory_bytes: 3756
N = int(input())
numbers = [int(n) for n in input().split(' ')]
distances = []
if N == 1:
    print(0)
else:
    counter = 0
    for i in range(0, len(numbers)):
        if i == len(numbers) - 1:
            distances.append(counter)
            break
        if numbers[i] >= numbers[i + 1]:
            counter += 1
        else:
            distances.append(counter)
            counter = 0

    print(max(distances))

Measured memory_bytes: 14224
process.stdin.resume();
process.stdin.setEncoding('utf8');
var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});
process.stdin.on('end', function() {
    var args = input.split('\n').map(Number);
    for (var i = 0; i < args.length && args[i] != 0; i++) {
        console.log('Case %d: %d', i + 1, args[i]);
    }
});

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

using namespace std;

int main(void) {
	int num, len, i = 0,  j = 0, sum, a, c, ans = 0;
	cin >> num >> len >> c;
	vector<int> b(len);
	for (; i < len; i++)
		scanf("%d", &b[i]);
	for (; j < num; j++) {
		sum = c;
		for (i = 0; i < len; i++) {
			scanf("%d", &a);
			sum += a * b[i];
		}
		if (sum > 0)
			ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector> //可変長配列
#include <queue> //キュー
#include <unordered_map> //ハッシュ連想配列
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define ll long long int
#define INFTY (1<<21)

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    ll N,n,a=0;
    cin>>N;
    n = N;
    while(n%10 != 0){
        a += n % 10;
        n /= 10;
    }
    cout<<((N%a==0)?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
A = [int(_) for _ in input().split()]
A = sorted(A)
List = []

if N % 2 == 0:
    for i in range(N):
        List.append(i//2 * 2 + 1)
else:
    for i in range(N):
        List.append(math.ceil(i/2) * 2)

if A != List:
    print(0)
else:
    print(2**(N//2) % (10**9+7))

Measured memory_bytes: 13812
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_ ; ++i)
#define drep(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_ ; --i)
#define clear(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = (x << 3) + (x << 1) + (ch - 0x30);
		ch = getchar();
	}
	return flag * x;
}
 
#define Max 509
int H, W;
int blue[Max][Max], red[Max][Max];
int data[Max][Max];
int main() {
	H = read(), W = read();
	rep(i, 1, H) {
		rep(j, 1, W) {
			char ch = getchar();
			if(ch == '.') data[i][j] = 0;
			if(ch == '#') data[i][j] = 1;
		}
		getchar();
	}
	rep(i, 1, W) red[1][i] = 1;		
	rep(i, 1, W) blue[H][i] = 1;		
	rep(i, 2, H - 1)
		rep(j, 1, W)
			if(j & 1) red[i][j] = 1;
			else blue[i][j] = 1;
	rep(i, 1, H)
		rep(j, 1, W)
			if(data[i][j]) red[i][j] = blue[i][j] = 1;
	rep(i, 1, H){
		rep(j, 1, W)
			printf("%c", red[i][j] ? '#' : '.');
		puts("");
	}
	puts("");
	rep(i, 1, H){
		rep(j, 1, W)
			printf("%c", blue[i][j] ? '#' : '.');
		puts("");
	}
	return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

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

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  dp[k][u][v] : uからvへの長さkのパスの場合の数
}*/

typedef vector<int> vec;
typedef vector<vec> mat;

mat mul(mat &a, mat &b)
{
  mat c(a.size(), vec(b[0].size()));
  for(int i = 0; i < a.size(); i++){
    for(int k = 0; k < b.size(); k++){
      for(int j = 0; j < b[0].size(); j++){
        (c[i][j] += a[i][k]*b[k][j]%mod) %= mod;
      }
    }
  }
  return c;
}

mat pow(mat a, int n)
{
  mat b(a.size(), vec(a.size()));
  for(int i = 0; i < b.size(); i++) b[i][i] = 1;
  while(n > 0){
    if(n & 1) b = mul(b, a);
    a = mul(a, a);
    n >>= 1;
  }
  return b;
}

signed main()
{
  int n, k;
  cin >> n >> k;

  mat a(n, vec(n));
  rep(i, 0, n) rep(j, 0, n){
    cin >> a[i][j];
  }

  a = pow(a, k);
  int ans = 0;
  rep(i, 0, n) rep(j, 0, n){
    (ans += a[i][j]) %= mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
	;
		int max = (int) Math.max(a,b);
		int ans= -1;
		for(int i = max ; i < 10001 ;i ++) {
			if(Math.floorDiv(i*2, 25) == a && Math.floorDiv(i, 10) == b ) {
				ans = i;
				break;
			}
			}
		System.out.println(ans);
	}
	
}


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

#define rep(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define repn(i, m, n) for (int (i) = (m) ; (i) < (int)(n) ; ++(i))
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define repn_rev(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= (m) ; --(i))

#define INF 2e9
#define ll long long
#define MOD 1e9+7
#define MAX_V 20005
// dinic
template <typename T = long long>
struct Dinic {
    struct edge { int to; T cap; int rev; };
    vector<vector<edge>> G;
    vector<int> itr, level;
    int n;
    T inf;
 
    explicit Dinic(int n): n(n), G(n) {inf=numeric_limits<T>::max();}
 
    void add_edge(int from, int to, T cap) {
        G[from].push_back((edge) {to, cap, (int) G[to].size()});
        G[to].push_back((edge) {from, 0, (int) G[from].size()-1});
    }
 
    void bfs(int s) {
        level.assign(n, -1);
        queue<int> q;
        level[s] = 0;
        q.push(s);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (auto &e: G[v]) {
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }
 
    T dfs(int v, int t, T f) {
        if (v == t) return f;
        for (int& i = itr[v]; i < (int) G[v].size(); ++i) {
            edge& e = G[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                T 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;
    }
 
    T max_flow(int s, int t) {
        T ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(n, 0);
            while ((f = dfs(s, t, inf)) > 0) ret += f;
        }
        return ret;
    }
};

int main(){
    int n;
    cin >> n;
    ll a[n];
    ll ans = 0;
    rep(i, n) cin >> a[i];
    auto dinic = Dinic<ll>(n+3);
    rep(i, n) {
        ll tmp = 2 * (i+1);
        if(a[i] <= 0){
            dinic.add_edge(0, i+1, (-1)*a[i]);
        }
        else{
            dinic.add_edge(i+1, n+1, a[i]);
            ans += a[i];

        }
        while(tmp <= n){
            dinic.add_edge(i+1, tmp, INF);
            tmp += i+1;
            //cout << i+1 << " " << tmp << endl;
        }
    }

    cout << ans - dinic.max_flow(0, n+1) << endl;

    return 0;
}



Measured memory_bytes: 256