akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int V,E;
int G[501][501]; // ??°???????????£??\???????????¨???
vector<int> used; // DFS??§?????§???????????????????????°

// from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from, int to, int cap) {
    G[from][to] = G[to][from] = cap;
}

// ?¢?????????????DFS??§??¢???
int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < V; i++) {
        auto &cap = G[v][i];
        if (!used[i] && cap > 0) {
            int d = dfs(i, t, min(f, cap));
            if (d > 0) {
                cap -= d;
                G[i][v] += d;
                return d;
            }
        }
    }
    return 0;
}

// s??????t???????????§???????±???????
int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        fill(used.begin(), used.end(), 0);
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}

/* one_path check*/
bool check(int v, int t) {
	if (v == t)return true;
	used[v] = true;
	for (int i = 0; i < V;i++) {
		auto& cap = G[v][i];
		if (!used[i] && cap > 0) {
			if (check(i, t)) {
				cap--;
				G[i][v]++;
				return true;
			}
		}
	}
	return false;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> V >> E;
    int Q; cin >> Q;
    for(int i = 0; i < 501;i++){
        for(int j = 0;j < 501;j++){
            G[i][j] = 0;
        }
    }
    used.resize(V);
    for (int i = 0; i < E;i++) {
        int s, t; cin >> s >> t;
        s--;t--;
        add_edge(s, t, 1);
    }
    
    int f = max_flow(0, V - 1);
    for(int i = 0; i < Q;i++){
        int M,A,B; cin >> M >> A >> B;
        A--;B--;
        if(M == 1){
            G[A][B] = G[B][A] = 1;
            fill(used.begin(),used.end(),0);
            f += dfs(0,V-1,INF);
        }else{
            if(G[A][B] == 0 || G[B][A] == 0){
                int u,v;
                if(G[A][B] == 0){ u = A; v = B;}
                else{u = B; v = A;}
				fill(used.begin(), used.end(), 0);
                if(!check(u,v)){
                    fill(used.begin(),used.end(),0);
					check(u, 0);
                    fill(used.begin(),used.end(),0);
					check(V - 1, v);
                    f--;
                }
            }
            G[A][B] = G[B][A] = 0;
        }
		cout << f << endl;
	}
    return 0;
}

Measured memory_bytes: 4204
import sys
readline = sys.stdin.buffer.readline
数字 = int(readline())
文字 = readline().rstrip().decode('utf-8')

答え = 0
答えの最大値 = 0

for 文字の1要素 in 文字:
    if 文字の1要素 == "I":
        答え += 1
        答えの最大値 = max(答えの最大値,答え)
    else:
        答え -= 1

print(答えの最大値)

Measured memory_bytes: 38896
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f
#define iinf 0x3f3f3f3f3f3f3f3f
#define lowbit(xxx) (xxx&(-xxx))
#define next liuyifan_next
using namespace std;
struct node
{
    ll to,next;
}w[1000005];
ll n,a[1000005],h[1000005],cnt,f[1000005],ans;
inline void add(reg ll x,reg ll y)
{
    w[++cnt].next=h[x];
    w[cnt].to=y;
    h[x]=cnt;
}
inline void dfs(ll u,ll fa)
{
    f[u]=a[u];
    for(reg int i=h[u];i;i=w[i].next)
    {
        reg int v=w[i].to;
        if(v!=fa)
        {
            dfs(v,u);
            f[u]+=max(0ll,f[v]);
        }
    }
    ans=max(ans,f[u]);
}
int main()
{
    scanf("%lld",&n);//n个节点
    cout<<n*n*n;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#include<algorithm>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
#define pb push_back
#define mp make_pair
#define mh make_heap
#define F first
#define S second
//#define fin cin
//#define fout cout
#define file ifstream fin("input.txt");ofstream fout("output.txt");
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long int ll;
typedef pair<ll,ll> pairs;
typedef vector<ll> vi;
typedef vector<pairs> vpair;

void solve()
{
    string s,t;
    cin>>s>>t;
    ll cnt=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]==t[i])
            cnt++;
    }
    cout<<cnt<<endl;
    return ;

}
int main()
{
    ll t=1;
    //cin>>t;
    fr(t)
    {
        solve();
    }
    return 0;
}


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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n;
    cin>>n;
    ll sum=0;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum += a[i];
    }
    ll now = 0;
    ll ans = 1e15;
    for(int i=0;i<n;i++){
        now += a[i];
        if(sum %2 == 0 && now == sum/2){
            cout << 0 << endl;
            return 0;
        }
        if(now > sum-now){
            ans = min(ans,2*now-sum);
        }
    }
    now = 0;
    for(int i=n-1;i>=0;i--){
        now += a[i];
        if(now > sum-now){
            ans = min(ans,2*now-sum);
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define inf 1000000007
using namespace std;
int cost[310][310],dp[310][310];
signed main(){
	int h,w;
	cin>>h>>w;
	vector<string> f;
	for(int i=0;i<h;i++){
		string st;
		cin>>st;
		f.pb(st);
	}
	ll ans = 0;
	for(int k=0;k<w-1;k++){
		for(int i=0;i<=h;i++){
			cost[h][i]=0;
			cost[i][h]=0;
		}
		for(int i=h-1;i>=0;i--){
			for(int j=h-1;j>=0;j--){
				cost[i][j] = cost[i+1][j+1];
				if( f[h-i-1][k] == f[h-j-1][k+1])cost[i][j]++;
			}
		}
		dp[0][0]=0;
		for(int i=1;i<=h;i++){
			dp[i][0] = dp[i-1][0]+cost[i-1][0];
			dp[0][i] = dp[0][i-1]+cost[0][i-1];
		}
		for(int i=1;i<=h;i++){
			for(int j=1;j<=h;j++){
				dp[i][j] = min(dp[i-1][j]+cost[i-1][j],dp[i][j-1]+cost[i][j-1]);
			}
		}
		ans += dp[h][h];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc153_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputMonsterHpAndRaccoonAttackCount = Console.ReadLine().Split(' ');
            var monsterHp = int.Parse(inputMonsterHpAndRaccoonAttackCount[0]);

            var inputdamages = Console.ReadLine().Split(' ');
            var attackDamages = Array.ConvertAll(inputdamages, int.Parse);

            Console.WriteLine(ObtainBattleResult(monsterHp, attackDamages));
            Console.Read();
        }

        private static string ObtainBattleResult(int monsterHp, int[] attackDamages)
        {
            attackDamages.OrderBy(a => -a);

            foreach (var damage in attackDamages)
            {
                monsterHp -= damage;

                if (monsterHp <= 0)
                {
                    return "Yes";
                }
            }

            return "No";
        }
    }
}


Measured memory_bytes: 35776
import string
def cipher(s, i):
    if s in string.ascii_lowercase:
        return string.ascii_lowercase[(ord(s) - ord('a')+ i) % 26]
    elif s in string.ascii_uppercase:
        return string.ascii_uppercase[(ord(s) - ord('A')+ i) % 26]
    else:
        return s

def decode(s, i):
    return ''.join([cipher(x, i) for x in s])

while True:
    try:
        sent = input().split()
    except:
        break

    for i in range(26):
        si = [decode(s, i) for s in sent]
        if 'the' in si or 'this' in si or 'that' in si:
            print(' '.join(si))

Measured memory_bytes: 6724
#include<stdio.h>
#include<string.h>
int main(void)
{
    int n,i,a[100],w,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	    scanf("%d",&a[i]);
	}
	for(i=0;i<n-1;i++){
	    for(j=i+1;j<n;j++){
		    if(a[i]>a[j]){
			    w=a[i];
				a[i]=a[j];
				a[j]=w;
			}
		}
	}
	w=a[n-1]-a[0];
	printf("%d\n",w);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt();
    if(a+b>=c){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 21844
//used C i/o for faster peformance

#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

int x,y,z,n,m,road[200005],rail[200005],connect[200005];
pair<pair<int,int>,int> total[200005];

int root (int ind) {
	if (road[ind] == ind) return ind; else 
	return road[ind] = root(road[ind]);
}

void onion(int l, int r) {
	if (root(l) != root(r)) road[root(l)] = root(r);
}

int root2(int ind) {
	if (rail[ind] == ind) return ind; else 
	return rail[ind] = root2(rail[ind]);
}

void onion2(int l, int r) {
	if (root2(l) != root2(r)) rail[root2(l)] = root2(r);
}

int main() {
	scanf("%d%d%d",&x,&y,&z);
	for (int i = 0; i <= x; i++) {
		rail[i] = i;
		road[i] = i;
	}
	for (int i = 0; i < y; i++) {
		scanf("%d%d",&n,&m);
		onion(n,m);
	}
	for (int i = 0; i < z; i++) {
		scanf("%d%d",&n,&m);
		onion2(n,m);
	}
	for (int i = 1; i <= x; i++) {
		total[i] = make_pair(make_pair(root(i),root2(i)),i);
	}
	sort(total+1,total+1+x);
	total[x+1].f.f = total[x+1].f.s = -31415;
	stack<int> st; while (!st.empty()) st.pop();
	int a1 = 0,a2 = 0,b1 = 0,b2 = 0;
	for (int i = 1; i <= x+1; i++) {
		a1 = total[i].f.f, a2 = total[i].f.s;
		if (!(st.empty() || (a1 == b1 && a2 == b2))) {
			int tmp = st.size();
			while (!st.empty()) {
				connect[st.top()] += tmp-1;
				st.pop(); 
			}
		} 
		b1 = a1, b2 = a2;
		st.push(total[i].second);
	}
	for (int i = 1; i <= x; i++) {
		printf("%d ",connect[i]+1);
	}
}

Measured memory_bytes: 8392
#include<iostream>
#include<vector>
#include<cmath>
#include<stdio.h>
#include<string>
#include <algorithm>
using namespace std;

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

	cout << max({a*c, a*d, b*c, b*d}) << endl;
	

	return 0;
}


Measured memory_bytes: 3624
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, Q, Score[int(2e5 + 5)];
bool visited[int(2e5 + 5)];
vector <int> Graph[int(2e5 + 5)];

int main(){
  scanf("%d%d", &N, &Q);
  for (int i = 0; i < N - 1; i++){
    int A, B; scanf("%d%d", &A, &B);
    Graph[A].push_back(B);
    Graph[B].push_back(A);
  }
  for (int i = 0; i < Q; i++){
    int P, X; scanf("%d%d", &P, &X);
    Score[P] += X;
  }
  
  queue <int> que;
  que.push(1); visited[1] = true;

  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < Graph[Q].size(); i++){
      int next = Graph[Q][i];
      if (visited[next]) continue;
      visited[next] = true;
      Score[next] += Score[Q];
      que.push(next);
    }
  }
  
  for (int i = 1; i <= N; i++){
    printf("%d", Score[i]);
    if (i == N) printf("\n");
    else printf(" ");
  }
  
  return 0;
}


Measured memory_bytes: 15732
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string s;
    cin >> s;
    string tmp_s;
    rep(i, s.length()) {
        tmp_s += s[i];
        if ( tmp_s + "FESTIVAL" == s ) break; 
    }
    cout << tmp_s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> p;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template <class T> bool chmax(T &a, const T &b) {
  if(a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if(b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

  if(a * b % 2 == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

signed main(void)
{
	int n;
	long long cnt;
	cin >> n;
	pair<long long, long long> x[n];

	cnt = 0;
	rep(i, n) cin >> x[i].first >> x[i].second;
	for(int i = n - 1; i >= 0; i--)
	{
		x[i].first += cnt;
		if (x[i].first % x[i].second != 0)
			cnt += x[i].second * (x[i].first / x[i].second + 1) - x[i].first;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1792
n = int(input())

count = 1
c = 1

while c == 1:
    if n <= (26 ** count):
        c = 0
    else:
        n = n - 26 ** count
    count += 1

count -= 1
n -= 1

s = [0 for i in range(count)]


for i in range(count):
    s[i] = n % 26
    n = n // 26


result = ""
for i in range(count):
    result = chr(97 + s[i]) + result

print(result)

Measured memory_bytes: 9204
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int t,n,d;
int dp[128][128];

int main(void){
	for(int i=0;i<128;i++){
		for(int j=0;j<128;j++){
			dp[i][j]=i^j;
		}
	}
	scanf("%d",&t);
	for(int i=0;i<t;i++){
		scanf("%d%d",&n,&d);
		if(n%2==1)printf("%d\n",127*(n-1)+d);
		else printf("%d\n",127*n-d);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const double pi=acos(-1);
int main(){
  rep(k,MOD){
    int h,w;
    cin >> h >> w;
    if(h==0 && w==0) return 0;
    rep(i,h){
      rep(j,w){
        cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
  
  return 0;
}



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

int main()
{
    int N;
    cin >> N;
    vector<vector<long long>> first_last_num(10, vector<long long>(10, 0));
    rep(i, N)
    {
        string num = to_string(i + 1);
        int front_num = num.front() - '0';
        int back_num = num.back() - '0';
        first_last_num[front_num][back_num]++;
    }

    long long ans = 0;
    rep(front, 10) rep(back, 10)
    {
        //        cout << front << back << ":" << first_last_num[front][back] << endl;
        ans += first_last_num[front][back] * first_last_num[back][front];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    ll N, K, X, Y;
    cin >> N >> K >> X >> Y;
    if (N < K) {
        cout << X * N << endl;
    }
    else {
        cout << X * K + Y * (N - K) << endl;
    }
}

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

int main() {
  int N,x;
  cin>>N>>x;
  int a[N];
  for (int i=0; i<N; i++) {
    cin>>a[i];
  }
  sort(a,a+N);
  int result=0;
  for (int i=0; i<N; i++) {
    if (x>=a[i] && i<N-1) {
      x-=a[i];
      result++;
    }
    if (i==N-1 && x==a[i]) {
      x-=a[i];
      result++;
    }
  }
  cout<<result<<endl;
  return 0;
}


Measured memory_bytes: 256
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


MAX = 150

OUT = 0
IN = 1

class Info:
    def __init__(self,arg_weight,arg_TIME,arg_Type):
        self.weight = arg_weight
        self.TIME = arg_TIME
        self.Type = arg_Type

    def __lt__(self,another):
        if self.TIME != another.TIME:
            return self.TIME < another.TIME
        else:
            return self.Type < another.Type

while True:
    N = int(input())
    if N == 0:
        break

    Q = []

    for _ in range(N):
        weight,left,right = map(int,input().split())
        heappush(Q,Info(weight,left,IN))
        heappush(Q,Info(weight,right,OUT))

    tmp_sum = 0
    FLG = True

    while len(Q) > 0 and FLG == True:
        info = heappop(Q)
        if info.Type == IN:
            tmp_sum += info.weight
            if tmp_sum > MAX:
                print("NG")
                FLG = False
                break
        else:
            tmp_sum -= info.weight

    if FLG == True:
        print("OK")


Measured memory_bytes: 13892
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl a[n];
    cin(i,a);
    intl cnt = 0;
    bool f = true;
    while(true){
        rep(i,n)if(a[i]%2)f = false;
        if(!f)break;
        cnt++;
        rep(i,n)a[i] /= 2;
    }
    cout << cnt << endl;
    return 0;
}

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

public class Main {

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

		int N = sc.nextInt();
		int Q = sc.nextInt();
		String s = sc.next();

		int[] sum = new int[N + 1];
		Arrays.fill(sum, 0);
		for (int i = 0; i < N; i++) {
			if(i + 1 < N && s.charAt(i) == 'A' && s.charAt(i + 1) == 'C')
				sum[i + 1] = sum[i] + 1;
			else
				sum[i + 1] = sum[i];
		}

		for (int i = 0; i < Q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			int ans = sum[r - 1] - sum[l - 1];
			System.out.println(ans);
		}
	}

}


Measured memory_bytes: 65976
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;
  F f;//二項演算
  T ti;//単位元
  vector<T> dat;

  SegmentTree(){}
  SegmentTree(F f,T ti):f(f),ti(ti){}

  void init(int n_){//sizeがn_のsegtreeを作る
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }

  void build(const vector<T> &v){//vによってsegtreeをbuildする
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }

  void set_val(int k,T x){//k番目をxにする
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(int a,int b){//区間[a,b)に対しFを適応した値を返す
    if(a>=b) return ti;
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }

  template<typename C>
  int find(int st,C &check,T &acc,int k,int l,int r){//
    if(l+1==r){
      acc=f(acc,dat[k]);
      return check(acc)?k-n:-1;
    }
    int m=(l+r)>>1;
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
    if(st<=l&&!check(f(acc,dat[k]))){
      acc=f(acc,dat[k]);
      return -1;
    }
    int vl=find(st,check,acc,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(st,check,acc,(k<<1)|1,m,r);
  }

  template<typename C>
  int find(int st,C &check){
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }

  T &operator [] (int i) {return dat[i+n];};
};

int n,q;
vector<ll> a;

void solve(){
  cin >> n >> q;
  a.resize(n);
  rep(i,n) cin >> a[i];
  SegmentTree<ll> seg([](ll a,ll b){return a+b;},0);
  seg.build(a);
  rep(i,q){
    int t,u,v;cin >> t >> u >> v;
    if(t==0) seg.set_val(u,seg[u]+v);
    else cout << seg.query(u,v) << endl;
  }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 16456
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template<typename T>void read(T &x){
	x = 0;int f(1);char c = getchar();
	for(;!isdigit(c);c = getchar()) if(c == '-') f=-1;
	for(;isdigit(c);c = getchar()) x = x * 10 + c -'0';
	x *= f;
}
const ll p = 924844033;
int n,k;
ll inv[2005],jc[2005],invjc[2005];
ll dp[2005];
int line_size(int s){
	int tnum = (n-s) / (k<<1);
	int ret = tnum+1 <<1;
	if(s < k+1)	--ret;
	if(s+tnum*(k<<1)+k > n)	--ret;
	return ret;
}
ll c(int x,int y){return x > y?0:jc[y] * invjc[x] % p * invjc[y-x] % p;}
int main(){
	read(n);read(k);
	jc[0] = jc[1] = invjc[0] = invjc[1] = inv[1] = 1;
	for(int i(2);i<=n;++i){
		jc[i] = jc[i-1] * i % p;
		inv[i] = (p-p/i) * inv[p%i] % p;
		invjc[i] = invjc[i-1] * inv [i] % p;
	}
	dp[0] = 1;
	for(int s(1),asize(0);s<=min(n,k<<1);++s){
		int nsize = line_size(s); asize += ((n-s)/(k<<1)+1);
		for(int i = asize;i >= 0;--i)
			for(int j = i-1;j >= 0&&(i-j<=nsize-i+j+1);--j)
			dp[i] = (dp[i]+dp[j]*c(i-j,nsize-(i-j)+1))%p;
	}
	ll ans = 0;
	for(int i = 0,v = 1;i <= n;++i,v = -v)
		ans = (ans+v*dp[i]%p*jc[n-i]%p+p) %p;
	printf("%lld\n",ans);
	return 0;
}

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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (int i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)


int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n;
        cin>>n;
        ll a[n],mx=1000;
        loop(i,0,n-1)
        {
            cin>>a[i];
        }
        ll money=1000;
        loop(i,0,n-2)
        {
            ll stocks=0;
            if(a[i+1]>a[i]) stocks=money/a[i];
            money+=(a[i+1]-a[i])*stocks;
        }
        cout<<money;
        nl;
    }
    return 0;
}


Measured memory_bytes: 3572
from fractions import gcd
def lcm(a,b):
    return (a * b) // gcd(a, b)

A,B,C,D=map(int,input().split())

E=lcm(C,D)

num_C=B//C-(A-1)//C
num_D=B//D-(A-1)//D
num_CD=B//E-(A-1)//E

ans=(B-A+1)-(num_C+num_D-num_CD)
print(ans)

Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

ll h, w;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> h >> w;
	if (h % 3 == 0 || w % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll ret = min(h, w);
	bool odd = false;
	if (w & 1) odd = true;
	for (int i = 1; i < h; i++) {
		ll s1 = w * i, s2 = (h-i)*(w/2), s3 = s2;
		if (odd) s3 += h-i;
		ll ma = max(s1, s3), mi = min(s1, s2);
		ret = min(ret, ma-mi);
	}
	odd = false;
	if (h & 1) odd = true;
	for (int i = 1; i < w; i++) {
		ll s1 = h * i, s2 = (w-i)*(h/2), s3 = s2;
		if (odd) s3 += w-i;
		ll ma = max(s1, s3), mi = min(s1, s2);
		ret = min(ret, ma-mi);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

int eval(vector<int> &X, int P) {
	int ans = 0;
	for(int n=0;n<X.size();n++) {
		ans+=(X[n]-P)*(X[n]-P);
	}
	return ans;
}


int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	vector<int> X(N);
	FOR(n,N) {
		cin >> X[n];
	}
	sort(X.begin(), X.end());
	int left = X[0];
	int right = X[N-1];
	int lval=INT_MAX;
	int rval=INT_MAX;
	while(left<=right) {
		lval = eval(X,left);
		rval = eval(X,right);
		if(lval>rval) {
			left++;
		}
		else if(lval<rval) {
			right--;
		}
		else {
			left++;
			right--;
		}
	}
	
	cout << min(lval,rval) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b,c,d;
  string ans;
  cin >> n;
  
  a = n/1000;
  b = n%1000/100;
  c = n%100/10;
  d = n%10;
  
  if (a==b && b==c) {
    ans = "Yes";
  }
  else if (b==c && c==d) {
    ans = "Yes";
  }
  else {
    ans = "No";
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll int n,z,sum=0;
    cin>>n;
    for(ll int i=1;i<=n;i++)
    {
        for(ll int j=1;j<=n;j++)
        {
            z=__gcd(i,j);
            for(ll int k=1;k<=n;k++)
            {
                sum+=__gcd(z,k);
            }
        }
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3664
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))
table=[[0 for _ in range(W)] for _ in range(H)]
changeflag=0
#print(table)
i=0
back=0
zagflag=0
if H%2==0:
   j=0
   back=0
   zagflag=0
else:
    j=W-1
    back=1
    zagflag=1
allcnt=0
colorid=1
cnt=0
while (j!=0)or(i!=H-1):
    #print(i,j,back)
    if cnt==a[colorid-1]:
        colorid=colorid+1
        cnt=0
    table[i][j]=colorid
    cnt=cnt+1
    allcnt=allcnt+1
    if (((zagflag%2==1)and(j==0))or((zagflag%2==0)and(j==W-1)))and(allcnt!=0):
        i=i+1
        back=(back+1)%2
        zagflag=zagflag+1
    else:
        if back==0:
            j=j+1
        else:
            j=j-1
    #print(table,colorid,cnt)
    #input()
table[H-1][0]=N
for i in range(H):
    print(*table[i],sep=" ")



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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int r,c,k;
    cin>>r>>c>>k;
    vector<vector<int>> f(r,vector<int>(c));
    vector<vector<vector<ll>>> dp(r+1,vector<vector<ll>>(c+1,vector<ll>(4)));
    for(int i=0;i<k;++i){
        int r1,c1,v1;
        cin>>r1>>c1>>v1;
        r1--;c1--;
        f[r1][c1] = v1;
    }
    for(int i=0;i<r;++i)for(int j=0;j<c;++j){
        for(int rv=2;rv>=0;rv--){
            dp[i][j][rv+1] = max(dp[i][j][rv+1],dp[i][j][rv] + f[i][j]);
        }
        for(int rv=0;rv<4;++rv){
        if(i+1 < r){
            dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][rv]);
        }
        if(j+1 < c){
            dp[i][j+1][rv] =  max(dp[i][j+1][rv],dp[i][j][rv]);
        }
    }
    }
    ll ma = 0;
    for(int i=0;i<4;++i){
        ma = max(ma,dp[r-1][c-1][i]);
    }
    cout << ma << endl;
    return 0;
    
}

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

char a[55][55];
int main(){
	ios::sync_with_stdio(false);
	int x,y,k=0;
	cin>>x>>y;
	for(int i=1;i<=x;++i)
		for(int j=1;j<=y;++j)
			cin>>a[i][j];
	for(int i=1;i<=x;++i)
		for(int j=1;j<=y;++j)
			if(a[i][j]=='#'&&a[i][j+1]!='#'&&a[i][j-1]!='#'
			&&a[i+1][j]!='#'&&a[i-1][j]!='#')++k;
	if(k==0)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    String INPUT = "";

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    void run() {
        Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
        PrintWriter out = new PrintWriter(System.out);

        solve(sc, out);
        out.flush();
    }

    void solve(Scanner sc, PrintWriter out) {
        int n, m, l;
        
        n = sc.nextInt();
        m = sc.nextInt();
        l = sc.nextInt();
        long A[][] = new long[n][m];
        long B[][] = new long[m][l];
        long C[][] = new long[n][l];
        for (int i = 0; i < n; i++) {
        	for (int j = 0; j < m; j++) {
        	    A[i][j] = sc.nextLong();
            }
		}
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < l; j++) {
                B[i][j] = sc.nextLong();
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < l; j++){
                for(int k = 0; k < m; k++){
                    C[i][j] += A[i][k]*B[k][j];
                }
            
                if(j != 0 ){
                    System.out.print(" ");
                }
                System.out.print(C[i][j]);
            }
            System.out.println();
        }
    }
}



Measured memory_bytes: 52520
a,b,c = gets.split.map(&:to_i)
k = gets.to_i

ans = 'No'
(0..k).each do |i|
    if a < b * (2 ** i) && b * (2 ** i) < c * (2 ** (k - i))
        ans =  'Yes'
        break
    end
end

puts ans

Measured memory_bytes: 14392
#include<stdio.h>

#define N 1000000

int cnt=0;

void insertionSort(int *A, int n,int g){
  int i,j,v;

  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0&&A[j]>v){
      A[j+g] = A[j];
      j=j-g;
      cnt++;
    }
    A[j+g]=v;
  }
}

void shellSort(int *A,int n){
  int i,m,cm;
  cnt = 0;
  cm=0;
  m=5;
  int G[5]={1000,100,10,4,1};

  for(i=0;i<m;i++){
    insertionSort(A,n,G[i]);
    if(G[i]<=n) cm++;
  }
  printf("%d\n",cm);

  for(i=0;i<m-1;i++){
    if(G[i]<=n) printf("%d ",G[i]);
  }

  printf("%d\n",G[i]);
  printf("%d\n",cnt);
  for(i=0;i<n;i++) printf("%d\n",A[i]);
}

int main(){
  int n,i,A[1000000];

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&A[i]);

  shellSort(A,n);
  return 0;
}

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


int main(void){
  int N,M,C;
  cin >> N >> M >> C;
  vector<int> B;
  vector<vector<int>> A;

  B.resize(M);
  for(int i=0;i<M;i++){
    cin>>B[i];
  }

  A.resize(N);
  for(int i=0;i<N;i++){
    A[i].resize(M);
    for(int j=0;j<M;j++){
      cin>>A[i][j];
    }
  }

  int answer=0;
  for(auto index : A){
    int valueLeft=C;
    for(int j=0;j<M;j++){
      valueLeft+=index[j]*B[j];
    }
    if(valueLeft>0){
      answer++;
    }
  }

  cout<<answer<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

int dp[110000];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	for (int i = 0; i < 110000; i++)dp[i] = n;
	dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int pow6 = 1; pow6 <= i; pow6 *= 6) {
			dp[i] = min(dp[i], dp[i - pow6] + 1);
		}
		for (int pow9 = 1; pow9 <= i; pow9 *= 9) {
			dp[i] = min(dp[i], dp[i - pow9] + 1);
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <set>

using namespace std;

int main()
{
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int m;
  if(k <= a){
    m = k;
  }else if(k <= a+b){
    m =a;
  }else if(k <= a+b+c){
    m = a - (k-a-b);
  }
  cout << m << endl;
  
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N, X;
    cin >> N >> X;
    int ans = 1;
    vector<int> v(N);
    rep(i, N) cin >> v[i];
    int tmp = 0;
    rep(i, N) {
        if(v[i] + tmp <= X) {
            ans++;
        }
        tmp += v[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int r;

  std::cin >> r;

  std::cout << 3 * r * r << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int v[105],w[105];
long long dp[100005];

int main()
{
	int n,W;
	cin>>n>>W;
//	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
		cin>>w[i]>>v[i];
	for(int i=1;i<=n;i++)
		for(int j=W;j>=w[i];j--)
			dp[j]=max(dp[j-w[i]]+v[i],dp[j]);
	long long ans=-1;
	for(int i=0;i<=W;i++)
		ans=max(ans,dp[i]);		
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int n;
vector<vector<int>> a;
ll dp[23][(1LL << 23LL)];

int main(void){
    cin >> n;
    a.resize(n);
    for(int i = 0; i < n; i++){
        a[i].resize(n);
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
        }
    }

    dp[0][0] = 1;

    for(int i = 0; i < n; i++){
        for(int bit = 0; bit < (1 << n); bit++){
            if(dp[i][bit] == 0)continue;
            for(int j = 0; j < n; j++){
                if(!((1 << j) & bit) && a[i][j]){
                    dp[i + 1][bit | (1 << j)] += dp[i][bit];
                    dp[i + 1][bit | (1 << j)] %= MOD;
                }
            }
        }
    }
    cout << dp[n][(1 << n) - 1] % MOD << endl;
}

Measured memory_bytes: 323840
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9 + 7;

int main(void){
  int n;
  map<ll,ll> a;
  cin >> n;
  for(int i = 0;i < n;++i){
    ll tmp;
    cin >> tmp;
    a[tmp]++;
  }
  vector<pair<ll,ll>> calc;
  for(auto p : a){
    calc.push_back(p);
  }
  if(a[0] == n){
    puts("Yes");
    return 0;
  }
  if(n % 3 != 0){
    puts("No");
    return 0;
  }
  if(calc.size() == 3 &&
     (calc[0].first ^ calc[1].first) == calc[2].first &&
     calc[0].second == n/3 &&
     calc[1].second == n/3 &&
     calc[2].second == n/3 ){
    cout << "Yes" << endl;
  } else if(calc.size() == 2 &&
            calc[0].first == 0LL &&
            calc[0].second == n/3 &&
            calc[1].second == (n * 2)/3){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 7284
#include <bits/stdc++.h>
using namespace std;
#define ll long long int


int main(){
    ll a, b;
    cin>>a>>b;
    if(a > 0 && b > 0){
        cout<<"Positive"<<endl;
    } else if (a < 0 && b < 0){
        if((abs(b) - abs(a) +1) % 2 == 0){
            cout<<"Positive"<<endl;
        } else {
            cout<<"Negative"<<endl;
        }
    } else if(a < 0 && b > 0){
        cout<<"Zero"<<endl;
    } else if(a == 0 || b == 0){
        cout<<"Zero"<<endl;
    }
}


Measured memory_bytes: 256
N=int(input())
S=input()
R=0
G=1
B=2
chk=[0]*N
lst=[[0 for e in range(3)] for f in range(N)]
if S[N-1]=="R":
 chk[N-1]=0
 lst[N-1][0]+=1
elif S[N-1]=="G":
 chk[N-1]=1
 lst[N-1][1]+=1
else:
 chk[N-1]=2
 lst[N-1][2]+=1
if N>=2:
 for i in range(1,N):
  lst[N-1-i][0]+=lst[N-i][0]
  lst[N-1-i][1]+=lst[N-i][1]
  lst[N-1-i][2]+=lst[N-i][2]
  if S[N-1-i]=="R":
   chk[N-1-i]=0
   lst[N-1-i][0]+=1
  elif S[N-1-i]=="G":
   chk[N-1-i]=1
   lst[N-1-i][1]+=1
  else:
   chk[N-1-i]=2
   lst[N-1-i][2]+=1
ans=0
if N<=2:
 print(0)
else:
 for i in range(N-2):
  for j in range(i+1,N-1):
   if chk[i]!=chk[j]:
    ans+=lst[j+1][3-chk[i]-chk[j]]
    if 2*j-i<=N-1:
     if chk[2*j-i]==3-chk[i]-chk[j]:
      ans-=1
print(ans)

Measured memory_bytes: 68852
from collections import Counter

n = int(input())
arr = list(map(int, input().split()))
q = int(input())

counter = Counter(arr)
total = sum(arr)

for i in range(q):
	b, c = list(map(int, input().split()))
	if counter[b] > 0:
		counter[c] += counter[b]
		total += counter[b] * (c - b)
		counter[b] = 0
		print(total)
	else:
		print(total)


Measured memory_bytes: 21420
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	cout << fixed << setprecision(10);
	const double PI = 3.14159265358979;
	double r; cin>>r;
	cout<<r*r*PI<<" "<<2*r*PI<<endl;


	return 0;
}


Measured memory_bytes: 3264
# 2019/02/09
# AtCoder Beginner Contest 118 - B

# Input
n, m = map(int,input().split())

# Calc
cnt = [0] * m
for i in range(n):
    a = list(map(int,input().split()))
    
    for j in range(1,a[0]+1):
        cnt[a[j]-1] += 1

ans = 0
for i in range(m):
    if cnt[i] == n:
        ans += 1

# Output
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <tuple>
#include <utility>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <map>
#include <sstream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

int main()
{
   int k,x;
   cin>>k>>x;

   for(int i=x-k+1;i<=x+k-1;i++){
            if(-1000000<=i&&i<=1000000){
                cout << i << " ";
            }
   }

   cout << endl;
    return 0; 

}


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

int main() {
    string text[4] = {"dream", "dreamer", "erase", "eraser"};
    int l[4] = {5, 7, 5, 6};
    string s; cin >> s;
    int cur = s.length();
    while (cur > 0) {
        bool ok = false;
        for (int i = 0; i < 4; i++) {
            if (cur >= l[i] && s.substr(cur - l[i], l[i]) == text[i]) {
                ok = true;
                cur -= l[i];
                break;
            }
        }
        if (!ok) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

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

using namespace std;

#define ll long long

int main(){
   int n;
   cin>>n;
   double x,sum=0;
   string s;
   while(n--){
       cin>>x>>s;
       if(s=="BTC"){
           x=x*380000.0;
       }
       sum=sum+x;
   }
   cout<<sum<<endl;


  

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()
 
int main(void) {
    ll n; cin >> n;
    vector<ll> p(n);
    rep(i, 0, n) {
        cin >> p[i];
    }

    ll min_val = LONG_MAX;
    ll ans = 0;
    rep(i, 0, n) {
        min_val = min(min_val, p[i]);
        if (p[i] <= min_val) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define int long long
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t;
    cin >> t;
    string s;
    set<string>ss;
    while(t--){
      cin >> s;
      ss.insert(s);
    }
    cout << ss.size();
}

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

int main(){
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;

    for(int i = 1; i < N+1; i++) cin >> t[i] >> x[i] >> y[i];
    bool can = true;
    int dist = 0;
    int dt = 0;
    for(int i = 1; i < N+1; i++){
        dt = t[i]-t[i-1];
        dist = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]);
        if (dt < dist){
            can = false;
            break;
        }
        if (dist % 2 != dt % 2){
            can = false;
            break;
        }  
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vpi;
typedef vector<string> vsi;
typedef map<ll, ll> mape;
#define rep(i, a, b) for(ll i=(ll)a;i<=(ll)b;i++)
#define per(i, a, b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define N 2100
#define MAX 1000000000001
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define MOD 1000000007

int main()
{
    fastio;

    clock_t tStart = clock();

    ll n, m;
    cin >> n >> m;
    ll cnt = 0;
    vi v(n);
    rep(i, 0, n-1) cin >> v[i];
    rep(i, 0, n-1) cnt += v[i];
    ll num = 0;
    rep(i, 0, n-1) {
        if(v[i]*4*m >= cnt) num++;
    }
    if(num >= m) cout << "Yes" << endl;
    else cout << "No" << endl;

    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>

void swap(int &x, int &y)
{
    int tmp = x;
    x = y;
    y = tmp;
}

int main()
{
    while(true) {
        int x, y;
        std::cin >> x >> y;
        if(x == 0 && y == 0) { break; }
	if(x > y) {
            swap(x, y);
        }
        std::cout << x << " " << y << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import sys
inputs = sys.stdin.readlines()

n, m = map(int, inputs[0].split())
B = set(map(int, inputs[1:]))
A = [0 if i in B else 1 for i in range(n+3)]
MOD = 10 ** 9 + 7

dp = [0]*(n+1)
dp[0], dp[1] = 1, A[1]
for i in range(1, n):
    dp[i+1] = (dp[i] + dp[i-1]) * A[i+1] % MOD
    if A[i] + A[i+1] == 0:
        break
print(dp[n])

Measured memory_bytes: 19088