akhauriyash/Code-Regression huggingface dataset:
from operator import itemgetter
N = int(input())
Red = [list(map(int,input().split())) for _ in range(N)] #赤
Blue = [list(map(int,input().split())) for _ in range(N)] #青

Red1 = sorted(Red, key=itemgetter(1),reverse = True)
Blue1 = sorted(Blue, key=itemgetter(0),reverse = False)

cnt = 0
for i in range(N):
    for j in range(N):
        if Red1[i][1] < Blue1[j][1] and  Red1[i][0] < Blue1[j][0] :
            cnt += 1
            Blue1[j][0] = -1
            break
print(cnt)

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

int main(){
  string s,t;
  cin >> s >> t;
  bool ok=true;
  vector<int>start;
  for(int i=0;i<s.size()-t.size()+1;i++){
    ok=true;
    for(int j=0;j<t.size();j++){
      if(s.at(i+j)!=t.at(j)&&s.at(i+j)!='?') ok=false;
    }
    if(ok) start.push_back(i);
  }
  if(start.size()==0){
    cout << "UNRESTORABLE\n";
  }else{
    string now="",ans="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
    for(int i=0;i<start.size();i++){
      now="";
      for(int j=0;j<start.at(i);j++){
        now+=(s.at(j)=='?'?'a':s.at(j));
      }
      now+=t;
      for(int j=start.at(i)+t.size();j<s.size();j++){
        now+=(s.at(j)=='?'?'a':s.at(j));
      }
      ans=min(ans,now);
    }
    cout << ans << endl;
  }
  return 0;
}

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

int hati(int a) {
  return ((a*8 - (a*8)%100)/100);
}

int juu(int a) {
  return ((a*10 - (a*10)%100)/100);
}

int main() {
  int ans = -1;
  int A,B;
  cin >> A >> B;
  for (int i = 1;i<10000;i++) {
    if ((hati(i) == A) && (juu(i) == B)) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int main(){
  int n;
  while(cin>>n,n){
    int data[10];
    memset(data,0,sizeof(data));
    for(int i=0;i<n;i++){
      int a;
      cin>>a;
      data[a]++;
    }
    for(int i=0;i<10;i++){
      if(data[i]==0)cout<<'-'<<endl;
      else{
        for(int j=0;j<data[i];j++){
          cout<<'*';
        }
        cout<<endl;
      }
    }
  }
}

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

struct UF{
   vector<int> par;
   vector<int> sz;
   UF(){}
   UF(int n){
       par.resize(n);
       sz.resize(n, 1);
       rep(i, 0, n) par[i] = i;
   }
   int find(int x){
       if(x == par[x]) return x;
       return par[x] = find(par[x]);
   }
   void unite(int x, int y){
       x = find(x); y = find(y);
       if(x == y) return;
       if(sz[x] < sz[y]) swap(x, y);
       sz[x] += sz[y];
       par[y] = x;
   }
   bool same(int x, int y){
       return find(x) == find(y);
   }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
        a[i]--;
    }
    UF uf(n);
    rep(i, 0, m){
        int s, t;
        cin >> s >> t;
        s--; t--;
        uf.unite(s, t);
    }
    int ans = 0;
    rep(i, 0, n){
        int t1 = uf.find(i);
        int t2 = uf.find(a[i]);
        if(t1 == t2) ans++;
    }
    cout << ans << endl;
}

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

int main() {
    int n;
    ll ans=0,temp;
    cin>>n;
    map<ll,ll> mp;
    rep(i,n) {
        cin>>temp;
        mp[temp]++;
    }
    for (auto v : mp) {
        if (v.second%2==1) ans++;
    } 
    cout<<ans<<endl;
}


Measured memory_bytes: 6528
M = []
ans = []

def main():
    H,W = map(int, input().split())  
    for i in range(H):
        M.append(input())
        ans.append('.' * W)

    bfs(0,0)

    for i in range(H):
        if(M[i] != ans[i]):
            print('Impossible')
            return
    print('Possible')


def bfs(x,y):
    if(x>=len(M) or y>=len(M[0])):
        return False
    if(M[x][y]=='#'):
        str_list = list(ans[x])
        str_list[y] = '#'
        ans[x] = "".join(str_list) 
        if(bfs(x,y+1) & bfs(x+1,y)):
            #失敗にする、気持ち悪いけど楽…
            str_list = list(ans[0])
            str_list[0] = '.'
            ans[0] = "".join(str_list) 
        return True
    return False


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    string S, T;
    cin >> S >> T;
    bool can = false;
    for (int i = 0; i < S.size(); ++i) {
        string S2 = S.substr(i) + S.substr(0, i);
        if (S2 == T) can = true;
    }
    cout << (can ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll h,w,k;
  cin >> h >> w >> k;
  vector<string> mp(h);
  rep(r,h) {
    cin >> mp[r];
  }
  ll ans = 0;
  rep(i,1ll<<h)rep(j,1ll<<w) {
    ll now = 0;
    rep(r,h) if (!(i>>r&1)) {
      rep(c,w) if (!(j>>c&1)) {
        // Here, (r,c) is remaining
        if (mp[r][c] == '#') {
          ++now;
        }
      }
    }
    if (now == k) {
      ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
ll n,rel,i,j,k,rgii;
ll rg[301][301];
bool p[301][301];
int main() {
    cin >> n;
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)cin >> rg[i][j];
    for (i=0;i<n;i++)
        for (j=i+1;j<n;j++) {
            rgii=rg[i][j];
            for (k=0;k<n;k++)
                if (k!=i and k!=j){
                    ll byp=rg[i][k]+rg[k][j];
                    if (rgii>byp){
                        cout << -1 << endl;
                        return 0;
                    }
                    else if (rgii==byp)p[i][j]=true;
                }
        }
    rel=0;
    for (i=0;i<n;i++)
        for (j=i+1;j<n;j++)
            if(!p[i][j]) rel += rg[i][j];
    cout << rel << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  int n,s;
  vector<int> v;
  int sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    sum+=s;
    v.pb(s);
  }
  sort(v.begin(),v.end());
  for(int i=0;i<v.size();i++){
    if(sum%10!=0){
      cout<<sum<<endl;
      return 0;
    }
    if(v[i]%10==0) continue;
    sum-=v[i];
  }
  cout<<0<<endl;
  return 0;
}


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

signed main(){
  lint N, K; cin >> N >> K;
  vector<lint> a(N);
  for(lint i = 0; i < N; i++) cin >> a[i];
  lint g = a[0];
  for(lint i = 1; i < N; i++) g = __gcd(a[i - 1], a[i]);
  lint m = *max_element(a.begin(), a.end());
  if(K % g == 0 && K <= m) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,int>;
using T = tuple<string,int,int>;

int main(){
  int n; cin >> n;
  vector<tuple<string,int,int>> a;
  for(int i = 1; i <= n; i++){
    string s;int p;
    cin >> s >> p;
    p *= -1;
    a.push_back(tie(s,p,i));
  }
  sort(a.begin(), a.end());
  for(int i = 0; i < n; i++){
    int ans = get<2>(a[i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct BIT {
	vector<int> bit;

	BIT(int n) : bit(n+1) {}

	int sum(int i) {
		int s = 0;
		while(i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}

	void add(int i,int x) {
		while(i <= bit.size()) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

int main() {
	int n, m;
	while(cin >> n >> m) {
		if(n == 0 && m == 0) break;

		BIT bit(100005);
		rep(i, n-1) {
			int a;
			cin >> a;

			bit.add(i+1, a);
		}

		int cur = 1;
		ll ans = 0;

		rep(i, m) {
			int a;
			cin >> a;

			ans += abs(bit.sum(cur+a-1) - bit.sum(cur-1));
			ans %= 100000;
			cur += a;
		}

		cout << ans << endl;
	}

	return 0;
}

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

int main()
{
  int64_t N;
  int64_t sum=0;
  cin >> N;
  for(int i=1; i<=N; i++)
  {
    if(!(i%3==0||i%5==0))
    sum+=i;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int h, w;
	cin >> h >> w;
	bool x[110] = { 0 }, y[110] = { 0 };
	vector<string>s(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	for (int i = 0; i<h; i++) {
		for (int j = 0; j<w; j++) {
			if (s[i][j] == '#') {
				x[i] = true;
				y[j] = true;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		if (x[i]) {
			for (int j = 0; j < w; j++) {
				if (y[j])cout << s[i][j];
			}
			cout << endl;
		}
	}
}



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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int main() {
    int X;
    cin >> X;
    int n500 = X / 500;
    int n5 = (X % 500) / 5;
    cout << n500 * 1000 + n5 * 5 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
 
constexpr auto INF = INT_MAX/2;
constexpr auto MOD = 1000000007;
 
int main() {
	int n;
	cin >> n;
 
	vector<queue<int>> vq(n);
 
	rep(i, n)rep(j, n - 1) {
		int a;
		cin >> a;a--;
		vq[i].push(a);
	}
 
	int k = 0;
	int ans = 0;
	int match = 0;
	bool uso = false;
 
	while (true) {
		int yester = match;
 
		vector<bool> game(n, false);
 
		rep(i, n) {
			if (vq[i].empty())continue;
			if (game[i])continue;
			int j = vq[i].front();
			if (i != vq[j].front())continue;
			if (game[j])continue;
 
			vq[i].pop();game[i] = true;
			vq[j].pop();game[j] = true;
			match++;
		}
 
 
		if (yester == match)break;
		ans++;
		if (ans == 200000) { uso = true;break; }
	}
 
	if (uso)cout << n * (n - 1) / 2 << endl;
	else if (match != n * (n - 1) / 2)cout << -1 << endl;
	else cout << ans << endl;
 
}


Measured memory_bytes: 6784
#include "bits/stdc++.h"
using namespace std;

int main() {

	int n, k, q;
	cin >> n >> k >> q;
	
	int got[n];
	memset(got, 0, sizeof got);
	
	for (int i=0; i<q; i++) {
		int a;
		cin >> a;
		got[a-1]++;
	}
	
	for (int i=0; i<n; i++) {
		int no = q - got[i];
		if (no >= k) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
   
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  if(abs(c-a)<=d||(abs(b-a)<=d&&abs(c-b)<=d)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        if (N % K == 0) {
            System.out.println(0);
        } else {
            System.out.println(1);
        }
    }

    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 21076
#include<stdio.h>
int main(void){
    int A,B,c[100],K,i,cou,cou2,d[100],z=0;

    scanf("%d %d %d",&A,&B,&K);
    if(A>=B){
    for(i=0;i<A;i++){
        cou=0;
        if(A%(i+1)==0){
            if(B%(i+1)==0){
                cou++;
            }
        }
        if(cou==1){
            c[i]=i+1;
        }else{
            c[i]=0;
        }
    }for(i=0;i<A;i++){
    if(c[i]!=0){
        d[z]=c[i];
        z++;
    }
    }
    printf("%d",d[z-K]);

    }else{
        for(i=0;i<B;i++){
        cou=0;
        if(A%(i+1)==0){
            if(B%(i+1)==0){
                cou++;
            }
        }
        if(cou==1){
            c[i]=i+1;
        }else{
            c[i]=0;
        }
    }for(i=0;i<B;i++){
    if(c[i]!=0){
        d[z]=c[i];
        z++;
    }
    }
    printf("%d",d[z-K]);


    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define len(a) (int)a.size()
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

struct UnionFind {
    vector<int> parent;
    UnionFind(int n) {
        parent.assign(n, -1);
    }
    int find(int x) {
        if (parent[x] < 0) return x;
        return (parent[x] = find(parent[x]));
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (size(x) < size(y)) swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
    }
    int size(int x) {
        return -parent[find(x)];
    }
};

int main() {
    int n, m; cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int a, b; cin >> a >> b;
        a--; b--;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i, n) {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 4028
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
    public static void main(String[] args) {Main instance = new Main();sc = instance.new Scanner();instance.solve();}
    private class Scanner {String[] s = new String[0];String regex = " ";int i = 0;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));public String next() {try {if (i < s.length) { return s[i++];}String st = br.readLine();while ("".equals(st)) { st = br.readLine(); }s = st.split(regex, 0);i = 0;return s[i++];} catch (IOException e) { return null; }}public int nextInt(){return Integer.parseInt(next());}}        
    private static Scanner sc;

    private void solve() {
        int H = sc.nextInt();
        int W = sc.nextInt();
        String[][] s = new String[H][W];
        for (int i = 0; i < H; i++) {
            s[i] = sc.next().split("");
        }
        
        // 幅優先探索
        int startX = 0, startY = 0, goalX = W-1, goalY = H-1;
        Deque<Integer> qx = new ArrayDeque<>();
        Deque<Integer> qy = new ArrayDeque<>();
        qx.add(startX); qy.add(startY);
        int[][] check = new int[H][W];
        int[] dirx = {0, 0, -1, 1}, diry = {-1, 1, 0, 0};
        check[startY][startX] = 1;
        while(qx.size()>0){
            int x = qx.poll(); int y = qy.poll();
            for (int i = 0; i < 4; i++) {
                int x1 = x + dirx[i], y1 = y + diry[i];
                if (0 <= x1 && x1 < W && 0 <= y1 && y1 < H) {
                    if (".".equals(s[y1][x1]) && check[y1][x1] == 0){
                        check[y1][x1] = check[y][x] + 1;
                        qx.add(x1); qy.add(y1);
                    }
                }
            }
            if (x == goalX && y == goalY){
                break;
            }
        }
        int result;
        if(check[goalY][goalX] == 0){
            result = -1;
        } else {
            result = check[goalY][goalX] - 1;
        }
        
        if (result == -1){
            System.out.println(-1);
        } else {
            int sharp = 0;
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if ("#".equals(s[i][j])) {
                        sharp += 1;
                    }
                }
            }
            System.out.println(H*W - (result+1) - sharp);
        }
    }
}

Measured memory_bytes: 23252
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(){
	const int INF=1<<29;
	for(int n;scanf("%d",&n),n;){
		vector<pair<int,int> >v(n+1);
		vector<vector<int> >m(n+1);
		for(int i=0;i<=n;i++){
			if(i)scanf("%d%d",&v[i].first,&v[i].second);
			m[i].resize(4),fill(m[i].begin(),m[i].end(),INF);
		}
		m[0][0]=0;
		int i=0;
		for(;i<n;i++){
			int f=0,j=0;
			for(;j<4;j++)if(m[i][j]<INF){
				int dist=abs(v[i+1].first-v[i].first),dt=v[i+1].second-v[i].second;
				if(j<3&&dist*(j+1)<=dt)f=m[i+1][j+1]=min(m[i+1][j+1],m[i][j]+dist);
				if(v[i+1].first+v[i].first*(j+1)<=dt)f=m[i+1][1]=min(m[i+1][1],m[i][j]+v[i+1].first+v[i].first);
			}
			if(!f)break;
		}
		if(i<n)
			printf("NG %d\n",i+1);
		else
			printf("OK %d\n",v[n].first+*min_element(m[n].begin(),m[n].end()));
	}
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n;
    cin >> n;
    vi a(3 * n);

    fo(i, 3 * n) cin >> a[i];
    sort(all(a));

    ll ans = 0;

    for ( int i = 3 * n - 2; i >= n ; i -= 2 ) {
        // cout << a[i] << endl;
        ans += a[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(2000)

n = int(input())

def dfs(is3, is5, is7, s):
    if s != "" and int(s) > n:
        return 0
    else:
        ans = 0
        if is3 and is5 and is7:
            ans += 1
        ans += dfs(True, is5, is7, s + "3")
        ans += dfs(is3, True, is7, s + "5")
        ans += dfs(is3, is5, True, s + "7")
    return ans

print(dfs(False,False,False,""))


Measured memory_bytes: 44008
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#define debug(x) cout << #x << "==" << x << endl;

using namespace std;

const int INF = 1e+8;

//??\???
#define MAX_N 50000
#define MAX_M 20
int N;
int M;
int C[MAX_M];

// dp ????????????
map<int,int> dp;


int least_coins(int s) {

  if(s < 0) { return INF; }     // checked ??§ out of bounds ??????????????????!!
  if(s == 0) { return 0; }

  if( dp.count(s) == 1 ) { return dp[s]; }

  int mn = INF;
  for(int i = 0; i < M; i++) {
    mn = min( mn, least_coins( s - C[i] ) + 1 );
  }


  return dp[s] = mn;

}

int main() {
  ios::sync_with_stdio(false);

  cin >> N >> M;
  for(int i = 0; i < M; i++) {
    cin >> C[i];
  }

  cout << least_coins(N) << endl;

  return 0;
}

Measured memory_bytes: 8560
import java.util.*;
public class Main
{
 public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    String a=sc.nextLine();
    char ch=a.charAt(0);
    if((int)ch>=65&&(int)ch<=90)
      System.out.println("A");
    else
      System.out.println("a");
  }
}

Measured memory_bytes: 35724
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    if(N==1)
    {
        cout << "Hello World" << endl;
    }else
    {
        ll A,B;
        cin >> A >> B;
        cout << A+B << endl;
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3540
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=rdsp;foreach(ref j;v.tupleof)pick(r,j);}}

void main()
{
  int n, k; readV(n, k);
  struct S { int t, d; }
  S[] s; readS(n, s);

  s.sort!"a.d>b.d";

  auto c = new int[](100001), p = 0L, q = 0L;
  foreach (i; 0..k) {
    if (c[s[i].t]++ == 0) ++q;
    p += s[i].d;
  }

  auto r = p+q*q, i = k-1, j = k;

  auto findOut(int i)
  {
    for (; i >= 0; --i)
      if (c[s[i].t] >= 2)
        return i;
    return -1;
  }

  auto findIn(int j)
  {
    for (; j < n; ++j)
      if (c[s[j].t] == 0)
        return j;
    return -1;
  }

  for (;;) {
    i = findOut(i);
    if (i == -1) break;
    --c[s[i].t];
    p -= s[i].d;
    --i;

    j = findIn(j);
    if (j == -1) break;
    ++c[s[j].t];
    p += s[j].d;
    ++j;

    ++q;
    r = max(r, p+q*q);
  }

  writeln(r);
}


Measured memory_bytes: 4476
# coding: utf-8

N = int(raw_input())

dataList = []
for i in range(N):
    list = map(int, raw_input().split())
    dataList.append(list)

# find max number
for i in range(len(dataList)):
    idx = dataList[i].index(max(dataList[i]))
    lar = dataList[i][idx]
    del dataList[i][idx]
    if lar**2 == dataList[i][0] ** 2 + dataList[i][1]**2:
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 6508
import math
#import itertools
#import statistics
#import numpy as np
#import collections
n = int(input())
#a = list(map(int, input().split()))
#a = list(map(int, input().split()))
s = input()
ans = 0
for i in range(1,len(s)):
    a = s[:i]
    b = s[i:]
    count = 0
    for j in range(len(a)):
        if a[j] in b:
            flag = True
            if j > 0:
                for k in range(j):
                    if a[j]==a[k]:
                        flag=False
            if flag:
                count += 1
                #print(a[j]+" "+str(count), end="")
    #print(count)
    #print()
    if ans < count:
        ans = count

print(ans)

Measured memory_bytes: 3064
#include <map>
#include <list>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int a,b,c,d;
int main()
{
    fast;
	cin>>a>>b>>c>>d;
	cout<<max(a*b,c*d)<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

dp = [float("inf")] * n
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2, n):
    dp[i] = min(dp[i - 1] + abs(h[i]-h[i - 1]), dp[i - 2] + abs(h[i]-h[i - 2]))

print(dp[n - 1])

Measured memory_bytes: 20624
n,c,k=map(int,input().split())
t=[int(input()) for i in range(n)]
t=sorted(t)
time=t[0]
cnt=0
ans=0
for i in range(n):
    #制限時間以内かつC人以内
    if time+k>=t[i] and cnt<=c-1:
        cnt+=1

    else:
        ans+=1
        time=t[i]
        cnt=1
print(ans+1)

Measured memory_bytes: 8280
#include <bits/stdc++.h>
#define INF (1e9)
#define N 1050
using namespace std;
int dat[N][N],dp[N][N],ans,ans2;
int m,n,y,x,p,k,sy,sx,check[N][N];
int ymin,ymax,xmin,xmax;
bool prime[N*N];

int main(){
  int dy[4]={0,-1,0,1};
  int dx[4]={1,0,-1,0};
  for(int i=0;i<N*N;i++)prime[i]=true;
  prime[0]=prime[1]=false;
  for(int i=0;i<=N*N/2;i++){
    if(!prime[i])continue;
    for(int j=i+i;j<N*N;j+=i)prime[j]=false;
  }
  while(1){
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)dat[i][j]=-1,dp[i][j]=check[i][j]=0;
    cin>>m>>n;
    if(!m&&!n)break;
    sy=sx=y=x=N/2;
    dat[y][x]=1;
    k=ymax=xmax=0,p=1;
    ymin=xmin=INF;
    while(p<m){
      p++;
      int lot=(k+1)%4;
      if(p!=2&&dat[y+dy[lot]][x+dx[lot]]<0)k=lot;
      y+=dy[k];
      x+=dx[k];
      dat[y][x]=p;
      ymin=min(ymin,y);
      xmin=min(xmin,x);
      ymax=max(ymax,y);
      xmax=max(xmax,x);
      if(p==n)sy=y,sx=x;
    }
    check[sy][sx]=1;
    for(int i=ymin;i<=ymax;i++)
      for(int j=xmin;j<=xmax;j++){
	if(!check[i][j])continue;
	check[i+1][j-1]=check[i+1][j]=check[i+1][j+1]=1;
      }
    ans=0;
    for(int i=ymin;i<=ymax;i++){
      for(int j=xmin;j<=xmax;j++){
	if(dat[i][j]<0||!check[i][j])continue;
	if(prime[dat[i][j]])dp[i][j]++;
	ans=max(ans,dp[i][j]);
	dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]);
	dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
	dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]);
      }
    }
    ans2=0;
    for(int i=ymin;i<=ymax;i++){
      for(int j=xmin;j<=xmax;j++){
	if(prime[dat[i][j]]&&check[i][j]&&ans==dp[i][j])ans2=max(ans2,dat[i][j]);
      }
    }
    if(ans!=0)cout<<ans<<' '<<ans2<<endl;
    else cout<<0<<' '<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 15160
n,t=map(int,input().split())
l=[[int(j) for j in input().split()] for i in range(n)]
a=[]
for i in range(n):
    if l[i][1]<=t:
        a.append(l[i][0])
if a!=[]:
    print(min(a))
else:
    print("TLE")

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

using namespace std;








int main(){

    int A=0;
    int B=0;
    int N=0;

     
    
    cin >> N >> A >> B;

    int x = (B-A)%2;
    
    if(x==0)cout << "Alice";
    else cout << "Borys";
    
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;


int main()
{
	int n;
	cin >> n;
	long long int lucas[87];
	lucas[0] = 2;
	lucas[1] = 1;
	for (int i = 2; i <= n; i++) {
		lucas[i] = lucas[i - 1] + lucas[i - 2];
	}
	cout << lucas[n] << 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++)
#define N 1000000007
typedef long long ll;
#define all(v) (v).begin(),(v).end()
#define sz(x) int(x.size())
const int MAX = 1000000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
	int x,y;
	cin>>x>>y;
	COMinit();
	ll ans;
	if((x+y)%3!=0){
		ans=0;
	}else{
	int r=(x*2-y)/3;
	
	
	ans=COM((x+y)/3,r);
	}
	cout<<ans<<endl;
	return 0;
	
}

Measured memory_bytes: 23680
#include<iostream>
using namespace std;
int bubbleSort(int A[],int N){
 int sw=0;
 bool flag=1;
 for(int i=0;flag;i++){
  flag=0;
  for(int j=N-1;j>=i+1;j--){
   if(A[j]<A[j-1]){
    swap(A[j],A[j-1]);
    flag=1;
    sw++;
   }
  }
 }
 return sw;
}
int main(){
 int A[100],N,sw;
 cin>>N;
 for(int i=0;i<N;i++)cin>>A[i];
 sw=bubbleSort(A,N);
 for(int i=0;i<N;i++){
  if(i)cout<<" ";
  cout<<A[i];
 }
 cout<<endl;
 cout<<sw<<endl;
 return 0;
}


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

    class Program
    {
        static void Main(string[] args)
        {
            var C = new List<List<int>>();
            for(int i=0;i<3;i++)
                C.Add(Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToList());

            if((C[0][0]- C[1][0]== C[0][1] - C[1][1]&& C[0][1] - C[1][1] == C[0][2] - C[1][2]) &&
               (C[0][0] - C[2][0] == C[0][1] - C[2][1] && C[0][1] - C[2][1] == C[0][2] - C[2][2])
                )
            {
                Console.WriteLine("Yes");
                return;
            }

            Console.WriteLine("No");
        }
    }

Measured memory_bytes: 11348
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int x=fs.nextInt(), y=fs.nextInt();
		if (y%2==1) {
			System.out.println("No");
			return;
		}
		y/=2;
		if (y<x || y>2*x) {
			System.out.println("No");
		}
		else {
			System.out.println("Yes");
		}
	}

	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 32684
#c welcome to atcoder
import sys
n,m=map(int,input().split())
ps=[]
num={}
#辞書
ac=0
pena=0
if m==0:
    print('0 0')
    sys.exit()
for i in range(m):
    result=input().split()
    ps.append(result)
    if result[1]=="AC":
        num[result[0]]=0

for x in ps:
    if not x[0] in num:
        continue
    if x[1]=="WA" and num[x[0]]==0:
        pena+=1
    if x[1]=="AC" and num[x[0]]==0:
        ac+=1
        num[x[0]]=1

print(ac,pena)

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

int main(void){
   int a,b;
   cin >> a >> b;
   
   if(a<b){
       cout << "a < b";
   }
   else if(a>b){
       cout << "a > b";
   }
   else{
       cout << "a == b";
   }
   cout << endl;
}


Measured memory_bytes: 3084
import java.util.ArrayList;
import java.util.Scanner;
// A - Number of Multiples
class Main{
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        int C = 0;

		ArrayList<Integer> lstA;

		lstA = new ArrayList<Integer>();

		for (int i=1; i <= N; i++) {
			int x = sc.nextInt();

			if (i%2!=0 && x%2!=0) {
				C++;
			}
		}
		System.out.println(C);
		return;


	}
}

Measured memory_bytes: 27172
#include <bits/stdc++.h>
 
typedef long long ll;

using namespace std;
using Graph = vector<vector<int>>;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;

const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000


void Main() {
    ll a, b, c, d;

    cin >> a >> b >> c >> d;

    while(true) {
        c = c - b;
        if (c <= 0) {
            COUT("Yes");
            break;
        }
        a = a - d;
        if (a <= 0) {
            COUT("No");
            break;
        }
    }
} 

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}



Measured memory_bytes: 3664
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left, bisect_right
from fractions import gcd
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A, B, C, D = MI()
    lcm = C * D // gcd(C, D)
    ans = B-(B // C + B // D - B // lcm)
    ans -= (A-1)-((A-1)//C + (A-1)//D - (A-1)//lcm)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 66156
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,x,y,ans=0,curr;
    scanf("%d",&n);
    scanf("%d",&k);

    curr = n%500;

    if(curr <= k)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<string,int> a;  //映射  
int main()
{
    int n,num=0;
    string s;
    cin>>n;
    for(int i=1;i<=n;i++)
	{
		 cin>>s;
		 if(a[s]==0)  
		 {
		 	 num++;a[s]++;
		 }
		 else
		    a[s]++;
	 } 
   cout<<num;
return 0;
}


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

using namespace std;
int n , m ,k , sx , sy;
int g[1000][1000];
int vis[1000][1000];
int dx[]={1 , 0 , -1 , 0 };
int dy[]={0 , 1 , 0 , -1 };
int ans ;
bool get(int x ,int y){
    return (x>=0 && y>=0 && x<n && y<m && g[x][y] && vis[x][y]==-1);
}

int calc(int x , int y){
    int a = min(x,y);
    a = min(a, min(n-1-x,m-1-y));
    return a/k+((a%k)>0);
}

int bfs(){
    ans = 100000;
    queue<pair<int,int> > Q ;
    Q.push(make_pair(sx,sy));
    memset(vis,-1,sizeof vis);
    vis[sx][sy]=0;
    while(!Q.empty()){
        int  x = Q.front().first;
        int y = Q.front().second;
        Q.pop();

        ans = min(ans , 1 + calc(x, y));
        if(vis[x][y]==k) continue;
        for(int i = 0 ; i< 4 ; i++){
            int xx = x +dx[i];
            int yy = y + dy[i];
            if(get(xx,yy)) {
                vis[xx][yy]=vis[x][y]+1;
                Q.push(make_pair(xx,yy));
            }
        }
    }
    return ans;
}

int main()
{

    cin >> n >> m >> k ;
    for(int i = 0 ; i< n ; i++){
        string s ;
        cin >> s ;
        for(int j = 0 ; j<m ; j++){
            if(s[j]=='.')g[i][j]=1;
            if(s[j]=='S')g[i][j]=1 , sx = i , sy = j;
        }
    }
    cout << bfs();
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define PB push_back
#define PF push_front
#define MP make_pair
typedef long long int ll;
const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  
  cout << n * (n - 1) / 2 <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MAX = 1e3;

int n;

vector<int> G[MAX];
vector<int> state(MAX);
vector<int> vs;

bool dfs(int v) {
  if (state[v] == 1) {
    vs.erase(vs.begin(), find(vs.begin(), vs.end(), v));
    return true;
  }
  else if (state[v] == -1) return false;
  state[v] = 1;
  vs.push_back(v);
  for (int u: G[v]) {
    if (dfs(u)) return true;
  }
  state[v] = -1;
  vs.pop_back();
  return false;
}

void solve() {
  vector<int> nxt(n), visited(n), erased(n, 1);
  rep(i, vs.size()) {
    int v = vs[i], u = vs[(i + 1) % vs.size()];
    nxt[v] = u;
    erased[v] = 0;
  }
  int v = vs[0];
  while (!visited[v]) {
    for (int u: G[v]) {
      if (erased[u]) continue;
      int nv = v;
      while (nxt[nv] != u) {
        nv = nxt[nv];
        erased[nv] = 1;
      }
      nxt[v] = u;
    }
    visited[v] = 1;
    v = nxt[v];
  }
  vector<int> ans;
  int sv = v;
  while (1) {
    ans.push_back(v);
    v = nxt[v];
    if (v == sv) break;
  }
  cout << ans.size() << endl;
  rep(i, ans.size()) cout << ans[i] + 1 << endl;
}


int main() {
  int m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
  }

  rep(i, n) {
    if (state[i] == 0) {
      if (dfs(i)) {
        solve();
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;



  
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<map>

using namespace std;
const int INF = 1<<30;
typedef long long int ll;

int main(){
	int a, b, k;cin>>a>>b>>k;
	for(int i=0;i<k;i++){
		if(i%2==0){
			a/=2;
			b+=a;
		}else{
			b/=2;
			a+=b;
		}
	}
	cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
int a,b;
std::string op;
std::vector<int> vec;
const int calc(){
	if(op=="+")return a+b;
	if(op=="-")return a-b;
	if(op=="*")return a*b;
	if(op=="/")return a/b;
}
int main(){
	do{
		std::cin>>a>>op>>b;
		if(op!="?")vec.push_back(calc());
	}while(op!="?");
	for(auto v:vec){
		std::cout<<v<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
const long long mod = 1000000007;

int main() {
	int N;
	scanf("%d", &N);
	int *p = new int[N];
	for (int i = 0; i < N; i++) {
		scanf("%d", &p[i]);
	}
	int res = 0;
	for (int i = 0; i < N - 2; i++) {
		if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) {
			res++;
		}
		if (p[i] > p[i + 1] && p[i + 1] > p[i + 2]) {
			res++;
		}
	}
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    if(S[0] == 'S'){
        cout << "Cloudy" << endl;
    }else if(S[0] == 'C'){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }

    return 0;
}

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

int main(){
  int s;
  cin >> s;
  vector<int> x(1000000);
  x[0]=s;
  for(int i=1;i<1000000;i++){
    if(x[i-1]%2==0){
      x[i]=x[i-1]/2;
    }else{
      x[i]=3*x[i-1]+1;
    }
    for(int j=0;j<i;j++){
       if(x[i]==x[j]){
         cout << i+1 << endl;
         return 0;
       }
    }
  }
}

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

bool if_Bingo(int A[3][3]){
    for(int i=0;i<3;i++){
        if(A[i][0]==0&&A[i][1]==0&&A[i][2]==0)return true;
        if(A[0][i]==0&&A[1][i]==0&&A[2][i]==0)return true;
    }
    if(A[0][0]==0&&A[1][1]==0&&A[2][2]==0)return true;
    if(A[2][0]==0&&A[1][1]==0&&A[0][2]==0)return true;
    return false;
}

void search_match(int A[3][3],int key){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(A[i][j]==key){A[i][j]=0;return;}
        }
    }
    return;
}

int main(){
    int A[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>A[i][j];
        }
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        search_match(A,k);
    }
    if(if_Bingo(A)){
        printf("Yes\n");return 0;
    }
    else{printf("No\n");return 0;}

}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int mx[1<<18][2];
vector<ll> A;

void mg(int *i, int *j, int *ptr) {
	int aa[2], bb[2];
	aa[0] = i[0]; aa[1] = i[1];
	bb[0] = j[0]; bb[1] = j[1];

	int a, b;
	a = b = 0;
	for(int i = 0; i < 2;) {
		if(A[aa[a]] < A[bb[b]]) {
			if(i==0 || bb[b] != ptr[i-1]) {
				ptr[i] = bb[b];
				i++;
			}
			b++;
		}
		else {
			if(i==0 || aa[a] != ptr[i-1]) {
				ptr[i] = aa[a];
				i++;
			}
			a++;
		}
	}
}

int main() {
	int N;
	cin >> N;
	A.resize((1<<N)+2);
	A[1<<N] = A[(1<<N)+1] = 0;
	rep(i,1<<N) cin >> A[i];

	rep(i,1<<N) {
		mx[i][0] = i;
		mx[i][1] = 1<<N;
	}

	rep(i,1<<N) {
		for(int j = 0; j < N; j++) {
			if( (i & (1<<j)) == 0) {
				//int zero[2] = {(1<<N)+1,1<<N};
				mg(mx[i], mx[i^(1<<j)], mx[i^(1<<j)]);
				//cout << mx[i^(1<<j)][0] << " " << mx[i^(1<<j)][1] << endl;
			}
		}
	}

	ll res = 0;
	rep(i,1<<N) {
		/*
		cout << "*" << i << endl;
		cout << "+" << mx[i][0] << " " << mx[i][1] << endl;
		// */
		res = max(res, A[mx[i][0]] + A[mx[i][1]]);
		if(i) {
			cout << res << endl;
		}
	}
	return 0;
}


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

using namespace std;

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

int a[3][7] = {{1, 3, 5, 7, 8, 10, 12}, {4, 6, 9, 11, 0, 0, 0}, {2, 0, 0, 0, 0, 0, 0}};

int main(){
    int x, y;
    cin >> x >> y;
    bool flag = false;
    REP(i, 3){
        if(find(a[i], a[i]+7, x)!=end(a[i]) && find(a[i], a[i]+7, y)!=end(a[i])){
            flag = true;
        }
    }
    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

int main(void)
{
	ios_base::sync_with_stdio(0);
	int a, b;
	cin >> a >> b;
	if(a >= 13)
                cout << b;
        else if(a <= 5)
                cout << 0;
        else
                cout << b / 2;
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n; cin >> n;
	vector<Int> a(n);
	for(auto &i:a) cin >> i;
	vector<Int> c(n, 0);
	for(auto i:a) ++c[i-1];
	vector<Int> d(n+2, 0);
	for(auto i:c) ++d[i];
	vector<Int> e(d);
	for(Int i=0; i<n+1; ++i)
		e[i] *= i;
	for(Int i=1; i<n+1; ++i)
		e[i] += e[i-1];
	for(Int i=n; i>=0; --i)
		d[i] += d[i+1];
	vector<Int> f(n+1);
	f[0] = n;
	for(Int i=1; i<n+1; ++i)
		f[i] = (e[i] + i*d[i+1]) / i;
	Int tmp = n;
	for(Int i=0; i<n; ++i){
		while(tmp > 0 && f[tmp] < i+1) --tmp;
		cout << tmp << "\n";
	}
//	for(Int i=0; i<n+1; ++i)
//		cout << " " << d[i] << " " << e[i] << " " << f[i] << "\n";
}

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

using namespace std;

int main(){

    int N;
    cin >> N;

    string s = to_string(N);
    int sn;
    for(int i=0; i<s.length(); i++){
        char n = s[i];
        sn += atoi(&n);
    }

    if(N%sn == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256