akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const ll INF = ll(6e18);

ll mult(ll a, ll b)
{
	if(a==0||b==0) return 0;
	if(a>=INF/b) return INF;
	return a*b;
}

ll add(ll a, ll b)
{
	if(a>=INF-b) return INF;
	return a+b;
}

void dfs(vector<vector<ll> > &seqs, vector<ll> &v, ll cur = 1)
{
	cout<<seqs.size()<<endl;
	bool nopush=1;
	if(mult(cur,2)<INF)
	{
		nopush=0;
		v.pb(2);
		dfs(seqs,v,cur*2);
		v.pop_back();
	}
	if(mult(cur,3)<INF)
	{
		nopush=0;
		v.pb(3);
		dfs(seqs,v,cur*3);
		v.pop_back();
	}
	if(mult(cur,5)<INF)
	{
		nopush=0;
		v.pb(5);
		dfs(seqs,v,cur*5);
		v.pop_back();
	}
	if(nopush) seqs.pb(v);
}

unordered_map<ll,ll> dp;
ll n,a,b,c,d; 
	
ll solve(ll n)
{
	if(n==0) return 0;
	if(n==1) return d;
	if(dp.count(n)) return dp[n];
	ll ans=mult(n,d);
	if(n/2+1<n) ans=min(ans,solve(n/2+1)+a+(2-n%2)*d);
	if(n/2>0) ans=min(ans,solve(n/2)+a+(n%2)*d);
	if(n/3+1<n) ans=min(ans,solve(n/3+1)+b+(3-n%3)*d);
	if(n/3>0) ans=min(ans,solve(n/3)+b+(n%3)*d);
	if(n/5+1<n) ans=min(ans,solve(n/5+1)+c+(5-n%5)*d);
	if(n/5>0) ans=min(ans,solve(n/5)+c+(n%5)*d);
	return (dp[n]=ans);
}

void solve()
{
	cin>>n>>a>>b>>c>>d;
	dp.clear();
	cout<<solve(n)<<'\n';
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t; cin>>t;
	while(t--) solve();
}


Measured memory_bytes: 4192
#include<iostream>
#include<cstdio>
#include<vector>
const int N=20;
typedef std::pair<int,int> P;
std::vector<P> g[N];
int main() {
    int ans=0,n;
    scanf("%d",&n);
    for(int i=0,a,x,y;i<n;i++) {
        scanf("%d",&a);
        while(a--) {
            scanf("%d%d",&x,&y);
            --x;
            g[i].push_back(P(x,y));
        }
    }
    for(int i=1;i<1<<n;i++) {
        bool ok=true;
        for(int j=0;j<n&&ok;j++) if(i>>j&1) {
            for(P c:g[j]) if((i>>c.first&1)!=c.second) ok=false;
        }
        if(ok) {
            int cnt=0;
            for(int j=0;j<n;j++) if(i>>j&1) cnt++;
            ans=std::max(ans,cnt);
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#define int long long
#define MAX(a,b) ((a) > (b)) ? (a) : (b)
#define MIN(a,b) ((a) < (b)) ? (a) : (b)
using namespace std;

signed main()
{
	int a, b;
	cin >> a >> b;
	if (a == 1) a = 20;
	if (b == 1) b = 20;
	if (a > b)
	{
		cout << "Alice" << endl;
	}
	else if (a < b)
	{
		cout << "Bob" << endl;
	}
	else
	{
		cout << "Draw" << endl;
	}
}


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

def main():
    N,M = map(int,input().split())
    a = list(map(int,input().split()))
    d = [-1,2,5,5,4,5,6,3,7,6]
    
    keta = [-1]*(N+10)
    keta[0] = 0
    
    for i in range(N):
        for num in a:
            if keta[i] != -1:
                keta[i+d[num]] = keta[i]+1

    use = N
    
    ans = [-1]*(N+10)
    ans[0] = 0
    for i in range(N):
        for num in a:
            if keta[i+d[num]] == keta[i]+1:
                ans[i+d[num]] = max(ans[i+d[num]],ans[i]*10+num)
    
    print(ans[N])
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 49884
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll N, M;
map<ll, vector<ll>> mp;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  for (ll i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    mp[a].push_back(b);
  }

  ll ans = 0;
  priority_queue<ll> pq;
  for (ll i = 1; i <= M; i++) {
    if (!mp[i].empty()) {
      for (auto e : mp[i]) {
        pq.push(e);
      }
    }

    if (!pq.empty()) {
      ll v = pq.top();
      pq.pop();
      ans += v;
    }
  }

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

Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define N 100005
using namespace std;
typedef long long ll;
string beg;
char s[N],t[N];
ll nxt[N][26],st[26],len1,len2,id,ans=1;
int main() {
	cin>>beg,len1=beg.size();
	for(int i=1;i<=len1;i++)s[i]=beg[i-1];
	cin>>beg,len2=beg.size();
	for(int i=1;i<=len2;i++)t[i]=beg[i-1];
    for(int i=len1;i>=0;i--){
        for(int j=0;j<26;j++)nxt[i][j]=st[j];
        if(i)st[s[i]-'a']=i;
    }
    for(int i=1;i<=len2;i++){
        if(nxt[id][t[i]-'a'])id=nxt[id][t[i]-'a'];
		else{
            if(!st[t[i]-'a']){
                cout<<-1<<endl;
                return 0;
            }
            id=st[t[i]-'a'];
            ans++;
        }
    }
    cout<<(ans-1)*len1+id<<endl;
    return 0;
}

Measured memory_bytes: 24284
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
  int key;
  Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
  Node *cur = nil->next;
  while ( cur != nil && cur->key != key ) {
      cur = cur->next;
  }
  return cur;
}

void init(){
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  Node  *cur = nil->next;
  int isf = 0;
  while(1){
    if ( cur == nil ) break;
    if ( isf++ > 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t){
  if (t == nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	    if ( com[6] == 'F' ) deleteFirst();
	    else if ( com[6] == 'L' ) deleteLast();
      } else {
	    deleteKey(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 33828
a = list(input())
op = [bin(i)[2:].zfill(3) for i in range(8)]
for i in range(8):
    ans = int(a[0])
    ans_ar = [a[0]]
    for j in range(3):
        if op[i][j] == "0":
            ans += int(a[j+1])
            ans_ar.append("+")
        else:
            ans -= int(a[j+1])
            ans_ar.append("-")
        ans_ar.append(a[j+1])
    if ans == 7:
        ans_ar = ans_ar + ["=", "7"]
        print("".join(ans_ar))
        exit()




Measured memory_bytes: 3064
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<functional>
 #include<utility>
 
 using namespace std;
 
 int main()
 {
   int N;
   while(cin>>N&&N)
   {
     long long int arr[100+2][100+2];
     int hand[100+2][100+2]={{0}};
     for(int i=0;i<N;i++) for(int j=0;j<N;j++) cin>>arr[i][j];
     for(int i=0;i<N;i++)
     {
       long long int max=0;
       int max_x,max_y;
       long long int dis=arr[0][i];
       int count=0;
       for(int j=0;j<N;j++)
       {
         //if(j>0) 
         //{
         //  if(arr[j][i]==dis) count++;        
         //} 
         if(arr[j][i]>max)
         {
           max=arr[j][i];
           max_x=j;
           max_y=i;                 
         }        
       }   
       for(int j=0;j<N;j++) if(arr[j][i]==max) hand[j][i]++;  
       //if(count<2) hand[max_x][max_y]++;
       //hand[max_x][max_y]++;
     } 
     for(int i=0;i<N;i++)
     {
       long long int min=1<<30;
       int min_x,min_y;
       long long int dis2=arr[i][0];
       int count2=0;
       for(int j=0;j<N;j++)
       {
         //if(j>0)
         //{
         //  if(arr[i][j]==dis2) count2++;       
         //}
         if(arr[i][j]<min)
         {
           min=arr[i][j];
           min_x=i;
           min_y=j;                 
         }        
       }   
       for(int j=0;j<N;j++) if(arr[i][j]==min) hand[i][j]++;     
       //if(count2<2) hand[min_x][min_y]++;
       //hand[min_x][min_y]++;
     }
     long long int result;
     bool flag=false;
     for(int i=0;i<N;i++)
     {
       for(int j=0;j<N;j++)
       {
         if(hand[i][j]==2)
         {
           result=arr[i][j];
           flag=true;
           break;                 
         }        
       }        
     }
     if(!flag) cout<<"0"<<endl;
     else cout<<result<<endl;
   }
   //while(1);
   return 0;
 }

 
  

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

int main(){
    int N, Y;
    cin >> N >> Y;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N - i; j++){
            int n = 10000 * i + 5000 * j + 1000 * (N - i - j);
            if (n == Y) {
                cout << i << " " << j << " " << N - i - j << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <boost/xpressive/xpressive.hpp>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;
namespace xp = boost::xpressive;

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

  S.pop_back();
  xp::smatch m;
  const xp::sregex re = xp::sregex::compile("^([a-z]+)\\1");
  xp::regex_search(S, m, re);
  cout << m.str().length() << endl;
  return 0;
}


Measured memory_bytes: 3880
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] s = saori.nextHayami().split("");
		if(s.length%2 != 0){
			System.out.println("No");
			return;
		}
		for(int i = 0;i < s.length;i++){
			if(i % 2 == 0){
				if(!s[i].equals("h")){
					System.out.println("No");
					return;
				}
			} else {
				if(!s[i].equals("i")){
					System.out.println("No");
					return;
				}
			}
		}
		System.out.println("Yes");
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

template<typename T>
T gcd(T a, T b) {
	if( a < b ) swap(a, b);
	
	T r;
	while( r = a % b ) {
		a = b;
		b = r;
	}
	
	return b;
}

template<typename T>
T lcm(T a, T b) {
	return (a / gcd(a, b)) * b;
}

int main(void) {
	ll a, b;
	cin >> a >> b;
	cout << lcm(a, b) << endl;
	
	return 0;
}


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

typedef long l;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define mp make_pair

const int DX[] = {1, 0, -1, 0, 1, 1, -1, -1}, DY[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, d;

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

  cout << min(a, b) + min(c, d) << endl;

}



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

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

#define MAX_ 5000000
int inv_list[MAX_]; //inv_list[i-1] = inverse of i
int fac[MAX_];
int finv[MAX_];
void nCk_init() {
  inv_list[0] = fac[0] = finv[0] = 1;
  for (int i = 0; i < MAX_ - 1; i++) {
    inv_list[i + 1] = MOD - ((inv_list[(MOD % (i + 2)) - 1] * (MOD / (i + 2))) % MOD);
    fac[i + 1]      = (fac[i] * (i + 2)) % MOD;
    finv[i + 1]     = (finv[i] * inv_list[i + 1]) % MOD;
  }
}
int nCk(int n, int k) {
  if (n == k or k == 0) return 1;
  return (fac[n - 1] * ((finv[k - 1] * finv[n - k - 1]) % MOD)) % MOD;
}

class FStrivore {
public:
  static void solve(istream &cin, ostream &cout) {
    int K;
    string S;
    cin >> K >> S;
    nCk_init();
    int ans = 0;
    rep(i, K + 1) {
      ans += mod(nCk(S.size() + i - 1, S.size() - 1) * bpm(25, i), MOD) * bpm(26, K - i);
      ans = mod(ans, MOD);
    }
    cout << ans << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  FStrivore solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf (1 << 21)
#define mod 1000000007

int main() {
    ll N, A, B, C, D, E; cin >> N >> A >> B >> C >> D >> E;
    ll minpart1 = min(A, B), minpart2 = min(C, D), minpart3 = min(minpart1, minpart2), m = min(E, minpart3);
    ll n = (N + m - 1) / m;
    ll ans = n + 4;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int n, m, k, x, y, sum, cnt, ans, a[200005],b [200005];
int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	scanf("%d", &n);
	FOR(i, 0, n-1) {
		scanf("%d", &a[i]);
		b[i]=a[i];
	}
	sort(b, b+n);
	FOR(i, 0, n-1) {
		if (a[i]==b[n-1]) printf("%d\n", b[n-2]);
		else printf("%d\n", b[n-1]);
	}
	return 0;
}

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

using namespace std;

int main(){
    long K;
    long A, B;
    cin>>K>>A>>B;

    if(A>=B || B-A==1){
        cout<<1+K<<endl;
        return 0;
    }

    long bis = 1 + A-1;
    K -= A-1;
    while(K>1){
        bis += B-A;
        K-=2;
    }
    if(K>0){
        bis+=1;
    }
    
    cout<<bis<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.awt.Point;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n, m;
		Point chart[] = new Point[200];
		Point stars[] = new Point[1000];
		Point cMove = new Point();
		Point sMove = new Point();

		n = scanner.nextInt();
		while (n != 0) {
			for (int i = 0; i < n; i++) {
				int a = scanner.nextInt();
				int b = scanner.nextInt();
				chart[i] = new Point(a, b);
			}
			m = scanner.nextInt();
			for (int i = 0; i < m; i++) {
				int a = scanner.nextInt();
				int b = scanner.nextInt();
				stars[i] = new Point(a, b);
			}
			cMove = translation(n, chart, chart[0]);

			for (int i = 0; i < m; i++) {
				sMove = translation(m, stars, stars[i]);

				if (contains(n, chart, m, stars)) {
					break;
				}

				translation(m, stars, sMove);
			}
			System.out.println((cMove.x - sMove.x) + " " + (cMove.y - sMove.y));
			n = scanner.nextInt();
		}
	}

	public static Point translation(int n, Point p[], Point move) {
		Point a = new Point(move.x, move.y);
		for (int i = 0; i < n; i++) {
			p[i].x -= a.x;
			p[i].y -= a.y;
		}
		a.x *= -1;
		a.y *= -1;
		return a;
	}

	public static boolean contains(int n, Point chart[], int m, Point stars[]) {
		int i, j;
		for (i = 0; i < n; i++) {
			for (j = 0; j < m; j++) {
				if (chart[i].equals(stars[j])) {
					break;
				}
			}
			if (j == m) {
				return false;
			}
		}
		return true;
	}

	public static void print(int n, Point a[]) {
		for (int i = 0; i < n; i++) {
			System.out.println(a[i].x + ", " + a[i].y);
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<algorithm>
#include<cstdint>

int const MAXN = 1e5;

int64_t p[MAXN+1], q[MAXN+1], r[MAXN];
int64_t x[MAXN*2+1];
int X, Y, A, B, C;

int main() {
  std::cin >> X >> Y >> A >> B >> C;
  for(int i = 0; i < A; ++i) std::cin >> p[i];
  for(int i = 0; i < B; ++i) std::cin >> q[i];
  for(int i = 0; i < C; ++i) std::cin >> r[i];
  std::sort(p, p+A);
  std::sort(q, q+B);
  std::sort(r, r+C);
  std::copy(p + A-X, p+A, x);
  std::copy(q + B-Y, q+B, x+X);
  std::sort(x, x+X+Y); x[X+Y] = 1e10;
  int ix = 0;
  for(int ic = C-1; ic >= 0; --ic) {
    if(x[ix] >= r[ic]) break;
    x[ix++] = r[ic];
  }
  int64_t ans = 0;
  for(int i = 0; i < X+Y; ++i) ans += x[i];
  std::cout << ans << std::endl;
  return 0;
}


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

struct Pos {
    int x, y, h;
};

bool h_sort(const Pos &a, const Pos &b) {
    return (a.h > b.h);
}

int main() {
    int n;
    int tmp;
    int cx, cy, ch;
    
    cin >> n;
    vector<Pos> p(n);
    
    for (int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y >> p[i].h;
    }
    
    sort(p.begin(), p.end(), h_sort);
    
    for (int x = 0; x <= 100; x++) {
        for (int y = 0; y <= 100; y++) {
            ch = -1;
            
            for (int i = 0; i < n; i++) {
                if (p[i].h == 0) {
                    break;
                }
                
                tmp = abs(x - p[i].x) + abs(y - p[i].y) + p[i].h;
                
                if (ch == -1) {
                    ch = tmp;
                }
                else if (ch != tmp) {
                    ch = -2;
                    break;
                }
            }
            
            if (ch == -2) {
                continue;
            }
            
            for (int i = 0; i < n; i++) {
                tmp = max(ch - abs(x - p[i].x) - abs(y - p[i].y), 0);
                
                if (tmp != p[i].h) {
                    ch = -2;
                    break;
                }
            }
            
            if (ch != -2) {
                cx = x;
                cy = y;
                break;
            }
        }
        
        if (ch != -2) {
            break;
        }
    }
    
    printf("%d %d %d\n", cx, cy, ch);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#define rep(i,rept) for(long long i = 0; i <(long long)rept;i++)
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0,x=0,y=0,z=0;
	char rikka, toka[100000];
	string saya, homu, kyok, mami, mado[50];
	bool gg = true;
	int manji, nk[26] = { false };
	cin >> saya>>homu;
	for (int i = 0; i < saya.length(); i++) {
		if (saya.substr(i, saya.length() - i) + saya.substr(0, i) == homu) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
var input = require("fs").readFileSync("/dev/stdin", "utf8");

var lines = input.split('\n');
var N = Number(lines[0]);
var An = lines[1].split(' ');
var Bn = lines[2].split(' ');
var Cn = lines[3].split(' ');

var listA = [];
var listB = [];
var listC = [];
for (var i = 0; i < N; i++) {
    listA.push(Number(An[i]));
    listB.push(Number(Bn[i]));
    listC.push(Number(Cn[i]));
}
function asc(a, b) { return a - b; }
listA.sort(asc);
listB.sort(asc);
listC.sort(asc);

var sum = 0;
var iA = 0;
var iC = 0;
var countA = 0;
var countC = 0;
for (var iB = 0; iB < N; iB++) {
    var b = listB[iB];
    for (var i = iA; i < N; i++) {
        var a = listA[i];
        if (b <= a) {
            break;
        } else {
            iA = i;
            countA = i + 1;
        }
    }
    for (var i = iC; i < N; i++) {
        var c = listC[i];
        if (b < c) {
            break;
        } else {
            iC = i;
            countC = i + 1;
        }
    }
    sum += countA * (N - countC);
}

console.log(sum);

Measured memory_bytes: 69968
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
 
using namespace std;
 
int main(){
int A,B;
 
cin >> A;
  cin >> B;
  
  
  if((A+B)%2 == 0){
  cout << (A + B)/2;
  }else{
  
 cout << ((A + B)/2) + 1;
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
public class Main {

	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String in = br.readLine();
		String out =new String();
		out = in.substring(0, 5)+' '+in.substring(6,13)+' '+in.substring(14);
		System.out.println(out);
	}
}


Measured memory_bytes: 8148
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
typedef set<ll> Set;
const ll max_s=1000010;
const ll MOD=1e9+7;

string s;
ll dp1[max_s],dp2[max_s];

void dp(){
    if(s[0]==0){
        dp1[0]=1;
        dp2[0]=0;
    }
    else{
        dp1[0]=2;
        dp2[0]=1;
    }
    for(ll i=1;i<s.size();i++){
        if(s[i]=='0'){
            dp1[i]=dp1[i-1];
            dp2[i]=dp2[i-1]*3;
            dp2[i]%=MOD;
        }
        else{
            dp1[i]=dp1[i-1]*2;
            dp1[i]%=MOD;
            dp2[i]=dp1[i-1]+dp2[i-1]*3;
            dp2[i]%=MOD;
        }
    }
}

int main(){
    cin >> s;
    rep(i,max_s){
        dp1[i]=0;dp2[i]=0;
    }
    dp();
    cout << (dp1[s.size()-1]+dp2[s.size()-1])%MOD << endl;
 
}



Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	string a,b;
 	cin >> a>>b;
 	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]){
 		cout << "YES" << endl;
 	}else{
 		cout << "NO" << endl;
 	}
 }

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

const int N = (int)1e5+5;

int grid[11][1001], sum[11][1001], tsum[11][1001];
string str[11];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int h,w,k,ans = INT_MAX;
    cin>>h>>w>>k;
    for(int i=1;i<=h;i++) {
        cin>>str[i];
        for(int j=1;j<=w;j++) {
            grid[i][j] = (str[i][j-1]-'0');
            sum[i][j] = sum[i][j-1];
            for(int k=1;k<=i;k++) {
                sum[i][j] += grid[k][j];
            }
        }
    }
    for(int mask=0;mask<(1<<(h-1));mask++) {
        int prev = 0,cuts = __builtin_popcount(mask);
        vector<int> rows;
        for(int i=1;i<=h;i++) {
            for(int j=1;j<=w;j++) {
                tsum[i][j] = sum[i][j] - sum[prev][j];
            }
            if(i==h || ((1<<(i-1))&mask)) {
                prev = i;
                rows.push_back(i);
            }
        }
        bool ch = true;
        for(int i=1;i<=h && ch;i++) {
            for(int j=1;j<=w;j++) {
                if (tsum[i][j]-tsum[i][j-1] > k) {
                    ch = false;
                    break;
                }
            }
        }
        if (!ch) {
            continue;
        }
        prev = 0;
        for(int j=1;j<=w;j++) {
            for(auto i:rows) {
                if(tsum[i][j]-tsum[i][prev] > k) {
                    prev = j-1;
                    cuts++;
                    break;
                }
            }
        }
        ans = min(ans,cuts);
    }
    cout<<ans;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
const int MAX_N = 10000;
vector<ll> A;
ll sum[2];
bool del_values[MAX_N];
int main() {
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    if (A[i] > 0){
      sum[i % 2] += A[i];
    }else{
      del_values[i] = true;
    }
  }
  ll result = max(sum[0], sum[1]);
  if (result == 0){
      int pos = max_element(A.begin(), A.end()) - A.begin();
      del_values[pos] = false;
      cout << A[pos] << endl;
  }else{
    for (int i = 0; i < N; i++){
      if (sum[i % 2] < sum[(i + 1) % 2]){
        del_values[i] = true;
      }
    }
    cout << result << endl;
  }
  vector<int> procedures;
  int r = N - 1;
  while (del_values[r]){
    procedures.push_back(r);
    r--;
  }
  int l = 0;
  while (del_values[l]){
    procedures.push_back(0);
    l++;
  }
  for (l += 2; l <= r; l += 2){
    procedures.push_back(del_values[l] ? 2 : 1);
  }
  cout << procedures.size() << endl;
  for (const auto &val : procedures){
    cout << val + 1 << endl;
  }
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    long long int ans = 0;
    for(int i=1;i<=n;i++){
        if(i % 3 == 0 || i % 5 == 0)continue;
        else{
            ans += i;
        }
    }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

int one[300005][66];
int zero[300005][66];
ll a[300005];
int main() {
  int n;
  cin >> n;

  for(int i = 0; i < n; i++) {
    cin >> a[i];
    for(int j = 0; j < 60; j++) {
      ll s = (1ll << j);
      if(a[i] & s) one[i][j]++;
      else zero[i][j]++;
    }
  }

  for(int i = 0; i < 60; i++) {
    for(int j = 1; j < n; j++) {
      one[j][i] = one[j][i] + one[j-1][i];
      zero[j][i] = zero[j][i] + zero[j-1][i];
    }
  }

  ll ans = 0;
  for(int i = n - 1; i > 0; i--) { 
    for(int j = 0; j < 60; j++) {
      ll s = (1ll << j);
      if(a[i] & s) {
	ans = (ans + (zero[i-1][j] * (s % mod) % mod)) % mod;
      }
      else {
	ans = (ans + (one[i-1][j] * (s % mod) % mod)) % mod;
      }
    }
  }

  cout << ans << endl;
}

  
  
    


Measured memory_bytes: 157312
#include <algorithm>
#include <bitset>
#include <boost/dynamic_bitset.hpp>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <vector>

using namespace std;

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

constexpr ll LL_MOD = 1000000009;
constexpr int I_MOD = 1000000007;
constexpr double EPS = numeric_limits<double>::epsilon();
constexpr double PI = 3.14159265358979323846264338327950288;

template <class T> void scan(vector<T> &v);
void scan(vector<string> &v, bool isWord = true);
boost::dynamic_bitset<> scan(char trueValue = 'o');

class Point {
public:
  int cur;
  set<int> s;
  Point(int p) : cur(p), s() {}
  bool in(int next) { return s.find(next) != end(s); }
	void add(int next) { s.insert(next); }
};

int main(int argc, char *argv[]) {
  // INFILE();
  int n, m;
  cin >> n >> m;

  vector<vector<int>> edges(m);
  for (auto &e : edges) {
    e.resize(2);
    scan(e);
  }

  multimap<int, int> em;
  for (const auto &e : edges) {
    em.insert(make_pair(e[0], e[1]));
    em.insert(make_pair(e[1], e[0]));
  }

	queue<Point> q;
	Point point(1);
	point.add(1);
	q.push(point);

	int total = 0;
	while (!q.empty()) {
		Point next_p = q.front();
		q.pop();
		
		if (next_p.s.size() == n) {
			total++;
			continue;
		}

		auto keys = em.equal_range(next_p.cur);
		for (auto s = keys.first; s != keys.second; s++) {
			if (next_p.in(s->second)) {
				continue;
			}

			Point new_point = next_p;
			new_point.cur = s->second;
			new_point.add(s->second);
			q.push(new_point);
		}
	}

	cout << total << "\n";
  return 0;
}

template <class T> void scan(vector<T> &v) {
  map<type_index, const char *const> m = {{typeid(int), "%d"},
                                          {typeid(ll), "%lld"},
                                          {typeid(double), "%lf"},
                                          {typeid(char), "%c"}};

  auto tFormat = m[typeid(T)];

  for (T &n : v) {
    scanf(tFormat, &n);
  }
}

void scan(vector<string> &v, bool isWord) {
  if (isWord) {
    for (auto &n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

boost::dynamic_bitset<> scan(char trueValue) {
  string s;
  getline(cin, s);

  if (s.size() == 0) {
    getline(cin, s);
  }

  for_each(begin(s), end(s),
           [trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
  return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
}


Measured memory_bytes: 2304
#include<stdio.h>
int main(){
  int n,k,i,j,min,s,e;
  int d[10000][100];
  while(scanf("%d %d %d",&n,&s,&e),n||s||e){
    for(i=0;i<n;i++){
      scanf("%d",&k);
      d[i][0]=s;
      for(j=0;j<2*k;j++){
	scanf("%d",&d[i][j+1]);
      }
      d[i][j+1]=e;
    }
    int max=0,g=s,r=0;
    int p[10000]={0};
    while(e-g){//printf("%d\n",r);
      for(i=0;i<n;i++){
	for(;d[i][p[i]+1]<g;p[i]+=2);
	if(d[i][p[i]]<=g){
	  j=d[i][p[i]+1]-g;
	  r-=40*((d[i][p[i]+1]/100)-(g/100));
	  r+=j;
	  g=d[i][p[i]+1];
	  p[i]+=2;
	  break;
	}
      }
      if(n==i){
	if(max<r)max=r;
	r=0;
	min=d[0][p[0]];
	for(i=1;i<n;i++){
	  if(min>d[i][p[i]])min=d[i][p[i]];
	}
	g=min;
      }
    }
    if(max<r)max=r;
    printf("%d\n",max);
  }
  return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdint>
using namespace std;

void solver(int d, int64_t v, vector<int64_t> &all) {
    all.push_back(v);
    if (d == 10) return;

    for (int i = -1; i <= 1; ++i) {
        int add = (v % 10) + i;
        if (add < 0 || 9 < add) continue;

        solver(d + 1, v * 10 + add, all);
    }
}

int main() {
    int k; cin >> k;

    vector<int64_t> all;
    for (int i = 1; i <= 9; ++i) solver(1, i, all);
    sort(all.begin(), all.end());

    cout << all[k - 1] << endl;
}



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

using namespace std;

int n, k;

const int mod = 998244353;

long long c[4002][4002];

long long logpow (long long a, int b) {
  long long p = 1;
  while (b) {
    if (b & 1)
      p = p * a % mod;
    a = a * a % mod;
    (b >>= 1);
  }
  return p;
}

int main()
{
  cin >> k >> n;
  for (int i = 0; i <= 4000; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++)
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
  }
  for (int i = 2; i <= 2 * k; i++) {
    int a = 0, b = 0;
    for (int j = 1; j <= k; j++) {
      if (j < i && j < i - j && i - j <= k)
        a++;
      if (j >= i || i - j > k)
        b++;
    }
    long long ans =0;
    for (int j = 0; j <= a; j++) {
      if (j + b == 0)
        continue;
      ans += 1ll * logpow(2, j) * c[a][j] % mod * c[n + b - 1][j + b - 1] % mod;
      ans %= mod;
      if (i % 2 == 0) {
        ans += 1ll * logpow(2, j) * c[a][j] % mod * c[n + b - 2][j + b - 1] % mod;
        ans %= mod;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}


Measured memory_bytes: 123648
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		//int[] aArray = new int[n];

		int ans = 0;

		for(int i = 0;i<n;i++) {
			int checkNum = fs.nextInt();

			if(i%2==0 && checkNum%2==1) {
				ans++;
			}

		}

		//Output
		PrintWriter out = new PrintWriter(System.out);
		out.println(ans);

		out.flush();

	}

}

//Input
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 32528
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
import random
import time
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def scorei(ti, i, last, minus):
        k = [i for i in last]
        mi = minus-(i+1-last[ti])*c[ti]
        v = s[i][ti]-mi
        mi += sum_
        k[ti] = i+1
        return v, k, mi

    def score(t):
        n = 26
        v = 0
        minus = sum_ = sum(c)
        last = [0]*n
        for i in range(d):
            ti = t[i]-1
            minus -= (i+1-last[ti])*c[ti]
            v += s[i][ti]-minus
            minus += sum_
            last[ti] = i+1
        return v
    start = time.time()
    d = I()
    c = LI()
    s = LIR(d)
    n = 26
    m = 50
    sum_ = sum(c)
    q = [(0, [], [0]*n, sum_)]
    argmax = 0
    for i in range(d):
        nq = []
        for _ in range(m):
            if not q:
                break
            v, t, last, minus = heappop(q)
            for ti in range(n):
                nt = [i for i in t]
                vi,nl,nm = scorei(ti,i,last,minus)
                nv = v-vi
                nt.append(ti)
                heappush(nq,(nv,nt,nl,nm))
        q = [i for i in nq]
    t = [i+1 for i in heappop(q)[1]]
    v = score(t)
    i = 0
    while time.time() < 1.8+start:
        nt = [i for i in t]
        r = random.randrange(1,n+1)
        nt[i] = r
        nv = score(nt)
        if v < nv:
            t = [i for i in nt]
            v = nv
        i += 1
        i %= d
    for i in t:
        print(i)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 186840
def main():
    n, m = map(int, input().split())
    n2 = n//2
    if n%2:
        for i in range(1, m+1):
            print(i, n-i+1)
    else:
        for i in range(1, m+1):
            if n+1-2*i <= n2:
                print(i, n-i)
            else:
                print(i, n-i+1)
                
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9280
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
char a[N];
int ch(int l,int r){
  for(int i=l;i<r;i++){
    if(a[i]!=a[r--])return 0;
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin>>a+1;
  int n=strlen(a+1);

  if(ch(1,n) && ch(1,(n-1)/2) && ch( (n+3)/2,n))cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}

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

int a[400000],b[400000];
int main(){
	int n;cin>>n;
	rep(i,n){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n);
	int cnt=0;
	rep(i,n){
		if(a[i]!=b[i])cnt++;
	}
	if(cnt==0){
		puts("0");return 0;
	}
	int q;cin>>q;
	rep(i,q){
		int x,y;cin>>x>>y;x--;y--;
		if(a[x]!=b[x])cnt--;
		if(a[y]!=b[y])cnt--;
		swap(a[x],a[y]);
		if(a[x]!=b[x])cnt++;
		if(a[y]!=b[y])cnt++;
		if(cnt==0){
			cout<<i+1<<endl;
			return 0;
		}
	}
	puts("-1");
}



Measured memory_bytes: 5496
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>

using namespace std;
#define REP(i,m,n) for(long long i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

vector<vector<int>>v(1407);
vector<int>ans, hoge;

int main() {
	int n = 1407, k = 38;
	v[0].push_back(1);
	REP(i, 1, 1407) {
		v[i].push_back((i + 36) / 37);
	}
	int tmp = 2;
	REP(i, 0, 38) {
		REP(j, 0, 37) {
			v[i].push_back(tmp);
			tmp++;
		}
	}
	REP(i, 0, 37) {
		REP(j, 0, 37) {
			REP(k, 0, 37) {
				v[i * 37 + j + 38].push_back(v[k + 1][(k*i + j) % 37 + 1]);
			}
		}
	}
	cout << n << " " << k << endl;
	REP(i, 0, 1407) {
		REP(j, 0, 38) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 896
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MOD 1000000007

int main(void) {
	int a[100010], i, N, P;
	scanf("%d", &N);
	for (i=0;i<N;i++) scanf("%d", &a[i]);

	P = 0;
	for (i=0;i<N;i++) {
		if (a[a[i]-1] == i+1) P++;
	}
	printf("%d\n", P/2);

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>

#define pii pair <int, int>
#define ff first
#define ss second

using namespace std;

int n, m, ans;
int A[1010], B[1010], C[1010];
int D[110][110], vis[110], v[110];
vector <pii> V[110];
priority_queue <pii, vector<pii>, greater<pii>> Q;

int main()
{
	cin >> n >> m;
	
	for(int i=1; i <= m; i++) {
		cin >> A[i] >> B[i] >> C[i];
		V[A[i]].push_back({B[i], C[i]});
		V[B[i]].push_back({A[i], C[i]});
	}
	for(int i=1; i <= n; i++) {
		for(int h=1; h <= n; h++)
			D[i][h] = 1e9;
		
		Q.push({0, i}), D[i][i] = 0, memset(vis, 0, sizeof(vis));
		while (!Q.empty()) {
			int nd = Q.top().ss;
			int val = Q.top().ff;
			
			Q.pop();
			
			if (vis[nd])
				continue;
			
			vis[nd] = 1;
			for (auto h: V[nd])
				if (!vis[h.ff] && D[i][h.ff] > val+h.ss)
					D[i][h.ff] = val+h.ss, Q.push({D[i][h.ff], h.ff});
		}
	}
	for(int i=1, a=0; i <= m; i++, a=0) {
		for(int h=1; h <= n; h++)
			v[h] = 1e9, vis[h] = 0;
		
		Q.push({C[i], A[i]}), v[A[i]] = C[i];
		while (!Q.empty()) {
			int nd = Q.top().ss;
			int val = Q.top().ff;
			
			Q.pop();
			
			if (vis[nd])
				continue;
			
			vis[nd] = 1;
			for (auto h: V[nd])
				if (!vis[h.ff] && v[h.ff] > val+h.ss)
					v[h.ff] = val+h.ss, Q.push({v[h.ff], h.ff});
		}
		for(int h=1; h <= n; h++) {
			if(D[B[i]][h] == v[h])
				a=1;
			v[h] = 1e9, vis[h] = 0;
		}
		Q.push({C[i], B[i]}), v[B[i]] = C[i];
		while (!Q.empty()) {
			int nd = Q.top().ss;
			int val = Q.top().ff;
			
			Q.pop();
			
			if (vis[nd])
				continue;
			
			vis[nd] = 1;
			for (auto h: V[nd])
				if (!vis[h.ff] && v[h.ff] > val+h.ss)
					v[h.ff] = val+h.ss, Q.push({v[h.ff], h.ff});
		}
		for(int h=1; h <= n; h++)
			if(D[A[i]][h] == v[h])
				a=1;
		
		if(a == 0)
			ans++;
	}
	cout << ans;
}

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

using namespace std;

int main() {
  int a, b;
  double tmp;

  cin >> a >> b;

  // 切り上げは　(A + B - 1) / B
  tmp = (a + b + 2 - 1) / 2;
  cout << ceil(tmp) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
int main(void){
    int n,a,b,i1,tmp,out=0,sum=0;


    cin >> n >> a >> b;
    for(int i=0;i<=n;i++){
        sum=0;
        i1=i;
        for(int j=10000;j>0;j/=10){
        tmp=i1/j;
        sum+=tmp;
        i1-=tmp*j;
    }

    if(sum>=a&&sum<=b)out+=i;
    }

    cout << out << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
    char S[11];
    int A,B;
    int i,j=0,k=0,l;
  
    scanf("%d%d",&A,&B);
    scanf("%s",S);
  
    if(strlen(S)!=A+B+1) { printf("No\n"); return 0; }
    for(i=0;i<strlen(S);i++){
      if((S[i]>='0')&&(S[i]<='9')) j++;
      else if(S[i]=='-') { k++; l=j; j=0; }
      else { printf("No\n"); return 0; }
    }
    if((l==A)&&(j==B)){
      if(k==1) { printf("Yes\n"); return 0; }
    }
    else { printf("No\n"); return 0; }
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

const int MOD = 1000000007;

using namespace std;



int main(){

    int a,b;
    cin >> a >> b;
    if((a-b)%2 == 0){
        cout << abs(a - (a-b)/2) << endl; 
    }else{
        cout << "IMPOSSIBLE" << endl; 
    }


    return 0;
}

Measured memory_bytes: 256
S = input()
Q = int(input())

flag = 1
s1 = ''

for i in range(Q):
	q = input()
	if len(q) == 1:
		s1,S = S,s1
	else:
		T,F,C = q.split(' ')
		if int(F) == 1:
			s1 = s1 + C
		else:
			S = S + C

print(s1[::-1] + S)


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

int main() {
  int n, a;
  cin >> n >> a;
  
  n = n % 500;
  if (n <= a) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3576