akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 12
#define M 13
#define MOD 1000003
#define Gard 0

void InsertWord(char []);
int ChangeNum(char );
long long Convert(char []);
int CalH(int );
int CalAnoH(int );
int SearchWord(char []);

char Hash[MOD][M];

int main(){
  int loop,judge=0,i;
  char order[N],spel[N];

  scanf("%d",&loop);
  for(i=0;i<loop;i++){
    scanf("%s %s",order,spel);

    if(order[0]=='f'){
 
      judge=SearchWord(spel);

      if(judge==1){
	printf("yes\n");
      }
      

      else if(judge==Gard){
	printf("no\n");
      }
      
    }

    else if(order[0]=='i'){
      InsertWord(spel);
    }
    
  }
  return 0;
}

void InsertWord(char spel[]){
  long long result,phase,judge;
  int equalch=0;
  int slength=0;
 

  judge=Convert(spel);

  phase=0;
  
  while(1){
    result=(CalH(judge)+CalAnoH(judge)*phase)%MOD;

    equalch=strcmp(Hash[result],spel);
    slength=strlen(Hash[result]);

    if(equalch==Gard){
      break;
    }

    else if(slength==Gard){
      strcpy(Hash[result],spel);
      break;
    }

    else{
      phase++;
    }
    
  }
}

long long Convert(char spel[]){
  long long result=0,value;
  long long i;

  value=1;

  for(i=0;i<(long long)strlen(spel);i++){
    result+=value*(ChangeNum(spel[i]));
    value=value*5;
  }

  return result;
}

int ChangeNum(char spel){

  if(spel=='A'){
    return 1;
  }

  else if(spel=='C'){
    return 2;
  }

  else if(spel=='G'){
    return 3;
  }

  else if(spel=='T'){
    return 4;
  }

  return 0;
}

int CalH(int judge){
  int res=0;

  res=judge%MOD;

  return res;
}

int CalAnoH(int judge){
  int res=0;

  res=(judge%(MOD-1))+1;

  return res;
}

int SearchWord(char spel[]){
  long long result,phase,judge;
  int equalch=0;
  int slength=0;
  int flag=0;
 
  judge=Convert(spel);

  phase=0;
  
  while(1){
    result=(CalH(judge)+CalAnoH(judge)*phase)%MOD;

    equalch=strcmp(Hash[result],spel);
    slength=strlen(Hash[result]);

    if(equalch==Gard){
      flag=1;
      break;
    }

    else if(slength==Gard){
      flag=0;
      break;
    }

    else{
      phase++;
    }
    
  }

  if(flag==1){
    return 1;
  }
  
  return 0;
}




Measured memory_bytes: 14380
h,w=map(int,input().split())
s=list()
for i in range(h):
    line=str(input())
    s.append(line)


result=list()
for i in range(h):
    line=list()
    for j in range(w):
        line.append(0)
    result.append(line)
def se(x,y):
    if x==0 and y==0:
        if s[0][0]=="#":
            result[x][y]=1
        else:
            result[x][y]=0
    elif x==0:
        if s[x][y-1]!=s[x][y]:
            result[x][y]=result[x][y-1]+1
        else:
            result[x][y]=result[x][y-1]
    elif y==0:
        if s[x-1][y]!=s[x][y]:
            result[x][y]=result[x-1][y]+1
        else:
            result[x][y]=result[x-1][y]
    else:
        if s[x][y-1]!=s[x][y]:
            a=result[x][y-1]+1
        else:
            a=result[x][y-1]
        if s[x-1][y]!=s[x][y]:
            b=result[x-1][y]+1
        else:
            b=result[x-1][y]
        result[x][y]=min(a,b)
        
for i in range(h):
    for j in range(w):
        se(i,j)
        
if s[h-1][w-1]=="#":
    result[h-1][w-1]+=1
else:
    pass


print(int(result[h-1][w-1]/2))

Measured memory_bytes: 3188
import copy
n = int(input())
s = input()
ans = 0
for i in range(n-2):
    RGB = ['R', 'G', 'B']
    RGB.remove(s[i])
    Rc = s[i+1:].count('R')
    Gc = s[i+1:].count('G')
    Bc = s[i+1:].count('B')
    # print(RGB, Rc, Gc, Bc)
    for j in range(i+1, n-1):
        RGBcopy = copy.copy(RGB)
        if not s[j] in RGB:
            if s[j] == 'R':
                Rc = max(0, Rc-1)
            elif s[j] == 'G':
                Gc = max(0, Gc-1)
            else:
                Bc = max(0, Bc-1)
            continue
        
        if s[j] == 'R':
            Rc = max(0, Rc-1)
            RGBcopy.remove('R')
            if RGBcopy[0] == 'G':
                cnt = Gc
                if 2*j-i <= n-1:
                    if s[2*j-i] == 'G':
                        cnt = max(0, cnt-1)
            else:
                cnt = Bc
                if 2*j-i <= n-1:
                    if s[2*j-i] == 'B':
                        cnt = max(0, cnt-1)

        elif s[j] == 'G':
            Gc = max(0, Gc-1)
            RGBcopy.remove('G')
            if RGBcopy[0] == 'R':
                cnt = Rc
                if 2*j-i <= n-1:
                    if s[2*j-i] == 'R':
                        cnt = max(0, cnt-1)
            else:
                cnt = Bc
                if 2*j-i <= n-1:
                    if s[2*j-i] == 'B':
                        cnt = max(0, cnt-1)

        else:
            Bc = max(0, Bc-1)
            RGBcopy.remove('B')
            if RGBcopy[0] == 'G':
                cnt = Gc
                if 2*j-i <= n-1:
                    if s[2*j-i] == 'G':
                        cnt = max(0, cnt-1)
            else:
                cnt = Rc
                if 2*j-i <= n-1:
                    if s[2*j-i] == 'R':
                        cnt = max(0, cnt-1)
        # print(i, j, cnt, Rc, Gc, Bc)
        ans += cnt
        # print(RGBcopy)

print(ans)


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

class binaryTree{
  enum tag{ROOT, INTERNALNODE, LEAF};
  class node{
  public:
    tag t;
    int left, right, parent, sib;
    int degree, depth, height;
    node(){
      left = right = parent = sib = -1;
      degree = depth = height = 0;
    }
    void printNode(int id){
      cout << "node " << id << ": parent = " << parent << ", sibling = " << sib;
      cout << ", degree = " << degree << ", depth = " << depth << ", height = " << height << ", ";
      if(t==ROOT) cout << "root" << endl;
      else if(t==INTERNALNODE) cout << "internal node" << endl;
      else cout << "leaf" << endl;
    }
  };
public:
  binaryTree(int n){
    nodes = new node[n];
    num = n;
  }
  void printNodes(){
    for(int i=0; i<num; i++){
      nodes[i].printNode(i);
    }
  }
  int findroot(){
    for(int i=0; i<num; i++){
      if(nodes[i].parent==-1) return i;
    }
  }
  void init(int i){
    initnode(&nodes[i]);
  }
  int num;
  node* nodes;
private:
  void initnode(node* n){
    int hl=0, hr=0;
    if(n->left != -1) {
      n->degree++;
      nodes[n->left].depth = n->depth+1;
      initnode(&nodes[n->left]);
      hl = nodes[n->left].height+1;
    }
    if(n->right != -1){
      n->degree++;
      nodes[n->right].depth = n->depth+1;
      initnode(&nodes[n->right]);
      hr = nodes[n->right].height+1;
    }
    n->height = max(hl, hr);
    if(n->parent == -1) n->t=ROOT;
    else if(n->left == -1 && n->right == -1) n->t=LEAF;
    else n->t=INTERNALNODE;
  }
};

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

  binaryTree bt(n);
  int id, left, right;
  for(int i=0; i<n; i++){
    cin >> id >> left >> right;
    bt.nodes[id].left = left;
    bt.nodes[id].right = right;
    bt.nodes[left].parent = id;
    bt.nodes[right].parent = id;
    bt.nodes[left].sib = right;
    bt.nodes[right].sib = left;
  }
  bt.init(bt.findroot());

  bt.printNodes();

  return 0;
}



Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
using namespace std;
 
int n,mini;
int A[36],B[36];
char a[36],b[36];
 
string check(){
  for(int i=0;i<n;i++){
    if(a[i]==b[i]&&A[i]==B[i])continue;
    return "Not stable";
  }
  return "Stable";
}
 
int main(){
  cin>>n;
 
  for(int i=0;i<n;i++){
    cin>>a[i]>>A[i];
    b[i]=a[i];
    B[i]=A[i];
  }
 
  for(int i=0;i<n-1;i++){
    for(int j=n-1;j>i;j--){
      if(A[j]<A[j-1]){
    swap(a[j],a[j-1]);
    swap(A[j],A[j-1]);
      }
    }
  }
 
  for(int i=0;i<n-1;i++){
    mini=i;
    for(int j=i+1;j<n;j++){
      if(B[j]<B[mini])mini=j;
    }
    swap(b[i],b[mini]);   
    swap(B[i],B[mini]);
  }
 
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<a[i]<<A[i];
  }
  cout<<endl<<"Stable"<<endl;
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<b[i]<<B[i];
  }
  cout<<endl<<check()<<endl;
  return 0;
}

Measured memory_bytes: 1204
def main():
    import sys
    input = sys.stdin.readline
    from math import factorial
    mod = 10**9 + 7
    N, K = map(int, input().split())
    ans = 0
    for i in range(K, N+2):
        ans += i * ((2 * N + 1) - i) // 2 - i * (i - 1) // 2 + 1 
        ans %= mod
    print(ans%mod)


if __name__ == '__main__':
    main()

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

using namespace std;

int main(int argc, char *argv[]) {
    string S;
    cin >> S;

    int ans = INT_MIN;
    for (int i = 0; i < S.size(); i++) {
        for (int len = 1; len <= S.size() - i; len++) {
            string s = S.substr(i, len);
            bool ok(true);
            for (int j = 0; j < s.size(); j++) {
                if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') {
                } else {
                    ok = false;
                }
            }
            if (ok) {
                if (ans < (int)s.size()) {
                    ans = (int)s.size();
                } 
            }
        }
    }
    cout << ((ans == INT_MIN) ? 0 : ans) << endl;
    return 0;
}


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

using namespace std;

int main() {
  int n, k, a[100] = {}, d, b, ans = 0;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> b;
      b--;
      a[b] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            int H = input[0];
            int W = input[1];
            string[] s = new string[H];
            for(var i=0;i<H;i++){
                s[i] = Console.ReadLine();
            }
            char[,] S = new char[H+2,W+2];
            for(var i=0;i<H+2;i++){
                for(var j=0;j<W+2;j++){
                    if(i==0||i==H+1){
                        S[i,j] = '.';
                    }else if(j==0||j==W+1){
                        S[i,j] = '.';
                    }else{
                        S[i,j] = s[i-1][j-1];
                    }
                }
            }
            for(var i=1;i<H+1;i++){
                for(var j=1;j<W+1;j++){
                    if(S[i,j]=='#'){
                        if(S[i-1,j]=='.' && S[i+1,j]=='.' && S[i,j-1] == '.' && S[i,j+1] == '.'){
                            Console.WriteLine("No");
                            return;
                        }
                    }
                }
            }
            Console.WriteLine("Yes");
            return;
        }
    } 
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll N;
    cin >> N;
    ll ans = 1;
    while(ans * 2 <= N) ans *= 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

n=I()
lis=LI()
p=lis[0]
for i in range(n-1):
    p=gcd(p,lis[i+1])
print(p)
    

    

Measured memory_bytes: 20268
# 二項係数を"やるだけ"にしてくれるライブラリ
from collections import Counter
MAX = 1000005
MOD = 998244353
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()

N, M, K = map(int, input().split())  # N個のブロック, M色のパターン, 隣合う組で色が同じなのはK組以下
# 同じ色の組が0~Kを考える
ans = 0
for i in range(K+1):
    # i: 消滅させるブロック
    ans += M * pow(M-1, N-1-i, MOD) * COM(N-1, i)
    ans %= MOD

print(ans%MOD)

Measured memory_bytes: 127888
#include <iostream>

using namespace std;

int abs(int n){
    if(n < 0){
        n = -1 * n;
    }
    return n;
}

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(abs(b - a) <= d && abs(c - b) <= d){
        cout << "Yes" << endl;
    }else if(abs(a - c) <= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a;
  a.push_back(0);
  rep(i,n){
    ll x; cin>>x;
    a.push_back(x);
  }
  a.push_back(0);
  ll sum=0;
  rep(i,n+1){
    sum+=abs(a[i+1]-a[i]);
  }
  
  reps(i,n){
    if(a[i-1]<=a[i+1]){
      if(a[i-1]<=a[i]&&a[i]<=a[i+1]){
        cout<<sum<<endl;
      }else{
        if(a[i]<a[i-1]){
          cout<<sum-abs(a[i-1]-a[i])*2<<endl;
        }else{
          cout<<sum-abs(a[i+1]-a[i])*2<<endl;
        }
      }
    }else{
      if(a[i+1]<=a[i]&&a[i]<=a[i-1]){
        cout<<sum<<endl;
      }else{
        if(a[i]<a[i+1]){
          cout<<sum-abs(a[i+1]-a[i])*2<<endl;
        }else{
          cout<<sum-abs(a[i-1]-a[i])*2<<endl;
        }
      }
    }
  }
  
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i,N){
        cin >> d[i];
    }
    int ans = 0;
    for(int i = 0;i < N; i++){
        for(int j = i+1;j < N;j++){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}


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



int main(){
    
    ll N,x[200020],sor[200020];
    cin>>N;
    rep(i,0,N){
        cin>>x[i];
        sor[i]=x[i];
    }
    sort(sor,sor+N);
    ll l,r;
    l=sor[N/2-1];
    r=sor[N/2];
    rep(i,0,N){
        if(x[i]<=l)cout<<r<<endl;
        else if(x[i]>=r)cout<<l<<endl;
    }
}






Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int main()
{

	FAST();
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ll n; cin>>n; ll arr[n]; REP(i,0,n) cin>>arr[i];

ll size2=n-1;
ll sum[size2];
sum[size2-1]=arr[n-1];
ll k=n-2;
for(int i=size2-2;i>=0;i--){
	sum[i]=(sum[i+1]%MOD+arr[k]%MOD)%MOD;
	k--;
}

for(auto i:sum)
	 cerr<<i<<" ";
  
ll finalsum=0;

/*REP(i,0,n){
	finalsum+=(arr[i]%MOD*(sum[i])%MOD)%MOD;
}
*/
REP(i,0,n-1){
	finalsum=((finalsum)%MOD+((arr[i]%MOD*sum[i]%MOD)%MOD)%MOD)%MOD;
}

//cerr<<"sum= "<<finalsum;
cout<<finalsum;
	return 0;
}

Measured memory_bytes: 6756
import java.awt.print.Printable;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

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


        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
        int c = Integer.parseInt(scan.next());

        if((a == b && b != c) || (a == c && a != b) || (b == c && a != b) ) {
            out.print("Yes");
        } else {
            out.print("No");
        }

        out.flush();
    }
}


Measured memory_bytes: 24020
from collections import namedtuple

Robot = namedtuple('Robot', ['end_pos', 'start_pos'])

class Solver:
    def __init__(self, n, robots):
        self.n = n
        self.robots = robots

    def order_by_endpos(self, robots):
        return map(lambda x:Robot(x[0], x[1]), sorted(map(lambda x:(x[0]+x[1], max(x[0]-x[1], 1)), robots)))

    def solve(self):
        current_pos = 0
        keep = 0
        for r in self.order_by_endpos(self.robots):
            if current_pos <= r.start_pos:
                keep += 1
                current_pos = r.end_pos
        return keep


if __name__ == "__main__":
    n = int(input())
    robots = []
    for _ in range(n):
        robots.append(tuple(map(int, input().split())))

    s = Solver(n, robots)
    print(s.solve())


Measured memory_bytes: 30808
import sys
from string import ascii_lowercase
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    S = [readstr() for _ in range(N)]
    cl = {x: 0 for x in ascii_lowercase}
    for i, s in enumerate(S):
        for x in ascii_lowercase:
            if not i:
                cl[x] = s.count(x)
            else:
                cl[x] = min(cl[x], s.count(x))
    print(''.join([k * v for k, v in sorted(cl.items(), key=lambda x: x[0])]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3768
#include <iostream>
#include <cstring>
#include <cstdio>
#include<algorithm>
#include <queue>
#include <cmath>
#include <limits>
#include <map>
#include <iomanip>
using namespace std;
#define ll long long int

int main(){
  ll n, k;
  cin >> n >> k;
  ll tmp = 0;
  n = n % k;
  tmp = k - n;
  cout << min(n,tmp) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using ld = double;
int n;
ld dp[305][305][305];

ld memo_rec(int One, int Two, int Three){
    if(dp[One][Two][Three] != -1)   return dp[One][Two][Three];
    if(One + Two + Three == 0)  return dp[One][Two][Three] = 0.0;
    
    ld res = 1.0;
    if(One > 0) res += memo_rec(One - 1, Two, Three) * One / n;
    if(Two > 0) res += memo_rec(One + 1, Two - 1, Three) * Two / n;
    if(Three > 0)   res += memo_rec(One, Two + 1, Three - 1) * Three / n;
    res *= (ld)n / (One + Two + Three);

    return dp[One][Two][Three] = res;
}

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

    cin >> n;
    vector<int> cnt(4, 0);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        ++cnt[a];
    }
    
    for(int i = 0; i <= 300; ++i){
        for(int j = 0; j <= 300; ++j){
            for(int k = 0; k <= 300; ++k){
                dp[i][j][k] = -1;
            }
        }
    }

    cout << fixed << setprecision(15);
    cout << memo_rec(cnt[1], cnt[2], cnt[3]) << endl;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

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

// べき剰余 (x^k) % n
int powMod(int x, int k, int m){
    if(k == 0) return 1;
    if(k % 2 == 0) return powMod(x*x % m, k/2, m);
    else return x*powMod(x, k-1, m) % m;
}

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

    int N, P;
    string S;

    cin >> N >> P;
    cin >> S;

    reverse(S.begin(),S.end());

    ll ans = 0;
    if(P == 2 || P == 5){
        REP(i,S.size()){
            if((S[i] - '0') % P == 0){
                ans += S.size() - i;
            }
        }
    }
    else{
        map<int,int> count;
        int prev_amari = 0;
        REP(i,S.size()){
            int temp = (prev_amari + ((S[i] - '0') * powMod(10,i,P)) % P) % P;
            count[temp]++;
            prev_amari = temp;
        }

        for(auto itr = count.begin(); itr != count.end(); itr++){
            ll temp = itr->second;
            if(itr->first == 0){
                ans += temp;
            }
            ans += temp*(temp-1)/2;
        }
    }

    cout << ans << "\n";

return 0;
}

Measured memory_bytes: 916
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
 
using namespace std;

int main(){
    string s, T, S;

    cin >> s >> T;

    bool flag = false;
    for(int i = 0; i < s.size()-T.size()+1; i++){

        string check = s.substr(i, T.size());
        bool f = false;
        for(int j = 0; j < check.size(); j++){
            if(check[j] != '?' && check[j] != T[j]){
                f = false;
                break;
            }else{
                f = true;
            }
        }

        if(f){
            S = s;
            int z = 0;
            for(int k = i; k < T.size()+i; k++){
                S[k] = T[z];
                z++;
            }
            flag = true;

        }

    }

    if(flag){
        for(int i = 0; i < S.size(); i++){
            if(S[i] == '?') S[i] = 'a';
        }
        cout << S << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }

    return 0;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, y, k;
string s, t;

// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n;
	cout<< 3*n*n;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3624
def main(argv)
  s = gets.chomp
  n = s.size

  if s == 'zyxwvutsrqponmlkjihgfedcba' then
    puts (-1).to_s
    return
  end

  if n < 26 then
    f = [false] * 26
    s.split('').each{ |c| f[c.ord - 'a'.ord] = true }
    ch = ('a'.ord + f.find_index(false)).chr
    puts (s + ch)
    return
  end

  t = []
  (n - 1).times do |i|
    j = (n - 1) - i
    t.push(s[j])
    if s[j - 1] < s[j] then
      t = t.sort.select{ |c| c > s[j - 1] }
      s = s[0...(j - 1)] + t[0]
      break
    end
  end
  puts s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N; 
  vector<int> a(N);
  
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  sort(a.begin(),a.end());
  
  cout << a.at(N-1) - a.at(0) << endl;
  

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i,m,n) for(int i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
int main() {
  lli A,B=1,C=0,D=0,E,F=INF;
  string S,T,K;
  cin >> S;
  A=S.size()-1;
  S=S.substr(0,A);
  rep(i,0,A){
    if((A-i)%2==1){
     S=S.substr(0,(A-i));
      continue;
    }
    T=S.substr(0,(A-i)/2);
    K=S.substr((A-i)/2,(A-i)/2);
    if(T==K){
      Out(A-i);
      break;
    }
    S=S.substr(0,(A-i));
  }
}

Measured memory_bytes: 256
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int, sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())


def FLIST(n):
    res = [1]
    for i in range(1, n+1):
        res.append(res[i-1]*i % DVSR)
    return res


X = II()
if X >= 30:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int k, x;
    cin >> k >> x;
    for(int i = x - k + 1; i <= x + k - 1; i++) cout << i << ' ';
    cout << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

int main(int argc, char const *argv[]) {

    std::string w;
    std::cin >> w;

    std::vector<int> showed_alphabet_map(26);
    for(const auto& word : w)
    {
        int alphabet_index = word - 'a';
        showed_alphabet_map[alphabet_index]++;
    }

    bool showd_odd_number = false;
    for(const auto& showed_times : showed_alphabet_map)
    {
        if(showed_times % 2 != 0)
        {
            showd_odd_number = true;
            break;
        }
    }

    std::cout << (showd_odd_number ? "No" : "Yes" ) << '\n';
    return 0;
}


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

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

const int INF = 1000000007;

int main(void){
	int n; cin>>n;
	vector<int> A, B, C;
	for(int i=0;i<3;i++) {
		for(int j=0;j<n;j++) {
			int elm; cin>>elm;
			if(i == 0) A.push_back(elm);
			else if(i == 1) B.push_back(elm);
			else if(i == 2) C.push_back(elm);
		}
	}

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	ll ans = 0, a_cnt = 0, b_cnt = 0, c_cnt = 0;
	for(int i=0;i<n;i++) {
		auto a_ite = lower_bound(A.begin(), A.end(), B[i]);
		auto c_ite = upper_bound(C.begin(), C.end(), B[i]);
		a_cnt = distance(A.begin(), a_ite);
		c_cnt = distance(c_ite, C.end());

		ans += a_cnt * c_cnt;		
	}

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

Measured memory_bytes: 1912
import sys

a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if v <= w:
  print('NO')
  sys.exit()

a_b_dist = abs(a-b)
v_w_dist = abs(v-w)

if v_w_dist * t < a_b_dist:
  print('NO')
  sys.exit()

print('YES')


Measured memory_bytes: 9180
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;
const int MOD = 1e9+7;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n;cin >> n;
    vector<int> b(n-1);rep(i,n-1)cin >> b[i];
    int ans = 0;
    ans += b[0];
    ans += b[n-2];
    for(int i=0;i<n-2;i++){
        ans += min(b[i],b[i+1]);
    }
    cout << ans << endl;
    return 0;
}

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

int gcd(long a, long b){
  long A,B;
  A = max(a,b); B = min(a,b);
  if(B==0){return A;}
  else{return gcd(B,A%B);}
}

int main(){
  int N; cin >> N;
  int A[N]; for(int i=0; i<N; i++){cin >> A[i];}
  
  long buf = A[0];
  for(int i=1; i<N; i++){
    buf = gcd(buf,A[i]);
    //cout << buf << endl;
  }
  
  cout << buf;
  
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n;


bool is_prime(int x){
  if(x<2) return false;
  for(int i=2;i*i<=x;i++){
    if(x%i==0) return false;
  }
  return true;
}

main(){
  cin>>n;


  /*  
  FOR(i,1,n){
    if(n/i==n%i){
      cout<<i<<endl;
    }
  }
  */
  
  int ans=0;
 
  

  for(int i=1;i*i<n;i++){
    if(n%i==0){
      if(i*(i+1)==n) continue;
//      cout<<' '<<n/i<<endl;
      ans+=n/i;
      ans--;
    }
  }

  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#define NUM 8
#define FREE -1
#define NOT 1

void recursive(int);
void print();
    
int chess[NUM][NUM];
int row[NUM];
int col[NUM];
int dpos[2*NUM-1];
int dneg[2*NUM-1];

int main(){
    int k,r,c,i,j;

    for(i=0;i<NUM;i++){
        row[i]=FREE;
        col[i]=FREE;
    }
    for(i=0;i<2*NUM-1;i++){
        dpos[i]=FREE;
        dneg[i]=FREE;
    }
    for(i=0;i<NUM;i++){
        for(j=0;j<NUM;j++){
            chess[i][j]=0;
        }
    }

    scanf("%d",&k);
    for(i=0;i<k;i++){
        scanf("%d%d",&r,&c);
        chess[r][c]=1;
    }



    for(i=0;i<8;i++){
        for(j=0;j<8;j++){

        }
    }

    recursive(0);
    return 0;
}

void recursive(int i){
    int j;
    if(i==NUM){
        print();
        return;
    }
    for(j=0;j<NUM;j++){
        if(NOT==col[j] || NOT==dpos[i+j] || NOT==dneg[i-j+NUM-1]) continue;
        row[i]=j;//Q配置
        col[j]=dpos[i+j]=dneg[i-j+NUM-1]=NOT; //Q配置
        recursive(i+1);
        row[i] = col[j] = dpos[i + j] = dneg[i - j + NUM - 1] =FREE;
    }
}

void print(){
    int i,j;
    for(i=0;i<NUM;i++){
        for(j=0;j<NUM;j++){
            if(chess[i][j]==1){
                if(row[i]!=j)return;
            }
        }
    }
    for(i=0;i<NUM;i++){
        for(j=0;j<NUM;j++){
            if(row[i]==j) printf("Q");
            else printf(".");
        }
        printf("\n");
    }
}



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

int main() {
	int n;
	string s;
	cin >> n >> s;
	int x = 0, m = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == ')') {
			x++;
			m = max(m, x);
		} else {
			x--;
		}
	}
	int a = m, b = m - x;
	for (int i = 0; i < a; i++) cout << '(';
	cout << s;
	for (int i = 0; i < b; i++) cout << ')';
	cout << endl;
	return 0;
}

Measured memory_bytes: 3132
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        Integer[] A = new Integer[N];
        Integer[] B = new Integer[N];
        Integer[] C = new Integer[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        for (int i = 0; i < N; i++) {
            B[i] = scan.nextInt();
        }
        for (int i = 0; i < N; i++) {
            C[i] = scan.nextInt();
        }
        Arrays.sort(A);
        Arrays.sort(B);
        Arrays.sort(C);
        long answer = 0;
        int s = 0;
        int t = 0;
        for (int i = 0; i < N; i++) {
            while(s<N&&A[s]<B[i]) {
                s += 1;
            }
            while(t<N&&C[t]<=B[i]){
                t += 1;
            }
            answer += (long) (s)*(N-t);
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 101084
#include <stdio.h>

int main(void){
  int a, b, c;
  int i, ans = 0;
  
  scanf("%d %d %d",&a, &b, &c);
  
  for(i=a;i<=b;i++){
    if(c % i == 0){
      ans += 1;
    }
  }
  
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int a, b; cin >> a >> b;
	
	if(a > 8 or b > 8) cout << ":(" << endl;
	else cout << "Yay!" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n);
	std::string s; cin >> s;
	
	int A = 0;
	for(int i = 0; i < s.size(); i++) A += (s[i] == '.');
	
	int ans = A, B = 0;
	for(int i = 0; i < s.size(); i++) {
		A -= (s[i] == '.');
		B += (s[i] == '#');
		ans = std::min(ans, A + B);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
from scipy.sparse.csgraph import dijkstra
import numpy as np 

def main():
    H,W = map(int,input().split())
    graph = []
    for i in range(10):
        graph.append(list(map(int,input().split())))
    c = []
    for j in range(H):
        c.append(list(map(int,input().split())))

    dist = np.array(dijkstra(graph),dtype="int32")
    ans = 0
    for i in range(H):
        for j in c[i]:
            if j != -1:
                ans += dist[j][1] 
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 18924
N,M = map(int,input().split())
AC_flag = [False]*N
WA_count = [0]*N
for m in range(M):
    P,S = map(str,input().split())
    p = int(P)
    if AC_flag[p-1] == False and S == "AC":
        AC_flag[p-1] = True
    elif AC_flag[p-1] == False and S == "WA":
        WA_count[p-1] += 1

AC = 0
WA = 0
for n in range(N):
  if AC_flag[n] == True:
    AC += 1
    WA += WA_count[n]
#print(AC_flag,WA_count)
print(*[AC,WA])


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

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int k;
	cin >> k;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != s[k-1]) s[i] = '*';
	}
	cout << s << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;
int dp[1010][10010] = {};

/*----------------------------------------------------------------*/
signed main(){

    int h,n;
    cin >> h >> n;
    vll a(n);
    vll b(n);
    rep(i,n)cin >> a[i] >> b[i];

    rep(i,n+1)rep(j,h+1)dp[i][j] = INF;
    dp[0][0] = 0;

    for(int i = 1;i <= n;i++){
        int A = a[i-1];
        int B = b[i-1];
        for(int j = 0;j <= h;j++){
            if(j-A >= 0)dp[i][j] = min(dp[i-1][j],dp[i][j-A]+B);
            else dp[i][j] = dp[i-1][j];
        }
        for(int j = 0;j <= h;j++){
            int z = h-j;
            dp[i][h] = min(dp[i][h],dp[i-1][j] + B*((z+A-1)/A));
        }
    }

    cout << dp[n][h] << endl;

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc153.contest.atcoder.jp/tasks/abc153_b

Measured memory_bytes: 78592
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int fa[N];
int dis[N];
int n,m,x,y,d;
void init()
{
    for(int i=1;i<=n;i++)
        fa[i]=i,dis[i]=0;
}
int find(int x)
{
    if(fa[x]==x)return x;
    int k=fa[x];
    fa[x]=find(fa[x]);
    dis[x]+=dis[k];
    return fa[x];
}
void merge(int x,int y)
{
	int xx=find(x),yy=find(y);
    fa[yy]=xx;
    dis[yy]=dis[x]+d-dis[y];
}
int main()
{
    cin>>n>>m;
    init();
    while(m--)
    {
        cin>>x>>y>>d;
        if(find(x)!=find(y))
        {
            merge(x,y);
        }
        else{
            if(dis[y]-dis[x]!=d)
        	{
        		puts("No");
        		return 0;
        	}
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;
const ll INF=1LL<<60;

struct edge{int to;ll cap;int rev;};

vector<edge> G[MAX];
int level[MAX];
int iter[MAX];

void add_edge(int from,int to,ll cap){
    G[from].push_back((edge){to,cap,int(G[to].size())});
    G[to].push_back((edge){from,0LL,int(G[from].size())-1});
}

void BFS(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s] =0;
    que.push(s);
    while(!que.empty()){
        int v=que.front();que.pop();
        for(int i=0;i<G[v].size();i++){
            edge &e =G[v][i];
            if(e.cap>0&&level[e.to]<0){
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}

ll DFS(int v,int t,ll f){
    if(v==t) return f;
    for(int &i=iter[v];i<G[v].size();i++){
        edge &e =G[v][i];
        if(e.cap>0&&level[v]<level[e.to]){
            ll 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;
}

ll max_flow(int s,int t){
    ll flow=0;
    for(;;){
        BFS(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        ll f;
        while((f=DFS(s,t,INF))>0){
            flow+=f;
        }
    }
}

int main(){
    
    int N;cin>>N;
    ll ans=0;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]>=0){
            ans+=A[i];
            add_edge(0,i+1,A[i]);
            add_edge(i+1,200,0LL);
        }else{
            add_edge(0,i+1,0LL);
            add_edge(i+1,200,-A[i]);
        }
    }
    
    for(int i=1;i<=N;i++){
        for(int j=2*i;j<=N;j+=i){
            add_edge(j,i,INF);
        }
    }
    
    cout<<ans-max_flow(0,200)<<endl;
    
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ins insert
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)

#define pi 3.1415926535897932384626433832
const int pinf=LLONG_MAX;
const int ninf=LLONG_MIN;
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("../in.txt","w",stdout);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int a,b;
    cin>>a>>b;

    if(a>=13) cout<< b;
    else if(a>=6 and a<=12) cout<< b/2;
    else cout<< "0";


    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100000
int n,Q;
int u,v,ans;
int cnt[MAXN+5],red[MAXN+5];
int main()
{
	scanf("%d%d",&n,&Q);
	red[1]=1;
	while(Q--)
	{
		scanf("%d%d",&u,&v);
		if(red[u])
		{
			if(!cnt[u])red[u]=0;
			red[v]=1;
		}
		cnt[u]--,cnt[v]++;
	}
	for(int i=1;i<=n;i++)if(red[i])ans++;
	printf("%d",ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lson root<<1,l,midd
#define rson root<<1|1,midd+1,r
const int M=2e5+5;
const int inf=0x3f3f3f3f;
struct Segtree{
    ll tr[M<<2],lz[M<<2];
    void build(int root,int l,int r){
        tr[root]=0,lz[root]=0;
        if(l==r)
            return ;
        int midd=(l+r)>>1;
        build(lson);
        build(rson);
    }
    void pushdown(int root){
        ll c=lz[root];
        tr[root<<1]+=c,tr[root<<1|1]+=c;
        lz[root<<1]+=c,lz[root<<1|1]+=c;
        lz[root]=0;
    }
    void update(int L,int R,ll val,int root,int l,int r){
        if(L<=l&&r<=R){
            tr[root]+=val;
            lz[root]+=val;
            return ;
        }
        if(lz[root])
            pushdown(root);
        int midd=(l+r)>>1;
        if(L<=midd)
            update(L,R,val,lson);
        if(R>midd)
            update(L,R,val,rson);
        tr[root]=min(tr[root<<1],tr[root<<1|1]);
    }
    ll query(int L,int R,int root,int l,int r){
        if(L<=l&&r<=R){
            return tr[root];
        }
        if(lz[root])
            pushdown(root);
        ll res=1e18;
        int midd=(l+r)>>1;
        if(L<=midd)
            res=min(res,query(L,R,lson));
        if(R>midd)
            res=min(res,query(L,R,rson));
        tr[root]=min(tr[root<<1],tr[root<<1|1]);
        return res;
    }
}x,y;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    x.build(1,1,m),y.build(1,1,m);
    for(int i=1;i<=m;i++)
        y.update(i,i,-i,1,1,m);
    for(int i=1;i<=n;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        ///b+1
        x.update(b+1,b+1,min(1ll*(b+1+y.query(1,b,1,1,m))-x.query(b+1,b+1,1,1,m),0ll),1,1,m);
        y.update(b+1,b+1,min(y.query(1,b,1,1,m)-y.query(b+1,b+1,1,1,m),0ll),1,1,m);
        ///a~b
        x.update(a,b,1e9,1,1,m);
        y.update(a,b,1e9,1,1,m);
        ///向下
        x.update(1,m,1,1,1,m);
        y.update(1,m,1,1,1,m);
        ll ans=x.query(1,m,1,1,m);
        if(ans>=1e9)
            puts("-1");
        else
            printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 20168
# coding: utf-8
# Here your code !

H,W=map(int,raw_input().split())
c=0
for _ in xrange(H):
    s=raw_input()
    for i in xrange(W):
        if s[i]=="#": c+=1
if H+W-1==c: print "Possible"
else: print "Impossible"

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

int main() {

    int P, Q, R;

    cin >> P >> Q >> R;

    if (P <= Q && P <= R) {
        cout << P + min(Q, R) << endl;
    }
    else if (Q <= P && Q <= R) {
        cout << Q + min(P, R) << endl;
    }
    else if (R <= Q && R <= P) {
        cout << R + min(Q, P) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <numeric>


using lolo=long long;
using namespace std;
using vec=vector<lolo>;
using vvec=vector<vec>;
using vecb=vector<bool>;
#define FOR(i,n) for (lolo i=0; i<n; ++i)
#define FORN(i,a,b) for (lolo i=a; i<b; ++i)
#define REV(i,a,b) for (lolo i=a; i>b; --i)
#define ALL(x) x.begin(), x.end()

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

	vec A(N), B(N);
	FOR(i, N) {
		cin >> A[i] >> B[i];
	}

	lolo ans = 0;
	REV(i, N - 1, -1) {

		auto a = A[i];
		auto b = B[i];
		a = (a + ans);
		
		if (a % b == 0) continue;
		ans += b - (a % b);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	int n, m;
	cin >> n >> m;
	int ans = 0;
	if (n >= 2) ans += n * (n - 1) / 2;
	if (m >= 2) ans += m * (m - 1) / 2;
	cout << ans << endl;
}

Measured memory_bytes: 256