akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

void solve(int n, int m){
    auto A = make_v(n, n, 0);
    auto B = make_v(m, m, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> A[i][j];
        }
    }
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> B[i][j];
        }
    }
    vector<pair<int, int>> ans;
    for (int k = 0; k < 4; ++k) {
        for (int i = 0; i+m <= n; ++i) {
            for (int j = 0; j+m <= n; ++j) {
                int ok = 1;
                for (int y = 0; y < m; ++y) {
                    for (int x = 0; x < m; ++x) {
                        if(~B[y][x] && A[i+y][j+x] != B[y][x]){
                            ok = 0;
                            y = x = m;
                        }
                    }
                }
                if(ok){
                    for (int y = 0; y < m; ++y) {
                        for (int x = 0; x < m; ++x) {
                            if(~B[y][x]){
                                ans.emplace_back(y+i, x+j);
                                i = j = x = y = n;
                            }
                        }
                    }
                }
            }
        }
        auto BB = B;
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < m; ++j) {
                B[i][j] = BB[m-j-1][i];
            }
        }
    }
    if(ans.empty()){
        puts("NA");
    }else {
        sort(ans.begin(),ans.end());
        printf("%d %d\n", ans[0].second+1, ans[0].first+1);
    }
}

int main() {
    int n, m;
    while(cin >> n >> m, n){
        solve(n, m);
    }
    return 0;
}


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

int n;
int B[108];


int main() {
	cin >> n;
	for (int i = 0;i < n-1;i++) {
		cin >> B[i];
	}

	int sum = B[0];
	for (int i = 1;i < n-1;i++) {
		if (B[i - 1] <= B[i])sum += B[i - 1];
		else sum += B[i];
	}
	sum += B[n - 2];

	cout << sum<<"\n";

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                for(int k = 1; k <= n; k++){
                    sum += gcd(i, gcd(j, k));
                }
            }
        }
        System.out.println(sum);
    }
    static int gcd (int a, int b) {
        int temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
}


Measured memory_bytes: 35824
using System;
using System.Linq;
using System.Text.RegularExpressions;

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

            string c = Console.ReadLine();
            string ans = string.Empty;
            string[] vowels = new string[] { "a","e","i","o","u"};

            if ( 0 <= Array.IndexOf(vowels,c))
            {
                ans = "vowel";
            }
            else
            {
                ans = "consonant";
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13024
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する



int main() {
    unsigned int N;
    cin >> N;
    cout << "ABC" << N << endl;

    return 0;

}


Measured memory_bytes: 256
S = input()
n = len(S)
confS = S[::-1]
flag1 = False
flag2 = False
flag3 = False
s1 = S[0:int((n-1)/2)]
confs1 = s1[::--1]
s2 = S[int((n+3)/2)-1:n]
confs2 = s2[::-1]
if S == confS:
  flag1 = True
if s1 == confs1:
  flag2 = True
if s2 == confs2:
  flag3 = True
if flag1 and flag2 and flag3:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 8848
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
const int N = 1e9;
using namespace std;
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define ll long long

int main(){

	string s,ss;
	cin>>s>>ss;
	cout<<ss<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;
const int mod998 = 998244353;

string s;

bool slove() {
	int p;
	p = s.size();
	while (p) {
		if (p >= 5 && s.substr(p - 5, 5) == "dream") {
			p -= 5;
			continue;
		}
		if (p >= 5 && s.substr(p - 5, 5) == "erase") {
			p -= 5;
			continue;
		}
		if (p >= 6 && s.substr(p - 6, 6) == "eraser") {
			p -= 6;
			continue;
		}
		if (p >= 7 && s.substr(p - 7, 7) == "dreamer") {
			p -= 7;
			continue;
		}
		return false;
	}
	return true;
}

int main() {
	cin >> s;
	if (slove()) {
		puts("YES");
	}
	else {
		puts("NO");
	}
}

Measured memory_bytes: 512
#include <iostream>
#define INF 1e9

using namespace std;

void chmax(long long int& a, long long int b) {
    if(b > a) {
        a = b;
    }
    return;
}

int main() {
    int N, W;
    cin >> N >> W;
    long long int weight[N], value[N];
    for(int i = 0; i < N; i++) {
        cin >> weight[i] >> value[i];
    }

    long long int dp[N+1][W+1];
    for(int i = 0; i < N+1; i++) {
        for(int j = 0; j < W+1; j++) {
            dp[i][j] = 0;
        }
    }

    for(int i = 0; i < N; i++) {
        for(int sum_w = 0; sum_w <= W; sum_w++) {
            if(sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <cstdio>
using namespace std;
int main(int argc, char *argv[]){
  int a,b;
  cin >> a;
  cin >> b;
  if(a < b){
    cout << "a < b" << endl;
  }else if(a > b){
    cout << "a > b" << endl;
  }else{
    cout << "a == b" << endl;
  return 0;
  }
}

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int X;
	int dp[100200]={1};

	cin >> X;
	for(int i=0;i<=X;i++)
	{
		if(dp[i])
		{
			dp[i+100]=1;
			dp[i+101]=1;
			dp[i+102]=1;
			dp[i+103]=1;
			dp[i+104]=1;
			dp[i+105]=1;
		}
	}

	cout << dp[X] << endl;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector> //可変長配列
#include <queue> //キュー
#include <unordered_map> //ハッシュ連想配列
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define ll long long int
#define INFTY (1<<21)

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    int n,a,b;
    cin>>n>>a>>b;
    a *= n;
    cout<<(a>b?b:a)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> vec;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        vec.push_back(x);
    }
    int q;
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        int b, m, e;
        cin >> b >> m >> e;
        rotate(vec.begin() + b, vec.begin() + m, vec.begin() + e);
    }
    for(int i = 0; i < n; i++)
    {
        if(i > 0) cout << " " << vec[i];
        else cout << vec[i];
    }
    cout << endl;
    return 0;
}




Measured memory_bytes: 3216
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    int a[n], b[n], c[m], d[m];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < m; i++)
    {
        cin >> c[i] >> d[i];
    }

    for (int i = 0; i < n; i++)
    {
        int min_dist = INT_MAX;
        int min_indx;
        for (int j = 0; j < m; j++)
        {
            int dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (dist < min_dist)
            {
                min_indx = j;
                min_dist = dist;
            }
        }
        cout << min_indx + 1 << endl;
    }
    return 0;
}

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

// aCb
int comb(int a)
{
    int bunshi = 1;
    for (int i = 0; i < 2; i++)
    {
        bunshi *= (a - i);
    }

    return bunshi / 2;
}

int main()
{
    int N, M;
    cin >> N >> M;

    int result = 0;
    if (N > 1)
    {
        // n! / 2 * (N-2)!
        result += comb(N);
    }

    if (M > 1)
    {

        result += comb(M);
    }

    cout << result;

    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
td = sorted([list(map(int, input().split())) for i in range(n)], reverse=True, key=lambda x: x[1])

type = set()
L = []
Sum = 0
for x in td[:k]:
    Sum += x[1]
    if x[0] not in type:
        type.add(x[0])
    else:
        L.append(x[1])

L = L[::-1]
type_cnt = len(type)
ans = Sum + type_cnt ** 2
for x in td[k:]:
    if len(L)==0:break
    if x[0] not in type:
        type.add(x[0])
        type_cnt += 1
        Sum = Sum - L.pop(0) + x[1]
        ans = max(ans, Sum + type_cnt ** 2)
print(ans)


Measured memory_bytes: 30776
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
ll MOD = 1000000007;

ll dp[1010][1010];
int main() {
	int H,W;
	cin >> H >> W;
	vector<string> map(H);
	rep(i,H) cin >> map[i];
	rep(i,H) rep(j,W) dp[i][j] = 0;
	dp[0][0] = 1;
	rep(i,H) rep(j,W) {
		if(i==0 && j==0) continue;
		if(map[i][j] == '#') {
			dp[i][j] = 0;
			continue;
		}
		if (i != 0 && j != 0) {
			if(map[i-1][j] == '.') {
				dp[i][j] += dp[i-1][j];
				dp[i][j] %= MOD;
			}
			if(map[i][j-1] == '.') {
				dp[i][j] += dp[i][j - 1];
				dp[i][j] %= MOD;
			} 
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}
		else if (i == 0) {
			if(map[i][j-1] == '.') {
				dp[i][j] += dp[i][j - 1];
				dp[i][j] %= MOD;
				//cout << "in" << endl;
			} 
			//cout << i << " " << j << " " << dp[i][j] << " " << dp[i][j-1] << endl;
		}
		else if (j == 0) {
			if(map[i-1][j] == '.') {
				dp[i][j] += dp[i-1][j];
				dp[i][j] %= MOD;
			}
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	cout << dp[H-1][W-1] << endl;
	
  return 0;
}


Measured memory_bytes: 9216
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
 
public class Main {

  public static class edge {
    int from;
    int to;
    edge (int _from, int _to) {
      from = _from;
      to   = _to;
    }
  }

  static final int V = 100;
  static int n, t;
  static int d[], f[];
  static ArrayList<ArrayList<edge>> es;

  public static void dfs(int v) {  
    int i;
    d[v] = ++t;
    for (i=0; i<es.get(v).size(); i++) {
      int to = es.get(v).get(i).to;
      if (d[to] == -1) dfs(to);
    }
    f[v] = ++t;
  }

  public static void main(String[] args) {
    int i, j;

    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    es = new ArrayList<ArrayList<edge>>();
    d = new int[n];
    f = new int[n];
    Arrays.fill(d, -1);
    Arrays.fill(f,  0);

    for (i=0; i<n; i++) {
      int u = Integer.parseInt(sc.next());
      int k = Integer.parseInt(sc.next());
      ArrayList<edge> l = new ArrayList<edge>();
      for (j=0; j<k; j++) {
        int v = Integer.parseInt(sc.next());
        l.add(new edge(u-1, v-1));
      }
      es.add(new ArrayList<edge>(l));
    }

    t = 0;
    for (i=0; i<n; i++)
      if (d[i] == -1) dfs(i);

    for (i=0; i<n; i++) {
      System.out.print(String.valueOf(i+1) + ' ');
      System.out.print(String.valueOf(d[i]) + ' ');
      System.out.println(f[i]);
    }
  }
}

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

int main(){
    int h,w,m;
    cin >> h >> w >> m;
    vi tate_count(h,0);
    vi yoko_count(w,0);
    vector<pair<int,int>> m_save;
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        tate_count[a]++;
        yoko_count[b]++;
        pair<int,int> kani=make_pair(a,b);
        m_save.push_back(kani);
    }
    int maxi_t=0;
    for(int i=0;i<h;i++){
        maxi_t=max(maxi_t,tate_count[i]);
    }
    int maxi_y=0;
    for(int i=0;i<w;i++){
        maxi_y=max(maxi_y,yoko_count[i]);
    }
    int ans=maxi_y+maxi_t;
    map<int,int> tate,yoko;
    for(int i=0;i<h;i++){
        if(maxi_t==tate_count[i]){
            tate[i]++;
        }
    }
    for(int i=0;i<w;i++){
        if(maxi_y==yoko_count[i]){
            yoko[i]++;
        }
    }
    ll tc=tate.size(),yc=yoko.size();
    ll count=0;
    for(int i=0;i<m;i++){
        if(tate[m_save[i].first]==1&&yoko[m_save[i].second]==1){
            count++;
        }
    }
    if(count>=tc*yc) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 36060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char yes[] = "Yes\n";
const char no[] = "No\n"; 
char **toalloc(int n){
	char **aloc = malloc(sizeof(char*)*n);
	for(int i = 0; i < n; ++i){
		aloc[i] = malloc(sizeof(char)*n+5);
	}
	return aloc;
}
void read(char **vetor, int n){
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			scanf(" %c", &vetor[i][j]);
		}
	}
	return;
}
int main(){
	int m, n, found = 0, sposi;
	char **a, **b, *start;
	scanf("%d%d", &n/*A*/, &m/*B*/);
	a = toalloc(n);
	b = toalloc(m);
	read(a, n);
	read(b, m);
	//search
	for(int lin = 0; lin < n; ++lin){
		for(int col = 0; col < n; ++col){
			if(lin + m -1> n || col + m -1> n) continue;
			found = 1;
			for(int lb = 0; lb < m; ++lb){
				for(int cb = 0; cb < m; ++cb){
					if(a[lin+lb][col+cb] != b[lb][cb]){
						found = 0;
						break;
					}
					if(!found) break;
				}
				if(!found) break;
			}
			if(found) break;
		}
		if(found) break;
	}
	printf("%s", found ? yes: no);
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;

namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) != 1 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) != 1;
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
//  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}
int main() {
  int n;
  while(cin >> n, n) {
    vector<P> vp;
    vector<L> v;
    REP(i,n) {
      double x,y;
      cin >>x>>y;
      vp.push_back(P(x,y));
    }
    REP(i,n) v.push_back(L(vp[i], vp[(i+1)%n]));
    int res = 0;
    for (int y=-2000; y<=2000; ++y) {
      L l1(P(-2001,y), P(2001,y));
      L l2(P(-2001,y+1), P(2001,y+1));
      vector<double> tmp1, tmp2;
      REP(i, v.size()){
        if (intersectSS(l1, v[i]) && intersectSS(l2, v[i])) {
          tmp1.push_back(crosspoint(l1, v[i]).real());
          tmp2.push_back(crosspoint(l2, v[i]).real());
        }
      }
      sort(ALL(tmp1));// tmp1.erase(unique(ALL(tmp1)), tmp1.end());
      sort(ALL(tmp2));// tmp2.erase(unique(ALL(tmp2)), tmp2.end());
      // if (tmp1.size())
      //   cout << y << " " << tmp1.size() << endl;
      int last = -2000;
      REP(i, tmp1.size()) {
        if (i%2 == 0) continue;
        int low = min((int)floor(tmp1[i-1]), (int)floor(tmp2[i-1]));
        int high = max((int)ceil(tmp1[i]), (int)ceil(tmp2[i]));
        // cout << "y = " << y << endl;
        // cout << low << " " << high << endl;
        // cout << endl;
        res += high-max(low, last);
        last = high;
      }
    }
    cout << res << endl;
  }
}

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

int main(){
int n,l;
cin>>n>>l;
string t;
vector<string>s(n);
for(int i=0;i<n;i++){
  cin>>s.at(i);
  }
sort(s.begin(),s.end());
for(int i=0;i<n;i++){
  t+=s.at(i);
  }
  cout<<t<<endl;
return 0;
}
 

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

int main() {
  string w;
  cin >> w;
  for (int i = 0; i < w.length(); i++) {
    int count = 0;
    for (int j = 0; j < w.length(); j++) {
      if (w.at(i) == w.at(j)) count++;
    }
    if (count % 2 != 0) {
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}


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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 
ll fff(ll n, vector<ll>& v, ll i, ll j, ll rl){
  ll can = 0;
  ll can_i = 0;

  cout << v[0]<<endl;
  
  // right
  if(rl == 0){
    rep(k, n){
      if(v[k]*(j-k)>can){
	can = v[k]*(j-k);
	can_i = k;
      }
      //cout << can<<endl;
    }
    v[can_i] = 0;
    return can;
  }
  // left
  else{
    rep(k, n){
      if(v[k]*(k-i)>can){
	can = v[k]*(k-i);
	can_i = k;
      }
      //cout << can<<endl;

    }
    v[can_i] = 0;
    return can;
  }
  
}


int main(){
  ll a,b,c;

  cin>>a>>b>>c;

  set<ll> s={a%b};

  ll tmp = a;
  rep(i, b){
    tmp = (tmp+a) % b;
    s.insert(tmp);
    if(tmp==c){
      cout << "YES"<<endl;
      return 0;
    }
  }
  cout << "NO"<<endl;
  
  
}


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


using namespace std;



#define For(i,x,n)  for(long long i=x;i<n;i++)
#define rFor(i,x,n) for(long long i=x;i>=n;i--)
#define itFor(it,st)   for(auto it=st.begin() ; it!=st.end() ; it++)
#define MOD 1000000007
#define PI 3.141592653589793
#define INF 999999999999999999
#define N 1000005
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sp " "
#define cont continue
#define brk break

#define deb1(x)                cout<<#x<<": "<<x<<endl
#define deb2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define deb4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define deb5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define deb6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed;
    cout<<setprecision(3);
    srand(time(NULL));

    ll n;
    cin>>n;
    ll val[n+10] = {0};

    For(i,1,n+1){
    	for(ll j=i ; j<=n ; j+=i)
    		val[j]++;
    }
    ll ans = 0;
    For(i,1,n+1)
    	ans += (i*val[i]);
    cout<<ans;
    
    //cout<<"\nTime used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case
    return 0;
}

//s1.substr(1,3) - return 3 characters starting from position 1 as substring of string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan"
//num = atoi(s.c_str()); //convert string s to integer num
//n.erase(i,std::string::npos); //erase i th position in string n , decreasing string size
//s.find(b)!= std::string::npos - finds string b in string a - true if found
//cout<<"Time used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case                


Measured memory_bytes: 81728
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int c1,c2,c3,i,card[11],able,count=0;
    double pro;
    
    while(scanf("%d %d %d",&c1,&c2,&c3)!=EOF){
        for(i=1;i<=10;i++){
            if(i==c1)
                card[i]=1;
            else if(i==c2)
                card[i]=1;
            else if(i==c3)
                card[i]=1;
            else
                card[i]=0;
            //printf("%d:%d\n",i,card[i]);
        }
        able=20-(c1+c2);
        if(able>=11)
            printf("YES\n");
        else if(able>0){
            for(i=1;i<=10;i++){
                if(card[i]==0&&able>=i)
                    count++;
            }
            pro=(double)count/7;
            //printf("%d,%lf\n",count,pro);
            if(pro>=0.5000000)
                printf("YES\n");
            else
                printf("NO\n");
        }
        count=0;
    }
    return 0;
}

Measured memory_bytes: 1748
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, m = inintm()
s = input()
t = input()

c = {}

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

lcm_num = lcm(n,m)

for i in range(n):
    c[i*m + 1] = s[i]

for i in range(m):
    if i*n + 1 in c:
        if c[i*n + 1] != t[i]:
            print(-1)
            exit()

print(lcm_num)

Measured memory_bytes: 20672
import numpy as np
def resolve():
    count = 0
    li = np.array(list(map(int,input().split())))
    Barray = np.array(list(map(int,input().split())))
    for i in range(li[0]):
        Aarray = np.array(list(map(int,input().split())))
        if np.dot(Barray,Aarray) + li[2] > 0:
            count = count + 1
    print(count)        
resolve()    

Measured memory_bytes: 12504
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n,k,ans=1;
  cin>>n>>k;
  rep(i,n){
  ans += (ans<k ? ans : k);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
from itertools import chain, combinations

def powerset(iterable):
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

N, M = [int(x) for x in input().split(" ")]
Ss = [0] * N
bulbs = []
for i in range(M):
    s = [int(x) for x in input().split(" ")]
    k = s[0]
    ss = set(s[1:])
    bulbs.append(ss)
ps = [int(x) for x in input().split(" ")]
bulbs = list(zip(bulbs, ps))

def checkPattern(subset, bs, p):
    inter = subset.intersection(bs)
    res = len(inter) % 2 == p
    return res

count = 0
for subset in powerset(set(range(1, N+1))):
    subset = set(subset)
    pts = [checkPattern(subset, bs, p) for bs, p in bulbs]
    if all(pts):
        count += 1

print(count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
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;}

#define INF 1120000000

int main(){
  map<int,int> m;
  int n;
  cin>>n;
  rep(i,n){
    int d;
    cin>>d;
    m[d]++;
  }

  vector<int> vec;
  for(auto p : m){
    if(p.second>=2) vec.pb(p.first);
    if(p.second>=4) vec.pb(p.first);
  }
  sort(all(vec));

  if(vec.size()<2) cout << 0 << endl;
  else {
    int sz = vec.size();
    cout << (long)vec[sz-1]*vec[sz-2] << endl;
  }

  return 0;
}


Measured memory_bytes: 4992
n, m = map(int, input().split())
ans = [-1 for _ in range(n)]
l = [list(map(int, input().split())) for _ in range(m)]

if m == 0:
    if n == 1:
        print(0)
        exit()
    elif n == 2:
        print(10)
        exit()
    elif n == 3:
        print(100)
        exit()

for q in range(m):
    if l[q][0] == 1:
        break
else:
     ans[0] = 1

for k in range(m):
    if l[k][1] != 0:
        break
    for p in range(m):
        if l[p][0] == 1:
            break
        else:
            if n ==2:
                print(10)
                exit()
            elif n == 3:
                print(100)
                exit()

else:
    if n == 1:
        print(0)
        exit()
    else:
        print(-1)
        exit()

for i in range(m):
    if l[i][0] == 1 and l[i][1] == 0:
        print(-1)
        break
    if ans[l[i][0]-1] != -1 and ans[l[i][0]-1] != l[i][1]:
        print(-1)
        break
    else:
        ans[l[i][0]-1] = l[i][1]

else:
    for j in range(n):
        if ans[j] == -1:
            ans[j] = 0

    print(''.join(list(map(str,ans))))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[13];
  	a[2]=1;
  	a[4]=a[6]=a[9]=a[11]=2;
  	a[1]=a[3]=a[5]=a[7]=a[8]=a[10]=a[12]=3;
  	int x,y;cin>>x>>y;
  	if(a[x]==a[y]) cout<<"Yes";
  	else cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
//#include <string>
//#include <cmath>
// #include <vector>
// #include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main() {
  double r;
  const double PI = acos(-1);
  cin >> r;
  
  printf("%.6lf %.6lf\n", r*r*PI, 2*r*PI);
  
  return 0;
}



Measured memory_bytes: 3288
times = []
for _ in range(5):
    t = int(input())
    times.append((((t - 1) // 10) * 10, (t - 1) % 10 + 1))
times.sort(key=lambda x: x[1])
ans = 0
for x, r in times[1:]:
    ans += x + 10
ans += sum(times[0])
print(ans)


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

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  int dis;
  int d[n+1];
  for(int i = 1; i <= n; ++i) d[i] = 0;
  for(int i = 1; i <= n; ++i) {
    for(int j = 1; j <= n; ++j) {
      if(i < j) {
          dis = min(min(j-i, abs(x-i) + 1 + abs(y-j)), abs(x-j) + 1 + abs(y-i));
          ++d[dis];
      }
    }
  }
  for(int i = 1; i<n; ++i){
    cout << d[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
def f(r,l):
    # 3,2
    tmp = [0 for i in range(r+l)]
    if (r+l)%2==0:
        tmp[r-1]=(r+l)//2
        tmp[r]=(r+l)//2
    else:
        if r%2==0:
            tmp[r-1]=(r+l)//2
            tmp[r]=(r+l)//2+1
        else:
            tmp[r-1]=(r+l)//2+1
            tmp[r]=(r+l)//2
    return tmp

s = str(input())
cnt_r = 1
cnt_l = 0
pre = s[0]
ans = []
for i in range(1,len(s)):
    if pre == s[i]:
        if s[i]=='R':
            cnt_r += 1
        else:
            cnt_l += 1
    else:
        if s[i]=='R':
            ans += f(cnt_r,cnt_l)
            pre = s[i]
            cnt_r = 1
            cnt_l = 0
        else:
            pre = s[i]
            cnt_l += 1
ans += f(cnt_r,cnt_l)

tmp = ''
for i in ans:
    tmp += str(i) + ' '
print(tmp[:-1])

Measured memory_bytes: 10504
#include "iostream"

using namespace std;

int H, W;
char map;
int num = 0;

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> map;
			if (map == '#')num++;
		}
	}
	if (num == H + W - 1)cout << "Possible\n";
	else cout << "Impossible\n";
	return 0;
}

Measured memory_bytes: 764
fun main(args: Array<String>) {
    // 実行不安定
    var (n,m) = readLine()!!.split(" ").map{it.toInt()}
    var votes = readLine()!!.split(" ").map{it.toInt()}.toList()
    var total = votes.reduce{x,y->x+y}.toFloat()
    var com = (total/(4*m)).toFloat()
    var msg = "No"
    var cnt = votes.filter{it.toFloat() >= com}.count()
    
    if(cnt >= m) msg = "Yes"
    
    print(msg)
    
}


Measured memory_bytes: 38052
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String[] date = scan.next().split("/",0);
		if(Integer.parseInt(date[0])<2019||Integer.parseInt(date[1])<5){
			System.out.println("Heisei");
		}else{
			System.out.println("TBD");
		}
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(){
    int h,w;

    while(1){
        scanf("%d %d",&h ,&w);
        if(h == 0 && w == 0){
            break;
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(i==0 || i==h-1 || j==0 || j==w-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2104
#include <stdio.h>

int isprime(int n) {
  int i;
  for(i = 2; i * i <= n; i++) {
    if(n % i == 0) return 0;
  }
return 1;
}

int main(){
  int n, i;
  while(1){
    scanf("%d", &n);
    if(n == 0) break;
    for(i=n ; i >= 5 ; i--){
      if(isprime(i) && isprime(i-2)) break;
    }
    printf("%d %d\n", i - 2, i);
  }
  return 0;
}

Measured memory_bytes: 1760
D = 20
ds = [0]*D

from math import log10

for i in xrange(1, D):
    fr = 10**(i-1)-1
    to = 10**i-1
    ds[i] = ds[i-1] + (4-i)*(to/3 + to/5 - (to/15)*2 - fr/3 - fr/5 + (fr/15)*2) + (8-i)*(to/15 - fr/15) + i*(to-fr)

def calc(m):
    if m == 0:
        return 0
    c = int(log10(m))+1
    fr = 10**(c-1)-1
    to = m
    return ds[c-1] + (4-c)*(to/3 + to/5 - (to/15)*2 - fr/3 - fr/5 + (fr/15)*2) + (8-c)*(to/15 - fr/15) + c*(to-fr)

s = input()
left = 0; right = 10**18
while left+1 < right:
    mid = (left + right) / 2
    if calc(mid) <= s-1:
        left = mid
    else:
        right = mid
idx = calc(left)
num = left+1
ans = ""
while len(ans) < s - idx + 20:
    if num % 15 == 0:
        ans += "FizzBuzz"
    elif num % 3 == 0:
        ans += "Fizz"
    elif num % 5 == 0:
        ans += "Buzz"
    else:
        ans += str(num)
    num += 1
print ans[s-idx-1:s-idx+19]

Measured memory_bytes: 6788
#include<stdio.h>

int main(){
	long long i,T;
	long long num;
        long long  max, min, sum=0;
	scanf("%lld", &T);
	for (i = 0; i < T; i++){
		scanf("%lld", &num);
		if (i == 0){
			max = min = num;
		}
		else{
			if (max < num){
				max = num;
			}
			if (min > num){
				min = num;
			}
		}
		sum = sum + num;
	}
	printf("%lld %lld %lld\n", min, max, sum);
	return 0;

}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N, M; cin >> N >> M;
 
	vector<vector<int>> v(M);
 
	for (int i = 0; i < M; ++i) {
		int k; cin >> k;
		v[i].resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> v[i][j];
			--v[i][j];
		}
	}
 
	vector<int> p(M);
	for (int i = 0; i < M; ++i) cin >> p[i];
 
	int ans = 0;
	for (int bit = 0; bit < (1 << N); bit++) {
		bool flg = true;
		for (int j = 0; j < M; ++j) {
			int c = 0;
			for (int id : v[j]) {
				if ((bit >> id) & 1) {
					c++;
				}
			}
			c %= 2;
			if (c != p[j]) {
				flg = false;
			}
		}
		if (flg) {
		    ans++;
		}
	}
 
	cout << ans << endl;
 
	return 0;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
  static void Main(string[] args){
    string[] tmp=Console.ReadLine().Split(' ');
    int n = int.Parse(tmp[0]);
    int m = int.Parse(tmp[1]);
    int[] data=new int[m];
    for(int i=0;i<m;i++){data[i]=0;}
    for(int i=0;i<n;i++){
      string[] tmp2=Console.ReadLine().Split(' ');
      int k=int.Parse(tmp2[0]);
      for(int j=0;j<k;j++){
        data[int.Parse(tmp2[j+1])-1]++;
      }
    }
    Console.WriteLine(data.Count(b => b==n));
  }
}

Measured memory_bytes: 13268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{
 
    class Program
    {
        static void Main(string[] args)
        {
            long n=int.Parse(Console.ReadLine());
            n++;
            long[] array = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            Console.WriteLine("{0} {1} {2}",Min(array),Max(array),array.Sum());
        }

        static long Max(long[] array)
        {
            long max = -1000001;
            for(int i = 0; i < array.Length; i++)
            {
                if (max < array[i])
                {
                    max = array[i];
                }
            }
            return max;
        }
        static long Min(long[] array)
        {
            long min = 1000001;
            for(int i =0; i < array.Length; i++)
            {
                if (min > array[i])
                {
                    min = array[i];
                }
            }
            return min;
        }

    }
}

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

int main() {
  int n;
  cin >> n;
  int t[100010] = {};
  int x[100010] = {};
  int y[100010] = {};

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

Measured memory_bytes: 1408
#include <stdio.h>

int arr[200010];

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

  for (int i = 1; i < n; i++) {
    int tmp;
    scanf("%d", &tmp);
    arr[tmp - 1]++;
  }

  for (int i = 0; i < n; i++) {
    printf("%d\n", arr[i]);
  }
}


Measured memory_bytes: 2504
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >>n;
    int a[10005];
    for(int i =0;i<n;i++)
    {
        cin >> a[i];
    }
    while(n>=2 &&n<=10000)
    {
       int sum=0,ave;
       for(int i = 0;i<n;i++)
        sum +=a[i];
       ave = sum/n;
       int count=0;
       for(int i =0;i<n;i++)
       {
           if(a[i]<=ave)
            count++;
       }
       cout <<count<<endl;




    cin >>n;
    for(int i =0;i<n;i++)
    {
        cin >> a[i];
    }
    }



    return 0;
}



Measured memory_bytes: 3124
n,m=map(int,input().split())
a=[None]*m
b=[None]*m
c=[None]*m
for i in range(m):
  a[i],b[i]=map(int,input().split())
  c[i]=list(map(int,input().split()))
INF=10**18
dp=[INF for _ in  range(1<<n)]
dp[(1<<n)-1]=0
for bit in range((1<<n)-2,-1,-1):
  for u in range(m):
    dumy=bit
    flag=0
    for i in c[u]:
      i-=1
      if not ((bit>>i) & 1):
        dumy|=(1<<i)
        flag=1
    if flag:
      dp[bit]=min(dp[bit],dp[dumy]+a[u])
print([dp[0],-1][dp[0]==INF])

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

int check(string t){

  int n=t.length();
  rep(i,n){
    //cout<<t[i]<<" "<<t[n-(i+1)]<<endl;
    if(t[i]!=t[n-(i+1)]){
      return 0;
    }
  }
  return 1;
}

int main(){

 string s;
  
  cin>>s;
  
  int N=s.length();
  
  if(check(s)==0){cout<<"No"<<endl;return 0;}
  string s1=s.substr(0,(N-1)/2);
  //cout<<s1<<endl;
  if(check(s1)==0){cout<<"No"<<endl;return 0;}
  string s2=s.substr((N+3)/2-1,(N-1)/2);
  //cout<<s2<<endl;
  if(check(s2)==0){cout<<"No"<<endl;return 0;}
  
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
while n=gets
	n = n.chomp.to_i
	cn = 0
	for a in 0..9
		for b in 0..9
			for c in 0..9
				for d in 0..9
					if a+b+c+d==n
						cn += 1
					end
				end
			end
		end
	end
	puts cn
end

Measured memory_bytes: 8664
#include<iostream>
#include<string>
#include<stdio.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<vector>

using namespace std;

int main(){
    int N,M,X,Y;cin >> N >> M >> X >> Y;
    int x[100]={};
    int y[100]={};
    int flag = 1;
    for(int i = 0;i < N;i++)cin >> x[i];
    for(int i = 0;i < M;i++)cin >> y[i];
    for(int i = X+1;i <= Y;i++){
        flag = 1;
        for(int j=0;j < N;j++){
            if(x[j] >= i){
                flag = 0;
                continue;
            }
        }
        if(flag==0)continue;
        for(int j = 0;j < M;j++){
            if(y[j] < i){
                flag = 0;
                continue;
            }
        }
        if(flag == 1)break;
    }
    if(flag == 1)cout << "No War" << endl;
    else cout << "War" << endl;
}

Measured memory_bytes: 3596
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete

triMap f (x:xs@(y:z:_)) = f x y z : triMap f xs
triMap _ _ = []

main = getLine >> getInts >>= print . sum . map (\xs@(x:_) -> let len = length xs in cond (len-x) len (len>=x)) . group . sort

Measured memory_bytes: 39548
#include <bits/stdc++.h>
using namespace std;
int main() {
  double n, t, a, z=1000; int g=0; cin >> n >> t >> a;
  vector<double> h(n);
  vector<double> x(n);
  vector<double> y(n);
  for (int i=0;i<n;i++) {
    cin >> h[i];
    x[i]=t-h[i]*0.006;
    y[i]=abs(a-x[i]);
    z=min(y[i],z);
    if (z==y[i]){
      g=i+1;
    }
  }
  cout << g << endl;
  return 0;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  int w,h,t,p;
  while(cin>>w>>h>>t>>p,w){
    int paper[h*h+10][w*w+10]={};
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	paper[i][j]=1;
    int hcnt=0,wcnt=0;
    for(int i=0;i<t;i++){
      int d,c;cin>>d>>c;
      if(d==1){
	for(int j=0;j<c;j++){
	  for(int k=0;k<h*h;k++){
	    paper[k][wcnt+c+j]+=paper[k][wcnt+c-j-1];
	  }
	}
	wcnt+=c;
      }else if(d==2){
	for(int j=0;j<c;j++){
	  for(int k=0;k<w*w;k++){
	    paper[hcnt+c+j][k]+=paper[hcnt+c-j-1][k];
	  }
	}
	hcnt+=c;
      }
    }
    // for(int i=0;i<h;i++){
    //   for(int j=0;j<w;j++)
    // 	cout<<paper[i][j];
    //   cout<<endl;
    // }
    for(int i=0;i<p;i++){
      int x,y;cin>>x>>y;
      cout<<paper[y+hcnt][x+wcnt]<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 7272
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
#include <numeric>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define repi(m, itr) for (auto itr = m.begin();itr != m.end();++itr)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// C - Vacation
ll N;
ll ans = 0;
ll dp[105000][3];
ll a[105000], b[105000], c[105000];

int main(){
    cin >> N;
    rep(i, 0, N){
        cin >> a[i] >> b[i] >> c[i];
    }

    rep(i, 1, N+1){
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i-1];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i-1];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i-1];
    }

    ans = max(max(dp[N][0], dp[N][1]), dp[N][2]);
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 4992
n = int(input())
F = [[] * 10 for _ in range(n)]
P = [[] * 10 for _ in range(n)]

for i in range(n):
	F[i] = list(map(int, input().split()))

for i in range(n):
	P[i] = list(map(int, input().split()))


res = -1<<30
for item in range(1, 1 << 10):
	fund = 0
	for i in range(n):
		cnt = 0
		for x in range(10):
			if item >> x & 1 and F[i][x] == 1:
				cnt += 1
		fund += P[i][cnt]
	res = max(res, fund)

print(res)

Measured memory_bytes: 43756
import sys

n,m = map(int,input().split())
A = [list(input()) for i in range(n)]
B = [list(input()) for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if k == 0:
                C = [A[i][j:m+j]]
            else:
                C += [A[i+k][j:m+j]]
        if B == C:
            print('Yes')
            sys.exit()
print('No')

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	a := readInt()
	b := readInt()
	var answer int
	if b % a == 0 {
		answer = a + b
	} else {
		answer = b - a
	}
	fmt.Println(int(answer))
}

func read() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	i, e := strconv.Atoi(read())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
import functools
import fractions
MOD = 10**9+7


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(numbers):
    return functools.reduce(lcm_base, numbers, 1)


def main():
    n = int(input())
    x = list(map(int, input().split()))

    l = lcm(x)
    ans = 0
    for i in range(n):
        ans += l // x[i]

    print(ans % MOD)


main()


Measured memory_bytes: 6084