akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
template<class T>T updivide(T a,T b){if(b==1) return a;else if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(n);
    vector<int> vec(n);
    in(vec);
    int counter=0;
    rep(i,n){
        counter+=(vec[i]%2==0);
    }
    cout<<(counter==n?"second":"first")<<endl;
}

Measured memory_bytes: 3772
N,A,B=map(int,input().split())
S=input()
cnta=0
cntb=0
for i in range(N):
    temp=S[i]
    if S[i]=="a" and cnta+cntb<A+B:
        print("Yes")
        cnta+=1
    elif S[i]=="b" and cnta+cntb<A+B and cntb<B:
        print("Yes")
        cntb+=1
    else:
        print("No")


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
int main(){
  string ans;
  int A,B,C;
  cin >> A >> B >> C;
  vector<int> vec = {A,B,C};
  sort(vec.begin(),vec.end());
  if(vec[2] == vec[0]+vec[1])
    ans = "Yes";
  else
    ans = "No";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int w,n;//縦棒と横棒の本数
    int a[30],b[30];//横棒の行き先
    int amida[30];
    int i=0;
    int temp;
    
    scanf("%d",&w);
    scanf("%d",&n);
    
    while(scanf("%d,%d",&a[i],&b[i])!=EOF){
        i++;
    }
    
    for(i=0;i<w;i++){
        amida[i]=i+1;
    }
    
    for(i=0;i<n;i++){
        temp=amida[a[i]-1];
        amida[a[i]-1]=amida[b[i]-1];
        amida[b[i]-1]=temp;
    }
    
    for(i=0;i<w;i++){
        printf("%d\n",amida[i]);
    }
    
    return 0;
}

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

int main() {
    int64_t N;
    std::cin >> N;

    int64_t A[N];
    for (int64_t i = 0; i < N; ++i) {
        std::cin >> A[i];
        A[i] -= (i + 1);
    }

    std::sort(A, A + N);
    const int64_t b = A[N/2];

    int64_t ans0 = 0, ans1 = 0;
    for (int64_t i = 0; i < N; ++i) {
        ans0 += std::abs(A[i] - (b - 1));
        ans1 += std::abs(A[i] - b);
    }

    std::printf("%ld\n", std::min(ans0, ans1));

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>

using namespace std;
const int N=2e5+10,inf=1e9;
int dp[N][2];
char s[N];

int main(){
    int N,ans;
	cin >> N;
    ans = 180*(N-2);

	cout << ans << endl;
}


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

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String S = s.next();
        int Q = Integer.parseInt(s.next());
        StringBuilder origin = new StringBuilder(S);
        StringBuilder front = new StringBuilder();
        StringBuilder back = new StringBuilder();
        /**
         * 4 2 1 p 1 2 2 c 1
         */
        /**
         * 123 先頭にp追加 p123 反転 321p 末尾にc追加 321pc 反転 cp123 先頭にa追加 acp123 末尾にb追加 acp123b
         */
        // 反転しているかどうか
        // 反転していない場合の先頭追加、末尾追加
        // 反転している場合の先頭追加、末尾追加
        boolean normal = true;
        for (int i = 0; i < Q; i++) {
            String type = s.next();
            // 反転
            if (Objects.equals(type, "1")) {
                normal = !normal;
                continue;
            }
            // 追加処理
            String F = s.next();
            String C = s.next();
            if (Objects.equals(F, "1")) {
                // 先頭追加処理
                if (normal) {
                    front.append(C);
                } else {
                    back.append(C);
                }
            } else {
                // 末尾追加処理
                if (normal) {
                    back.append(C);
                } else {
                    front.append(C);
                }
            }
        }
        // 表示処理
        if (normal) {
            System.out.print(front.reverse());
            System.out.print(origin);
            System.out.println(back);
        }else{
            System.out.print(back.reverse());
            System.out.print(origin.reverse());
            System.out.println(front);
        }
    }
}

Measured memory_bytes: 88048
#include<bits/stdc++.h>
#define INF 2147483647
#define  ll long long
using namespace std;
const int Max=1e5+20;
const int Maxn=1e7+20;
const int mod=1e9+7;
inline int read()
{
    int f=1,x=0;
    char ch;
    do{ch=getchar(); if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return x*f;
}
int main()
{
    string s;
    cin>>s;
    int ans=0,count=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='R') count++;
        if(s[i]=='S'){ans=max(ans,count);count=0;}
    }
    ans=max(ans,count);
    cout<<ans<<endl;
  
}




Measured memory_bytes: 3520
while True:
    H,W = map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
                if i == 0 or i == H-1 or j == 0 or j == W-1:
                        print('#', end='')
                else:
                        print('.', end='')
        print()
    print()


Measured memory_bytes: 7004
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    int x,n;
    cin>>x>>n;
    vector<int> v(102);
    int a;
    REP(i,102){
        cin>>a;
        v[a]++;
    }
    int min=1000,ans=1000;
    REP(i,102){
        if(v[i]){
            continue;
        }
        if(min>abs(i-x)){
            min=abs(i-x);
            ans=i;
        }
    }
    cout<<ans;
    return 0;
}


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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int shift = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            string retstr = string.Empty;
            List<string> comp = new List<string> { "A", "B", "C", "D", "E", "F", "G"
            , "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
            foreach (var s in str)
            {
                for (int i = 0; i < comp.Count; i++)
                {
                    if (comp[i].CompareTo(s.ToString()) == 0)
                    {
                        if (i + shift >= 26)
                        {
                            retstr += comp[i + shift - 26];
                        }
                        else { retstr += comp[i + shift]; }
                        break;
                    }
                }
            }
            Console.WriteLine(retstr);
        }



    }
}

Measured memory_bytes: 35152
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <numeric>
using namespace std;

// Input
int K;
int S[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
    cin >> K;

    cout << S[K-1] << endl;
}


Measured memory_bytes: 888
import numpy as np
N,W = map(int, input().split())
INF =  10**10
V_max = 100001
N_max = 101
# dp = np.ones((N_max,V_max), dtype=np.int64)*INF
dp = np.ones(V_max,dtype=np.int64)*INF
dp[0] = 0
for i in range(N):
    a = np.ones(V_max)*INF
    w,v = map(int,input().split())
    # np.minimum(dp[i][:-v]+w,dp[i][v:],out=dp[i+1][v:])
    np.minimum(dp[:-v]+w,dp[v:],out=dp[v:])
ans = 0
for i,d in enumerate(dp):
    if d<=W:
        ans = i
print(ans)

Measured memory_bytes: 17584
#include <bits/stdc++.h>
#define yes { cout << "Yes\n"; exit(0); }
#define no { cout << "No\n"; exit(0); }

using namespace std;

int n;
map<int,int> mp;

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    int i, x;

    cin >> n;
    for(i=1; i<=n; ++i) cin >> x, mp[x]++;

    if(mp.count(0) && mp[0] == n) yes;
    if(n % 3) no;
    if(mp.size() > 3) no;

    int xr = 0;
    for(auto &it : mp)
    {
        if(it.second != n/3 && it.second != 2 * n/3) no;
        xr ^= it.first;
    }

    if(mp.size() == 2 && mp[0] != n/3) no;
    if(mp.size() == 3 && xr) no;
    yes;

    return 0;
}


Measured memory_bytes: 3840
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

using CostType = long double;
struct Edge {
  int src, dst; CostType cost;
  Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {}
  inline bool operator<(const Edge &x) const {
    return cost != x.cost ? cost < x.cost : dst != x.dst ? dst < x.dst : src < x.src;
  }
  inline bool operator<=(const Edge &x) const { return !(x < *this); }
  inline bool operator>(const Edge &x) const { return x < *this; }
  inline bool operator>=(const Edge &x) const { return !(*this < x); }
};

struct Dijkstra {
  using Pci = pair<CostType, int>;

  Dijkstra(const vector<vector<Edge>> &graph, const CostType CINF) : graph(graph), CINF(CINF) {}

  vector<CostType> build(int s) {
    int n = graph.size();
    vector<CostType> dist(n, CINF);
    dist[s] = 0;
    prev.assign(n, -1);
    priority_queue<Pci, vector<Pci>, greater<Pci>> que;
    que.emplace(0, s);
    while (!que.empty()) {
      CostType cost; int ver; tie(cost, ver) = que.top(); que.pop();
      if (dist[ver] < cost) continue;
      for (const Edge &e : graph[ver]) {
        if (dist[e.dst] > dist[ver] + e.cost) {
          dist[e.dst] = dist[ver] + e.cost;
          prev[e.dst] = ver;
          que.emplace(dist[e.dst], e.dst);
        }
      }
    }
    return dist;
  }

  vector<int> build_path(int t) {
    vector<int> res;
    for (; t != -1; t = prev[t]) res.emplace_back(t);
    reverse(ALL(res));
    return res;
  }

private:
  vector<vector<Edge>> graph;
  const CostType CINF;
  vector<int> prev;
};

int main() {
  int xs, ys, xt, yt, n; cin >> xs >> ys >> xt >> yt >> n;
  vector<int> x(n), y(n), r(n); REP(i, n) cin >> x[i] >> y[i] >> r[i];
  x.emplace_back(xs);
  y.emplace_back(ys);
  r.emplace_back(0);
  x.emplace_back(xt);
  y.emplace_back(yt);
  r.emplace_back(0);
  vector<vector<Edge> > graph(n + 2);
  REP(i, n + 2) REP(j, n + 2) {
    if (i == j) continue;
    long double dist = sqrtl(1LL * (x[i] - x[j]) * (x[i] - x[j]) + 1LL * (y[i] - y[j]) * (y[i] - y[j]));
    graph[i].emplace_back(i, j, max(dist - r[i] - r[j], 0.0L));
  }
  Dijkstra dij(graph, LINF);
  cout << dij.build(n)[n + 1] << '\n';
  return 0;
}


Measured memory_bytes: 73972
N = int(input())
W = [input()]
ans = 1
for i in range(N-1):
    new_word = input()
    if new_word in W:
        ans = 0
        break
    W.append(new_word)
    if W[i][-1]!=W[i+1][0]:
        ans = 0
        break

for j in range(N-i-2):
    input()

if ans == 0:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
bool isPrime(int x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

int main(){
    bool is_prime[1000000];

    is_prime[0] = is_prime[1] = false;
    for(int i=2;i<1000000;i++)
        is_prime[i] = true;

    for(int i=2;i*i<1000000;i++){
        if(is_prime[i]){
            for(int j=i*i;j<1000000;j+=i){
                is_prime[j] = false;
            }
        }
    }

    while(1){
        int n;
        cin >> n;

        if(cin.eof())   break;

        for(int i=n-1;i>0;i--){
            if(is_prime[i]){
                cout << i;
                break;
            }
        }
        for(int i=n+1;i<50022;i++){
            if(is_prime[i]){
                cout << " " << i << endl;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 4076
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    a, b = list(map(int, input().split()))
    l = []
    for i in range(math.ceil(max(a/0.08, b/0.1)), math.ceil(min((a+1)/0.08, (b+1)/0.1))):
        l.append(i)
    if l:
        print(l[0])
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5792
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

int main() {

    string s;
    cin>>s;

    ll n=s.size();

    vector<ll>a(n+1);

    rep(i,n)if(s[i]=='<')a[i+1]=a[i]+1;
    repr(i,n-1,0)if(s[i]=='>')a[i]=max(a[i],a[i+1]+1);

    ll sum=0;

    rep(i,n+1)sum+=a[i];

    cout<<sum<<endl;


}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct SegTree{
    int n; vector<ll> dat;
    // 初期化
    SegTree(int _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<ll>(2*n-1,0);
    }
    // k番目(0-indexed)の値をaに変更
    void update(int k, ll a){
        k+=n-1;
        dat[k]=a;
        //更新
        while(k>0){
            k=(k-1)/2;
            dat[k]=dat[2*k+1]+dat[2*k+2];
        }
    }
    // 内部的に投げられるクエリ
    ll _query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return 0;

        if(a<=l && r<=b) return dat[k];

        ll vl=_query(a,b,2*k+1,l,(l+r)/2);
        ll vr=_query(a,b,2*k+2,(l+r)/2,r);
        return vl+vr;
    }
    // [a,b)
    ll query(int a, int b){
        return _query(a,b,0,0,n);
    }
};

int main(){
    int n,d,a;
    cin >>n >>d >>a;

    vector<pair<int,int>> v(n);
    vector<int> ux(n);
    rep(i,n){
        int x,h;
        cin >>x >>h;
        h = (h+a-1)/a;
        v[i] = {x,h};
        ux[i] = x;
    }
    sort(all(v));
    sort(all(ux));

    ll ans = 0;
    SegTree st(n);
    rep(i,n){
        int x = v[i].fi-2*d;
        int idx = lower_bound(all(ux),x) - ux.begin();

        ll add = max(0LL, v[i].se-st.query(idx,i));
        st.update(i,add);
        ans += add;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <algorithm>

#define rep(var, start, end)  for(int var = start; var <= end; ++var)
#define drep(var, start, end) for(int var = start; var >= end; --var)

using namespace std;

int main() {

    unsigned int n;
    unsigned int d[100] = {0};

    cin >> n;
    rep(i, 0, n) cin >> d[i];

    sort(d, d+n, greater<unsigned int>());

    int cnt = 1;
    int now = d[0];
    rep(i, 1, n - 1) {
        if (d[i] < now) {
            ++cnt;
            now = d[i];
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
using namespace std;
int main(){
    long int N,p,i;
    cin >> N;
    p = 1;
    for(i = 1;i <= N;i++){
        p = (p * i) % 1000000007;
    }
    cout << p << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>
int main(){
	int n;
	char weather[3][8]={"Sunny","Cloudy","Rainy"};
	char compare[8];
	gets(compare);
	if(!strcmp(compare,weather[0]))
		puts(weather[1]);
	else if(!strcmp(compare,weather[1]))
		puts(weather[2]);
	else
		puts(weather[0]);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n;
  scanf("%lld", &n);
  ll a[n][n], dp[1 << n], cnt[1 << n];
  for(i = 0; i < n; ++i) for(j = 0; j < n; ++j) scanf("%lld", &a[i][j]);
  for(i = 0; i < (1 << n); ++i) dp[i] = 0;
  for(i = 0; i < (1 << n); ++i) {
    ll tmp = 0;
    for(j = 0; j < n; ++j) if(i & (1 << j)) tmp++;
    cnt[i] = tmp;
  }
  dp[0] = 1;
  for(i = 1; i < (1 << n); ++i) for(j = 0; j < n; ++j) if(i & (1 << j)) {
    if(a[j][cnt[i] - 1]) dp[i] += dp[i ^ (1 << j)], dp[i] %= mod;
  }
  printf("%lld", dp[(1 << n) - 1]);
  return 0;
}

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

int main(){

  int n;
  cin>>n;
  vector<int> p(n);
  vector<int> q(n);
  
  rep(i,n) cin>>p[i];
  rep(i,n) cin>>q[i];
  
  vector<int> a(n);
  rep(i,n) a[i]=i+1;
 
  map<vector<int>, int> mp;
  do{
  	mp[a]= mp.size();
  }while(next_permutation(a.begin(), a.end()));
  
  int ans=abs(mp[q]-mp[p]);
  cout << ans <<endl;                     
  return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
bitset<35000> x,y;
int main(){
	ll xx,yy;
	string s;
	cin>>s>>xx>>yy;
	ll n=s.size();
	ll spos = 0;
	while(spos<n && s[spos] == 'F'){
		xx--;
		spos++;
	}
	vector<ll> xmv,ymv;
	ll mde = 0,cnt = 0;
	for(int i=spos;i<n;i++){
		if(s[i]=='T'){
			if(mde == 0){
				xmv.pb(cnt);
			}
			else{
				ymv.pb(cnt);
			}
			cnt = 0;
			mde=1-mde;
		}
		else{
			cnt++;
		}
	}
	if(mde == 0){
		xmv.pb(cnt);
	}
	else{
		ymv.pb(cnt);
	}
	/*for(int i=0;i<xmv.size();i++){
		cout<<xmv[i]<<endl;
	}
	for(int i=0;i<ymv.size();i++){
		cout<<ymv[i]<<endl;
	}*/
	ll ze = 17000;
	x.set(ze);
	for(int i=0;i<xmv.size();i++){
		x = (x<<xmv[i])|(x>>xmv[i]);
	}
	y.set(ze);
	for(int i=0;i<ymv.size();i++){
		y = (y<<ymv[i])|(y>>ymv[i]);
	}
	if( x[xx+ze] & y[yy+ze] ){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

long long int search(const vector<pair<long long int, long long int>> &sushi, const long long int &C)
{
    auto leftSum = [&sushi, &C](int A, bool reset = false) {
        static vector<long long int> leftSum(sushi.size() + 2);
        static bool cached = false;
        if (!cached || reset)
        {
            for (int i = sushi.size() + 1; i >= 1; i--)
            {
                if (i == sushi.size() + 1)
                {
                    leftSum[i] = 0;
                }
                else
                {
                    leftSum[i] = leftSum[i + 1] + sushi[i - 1].second;
                }
            }
            cached = true;
        }
        if (A <= sushi.size())
        {
            return leftSum[A] - (C - sushi[A - 1].first) * 2;
        }
        else
        {
            return leftSum[A];
        }
    };
    auto rightSum = [&sushi](int B, bool reset = false) {
        static vector<long long int> rightSum(sushi.size() + 2);
        static bool cached = false;
        if (!cached || reset)
        {
            for (size_t i = 0; i < sushi.size() + 1; i++)
            {
                if (i == 0)
                {
                    rightSum[i] = 0;
                }
                else
                {
                    rightSum[i] = rightSum[i - 1] + sushi[i - 1].second;
                }
            }
            cached = true;
        }
        if (B != 0)
        {
            return rightSum[B] - sushi[B - 1].first;
        }
        else
        {
            return rightSum[B];
        }
    };
    leftSum(0, true);
    rightSum(0, true);
    long long int ans = 0;
    vector<long long int> maxAtoO(sushi.size() + 1);
    for (int B = sushi.size(); B >= 0; B--)
    {
        if(B == sushi.size()){
            maxAtoO[B] = leftSum(B+1);
        }
        else
        {
            maxAtoO[B] = max(leftSum(B + 1), maxAtoO[B + 1]);
        }
    }

    for (size_t B = 0; B <= sushi.size(); B++)
    {
            long long int sum = 0;
            sum += maxAtoO[B];
            sum += rightSum(B);
            if (ans < sum)
            {
                ans = sum;
            }
        
    }
    return ans;
}

int main(int argc, char const *argv[])
{
    int N;
    long long int C;
    scanf("%d %lld\n", &N, &C);
    vector<pair<long long int, long long int>> sushi(N), sushiReversed(N);
    for (size_t i = 0; i < N; i++)
    {
        scanf("%lld %lld\n", &(sushi[i].first), &(sushi[i].second));
        sushiReversed[N - i - 1].first = C - sushi[i].first;
        sushiReversed[N - i - 1].second = sushi[i].second;
    }
    long long int leftStart, rightStart;
    leftStart = search(sushi, C);
    rightStart = search(sushiReversed, C);
    cout << max(leftStart, rightStart) << endl;
    return 0;
}


Measured memory_bytes: 5760
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class AOddsOfOddness {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            double ans = 0;
            int n = in.nextInt();
            ans = (double) (n / 2 + n % 2) / n;
            out.printf("%.10f", ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23380
import java.util.*;
import java.util.stream.Collectors;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        final int N= scanner.nextInt();
        int result=0;
        for(int i=0;i<N;i++){
            result+=func(scanner.nextInt());
        }
        System.out.println(result);
    }
    public static int func(int n){
        if(n%2!=0){
            return 0;
        }
        return func(n/2)+1;
    }
}


Measured memory_bytes: 34064
#include<bits/stdc++.h>
using namespace std;
struct Node
{
    int num, p;
    string name;
    bool operator < (const Node &t) const
    {
        if(name == t.name)
            return num > t.num;
        return name < t.name;
    }
};
/*
bool cmp(Node a, Node b)
{
    return a.name < b.name;
}
*/
int n;

int main()
{
    Node node[120];
    scanf("%d", &n);
    //int i = 0, j = n;
    for(int i = 0; i < n; i++)
    {
        //scanf("%s %d", node[i].name, &node[i].num);
        cin >> node[i].name >> node[i].num;
        node[i].p = i + 1;
        //printf("*****%d*****\n", node[i].p);
    }
    //printf("**1**");
    sort(node, node + n);
    //printf("**1**");
    for(int i = 0; i < n; i++)
    {
        printf("%d\n", node[i].p);
        //cout << node[i].name << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#define MAX 1e8
//#define MAX 100
using namespace std;

int main(){
    int k, a=1;
    cin >>k;
    uint64_t ans = 7;
    while( a <= k){
        //int digit = to_string(9*a*k+1).size();
        if(ans%k == 0) break;
        ans = 10*ans + 7;
        ans %= k;
        a++;
    }
    if(a <= k) cout << a;
    else cout << -1;
    return 0;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
#define int long long
int *arr;
int memo[3000][3000][2];

// TIME COMPLEXITY = O(N^2)
// SPACE COMPLEXITY = O(N^2)

// find will return the required ans,  turn is 0 or 1 denoting taro and jiro resp

int find(int start, int end, int turn){
	
	// base case
	if(start == end){
		if(turn==0) return arr[start];
		else return -1*arr[start];
	}
	
	if(memo[start][end][turn] != -1) 
		return memo[start][end][turn];
	int ans;

	if(turn==0){
		int a = arr[start] + find(start+1,end,turn^1);
		int b = arr[end] + find(start, end-1, turn^1);
		ans = max(a,b);
	}
	else{
		int a = -1*arr[start] + find(start+1, end, turn^1);
		int b = -1*arr[end] + find(start, end-1, turn^1);
		ans = min(a, b);
	}

	memo[start][end][turn] = ans;
	return ans;
}

signed main(){
	
	int n;
	cin >> n;
	arr = new int[n];
	for(int i=0;i<n;i++) cin >> arr[i];

	for(int i=0;i<3000;i++){
		for(int j=0;j<3000;j++){
			memo[i][j][0] = -1;
			memo[i][j][1] = -1;
		}
	}

	cout << find(0, n-1, 0) << endl;
	

	return 0;
}

Measured memory_bytes: 144472
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

iscanl :: (Int -> a -> b -> a) -> a -> V.Vector b -> V.Vector a
iscanl !k !a !v = V.scanl' (\(!x) (!i, !v) -> k i x v) a (V.indexed v)

iscanlU
  :: (VU.Unbox a, VU.Unbox b)
  => (Int -> a -> b -> a)
  -> a
  -> VU.Vector b
  -> VU.Vector a
iscanlU !k !a !v = VU.scanl' (\(!x) (!i, !v) -> k i x v) a (VU.indexed v)

solve :: Int -> Int -> V.Vector (VU.Vector Bool) -> Int
solve !h !w !ahw = VU.last $ V.last dp
 where
  add !x !y = (x + y) `mod` (10 ^ 9 + 7)

  dp :: V.Vector (VU.Vector Int)
  dp = iscanl
    ( \(!i) (!acc) (!row) -> VU.tail $ iscanlU
      (\(!j) (!prev) (!ch) -> if ch then 0 else acc VU.! j `add` prev)
      0
      row
    )
    (VU.generate w (\(!i) -> if i == 0 then 1 else 0))
    ahw

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (h, w) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  ahw <-
    V.replicateM h
    $   VU.unfoldrN w (\bs -> Just (B.head bs == '#', B.tail bs))
    <$> B.getLine
  print $ solve h w ahw


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

int N, K;

int main(void){
    
    cin >> N >> K;
    ll ans = K;
    for(int i = 0; i < N - 1; ++i){
        ans *= K - 1;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PI;
#define MAX 99999999
int main(){
    string s;
    int sum=0;
    while(cin>>s){
        bool check=true;
        vi v;
        rep(i,s.size()){
            if(48<=s[i]&&s[i]<=57){
                v.push_back(s[i]-48);
                check=true;
            }else check=false;
            if((!check&&!v.empty())||i==s.size()-1){
                rep(j,v.size()){
                    int temp=v[j]*(int)pow((double)10, v.size()-j-1);
                    sum+=temp;
                    if(j==v.size()-1) v.erase(all(v));
                }
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

int d[110][110];
int a[1110], b[1110], c[1110];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    rep(i, 0, n){
        rep(j, 0, n){
            d[i][j] = INF;
        }
        d[i][i] = 0;
    }
    rep(i, 0, m){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        chmin(d[a[i]][b[i]], c[i]);
        chmin(d[b[i]][a[i]], c[i]);
    }
    rep(k, 0, n){
        rep(i, 0, n){
            rep(j, 0, n){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    int ans = 0;
    rep(i, 0, m){
        bool f = false;
        rep(j, 0, n){
            rep(k, 0, n){
                if(j == k) continue;
                if(d[j][k] == d[j][a[i]] + c[i] + d[b[i]][k]) f = true;
            }
        }
        if(!f) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>=0;(i)--)
typedef long long lint;

int main(){
   lint N,K;
   cin >>N>>K; lint M[N];
   rep(i,N)cin >> M[i];
   lint dp[N];
   dp[0]=0;
 repp(i,1,min(N,K+1)){
    dp[i]=abs(M[i]-M[0]);
 }
    
    
 
   rep(i,N-K-1){
       
       rep(j,K){
          if(j==0)dp[i+K+1]=dp[i+1+j]+abs(M[i+1+K]-M[i+j+1]);
          dp[i+K+1]=min(dp[i+K+1],dp[i+1+j]+abs(M[i+1+K]-M[i+j+1]));
       }
   }
   cout<<dp[N-1]<<endl;
   
 }



  


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

int main() {
  int N, K, x, dis, i;
  cin >> N >> K;
  dis = 0;
  
  for(i=0; i<N; i++){
    cin >> x;
    if(x < K - x)
      dis += 2 * x;
    else
      dis += 2 * (K - x);
  }
  cout << dis << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

template<typename T>
void maxi(T &a, T &b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T &b) {
	a = min(a, b);
}

int main() {
	makei(A);
	makei(B);
	say((A + B) % 24);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	int a;
	cin >> a;

	const long long l0 = 2;
	const long long l1 = 1;

	long long ln = l1;
	long long ln1 = l1;
	long long ln2 = l0;

	for (int i = 1; i < a; i++) {
		ln = ln1 + ln2;
		ln2 = ln1;
		ln1 = ln;
	}
	cout << ln << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int A = Integer.parseInt(sc.next());
        final int B = Integer.parseInt(sc.next());
        String[] ss = sc.next().split("-");
        
        if (ss.length > 1
                && ss[0].length() == A
                && ss[0].matches("[0-9]+")
                && ss[1].length() == B
                && ss[1].matches("[0-9]+")) {
            out.println("Yes");
        } else {
            out.println("No");
        }
        
        out.flush();
    }
}

Measured memory_bytes: 23764
#include <stdio.h>

int main(void){
    long long a, b, c, k;
    scanf("%lld", &a);
    scanf("%lld", &b);
    scanf("%lld", &c);
    scanf("%lld", &k);

    if(k % 2 != 0){
        if(b - a < -1000000000000000000 || b - a > 1000000000000000000){
            printf("Unfair\n");
        }else{
            printf("%lld\n", b - a);
        }
    }else{
        if(a - b < -1000000000000000000 || a - b > 1000000000000000000){
            printf("Unfair\n");
        }else{
            printf("%lld\n", a - b);
        }
    }
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
int main()
{
    //cout << fixed << setprecision(10);//小数点以下10桁出力
    long long int h , w;

    cin >> h >> w;

    long long int ans = h * w;
    
    if(h == 1 || w == 1){
        cout << 1 << endl;
    }else{
        if(ans % 2 == 0){
        cout << ans / 2 << endl;
        }else{
            cout << (ans / 2) + 1 << endl;
        }
    }


    
    
    return 0;
}

Measured memory_bytes: 256
s = gets.chomp.split("")
arr = []
arr << s
arr = arr.flatten
q = gets.chomp.to_i
key = "a"
#reverseを使ったら、TEL
q.times do |i|
    qq = gets.chomp.split(" ")
    if qq[0] == "1"
        if key == "a"
            key = "b"
        elsif key == "b"
            key = "a"
        end
    elsif qq[0] == "2"
        if qq[1] == "1" && key == "a"
            arr.unshift(qq[2])
        elsif qq[1] == "2" && key == "a"
            arr << qq[2]
        elsif qq[1] == "1" && key == "b"
            arr << qq[2]
        elsif qq[1] == "2" && key == "b"
            arr.unshift(qq[2])
        end
    end
end
if key == "a"
puts arr.join("")
elsif key == "b"
puts arr.reverse.join("")
end

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

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var S = IO.GetString();
            var ans = "Yes";
            for(int i = 0; i < S.Length; i++)
            {
                if ((i % 2 != 0 && S[i] == 'R') || (i % 2 == 0 && S[i] == 'L'))
                {
                    ans = "No";
                    break;
                }
            }

            Console.WriteLine(ans);
        }

    }


    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto&& [l, r] : a) {
    int x, y;
    cin >> x >> y;
    l = x - y;
    r = x + y;
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  vector<pair<int, int>> keep;
  keep.emplace_back(a[0]);
  for (auto&& [l, r] : a) {
    if (r <= keep.back().first) {
      keep.emplace_back(make_pair(l, r));
    }
  }
  cout << (int)keep.size() << '\n';
  return 0;
}

Measured memory_bytes: 4892
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    ll A, V, B, W, T;
    io.read(A, V, B, W, T);
    string ans = "NO";
    if(max(B - A, A - B) + W * T <= V * T) ans = "YES";
    cout << ans;
    return 0;
}

Measured memory_bytes: 3624
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// fn main() {
//     input! {
//         n: usize,
//         m: i32,
//         q: usize,
//         abcd: [(usize,usize,i32,i32);q],
//     }
//     let mut val = vec![1i32; n + 1];

//     println!("{:?}", dfs(&mut val, 1, m, &abcd));
// }

// fn dfs(buf: &mut Vec<i32>, d: usize, ub: i32, abcd: &Vec<(usize, usize, i32, i32)>) -> i32 {
//     let mut sum = 0;
//     if d == buf.len() {
//         for &(a, b, c, d) in abcd {
//             if buf[b] - buf[a] == c {
//                 sum += d;
//             }
//         }
//     } else {
//         for i in buf[d - 1]..ub + 1 {
//             buf[d] = i as i32;
//             sum = std::cmp::max(sum, dfs(buf, d + 1, ub, abcd));
//         }
//     }
//     sum
// }

fn main() {
    input! {
       n: usize,
       m: i32,
       q: usize,
       abcd: [(usize,usize,i32,i32);q],
    }

    // 今回の問題は前の数以上の数を入れていくので
    // 最初の基準となる数が必要。
    // [1 ,...n個]
    //  ↑これを基準点にする
    let mut buf = vec![1i32; n + 1];
    println!("{}", dfs(&mut buf, 1, m, &abcd))
}

fn dfs(buf: &mut Vec<i32>, index: usize, ud: i32, abcd: &Vec<(usize, usize, i32, i32)>) -> i32 {
    let mut result = 0;
    if index == buf.len() {
        // 最大値を計算
        for &(a, b, c, d) in abcd {
            if buf[b] - buf[a] == c {
                result += d;
            }
        }
    } else {
        for j in buf[index - 1]..ud + 1 {
            buf[index] = j;
            result = std::cmp::max(result, dfs(buf, index + 1, ud, abcd));
        }
    }
    result
}


Measured memory_bytes: 2120
#include<iostream>
#include<vector>
#include<utility>
using namespace std;
int main() {
  int H,W,K;
  cin >> H >> W >> K;
  vector<vector<int>> s(H,vector<int>(W));
  long long i,j,k;
  char c;
  for(i=0;i<H;i++)for(j=0;j<W;j++) {
    cin >> c;
    s[i][j] = c - '0';
  }
  vector<vector<vector<int>>> cnt(H,vector<vector<int>>(H,vector<int>(W+1,0)));
  for(i=0;i<H;i++)for(j=0;j<W;j++) {
    cnt[i][0][j+1] = cnt[i][0][j] + s[i][j];
    for(k=1;k<=i;k++)cnt[i-k][k][j+1] = cnt[i-k][k-1][j+1] + cnt[i][0][j+1];
  }
  int cut;
  long long ans = (long long)1 << 60,temp;
  for(i=(1<<(H-1));i<(1<<H);i++) {
    temp = -1;
    vector<pair<int,int>> d;
    cut = 0;
    for(j=0;j<H;j++) {
      if((i & (1<<j)) > 0) {
        d.push_back(pair<int,int>(cut,j-cut));
        cut = j+1;
        temp++;
      }
    }
    cut = 0;
    for(j=1;j<=W;j++) {
      for(k=0;k<d.size();k++) {
        if(cnt[d[k].first][d[k].second][j]-cnt[d[k].first][d[k].second][cut] > K) {
          if(cut == j-1)temp = 2000;
          cut = j-1;
          temp++;
          break;
        }
      }
    }
    ans = min(ans,max((long long)0,temp));
  }
  cout << ans << endl;
}

Measured memory_bytes: 4016
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n = int(input())
s = [''.join(sorted(input())) for i in range(n)]
c = collections.Counter(s)
count = list(c.values())
ans = 0
for num in count:
    if num >= 2:
        b = cmb(num, 2)
        ans += int(b)
print(ans)

Measured memory_bytes: 69592
#include<iostream>
#include<algorithm>

using namespace std;
int main(){
int N;
cin >>N;


int px[N],py[N],ph[N];
int mark;
for(int i=0;i<N;i++){
cin>>px[i]>>py[i]>>ph[i];
if(ph[i]!=0){
mark=i;
}
}
int h;

for(int x=0;x<=100;x++){
    for(int y=0;y<=100;y++){
        bool ans=true;
        h=ph[mark]+abs(x-px[mark])+abs(y-py[mark]);
        
        for(int i=0;i<N;i++){
           if(ph[i]!=max(h-abs(x-px[i])-abs(y-py[i]),0)){
           ans=false;
           break;
           }
        }
        if(ans){
            cout<<x<<" "<<y<<" "<<h<<endl;
        }
    }
}

 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
 main()
{
    int flag = 0;
    string n;
    cin>>n;
    for(int i=0; i < n.size(); i++)
        if(n[i]=='7')flag = 1;
    if(!flag)cout<<"No\n";
    else cout<<"Yes\n";


    return 0;
}


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

using namespace std;


char mp[520][520];
int n;
int cntb;
int hasb[520];
int ans = 1e9;

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

	for (int i = 0; i < n; i++) {
		scanf("%s", mp[i]);
	}

	for (int i = 0; i < n; i++) 
		for (int j = 0; j < n; j++)
			if (mp[i][j] == '#') {
				cntb++;
			}
			else {
				hasb[j] = 1;
			}

	int tmpans = 0;
	for (int i = 0; i < n; i++)
		tmpans += hasb[i];
	if (cntb == 0) {
		ans = -1;
	}
	else if (cntb == n*n) {
		ans = 0;
	}
	else {
		for (int raw = 0; raw < n; raw++) {
			int cnt = 0;
			for (int i = 0; i < n; i++) {
				if (mp[raw][i] == '.')
					cnt++;
			}

			int all_black = 0;
			
			if (cnt == 0) {
				all_black = 1;
			}
			else {
				for (int i = 0; i < n; i++)
					if (mp[i][raw] == '#')
						all_black = 1;
			}

			if (all_black == 0 && cnt != n) {
				ans = min(ans, tmpans + cnt + 1);
			}

			if (all_black) {
				ans = min(ans, tmpans + cnt);
			}

		}

	}

	if (ans == 1000000000) ans = -1;

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 512