akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// Constant variables
const long double PI = (acos(-1));
const long long MOD = 1000000007;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    int n;
    cin >> n;
    vll p(n);
    ll sum = 0;
    REP(i, n) {
        int a;
        cin >> a;
        sum += a;
        p[i] = sum;
    }
    long double mid = sum % 2 == 0 ? sum / 2.0 : (sum + 1) / 2.0;
    auto itr = lower_bound(ALL(p), (ll)mid);
    DBG(*itr);
    ll ld = sum - 2 * (*(itr - 1)), rd = 2 * (*itr) - sum;
    cout << min(ld, rd) << "\n";

    return 0;
}


Measured memory_bytes: 1792
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,k = li()
a = list(li())
dp = [-1]*(k+1)
dp[0] = 0

for m in range(1,k+1):
    for ai in a:
        if m - ai >= 0:
            if dp[m-ai] == 0:
                dp[m] = 1
                break
    
        dp[m] = 0
    
print("First") if dp[k] == 1 else print("Second")

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

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

int main(void)
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    while(a>0 && c>0)
    {
        c-=b;
        a-=d;
    } 
    if(c<=0)
    {
        cout << "Yes" << endl; 
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>

char a[205], b[205];

int main(){
	int k, ans;
	char *p, *q, *wp, *wq;
	char *s[3] = { "IDENTICAL", "CLOSE", "DIFFERENT" };

	while (scanf("%s", a) && a[0] != '.') {
		scanf("%s", b); p = a, q = b; ans = -1, k = 0;
		while (*p && *q) {
			if (*p != *q) { ans = 2; break; }
			if (*p == '"') {
			    wp = ++p, wq = ++q;
				while (*p != '"'){
				    p++;
				}while (*q != '"'){
				    q++;
				}
				*p = *q = 0;
				k += 1 - (strcmp(wp, wq) == 0);
				if (k > 1) {
				    ans = 2; break;
				    }
			}
			p++, q++;
		}
		if (ans < 0){
		    if (*p == *q){
		        ans = k;
		        }else{
		            ans = 2;
		        }
		}
		puts(s[ans]);
	}
	return 0;
}


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

int main()
{
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int flag=0;
  int ans=0;
  while(true)
  {
    if(flag==0)
    {
      C-=B;
      if(C<=0)
      {
        cout<<"Yes"<<endl;
        break;
      }
      flag=1;
    }
    else
    {
      A-=D;
      if(A<=0)
      {
        cout<<"No"<<endl;
        break;
      }
      flag=0;
    }
  }
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  vector<int> a(n);
  ll s = 0;
  vector<vector<int>> nums(n+1, vector<int>());
  for(int i = 0; i < n; i++){
    cin >> a[i];
    nums[a[i]].push_back(i);
  }
  for(int i = 0; i < n; i++){
    if(nums[i+1].size())s += nums[i+1].size() * (nums[i+1].size() - 1) / 2;
  }
  for(int i = 0; i < n; i++){
    cout << s - (int(nums[a[i]].size()) - 1) << endl;
  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 11008
n , m = map(int, input().split())
N=1000000007
def fac(a):
    ans = 1
    while a>1:
        ans=ans*a%N
        a-=1
    return ans

if abs(n-m)==1:
    ans = fac(n)*fac(m)%N
elif n == m:
    ans = fac(n)*fac(m)*2%N
else:
    ans = 0
print(ans)


Measured memory_bytes: 3060
using System;
    using System.Collections.Generic;
    using System.Linq;
    using static Atcoder;
    using System.Threading.Tasks;
    using System.ComponentModel;
     
    public class Hello
    {
     
        public static void Main()
        {
            int[] n = SpRead(' ').Select(a => int.Parse(a)).ToArray();
            Console.WriteLine((n[0]*n[1]%2==0?"Even":"Odd"));
        }
    }
     
    public class Atcoder
    {
    static void Swap<T>(ref T a, ref T b)
    {
    var t = a;
    a = b;
    b = t;
    }
    public static int LCM(int a, int b)
    {
    int c = a * b;
    if (a < b) Swap(ref a, ref b);
    int d = a % b;
    while (d != 0)
    {
    a = b;
    b = d;
    d = a % b;
    }
    return c / b;
    }
    public static string strReverce(string s)
    {
    return new string(s.Reverse().ToArray());
    }
    public static int Cin()
    {
    return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
    if (n < 2) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
     
    //double sqrtNum = Math.Sqrt(n);
    for (int i = 3; i < n; i += 2)
    {
    if (n % i == 0) return false;
    }
    return true;
    }
    public static string[] SpRead(char c)
    {
    return Console.ReadLine().Split(c);
    }
    }

Measured memory_bytes: 11348
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int a, b;
	char ch;

	cin >> a >> ch >> b;
	if (ch == '+') cout << a + b;
	else cout << a - b;

	return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    while True:
        N, M = map(int, input().split())
        if N == 0:
            break
        path = [[False] * N for i in range(N)]
        for i in range(M):
            u, v = map(int, input().split())
            u -= 1; v -= 1;
            path[u][v] = True
            path[v][u] = True

        d = [-1] * N
        d[0] = 0
        q = [0]
        while len(q) > 0:
            now = q.pop(0)
            for i in range(N):
                if path[now][i] and d[i] == -1:
                    q.append(i)
                    d[i] = d[now] + 1
        ok = True
        for i in range(1, N):
            for j in range(i+1, N):
                if path[i][j] and d[i] == d[j]:
                    ok = False
                    break
            if not ok:
                break
        if not ok:
            print(0)
        else:
            num = 0
            for i in range(N):
                if d[i]&1:
                    num += 1
            if N&1:
                print(1)
                if num&1:
                    print((N-num)//2)
                else:
                    print(num//2)
            else:
                if num&1:
                    print(0)
                else:
                    if N//2 == num:
                        print(1)
                        print(num//2)
                    else:
                        print(2)
                        tmp = min(num, N-num)
                        print(tmp//2)
                        print((N-tmp)//2)




if __name__ == "__main__":
    main()



Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;

  int ans = 0;
  rep(i,k) {
    string tt;
    int it = i;
    while (it < n) {
      tt += t[it];
      it += k;
    }

    // suc = (直前の文字の連続している数)%2
    int suc = 0; 
    // suc && tt[j-1]==tt[j]  -> +point, suc = false;  "rpp"+'p'
    // suc && tt[j-1]!=tt[j]  -> +point, suc = false;  "rpp"+'s'
    // !suc && tt[j-1]==tt[j] -> +0,     suc = true;   "rrp"+'p' "prrr"+'r' "prp"+'p'
    // !suc && tt[j-1]!=tt[j] -> +point, suc = false;  "rrp"+'s' "rrr"+'s' "prp"+'s'

    rep(j,tt.size()) {
      char c = tt[j];
      if (suc) suc = 0;
      else {
        if (j && tt[j-1] == tt[j]) {
          suc = 1;
          continue;
        }
      }
      if (c == 'r') ans += p;
      if (c == 's') ans += r;
      if (c == 'p') ans += s;
    }
  }

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

Measured memory_bytes: 512
n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]
for i in range(n - 2):
    cnt = 0
    for j in range(3):
        if d[i + j][0] == d[i + j][1]:
            cnt += 1
    if cnt == 3:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 9184
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

int n,m,ans;P p[110000];
signed main(){
  cin>>n>>m;
  rep(i,m)cin>>p[i].second>>p[i].first;
  sort(p, p+m);
  int t = -1;
  rep(i,m){
    if(t < p[i].second){
      t = p[i].first-1;
      ans++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	UL gcd(UL a, UL b) { return b ? gcd(b, a % b) : a; }

	void Solve() {
		UL N; cin >> N;
		UL K; cin >> K;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		UL G = A[0]; rep(i, N) G = gcd(G, A[i]);
		UL M = 0; rep(i, N) M = max(M, A[i]);
		if (M < K) { cout << "IMPOSSIBLE" << endl; return; }
		if (K % G) { cout << "IMPOSSIBLE" << endl; return; }
		cout << "POSSIBLE" << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 640
import heapq

x,y,z,K = map(int, input().split())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort()
a.reverse()
b.sort()
b.reverse()
c.sort()
c.reverse()


memo = {}
i = j = k = 0

h = []
heapq.heappush(h, (-(a[i]+b[j]+c[k]), i,j,k))
for _ in range(K):
    cost, i, j, k = heapq.heappop(h)
    print(-cost)
    for dx, dy, dz in ((1,0,0), (0,1,0), (0,0,1)):
        if (i+dx, j+dy, k+dz) in memo:
            continue
        if i+dx<x and j+dy<y and k+dz<z:
            heapq.heappush(h, (-(a[i+dx]+b[j+dy]+c[k+dz]), i+dx, j+dy, k+dz))
            memo[(i+dx,j+dy,k+dz)] = 1         
        


Measured memory_bytes: 5032
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			cout << v[i][j] << "   ";
		}
		cout << endl;
	}
}


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

	int ans = 0;
	int cnt = 0;
	for(int i=0; i<S.size(); i++){
		if(S.at(i) == 'A' || S.at(i) == 'C' 
									|| S.at(i) == 'G' ||S.at(i) == 'T'){
			cnt++;
			continue;
		}
		else{
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt); //ここもやらんと 全部ACGT文字ならansが0になる

	cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.*;
 
class Main{
 
    int h, w;
    int sx, sy, gx, gy;
    int[][] grid;
 
    void solve(){
        Scanner sc = new Scanner(System.in);
 
        while(true){
 
            h = sc.nextInt();
            w = sc.nextInt();
            if(h==0 && w==0) break;
 
            grid = new int[h][w];
            for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    grid[i][j] = sc.nextInt();
                }
            }
            sy = sc.nextInt();
            sx = sc.nextInt();
            gy = sc.nextInt();
            gx = sc.nextInt();
 
            System.out.println(bfs());
        }
    }
 
    class Dice{
        int[] dice = new int[6];
        Dice(int a, int b, int c, int d, int e, int f){
            dice[0] = a; dice[1] = b; dice[2] = c;
            dice[3] = d; dice[4] = e; dice[5] = f;
        }
    }
 
    int[][] dd = {{1,5,2,3,0,4}, {3,1,0,5,4,2}, {4,0,2,3,5,1}, {2,1,5,0,4,3}};
 
    Dice rotate(Dice d, int idx){
        return new Dice(d.dice[dd[idx][0]], d.dice[dd[idx][1]], d.dice[dd[idx][2]], d.dice[dd[idx][3]], d.dice[dd[idx][4]], d.dice[dd[idx][5]]);
    }
 
    class P{
        Dice d;
        int[] num;
        P(int[] num, Dice d){
            this.num = num;
            this.d = d;
        }
    }
    
    int[] dx = {0, 1, 0, -1};
    int[] dy = {-1, 0, 1, 0};
    
    int bfs(){
        //x, y pena,direction
        PriorityQueue<P> 
            q = new PriorityQueue<P>(10, new Comparator<P>(){
                    public int compare(P a, P b){
                        return a.num[2] - b.num[2];
                    }
                });
        boolean[][][][] v = new boolean[h][w][6][6];
        Dice d = new Dice(1,2,3,4,5,6);
        q.add(new P(new int[]{sx, sy, 0}, d));
              
        int min = Integer.MAX_VALUE;
              
        while(q.size()>0){
            P p = q.poll();
            int[] qq = p.num;
            int x = qq[0], y = qq[1], pena = qq[2];
            Dice ddd = p.d;
            //System.out.println(x+" "+y+" "+pena+" "+Arrays.toString(ddd.dice));
 
            if(x==gx && y==gy) return pena;

            if(v[y][x][ddd.dice[0]-1][ddd.dice[1]-1]) continue;
            v[y][x][ddd.dice[0]-1][ddd.dice[1]-1] = true;
 
            for(int i=0; i<4; i++){
                int nx = x + dx[i], ny = y + dy[i];
                if(nx<0 || nx>=w || ny<0 || ny>=h) continue;
                Dice newDice = rotate(ddd, i);
                q.add(new P(new int[]{nx, ny, pena+grid[ny][nx]*newDice.dice[5], newDice.dice[0], newDice.dice[1]}, newDice));
            }
        }

        return min; 
    }
 
 
    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 61216
import java.util.*;

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

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        long Y = sc.nextLong();


        int cnt = 0;
        long cur = X;
        while (Y >= cur) {
            cnt++;
            cur *= 2;
        }   

        System.out.println(cnt);

        return;
    }   

}

Measured memory_bytes: 23892
from collections import deque

def bfs(maze, visited, sy, sx, gy, gx):
    H, W = len(maze), len(maze[0])
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        y, x = queue.popleft()
        if [y, x] == [gy, gx]:
            return visited[y][x]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if 0<=new_y<=H-1 and 0<=new_x<=W-1:
                if maze[new_y][new_x] == "." and                 visited[new_y][new_x] == -1:
                    visited[new_y][new_x] = visited[y][x] + 1
                    queue.append([new_y, new_x])
    return False

if __name__ == "__main__":
    H, W = map(int, input().split())
    sy, sx = 0, 0
    gy, gx = H-1, W-1

    maze = [input() for _ in range(H)]
    visited = [[-1]*W for _ in range(H)]
    min_root = bfs(maze, visited, sy, sx, gy, gx)
    
    if min_root:
    	white = 0
    	for raw in maze:
    		white += raw.count('.')
    	print(white-min_root-1)
    else:
    	print(-1)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}

const double PI = acos(-1);
ll nextLong() { ll x; scanf("%lld", &x); return x;}
const int MAX_N = 200000 + 10;
vector<pair<ll, ll>> p(MAX_N);

const ll INF = 1LL << 58;
ll dp[MAX_N];
int lis(const vector<pair<ll,ll>>& A, int N) {
  fill(dp, dp + N, INF);
  REP(i, N) {
    int pos = lower_bound(dp, dp + N, A[i].second) - dp;
    dp[pos] = A[i].second;
  }
  return lower_bound(dp, dp + N, INF) - dp;
}

int main2() {
  ll x1 = nextLong();
  ll y1 = nextLong();
  ll x2 = nextLong();
  ll y2 = nextLong();
  int N = (int) nextLong();
  REP(i, N) {
    ll X = nextLong();
    ll Y = nextLong();
    p[i].first = X;
    p[i].second = Y;
  }

  // (x1,y1) - (x2,y2) の矩形の外にある点は除く
  {
    int nn = 0;
    REP(i, N) {
      if (min(x1,x2) <= p[i].first  && p[i].first  <= max(x1,x2) && 
          min(y1,y2) <= p[i].second && p[i].second <= max(y1,y2)) {
        p[nn++] = p[i];
      }
    }
    N = nn;
  }


  if (x1 == x2 && y1 == y2) {
    printf("0\n");
    return 0;
  }
  if (x1 == x2) {
    if (y1 > y2) swap(y1, y2);
    double ans = 100 * (double)(y2 - y1);
    REP(i, N) {
      if (p[i].first == x1 && y1 < p[i].second && p[i].second < y2)
        ans += (-20 + 10 * PI);
    }
    printf("%.12f\n", ans);
    return 0;
  }
  if (y1 == y2) {
    if (x1 > x2) swap(x1, x2);
    double ans = 100 * (double)(x2 - x1);
    REP(i, N) {
      if (p[i].second == y1 && x1 < p[i].first && p[i].first < x2)
        ans += (-20 + 10 * PI);
    }
    printf("%.12f\n", ans);
    return 0;
  }

  if (x1 > x2) { swap(x1, x2); REP(i, N) p[i].first *= -1; }
  if (y1 > y2) { swap(y1, y2); REP(i, N) p[i].second *= -1; }
  
  sort(p.begin(), p.begin() + N);
  {
    ll mi = p[0].second;
    REP(i, N) chmin(mi, p[i].second);
    REP(i, N) p[i].second -= mi;
  }
  int ma = lis(p, N);
  double ans = (x2 - x1) * 100 + (y2 - y1) * 100 + ma * (-20 + 5 * PI);
  if (min(x2-x1, y2-y1) + 1 == ma) {
    ans = (x2 - x1) * 100 + (y2 - y1) * 100 + (ma-1) * (-20 + 5 * PI) + (-20 + 10 * PI);
  }
  printf("%.12f\n", ans);
  
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



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

using namespace std;

bool is_allowed(vector<int> vs) {
    assert(vs.size() == 4);
    auto check = [&]() {
        if (vs[0] == 0 && vs[1] == 1 && vs[2] == 2) {
            return false;
        }
        if (vs[1] == 0 && vs[2] == 1 && vs[3] == 2) {
            return false;
        }
        return true;
    };
    if (!check()) {
        return false;
    }
    for (int i = 0; i < 3; ++i) {
        swap(vs[i], vs[i+1]);
        if (!check()) {
            return false;
        }
        swap(vs[i], vs[i+1]);
    }
    return true;
}

vector<vector<int>> all_allowed() {
    vector<vector<int>> all;
    for (int a = 0; a < 4; ++a) {
        for (int b = 0; b < 4; ++b) {
            for (int c = 0; c < 4; ++c) {
                for (int d = 0; d < 4; ++d) {
                    vector<int> xs = {a, b, c, d};
                    if (is_allowed(xs)) {
                        all.push_back(xs);
                    }
                }
            }
        }
    }
    return all;
}

long long prime = 1000000007;

vector<vector<long long>> mul(vector<vector<long long>>& a, vector<vector<long long>>& b) {
    auto t0 = clock();
    assert (a[0].size() == b.size());
    int m = (int) a.size(), n = (int) b.size(), p = (int) b[0].size();
    // (m x n) * (n x p)
    vector<vector<long long>> c(m, vector<long long>(p, 0LL));
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < p; ++j) {
            long long s = 0;
            for (int k = 0; k < n; ++k) {
                s += (a[i][k] * b[k][j]) % prime;
            }
            c[i][j] = s % prime;
        }
    }
    cerr << "simple mul time: " << (clock() - t0) << " -- " << m << ", " << n << ", " << p << endl;
    return c;
}

vector<vector<long long>> pow(vector<vector<long long>> a, int r) {
    if (r == 1) {
        return a;
    }
    if (r % 2 == 1) {
        auto b = pow(a, r-1);
        return mul(a, b);
    }
    auto b = pow(a, r/2);
    return mul(b, b);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n == 3) {
        cout << 61 << endl;
        return 0;
    }
    map<vector<int>, int> mapping;
    for (auto& xs : all_allowed()) {
        int t = (int) mapping.size();
        mapping[xs] = t;
    }
    vector<vector<long long>> mat(mapping.size(), vector<long long>(mapping.size(), 0));
    for (auto& ys : all_allowed()) {
        for (int a = 0; a < 4; ++a) {
            vector<int> xs(ys.begin()+1, ys.end());
            xs.push_back(a);
            if (is_allowed(xs)) {
                ++mat[mapping[ys]][mapping[xs]];
            }
        }
    }
    vector<vector<long long>> u(mapping.size(), vector<long long>(1, 1LL));
    auto t0 = clock();
    vector<vector<long long>> v = u;
    if (n > 4) {
        auto x = pow(mat, n-4);
        v = mul(x, u);
    }
    cerr << "pow time = " << (clock() - t0) << endl;
    assert (v[0].size() == 1);
    long long result = 0;
    for (auto& p : v) {
        result += p[0];
    }
    cout << (result % prime) << endl;
    return 0;
}


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



int main(){
    string s;
    cin>>s;
    int n=s.size();
    if(s[n-1]=='1' || s[0]=='0'){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=0;i<n-1;i++){
        if(s[i]!=s[n-2-i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    vector<pair<int,int>> edges;
    int r=1;
    for(int i=0;i<n-1;i++){
        if(s[i]=='1'){
            edges.push_back(make_pair(r,i+2));
            r=i+2;
        }
        else{
            edges.push_back(make_pair(r,i+2));
        }
    }
    
    for(int i=0;i<edges.size();i++){
        cout<<edges[i].first<<" "<<edges[i].second<<endl;
    }
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
string s,t;
map<char,vector<int>>mps;
map<char,vector<int>>mpt;
vector<bool>b(26,true);
bool ans=true;
signed main(){
    cin>>s>>t;
    int l=s.size();
    rep(i,l){
        mps[s[i]].push_back(i);
        mpt[t[i]].push_back(i);
        b[t[i]-'a']=false;
    }
    for(char i='a';i<='z';i++){
        for(char j='a';j<='z';j++){
            if(b[j-'a']==false&&mps[i]==mpt[j]){
                b[j-'a']=true;
                break;
            }
        }
    }
    rep(i,26){
        if(b[i]==false)ans=false;
    }
    if(ans)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 4616
#include<stdio.h>


int main(){

  int in[1024],out[1024],a,b,i,j;

  i=0;
  j=0;

  while(scanf("%d",&a) != EOF){
    if(a != 0)
      {
      in[i]=a;
      i++;
      }
    else{
  out[j] = in[i-1];
  i--;
  j++;
  }
  }

  while(i<j)
    {
      printf("%d\n",out[i]);
      i++;
    }

  return 0;
}

Measured memory_bytes: 604
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

n = int(input())
p = LI()

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

Measured memory_bytes: 24436
#include <iostream>
using namespace std;
int main()
{
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    if((A1+A2+A3) >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
    return 0;
}

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

    using namespace std;
    typedef long long ll;
    typedef vector<ll> vl ;

    #define mp make_pair
    #define pb push_back
    #define f first
    #define s second
    #define all(v) (v).begin(),(v).end()


    const int MOD = 1000000007;
    const int N = 1000005;
    const double PI =4*atan(1);
    const double eps = 1e-7;
    
    ll a[N];
    ll b[N];
    ll ans;
    ll n;

    int main(){
        ios::sync_with_stdio(0);
        //freopen("easy.txt","r",stdin);
        cin >> n;
        ans=0;
        for(int i=0;i<n;i++){
            cin >> a[i];
        }
        for(int i=0;i<n;i++){
            cin >> b[i];
            ans+=max(0ll,a[i]-b[i]);
        }
        cout << ans;
        return 0;
    }
        
    

Measured memory_bytes: 2304
l = []

for _ in range(3):
    t = [int(x) for x in input().split()]
    l.append(t[0])
    l.append(t[1])
    l.append(t[2])
    
for _ in range(int(input())):
    t = int(input())

    for x in range(9):
        if l[x] == t:
            l[x] = 0

s = ["012", "345", "678", "036", "147", "258", "048", "246"]
flag = 0

for x in s:
    chk = 0
    for y in x:
        if l[int(y)] == 0:
            chk += 1

    if chk == 3:
        flag = 1
        break

print("Yes" if flag == 1 else "No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;int x[900][900],h,w,a,y[900],s,i,j;queue<int>Q,R;int main(){while(true){memset(x,0,sizeof(x));memset(y,0,3600);cin>>w>>h;if(!w){break;}for(i=0;i<h*2-1;i++){if(i%2){for(j=0;j<w;j++){cin>>a;if(!a){x[(i/2)*30+j][(i/2+1)*30+j]=1;}}}else{for(j=0;j<w-1;j++){cin>>a;if(!a){x[(i/2)*30+j][(i/2)*30+j+1]=1;}}}}Q.push(0);s=1;y[0]=1;while(!y[(h-1)*30+(w-1)]){while(!Q.empty()){a=Q.front();for(j=0;j<900;j++){if((x[a][j]||x[j][a])&&!y[j]){y[j]=1;R.push(j);}}Q.pop();}while(!R.empty()){Q.push(R.front());R.pop();}s++;if(s>999){s=0;break;}}while(!Q.empty()){Q.pop();}cout<<s<<endl;}}

Measured memory_bytes: 4392
n,p = map(int,input().split())
a = list(map(int,input().split()))

o, e = 0, 0
for i in a:
    if i % 2 == 0:
        e += 1
    else:
        o += 1

def comb(n, r):
    ret = 1
    for i in range(r):
        ret *= n - i
        ret //= i + 1
    return ret

res = 0 
if p == 0:
    for i in range(0, o + 1, 2):
        res += comb(o, i)
else:
    for i in range(1, o + 1, 2):
        res += comb(o, i)
res *= 2 ** e
print(res)


Measured memory_bytes: 38384
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    H = int(input())

    bin_k = 0
    tmp = H
    while True:
        bin_k += 1
        tmp = tmp // 2
        if tmp == 0:
            break

    ans = 0
    for i in range(bin_k):
        ans += 2 ** i

    print(ans)


if __name__ == '__main__':
    solve()


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

int main()
{
  int n,m;
  int a[100][100],b[100],c[100]={};
  cin>>n>>m;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin>>a[i][j];
    }
  }
  for(int i=0;i<m;i++){
      cin>>b[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      c[i]+=a[i][j]*b[j];
    }
  }
  for(int i=0;i<n;i++){
      cout<<c[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	ll n,m;cin>>n>>m;
	multiset<ll> s;
	rep(i,0,n){
		ll x;cin>>x;
		s.insert(x);
	}
	rep(i,0,m){
		auto it =s.end();it--;
		ll val=*it;
		s.erase(it);s.insert(val/2);
	}
	ll sum=0;
	for(auto i:s)sum+=i;
	cout<<sum;
	
	return 0;
}



Measured memory_bytes: 4992
/*
Problem:A - Digits Sum
Algorithm:
Status:
*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <utility>
#include <list>
#include <ctime>
#include <memory.h>
#include <stack>
#include <stdio.h>
#include <string.h>

using namespace std;

const int INF=1e9+7;

int dig(int n){
	return (n%10+(n/10)%10+(n/100)%10+(n/1000)%10+(n/10000)%10+(n/100000)%10+(n/1000000)%10);
}

int main()
{
	int ans=INF;
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		int a=i,b=n-i;
		int sa=dig(a);
		if(sa>ans)continue;
		int sb=dig(b);
		if(sa+sb<ans){
			ans=sa+sb; 
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
struct event {
	int t, x, d;
};
bool operator<(const event &lhs, const event &rhs) {
	if (lhs.t != rhs.t)
		return lhs.t < rhs.t;
	return lhs.d < rhs.d;
}
signed main() {
	cin >> N >> Q;
	vector< event > A(N * 2);
	rep(i, N) {
		int s, t, x;
		cin >> s >> t >> x;
		A[i * 2].t = s - x;
		A[i * 2].x = x;
		A[i * 2].d = 1;
		A[i * 2 + 1].t = t - x;
		A[i * 2 + 1].x = x;
		A[i * 2 + 1].d = -1;
	}
	sort(A.begin(), A.end());
	set< int > s;
	vector< int > D(Q);
	rep(i, Q) cin >> D[i];
	int j = 0;
	rep(i, Q) {
		int q = D[i];
		while (j < N * 2 && A[j].t <= q) {
			if (A[j].d == 1) {
				s.insert(A[j].x);
			} else {
				s.erase(A[j].x);
			}
			j++;
		}
		if (!s.empty()) {
			cout << (*(s.begin())) << endl;
		} else {
			cout << -1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 21504
#include<stdio.h>
#include<math.h>

int isPrime(int x){
  if(x==2){
    return true;
  }
  if(x<2 || x%2==0){
    return false;
  }

  int i=3;
  while(i<=sqrt(x)){
    if(x%i==0){
      return false;
    }
    i = i+2;
  }

  return true;
}

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

  int N[n];
  int c=0;
  for(int i=0;i<n;i++){
    scanf("%d",&N[i]);
    if(isPrime(N[i])){
      c++;
    }
  }
  printf("%d\n",c);

  return 0;
}



Measured memory_bytes: 2732
void main() {
  problem();
}

void problem() {
  auto N = scan!int;
  auto M = scan!int;
  auto K = scan!long;
  auto A = scan!long(N);
  auto B = scan!long(M);

  long solve() {
    long[] sumA = new long[N+1];
    foreach(i; 1..N+1) sumA[i] = sumA[i-1] + A[i-1];

    long[] sumB = new long[M+1];
    foreach(i; 1..M+1) sumB[i] = sumB[i-1] + B[i-1];

    sumA.deb;
    sumB.deb;

    long ans;
    long b = M;
    foreach(a; 0..N+1) {
      if (sumA[a] > K) continue;

      long rest = K - sumA[a];
      foreach_reverse(bi; 0..b+1) {
        if (sumB[bi] <= rest) {
          b = bi;
          break;
        }
      }
      
      if (ans < a + b) ans = a + b;
    }

    return ans;
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 22020
#include <iostream>
#include <string>

using namespace std;

int main(){

    string str;
    cin >> str;

    if((0 <= str.find("a") && str.find("a") <= 3) &&
       (0 <= str.find("b") && str.find("b") <= 3) &&
       (0 <= str.find("c") && str.find("c") <= 3)){
           cout << "Yes" << endl;
       }else{
           cout << "No" << endl;
       }

    return 0;
}

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

int main(){
    ll t,n,q,m,x,y;
    cin>>t;
    x = t%1000;
    if(x)
        x = 1000-x;
    cout<<x<<endl;
    return 0;
}







Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long A, long long B, long long C) {
  cout << min(B / A, C) << endl;
  ;
}

int main() {
  cout << setprecision(10);
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  solve(A, B, C);
  return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  if(a <= c && c <= b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int n, m, q;
int ans = 0;
vector<int> a, b, c, d;
void dfs(vector<int> A) {
  if (A.size() == n+1) {
    int now = 0;
    //得点を条件が合う場合加算
    for (int i = 0; i < q; i++) {
      if (A[b[i]]-A[a[i]]==c[i]) {
        now+= d[i];
      }
    }
    ans = max(ans, now);
    return;
  }
  //直前の値よりも少なくとも大きいため
  A.push_back(A.back());
  while (A.back() <= m) { //A[0]==1より、A.backを後ろにしている。そのため、条件がm以下となる。
    dfs(A);
    A.back()++;
  }
}
int main() {
  cin >> n >> m >> q;
  a = b = c = d =vector<int>(q);
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  //初期配列を長さが1、要素が1にする。
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}

//n=3の時
//123
//124
//125
//126
//127
//128
//129
//-
//-
//-


Measured memory_bytes: 3156
import sys
if sys.platform == 'ios':
	sys.stdin = open('input_file.txt')
	

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

a = [str(input()) for i in range(n)]
b = [str(input()) for i in range(m)]

s = [ [0]*m for i in range(m) ]

ans = 0

for i in range(n-m+1):
	for j in range(n-m+1):
		for k in range(m):
			#print(i,j,k)
			s[k] = a[i+k][j:j+m]
		#print(s)
		
		if s == b :
			#print(i,j,s)
			ans = ans +1

print('Yes' if ans >= 1 else 'No')
			


Measured memory_bytes: 3064
N = int(input())

import sys
sys.setrecursionlimit(10 ** 9)

memo = [-1] * (N + 1)

def dfs(x):
    if x >= 0 and memo[x] != -1:
        return memo[x]
    ans = False
    if x == 0:
        memo[x] = 1
        return True
    elif x < 0:
        return False
    else:
        ans |= dfs(x - 100)
        ans |= dfs(x - 101)
        ans |= dfs(x - 102)
        ans |= dfs(x - 103)
        ans |= dfs(x - 104)
        ans |= dfs(x - 105)
    memo[x] = 1 if ans else 0
    return ans
if dfs(N):
    print(1)
else:
    print(0)


Measured memory_bytes: 4596
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

class Edge {
    public:
    ll s, t, w;
    Edge(ll s, ll t, ll w) {
        this->s=s;
        this->t=t;
        this->w=w;
    }
};

ll N, M;
vector<Edge> edges;

int main(void) {
    cin >> N >> M;
    ll i, j, k;
    ll d[111][111];
    
    for(i=0; i<N; i++) {
        for(j=0; j<N; j++) {
            d[i][j]=(i==j ? 0 : INF);
        }
    }
    
    for(i=0; i<M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b]=c;
        d[b][a]=c;
        edges.pb(Edge(a, b, c));
    }
    
    for(k=0; k<N; k++) {
        for(i=0; i<N; i++) {
            for(j=0; j<N; j++) {
                chmin(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
    
    ll ans=0;
    for(i=0; i<edges.size(); i++) {
        Edge e=edges[i];
        if(d[e.s][e.t]!=e.w) ans++;
    }
    
    pt(ans);
}





Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int a;cin>>a;
  int ans=a+a*a+a*a*a;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int K, X;
    cin >> K >> X;
    for (int i = X - K + 1; i <= X + K - 1; i++) {
        if (i != X + K - 1) cout << i << " ";
        else cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#2-8
while True:
    try:

        def gcd(a,b):
            if b == 0:
                return a
            else:
                return gcd(b,a%b)

        a = list(map(int,input().split()))
        a.sort()
        a.reverse()
        ans1 = gcd(a[0],a[1])
        ans2 = int(a[0]*a[1]/ans1)

        print(ans1,ans2)
    except:
        break


Measured memory_bytes: 5596
#include <iostream>

using namespace std;

int cnt[101][10];
void rec(int idx, int d, int n){
  if(d >= 10)return;
  for(int i = idx+1 ; i < 10 ; i++){
    cnt[n+i][d+1]++;
    rec(i,d+1,n+i);
  }
}
void calc(){
  rec(-1,0,0);
}
int main(){
  calc();
  int n,s;
  while(cin >> n >> s, n||s){
    cout << cnt[s][n] << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<queue>
#include<cstring>
using namespace std;
int a[100005],c; 
int main()
{int n,k;
 cin>>n>>k;
 for(int i=0;i<n;i++){
 cin>>a[i];}
 if(n!=k && k!=2 && k!=1 && n/k!=k){
 for(int i=0;i<n;i++) 
 if(i%(k-1)==0)
 {c++;
 }
 c--;
 if((n+c-1)%k==0){
 int hans1=(n+c-1)/k;
 cout<<hans1<<endl;
}
 else if((n+c-1)%k!=0){
 int hans1=(n+c)/k;
 int hans2=(n+c)%k;
 if(hans1!=0){
 hans2=1;}
 else
 {hans2=0;
 }
 cout<<hans1+hans2<<endl;
}
}
 else if(n==k)
 {cout<<n/k<<endl;
 }
 else if(k==2)
 {cout<<n-1<<endl;
 }
 else if(k==1)
 {cout<<n<<endl;
 }
 else if(n/k==k)
 {cout<<k+1<<endl;
 }
 system("pause");
 return 0;
}

Measured memory_bytes: 888
n = gets.chomp.to_i
s = gets.chomp
h  = Hash.new(0)

n.times do |i|
  h[s[i]] += 1
end

MOD = 10**9 + 7
ans = 1
h.each do |k,v|
  ans *= (v + 1) % MOD
end

puts (ans - 1)%MOD


Measured memory_bytes: 1916