akhauriyash/Code-Regression huggingface dataset:
#-*- coding:utf-8 -*-
"""
高橋くんは今日も1人でしりとりの練習をしています。

しりとりとは以下のルールで遊ばれるゲームです。

・はじめ、好きな単語を発言する
・以降、次の条件を満たす単語を発言することを繰り返す
　・その単語はまだ発言していない単語である
　・その単語の先頭の文字は直前に発言した単語の末尾の文字と一致する

高橋くんは、10秒間にできるだけ多くの単語を発言する練習をしています。
高橋くんが発言した単語の個数Nとi番目に発言した単語Wiが与えられるので、
どの発言もしりとりのルールを守っていたかを判定してください。
"""
def check(words):
    answer = "Yes"

    # 同じ単語を使っていないか確認
    for i in range(0, len(words)):
        for j in range(i+1, len(words)):
            if(words[i] == words[j]):
                answer = "No"

    # 単語の最初と最後が一致しているか確認
    for i in range(0, len(words)-1):
        if(words[i][-1] != words[i+1][0]):
            answer = "No"

    return answer


def main(words):
    answer = check(words)
    print(answer)


if __name__ == "__main__":
    num = int(input())  # 単語の個数の読み込み
    str = [input() for i in range(0, num)]  # 単語の読み込み
    main(str)


Measured memory_bytes: 3064
# input
n = int(input())
w_list = list(map(int, input().split()))

result = -1
for x in range(n-1):
    s1 = w_list[:x+1]
    s2 = w_list[x+1:]
    
    sum1 = sum(s1)
    sum2 = sum(s2)
    
    if abs(sum2 - sum1) < result or result == -1:
        result = abs(sum2 - sum1)
print(result)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    string s;
    int X, num, ans = 1000;

    cin >> s;

    for (int i = 0; i <= s.size() - 3; i++) {
        num = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');
        ans = min(ans, abs(753 - num));
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
OutPut = 0

for i in range(1,N+1):
  moji = str(i)    #文字列
  leng = len(moji) #文字長
  
  S = 0
  for j in range(leng):
    S += int(moji[j])
  
  if S >= A and S <= B:
    OutPut += i
    
print(OutPut)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
             cout << std::setprecision(15) ;
         int h,w,k;
         cin>>h>>w>>k;
         string s[h];
         for(int i=0;i<h;i++)cin>>s[i];
      
        int p,q,d[h][w+1],r0,ans=h*w+1;bool t=true;
        for(int i=0;i<h;i++)d[i][0]=0;
        for(int i=(1<<(h-1));i<(1<<h);i++){
            r0=0;
                p=1;q=0;t=true;
                for(int r=0;r<w;r++){
                       
               for(int j=0;j<h;j++){
                       
                       if(s[j][r]=='1')q++;
                       if(i&(1<<j)){
                               if(q>k){t=false;break;}
                             d[j][r+1]=d[j][r]+q;
                             if(d[j][r+1]>k+d[j][r0]){r0=r;p++;}
                               q=0;
                       }

               }
             
              
              
               //  cerr<<p<<' ';
                }
              //  cerr<<endl;
               
                if(t){
                       
                        for(int j=0;j<h;j++)if(i&(1<<j))p++;
                        ans=min(p-2,ans);
                }


        }
        cout<<ans;

         
}

        


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;
ll INF = 1e12+10;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
vector<pair<ll, ll> > pairs;
#define print1(x) cerr << "x = " << x << endl;
#define print2(x, y) cerr<< "x,y = "  << x << "," << y << endl;
#define print3(x, y, z) cerr << "x,y,z = " << x << "," << y << "," << z << endl;
#define print4(x, y, z, w) cerr << "x,y,z,w = " << x << "," << y << "," << z << "," << w << endl;

ll A[400000];
ll cnt[64];

ll mod = ll(1e9 + 7);

int main()
{
    int N;
    cin >> N;
    rep(i, N){
        cin >> A[i];
        for (int j = 0; j < 62; j++){
            if (A[i] & (1LL << j)){
                cnt[j] ++;
            }
        }
    }
    ll ans = 0LL;
    ll num = 1LL;
    for (int j = 0; j < 62; j++){
        ll tmp = cnt[j] *  ((ll)N - cnt[j]);
        tmp %= mod;
        (tmp *= num) %= mod;
        (ans += tmp) %= mod;
        (num *= 2LL) %= mod;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 2560
eval"T,U,A,X,B,Y="+`dd`.split*?,
x,y=(A-B)*T,(X-Y)*U
x,y=-x,-y if x>0
puts x+y==0 ? :infinity :(s=-x/y+=x;s<0 ? 0 : s*2+(x%y>0 ? 1 : 0))

Measured memory_bytes: 4092
import java.util.Scanner
object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val hs = Array.fill(n)(sc.nextInt)
  val (max, count)  = hs.foldLeft(0, 0){case ((max, count), h) => if (max <= h) (h, count + 1) else (max, count)}
  println(count)
}

Measured memory_bytes: 27228
import math

n = int(input())

a = input().split()
#あくまで文字列として格納されている

cnt = 2020202022

length_sum = 0
length_sum_start_left = 0

for i in range(n): #区間の数
  length_sum += int( a[i] )

for i in range(n-1): #切れ目の数
  length_sum_start_left += int( a[i] )
  if( abs( length_sum - length_sum_start_left - length_sum_start_left ) < cnt ):
    cnt = abs( length_sum - length_sum_start_left - length_sum_start_left )
  if( cnt == 0 ):
    break

print(cnt)

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int clamp(int v, int a, int b) {
    return v < a ? a : v > b ? b : v;
}

vector<pii> merge(vector<pii> v) {
    vector<pii> res; res.push_back(v[0]);
    rep(i, 1, v.size()) {
        if (v[i].first <= res.back().second) {
            res.back().second = max(res.back().second, v[i].second);
        } else {
            res.push_back(v[i]);
        }
    }
    return res;
}

int main() {
    int n, w, h; cin >> n >> w >> h;
    vector<pii> vw, vh;
    rep(i, 0, n) {
        int x, y, q; cin >> x >> y >> q;
        vw.push_back({clamp(x-q, 0, w), clamp(x+q, 0, w)});
        vh.push_back({clamp(y-q, 0, h), clamp(y+q, 0, h)});
    }
    sort(all(vw)); sort(all(vh));
    vw = merge(vw); vh = merge(vh);
    // cout << vw.back().first << " " << vw.back().second << endl;
    if (vw == vector<pii>{{0, w}} || vh == vector<pii>{{0, h}}) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 5496
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

n, m = map(int, input().split())
p = list(map(lambda x:int(x)-1, input().split()))

i2p = {}
p2i = {}

for i, pi in enumerate(p):
    i2p[i] = pi
    p2i[pi] = i

xy = [list(map(lambda x:int(x)-1, input().split())) for _ in range(m)]

uf = UnionFind(n)

for x, y in xy:
    uf.union(i2p[x], i2p[y])

ans = 0
for pi in p:
    if uf.find(pi) == uf.find(i2p[pi]):
        ans += 1

print(ans)

Measured memory_bytes: 116340
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
int C[100001];
int T[100000];
int G[100000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  rep(i, N) {
    int x;
    cin >> x;
    C[x]++;
    T[x%M]++;
  }
  rep(x, 100001) {
    G[x%M] += C[x]/2;
  }
  int sum = 0;

  // 0, M/2
  rep(x, M) {
    if ((x+x)%M != 0) continue;
    sum += T[x]/2;
    T[x] %= 2;
  }

  // x, y
  rep(x, M) {
    int y = (M-x)%M;
    if (x == y) continue;
    int s = min(T[x], T[y]);
    T[x] -= s;
    T[y] -= s;
    sum += s;
  }
  rep(x, M) {
    sum += min(T[x]/2, G[x]);
  }
  cout << sum << "\n";
  return 0;
}


Measured memory_bytes: 1408
def main():
    x, k, d = map(int, input().split())
    # x > 0
    if x < 0:
        x = -1 * x
    #the number of d in x
    r = abs(x) // d
    k_rest = k - r
    if r > 0 and k_rest < 0:
        print(x - k * d)
        exit()

    x_r = x - d * r
    x_l = x_r - d

    # print(f"xr: {x_r}\nxl: {x_l}\nk: {k_rest}")

    if k_rest % 2 == 0:
        print(abs(x_r))
    else:
        print(abs(x_l))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9096
#include <stdio.h>

void Merge(int*, int, int, int);
void MergeSort(int*, int, int);

int count=0;

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

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  MergeSort(A,0,n);
  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
  printf("%d\n",count);
  
  return 0;
}

void Merge(int *A, int left, int mid, int right){
  int i, j, k, n1, n2;
  int L[250002], R[250002];
  n1 = mid - left;
  n2 = right - mid;
  for(i=0;i<n1;i++)
    L[i] = A[left+i];
  for(i=0;i<n2;i++)
    R[i] = A[mid+i];
  L[n1]=2000000000;
  R[n2]=2000000000;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      count++;
    }
    else{
      A[k]=R[j];
      j++;
      count++;
    }
  }
}

void MergeSort(int *A, int left, int right){
  int mid;
  if (left+1<right){
    mid = (left + right)/2;
    MergeSort(A, left, mid);
    MergeSort(A, mid, right);
    Merge(A, left, mid, right);
  }
}

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

namespace id_0031cs
{
    class Program
    {
        static void Main(string[] args)
        {
            string tmp;
            while((tmp = Console.ReadLine())!=null)
            {
                List<int> vs = new List<int>();
                var weight = int.Parse(tmp);
                for(int i = 512; i > 0; i = i / 2)
                {
                    if (weight == 0) break;
                    if(weight >= i)
                    {
                        vs.Add(i);
                        weight = weight - i;
                    }
                }
                vs.Sort();
                var result = vs.ConvertAll(x => x.ToString()).ToArray();
                Console.WriteLine(string.Join(" ", result));

            }
        }
    }
}



Measured memory_bytes: 9236
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define rg register
#define LL long long
#define __space putchar(' ')
#define __endl putchar('\n')
template <typename qwq> inline void read(qwq & x)
{
    x = 0;
    rg int f = 1;
    rg char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    x *= f;
}
template <typename qaq> inline void print(qaq x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}
int even,odd,n,x;
int main()
{
	read(n);
	for (rg int i = 1;i <= n;++i)
	{
		read(x);
		if (x & 1) ++odd;
		else ++even;
	}
	if (odd & 1) printf("NO");
	else printf("YES");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define em3 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define F first
#define S second
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define EPS 1e-7
#define iof freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
long long mod = 1e9;
const int N = 1e9;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1);
typedef complex <ll> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
int main()
{
    em3
    string s;
    cin >> s;
    if(s == "Sunny")
        cout << "Cloudy";
    else if(s == "Cloudy")
        cout << "Rainy";
    else
        cout << "Sunny";


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll N;
    cin>>N;
    ll a[N];
    rep(0,i,N)cin>>a[i];
    sort(a,a+N);
    cout<<a[N/2]-a[N/2-1]<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
class Node{
public:
  int location;
  int p,l,r;
  Node(){}
};
class Point{
public:
  int id,x,y;
  Point(){}
  Point(int id,int x,int y): id(id),x(x),y(y){}
  bool operator < (const Point &p){return id<p.id;}
};
static const int MAX =1000000;
static const int NIL = -1;
int n;
Point P[MAX];
Node T[MAX];
int np;
bool lessX(const Point &p1,const Point &p2){return p1.x<p2.x;}
bool lessY(const Point &p1,const Point &p2){return p1.y<p2.y;}
int makeKDTree(int l,int r, int d){
  if(!(l<r))return NIL;
  int mid=(l+r)/2;
  int t=np++;
  if(d%2==0)sort(P+l,P+r,lessX);
  else sort(P+l,P+r,lessY);
  T[t].location=mid;
  T[t].l=makeKDTree(l,mid,d+1);
  T[t].r=makeKDTree(mid+1,r,d+1);
  return t;
}
void find(int v,int sx,int tx,int sy,int ty,int d,vector<Point> &ans){
  int x=P[T[v].location].x;
  int y=P[T[v].location].y;
  if(sx<=x&&x<=tx&&sy<=y&&y<=ty)ans.push_back(P[T[v].location]);
  if(d%2==0){
    if(T[v].l!=NIL)if(sx<=x)find(T[v].l,sx,tx,sy,ty,d+1,ans);
    if(T[v].r!=NIL)if(x<=tx)find(T[v].r,sx,tx,sy,ty,d+1,ans);
  }
  else{
    if(T[v].l!=NIL)if(sy<=y)find(T[v].l,sx,tx,sy,ty,d+1,ans);
    if(T[v].r!=NIL)if(y<=ty)find(T[v].r,sx,tx,sy,ty,d+1,ans);
  }
}
int main(){
  int x,y;
  cin>>n;
  rep(i,n){
    scanf("%d %d",&x,&y);
    P[i]=Point(i,x,y);
    T[i].l=T[i].r=T[i].p=NIL;
  }
  np=0;
  int root=makeKDTree(0,n,0);
  int q;
  cin>>q;
  int sx,sy,tx,ty;
  vector<Point>ans;
  rep(i,q){
    scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
    ans.clear();
    find(root,sx,tx,sy,ty,0,ans);
    sort(ans.begin(),ans.end());
    rep(j,ans.size())printf("%d\n",ans[j].id);
    cout<<endl;
  }return 0;
}


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

namespace CSharpSample01
{
    
    

    class Program
    {
      
        static void Main(string[] args)
        {

            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');

            int s = 1001;

            int[] data = new int[s];
            
            long ans = 1;
            int sisu_cnt = 0;
            
            for(int i = 0; i < n; i++)
            {
                int m = int.Parse(str[i]);

                
                //kは素因数
                for (int k = 2; k <= Math.Sqrt(m); k++)
                {
                    sisu_cnt = 0;
                    while (m % k == 0)
                    {
                        sisu_cnt++;                       
                        m = m / k;
                    }

                    if (data[k] < sisu_cnt) data[k] = sisu_cnt;                    
                    
                }
                if (m != 1 && data[m] == 0) data[m] = 1;
            }

            for(int i = 2; i < s; i++)
            {               
                if (data[i] != 0) ans *= (long)Math.Pow(i, data[i]);
            }

            Console.WriteLine(ans);

        }
    }
}



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

//namespace _1_A
//{
class Program
{
    static void Main(string[] args)
    {
        int i;
        int ans = 0;
        int[] iarray = new int[3];
        string x = Console.ReadLine();
        string[] sarray = x.Split(' ') ;
        iarray[0] = int.Parse(sarray[0]);
        iarray[1] = int.Parse(sarray[1]);
        iarray[2] = int.Parse(sarray[2]);

        for(i = iarray[0]; i <= iarray[1]; i++)
        {
            if((iarray[2] % i) == 0)
                ans++;
        }

        Console.WriteLine(ans);

        //Console.Read();
    }
}
//}

Measured memory_bytes: 9172
#include <iostream>
using namespace std;
int main() {
    int a{ 0 };
    cin >> a;
    int h = a / 3600;
    int amari = a % 3600;
    int m = amari / 60;
    int s = amari % 60;
    
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


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

using namespace std;

int n;

int main()
{
    cin >> n;
    if (n==25)
        cout << "Christmas" << endl;
    else if (n==24)
        cout << "Christmas Eve" << endl;
    else if (n==23)
        cout << "Christmas Eve Eve" << endl;
    else if (n==22)
        cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n, m;
vector<int>G[114514];
int a[114514], b[114514];
int depth[114514], par[114514];
int hon[114514];
vector<P>ans;
set<P>st;
void dfs(int x) {
	rep(i, G[x].size()) {
		int to = G[x][i];
		if (depth[to] == -1) {
			par[to] = x; depth[to] = depth[x] + 1;
			st.insert({ min(to,x),max(to,x) });
			dfs(to);
		}
	}
}
signed main() {
	cin >> n >> m;
	if (m % 2) {
		cout << -1 << endl; return 0;
	}
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	REP(i, n)depth[i] = -1;
	dfs(0);
	rep(i, m) {
		if (st.find(make_pair(min(a[i], b[i]), max(a[i], b[i]))) == st.end()) {
			ans.push_back({ a[i],b[i] });
			hon[a[i]]++;
		}
	}
	vector<P>kouho;
	rep(i, n) {
		kouho.push_back({ depth[i],i });
	}
	sort(all(kouho), greater<>());
	rep(i, n - 1) {
		if (hon[kouho[i].second] % 2) {
			ans.push_back({ kouho[i].second,par[kouho[i].second] });
		}
		else {
			ans.push_back({ par[kouho[i].second],kouho[i].second });
			hon[par[kouho[i].second]]++;
		}
	}
	for (auto p : ans)cout << p.first + 1 << " " << p.second + 1 << endl;
}

Measured memory_bytes: 32116
#include<stdio.h>
int main(void)
{
	int n,x,cnt[10],i,j;
	while(1){
		for(i=0;i<10;i++){
			cnt[i]=0;
		}
		scanf("%d",&n);
		if(n<1)break;
		for(i=0;i<n;i++){
			scanf("%d",&x);
			cnt[x]++;
		}
		for(i=0;i<10;i++){
			if(cnt[i]>0){
				for(j=0;j<cnt[i];j++){
					printf("*");
				}
				printf("\n");
			}
			else{
				printf("-\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1000
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>

using namespace std;

#define ll long long
#define f0(i,n)for(i=0;i<n;i++)
#define f1(i,n)for(i=1;i<=n;i++)
#define fc(i,c,n)for(i=c;i<=n;i++)
#define f0r(i,n)for(i=n-1;i>=0;i--)
#define f1r(i,n)for(i=n;i>0;i--)
#define fcr(i,c,n)for(i=n;i>=c;i--)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef list<ll> LST;
typedef vector<ll> VEC;
typedef map<ll, ll> MAP;

long long i, j, q;

int main() {
	IO;
	//ifstream cin("In.txt");
	ll n,a=10000000000000000, b, ans = 0,cnta=0;
	cin >> n;
	f0(i, n) {
		cin >> b;
		if (b < 0)
			cnta++;
		a = min(a, abs(b));
		ans += abs(b);
	}
	if (cnta & 1)
		ans -= 2 * a;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

struct Point
{
    double x,y;
    Point(){ x = y = 0.0; }
    Point(double _x, double _y) : x(_x), y(_y){}

    Point operator+ (Point p)
    {
        return Point(p.x + x, p.y + y);
    }

    Point operator- (Point p)
    {
        return Point(x - p.x, y - p.y);
    }

    double operator* (Point p)
    {
        return p.x * x + p.y * y;
    }

    Point operator* (double t)
    {
        return Point(x*t, y*t);
    }

};

Point projection(Point p1, Point p2, Point o)
{
    Point a = (p2 - p1);
    Point b = (o - p1);
    return p1 + a * ( (a * b) / (a * a) );
}

int main()
{
    cout.precision(10);
    cout << fixed;
    int q;
    Point p1, p2, o, ans;
    cin >> p1.x >> p1.y >> p2.x >> p2.y;
    cin >> q;
    while(q--)
    {
        cin >> o.x >> o.y;
        ans = projection(p1, p2, o);
        Point aux = o + (ans - o) * 2.0;
        cout << aux.x << " " << aux.y << '\n';
    }

    return 0;
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

ll f(ll A){
  if(A <= 0) return 0;
  ll cnt = (A+1) % 4;
  ll res = 0;
  for(ll i = A-cnt+1; i <= A; i++){
    if(i == A-cnt+1) res = i;
    else res ^= i;
  }
  return res;
}

int main(){
  ll A,B;
  cin >> A >> B;
  ll ans =  f(B) ^ f(A-1) ;
  cout << ans << endl;
}


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

using namespace std;

int main(){
	int N;
	cin>>N;
	vector <int> s(N);
	for(int i=0 ; i<N ; i++){
		cin>>s[i];
	}
	
	int score=0;
	int maxscore=0;
	bool sta=false;
	
	for(int i=0 ; i<N ; i++){
		score+=s[i];
	}
	if(score%10!=0){
		cout<<score<<"\n";
		return 0;
	}
	score=0;
	
	for(int i=0 ; i<N ; i++){
		for(int j=0 ; j<N ; j++){
			if(j==i)continue;
			score+=s[j];
		}
		if(maxscore<score && score%10!=0){
			maxscore=score;
			sta=true;
		}
		score=0;
	}
	if(sta){
		cout<<maxscore<<"\n";
		return 0;
	}
	cout<<0<<"\n";
	
	return 0;
}


Measured memory_bytes: 256
import math

def main():
    A,B,H,M = [int(x) for x in input().split()]
    degH = (0.5*H*60 + 0.5*M)
    degM = 6*M
    theta = abs(degH-degM)
    if theta == 180:
        print(A+B)
        return
    if theta > 180:
        theta = 180 - (theta - 180)
    # print(degH,degM,theta)
    # print(math.cos(math.radians(theta)))
    print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(theta))))

if __name__ == '__main__':
    main()


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


int main(void) {
    int N, M;
    cin >> N >> M;
    int M_list[M];
    for ( int i = 0; i < M; i++ ) {
        M_list[i] = 0;
    }
    for ( int i = 0; i < N; i++ ) {
        int K;
        cin >> K;
        for ( int i = 0; i < K; i++ ) {
            int a;
            cin >> a;
            M_list[a-1] += 1;
        }
    }
    int ans = 0;
    for ( int i = 0; i < M; i++ ) {
        if ( M_list[i] == N ) {
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int n, cnt = 1;
void dfs(vector<string>v) {
	if (cnt == n) {
		for (string i : v) {
			for (char c : i) printf("%c", c);
			printf("\n");
		}
		return;
	}
	vector<string>res;
	for (string s : v) {
		set<char>st;
		for (char c : s) st.insert(c);
		rep(i, st.size() + 1) res.emplace_back(s + char('a' + i));
	}
	cnt++;
	dfs(res);
}
int main() {
	scanf("%d", &n);
	dfs({ "a" });
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    string S, T; cin >> S >> T;
    cout << T+S << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class arc092_f {
private:
    void dfs(int u, const vector<vector<int>> &g, vector<int> &vis, int nogo, int id) {
        vis[u] = id;
        for (int v : g[u]) {
            if (!vis[v] && v != nogo) {
                dfs(v, g, vis, nogo, id);
            }
        }
    }
public:
    void solve(istream& in, ostream& out) {
        int N, M;
        in >> N >> M;
        vector<int> a(M), b(M);
        vector<vector<int>> g(N);
        for (int i = 0; i < M; ++i) {
            in >> a[i] >> b[i];
            --a[i];
            --b[i];
            g[a[i]].push_back(b[i]);
        }
        vector<vector<int>> reachable(N, vector<int>(N, 0));
        for (int u = 0; u < N; ++u) {
            dfs(u, g, reachable[u], -1, 1);
        }
        vector<vector<int>> reach_from_a(N, vector<int>(N, 0));
        vector<vector<int>> reach_from_b(N, vector<int>(N, 0));
        for (int u = 0; u < N; ++u) {
            sort(begin(g[u]), end(g[u]));
            for (int v : g[u]) {
                if (!reach_from_a[u][v])
                    dfs(v, g, reach_from_a[u], u, v + 1);
            }
            for (int i = (int)g[u].size() - 1; i >= 0; --i) {
                int v = g[u][i];
                if (!reach_from_b[u][v])
                    dfs(v, g, reach_from_b[u], u, v + 1);
            }
        }
        for (int i = 0; i < M; ++i) {
            bool cond1 = reachable[b[i]][a[i]];
            bool cond2 = reach_from_a[a[i]][b[i]] != b[i] + 1
                        || reach_from_b[a[i]][b[i]] != b[i] + 1;
            out << ((cond1 == cond2) ? "same" : "diff") << "\n";
        }
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	arc092_f solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 16896
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
#define dbg(vec) for (size_t _ = 0; _ < vec.size(); ++_){std::cerr << #vec << "[" << _ << "] : " << vec[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

const double pi = 3.141592653589793;
vector<double> x(101), y(101);
int n; 

inline double naiseki(const double& x1, const double& y1, const double& x2, const double& y2) {
  return x1 * x2 + y1 * y2;
}

// 角度 theta の方向を最終的に向くとして計算
// theta は radian
double calc(const double& theta) {
  double res = 0.0;
  double dx = cos(theta), dy = sin(theta);
  for (int i = 0; i < n; ++i) {
    res += max(0.0, naiseki(dx, dy, x[i], y[i]));
  }
  return res;
}

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

  auto start = chrono::system_clock::now();

  cin >> n;
  rep(i, n) cin >> x[i] >> y[i];

  int step = 7777777;

  double ans = 0.0;

  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> r(0, step);

  auto msec = 0.0;

  do {
    double theta = 2.0 * pi * r(mt) / step;
    chmax(ans, calc(theta));
    auto end = chrono::system_clock::now();
    auto dur = end - start;
    msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  } while (msec <= 998);

  cout << setprecision(15) << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 1000
#define MO 1000000007
using namespace std;
typedef long long LL;
struct Matrix
{
	LL M[2][2];
	Matrix operator * (const Matrix &b)
	{
		Matrix ret;
		memset(ret.M,0,sizeof(ret.M));
		for(int i=0;i<2;i++)
			for(int j=0;j<2;j++)
				for(int k=0;k<2;k++)
					ret.M[i][j]+=M[i][k]*b.M[k][j]%MO;
		return ret;
	}
};
LL k;
int n,m;
char Map[MAXN+5][MAXN+5];
LL lr,ud,ev,eh,v;
LL PowMod(LL a,LL b)
{
	LL ret=1LL;
	while(b)
	{
		if(b&1)
			ret=ret*a%MO;
		a=a*a%MO;
		b>>=1LL;
	}
	return ret;
}
Matrix PowMod(Matrix a,LL b)
{
	Matrix ret;
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			if(i==j)
				ret.M[i][j]=1;
			else
				ret.M[i][j]=0;
	while(b)
	{
		if(b&1)
			ret=ret*a;
		a=a*a;
		b>>=1LL;
	}
	return ret;
}
int main()
{
	scanf("%d %d %lld",&n,&m,&k);
	for(int i=1;i<=n;i++)
		scanf("%s",Map[i]+1);
	for(int j=1;j<=m;j++)
		if(Map[1][j]=='#'&&Map[n][j]=='#')
			ud++;
	for(int i=1;i<=n;i++)
		if(Map[i][1]=='#'&&Map[i][m]=='#')
			lr++;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(Map[i][j]=='#')						v++;
			if(Map[i][j]=='#'&&Map[i][j+1]=='#')	eh++;
			if(Map[i][j]=='#'&&Map[i+1][j]=='#')	ev++;
		}
	if(ud!=0&&lr!=0)
	{
		printf("1\n");
		return 0;
	}
	if(ud==0&&lr==0)
	{
		LL ans=PowMod(v,k-1);
		printf("%lld\n",ans);
		return 0;
	}
	if(lr!=0&&ud==0)
	{
		swap(lr,ud);
		swap(eh,ev);
	}
	Matrix a;
	a.M[0][0]=v;
	a.M[0][1]=0;
	a.M[1][0]=ev;
	a.M[1][1]=ud;
	a=PowMod(a,k-1);
	LL ansV=(a.M[0][0]*1LL+a.M[0][1]*0)%MO;
	LL ansE=(a.M[1][0]*1LL+a.M[1][1]*0)%MO;
	printf("%lld\n",((ansV-ansE)+MO)%MO);
	return 0;
}

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

#define ll long long
#define fast_in_out  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
    fast_in_out;
    int n;
    cin >> n;
    bool found = false;
    while(n != 0)
    {
        if(n % 10 == 7)
        {
            found = true;
            break;
        }
        n /= 10;
    }
    if(found)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


Measured memory_bytes: 3568
from collections import Counter

N, *X = map(int, open(0).read().split())

x = Counter([i + 1 + X[i] for i in range(N)])
y = Counter([i + 1 - X[i] for i in range(N)])

ans = 0
for k, v in x.items():
    ans += v * y[k]
    
print(ans)


Measured memory_bytes: 150064
#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
*/
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
#include <typeinfo>
/**/ 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

void solve()
{
    int n;
    cin>>n;
    vll v(n);
    ll total=0;
    rep(i,n)
    {        
        cin>>v[i];
        total^=v[i];
    }
    rep(i,n)
    {
        ll hi=total^v[i];
        cout<<hi<<" ";
    }
    cout<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int cnt;
    cnt = 0;
    for( int i=0; i<=n-3; i++){
        if( s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            cnt++;
        }
    }
    cout << cnt << endl;
}




Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

#define int long long
#define dotimes(i, n) for (int i = 0, i##max__ = (n); i < i##max__; i++)
#define whole(f, x, ...) ([&](decltype((x)) c) { return (f)(begin(c), end(c), ## __VA_ARGS__); })(x)

int rint() {
  int x;
  scanf("%lld", &x);
  return x;
}

void wint(int x) {
  printf("%lld\n", x);
}

template<typename T> int size(T const& c) { return static_cast<int>(c.size()); }
template <typename T> bool maxs(T& a, T const& b) { return a < b ? a = b, true : false; }
template <typename T> bool mins(T& a, T const& b) { return a > b ? a = b, true : false; }
inline int lg(int x) { return 63 - __builtin_clzll(static_cast<unsigned int>(x)); }

class segment_tree {
  vector<int> xs;
public:
  segment_tree(int n) : xs(1 << (lg(2 * n - 1) + 1)) {}
  segment_tree(int n, function<int(int)> f) : segment_tree(n) {
    const int m = ::size(xs);
    dotimes(i, n)
      xs[m/2+i] = f(i);
    for (int i = m/2-1; i >= 1; i--)
      xs[i] = min(xs[2*i], xs[2*i+1]);
  }
  int operator[](int i) {
    return xs[::size(xs)/2+i];
  }
  void update(int i, int x) {
    i += ::size(xs) / 2;
    xs[i] = x;
    for (i /= 2; i >= 1; i /= 2)
      xs[i] = min(xs[2*i], xs[2*i+1]);
  }
  int query(const int i, const int j) {
    function<int(int, int, int)> rec;
    rec =
      [&](int k, int a, int b) {
        if (i <= a && b <= j)
          return xs[k];
        int c = a + (b - a) / 2;
        return j <= c ? rec(2*k, a, c) : c <= i ? rec(2*k+1, c, b) : min(rec(2*k, a, c), rec(2*k+1, c, b));
      };
    return rec(1, 0, ::size(xs)/2);
  }
};

signed main() {
  const int n = rint();
  const int q = rint();
  segment_tree st(n, [](int i) { return 2147483647; });
  dotimes(i, q) {
    const int com = rint();
    const int x = rint();
    const int y = rint();
    if (com)
      wint(st.query(x, y+1));
    else
      st.update(x, y);
  }
  return 0;
}



Measured memory_bytes: 4472
def main():
    N, M = map(int, input().split())

    i = 0
    AB = [0 for i in range(N)]
    while i < M:
        a, b = map(int, input().split())
        AB[a-1] += 1
        AB[b-1] += 1
        i += 1

    for i in AB:
        if i % 2 > 0:
            print('NO')
            break
    else:
        print('YES')

main()


Measured memory_bytes: 3888
#include <stdio.h>
#include <stdlib.h>

struct pr{
  int a;
  int b;
};

int asc(const void *x, const void *y){
  struct pr *A = (struct pr *)x;
  struct pr *B = (struct pr *)y;
  return A->a - B->a;
}

int
main(int argc, char *argv[])
{
  int n; long long k; struct pr p[100000];
  scanf("%d %lld", &n, &k);
  for(int i = 0; i < n; i++) scanf("%d %d", &p[i].a, &p[i].b);
  qsort(p, n, sizeof(struct pr), asc);
 
  long long sum = 0;
  for(int i = 0; i < n; i++){
    sum += (long long)p[i].b;
    if(sum >= k){
      printf("%d\n", p[i].a);
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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 ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a[22][22], dp[22][1<<21];

signed main() {
	cin >> n;
	rep(i,n) rep(j,n) cin >> a[i][j];
	dp[0][0] = 1;
	rep(i,n) rep(b,1<<n) if (dp[i][b]) rep(j,n) if (a[i][j] && ((b&(1<<j))==0))
		(dp[i+1][b|(1<<j)] += dp[i][b]) %= mod;
	cout << dp[n][(1<<n)-1] << endl;
}

Measured memory_bytes: 309504
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>



using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main()
{
	int n; cin >> n;
	vector<ll> a(n + 1);
	vector<ll> b(n);
	ll sum = 0;
	rep(i, n+1) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n+1)
		sum += a[i];
	rep(i, n) {
		if (a[i] > b[i]) {
			a[i] -= b[i];
			continue;
		}
		else if (a[i] < b[i]) {
			b[i] -= a[i];
			a[i] = 0;
			if (a[i + 1] > b[i]) {
				a[i + 1] -= b[i];

			}
			else
				a[i + 1] = 0;
		}
		else {
			a[i] = 0;
			b[i] = 0;
		}
	}
		ll sa = 0;
		rep(i, n+1)
		sa += a[i];
		cout << sum - sa;
	
}


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

int main() {
	long N, K;
	std::cin >> N >> K;
	std::vector<int> vec(N);
	for (int i = 0; i < K; i++) {
		int d;
		std::cin >> d;
		for (int k = 0; k < d; k++) {
			int place;
			std::cin >> place;
			vec[place - 1] = 1;
		}
	}
	int count = 0;
	for (auto num : vec) {
		if (num == 0) {
			++count;
		}
	}
	std::cout << count << std::endl;
	return 0;
}

Measured memory_bytes: 3172
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        v: [(usize1, usize); m]
    }
    let mut l = 0;
    let mut r = n;
    for (a, b) in v {
        l = max(l, a);
        r = min(r, b);
    }
    if l > r {
        println!("0");
    } else {
        println!("{}", r - l);
    }
}


Measured memory_bytes: 6396
def solve(k, i):
    if k == 0: return True
    if i < n and min(A[i:]) <= k <= sum(A[i:]):
        r1 = solve(k-A[i], i+1)
        if r1: return r1
        r2 = solve(k, i+1)
        if r2: return r2
n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())
for k in M:
    print 'yes' if solve(k, 0) else 'no'

Measured memory_bytes: 6452
w = int(input())
n = int(input())

ans = [i for i in range(w)]
for i in range(n):
    a,b = list(map(int, input().split(",")))
    temp = ans[a-1]
    ans[a-1] = ans[b-1]
    ans[b-1] = temp

for i in ans:
    print(i+1)

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

int main(){
  string S;
  cin >> S;
  
  int a =0;
  int z =0;
  
  for(int i=0; i<S.size(); i++){
    if(S.at(i) == 'A'){
      a = i;
      break;
    }
  }
  
  int j =S.size() - 1;
  while(j>= 0){
    if(S.at(j) == 'Z'){
      z = j;
      break;
    }
   j--;
  }
  cout << z - a + 1 << endl;      
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
using namespace std;
int main(){

  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<=N-1;i++){
  
    cin>>A[i];
  }
  bool flag=0;
  int checknum=1;
  int count=0;
  while(flag==0){
  
    checknum*=2;
    for(int i=0;i<=N-1;i++){
    
      if(A[i]%checknum!=0){
      
        flag=1;
        break;
      }
    }
    if(flag==0)count++;
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,x;
  cin>>n;
  vector<int>p(n),q(n);
  vector<int>r(n);
  x=1;
  for(int i=0;i<n;i++){
    cin>>p[i];
    r[i]=i+1;
  }
  for(int i=0;i<n;i++)
    cin>>q[i];
  do{
    if(p==r)a=x;
    if(q==r)b=x;
    x++;
  }while(next_permutation(r.begin(),r.end()));
  cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
  int i, j, k;
  long X;
  long A, B;
  long a, b;
  long ans = 0;
  scanf("%ld", &X);
  for (j = 0; j < 1000; j++) {
    A = j * j * j * j * j;
    for (i = 0; i < 1000; i++) {
      B = i * i * i * i * i;
      if ((A - B) == X) {
        printf("%d %d", j ,i);
        return 0;
      }
      B *= (-1);
      if ((A - B) == X) {
        printf("%d %d", j, i * (-1));
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool isvalid(int h, int w, int H, int W){
	if(h <0 || w < 0) return false;
	if(h >=H ||w >= W) return false;
	return true;
}
int main(){
	int x[] = {0,0,-1,1,1,1,-1,-1};
	int y[] = {1,-1,0,0,1,-1,1,-1}; 
	int H, W;
	string S;
	
	cin >> H >> W;
	vector< vector<int> > grid(H, vector<int>(W,0));
	for (int i = 0; i < H; i ++){
		cin >> S;
		for(int j = 0; j < W; j++){
			if (S[j] == '#'){
				grid[i][j] = -1; 
			}
		}
	}
	for (int i = 0; i < H; i++){
		for(int j =0; j < W; j ++){
			int count = 0;
			if (grid[i][j] == -1) continue;
			for (int k = 0; k < 8; k++){
				if (isvalid(i+x[k], j+y[k], H, W)){
					if(grid[i+x[k]][j+y[k]] == -1) count++;				
				}
			}
			grid[i][j] = count; 
		}
	}
	for (int i = 0; i < H; i++){
		for(int j =0; j < W; j ++){
			if(grid[i][j] == -1) cout << '#';
			else cout << grid[i][j];
		}
		cout << endl;
	}
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    int N;
    cin >> N;
    vector<int> L(N);
    int sum = 0;
    REP(i, N) {
        cin >> L.at(i);
        sum += L[i];
    }
    if (*max_element(ALL(L)) < sum - *max_element(ALL(L))) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256