akhauriyash/Code-Regression huggingface dataset:
# input
N = int(input())
As = list(map(int, input().split()))

# Nの偶奇。区間幅がNの偶奇と一致すれば太郎君目線
oe = N % 2

# def print_list(lis):
#   for l in lis:
#     print(l)


# score[i][j][p] : Asのi番目を左端、j番目を右端とした時の最終スコア
#                  p = 0 が太郎君目線、p = 1 が次郎くん目線
score = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
  # 初期化
  # 区間長さ1であれば1通りしかない
  if oe == 1:
    score[i][i] = As[i]
  else:
    score[i][i] = -As[i]

# print_list(score)

for k in range(1, N):
  # 配列の幅を広げながら計算を進める
  for i in range(0, N-k):
    # if k == 0:
    #   continue
    j = i + k
    if i == N - 1:
      if (k + 1) % 2 == oe:
        score[i][j] = score[i][j-1] + As[j]
      else:
        score[i][j] = score[i][j-1] - As[j]
    else:
      # print(i,j)
      if (k + 1) % 2 == oe:
        score[i][j] = max(score[i+1][j] + As[i], score[i][j-1] + As[j])
      else:
        score[i][j] = min(score[i+1][j] - As[i], score[i][j-1] - As[j])
    # print_list(score)

print(score[0][N-1])


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first



typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    cin >>n;
    list<int> l;

    for (int i = 0; i < n; i++){
        int ai;
        cin>>ai;
        
        if(i % 2==0){
            l.push_back(ai);
        }else{
            l.push_front(ai);
        }
    }
    
    if(n%2==1)l.reverse();
    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    for(int li : l)cout << li << " ";

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<typename V> struct ConvexHull {
	deque<pair<V,V>> Q;
	int cmptype=1; // 0-min 1-max
	V calc(pair<V,V> p, V x) {
		return p.first*x+p.second;
	}
	int dodo(pair<V,V> A,pair<V,V> B, pair<V,V> C) { // max or min
		return cmptype^((B.second-C.second)*(B.first-A.first)<=(A.second-B.second)*(C.first-B.first));
	}
	void add(V a, V b) { // add ax+b
		Q.push_front({a,b});
		while(Q.size()>=3 && !dodo(Q[0],Q[1],Q[2]))
			Q[1]=Q[0], Q.pop_front();
	}
	V query(V x) {
		int L=-1,R=Q.size()-1;
		while(R-L>1) {
			int M=(L+R)/2;
			((cmptype^((calc(Q[M],x)>=calc(Q[M+1],x))))?L:R)=M;
		}
		return calc(Q[R],x);
	}
};


int N;
ll T[303030],LS[303030],RS[303030];
int M;
ConvexHull<ll> LC, RC;
ll LD[303030],RD[303030],inc[303030],ninc[303030];
ll tmemo[303030];

void dfs(int LL,int RR) {
	if(RR-LL<=2) return;
	int MM=(LL+RR)/2;
	
	ConvexHull<ll> TLC, TRC;
	TLC.add(0,0);
	TRC.add(0,0);
	int i,j;
	for(i=LL;i<RR;i++) {
		if(i<MM) TLC.add(-(i+1), 1LL*i*(i+1)/2 + LD[i+1] + LS[i+1]);
		else tmemo[i]=TLC.query(i+1) + 1LL*(i+1)*(i+2)/2 - LS[i+1]+RD[N-1-i];
	}
	for(j=RR-1;j>=LL;j--) {
		i=N-1-j;
		if(j>=MM) TRC.add(-(i+1), 1LL*i*(i+1)/2 + RD[i+1] + RS[i+1]);
		else tmemo[j]=TRC.query(i+1) + 1LL*(i+1)*(i+2)/2 - RS[i+1]+LD[j];
	}
	
	ll ma=-1LL<<60;
	for(i=RR-1;i>=MM;i--){
		ma=max(ma,tmemo[i]);
		inc[i]=max(inc[i],ma);
	}
	ma=-1LL<<60;
	for(i=LL;i<MM;i++){
		ma=max(ma,tmemo[i]);
		inc[i]=max(inc[i],ma);
	}
	
	dfs(LL,MM);
	dfs(MM,RR);
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>T[i];
	
	LC.add(0,0);
	RC.add(0,0);
	FOR(i,N) {
		LS[i+1]=LS[i]+T[i];
		LD[i+1]=max(LD[i], LC.query(i+1) + 1LL*(i+1)*(i+2)/2 - LS[i+1]);
		LC.add(-(i+1), 1LL*i*(i+1)/2 + LD[i+1] + LS[i+1]);
		
		RS[i+1]=RS[i]+T[N-1-i];
		RD[i+1]=max(RD[i], RC.query(i+1) + 1LL*(i+1)*(i+2)/2 - RS[i+1]);
		RC.add(-(i+1), 1LL*i*(i+1)/2 + RD[i+1] + RS[i+1]);
	}
	FOR(i,N) {
		ninc[i]=LD[i]+RD[N-1-i];
		inc[i]=1-T[i];
	}
	dfs(0,N);
	
	
	cin>>M;
	FOR(i,M) {
		cin>>x>>y;
		x--;
		cout<<max(ninc[x], inc[x] + T[x] - y)<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 21376
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



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

    long long N,X;cin >> N >> X;
    cout << 3*(N-gcd(N,X)) << endl;
}

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int N;
	cin >> N;
	vector<long long> a(N);

	long long sumA = 0;
	long long sumS = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		sumS += a[i];
	}
	sumA += a[0];
	sumS -= a[0];

	long long ans = abs(sumA - sumS);
	for (int i = 1; i < N - 1; ++i) {
		sumA += a[i];
		sumS -= a[i];

		ans = min(ans, abs(sumA - sumS));
	}

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

Measured memory_bytes: 4812
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 3e3+5;

int a[N], dp[N][N];

int solve (int i, int j, int s) {
	if (i == j && s == 0) return a[i];
	if (i == j && s == 1) return -a[i];
	if (dp[i][j]) return dp[i][j];
	if (s == 0) dp[i][j] = max(a[j]+solve(i,j-1,!s), a[i]+solve(i+1,j,!s));
	else dp[i][j] = min(-a[j]+solve(i,j-1,!s), -a[i]+solve(i+1,j,!s));
	return dp[i][j];
}

signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    	cin >> a[i];
    cout << solve(0,n-1,0);
    return 0;
}

Measured memory_bytes: 70144
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> H >> W >> K;
	vector<string>s(H);
	for (auto &i : s)cin >> i;
	vector<vector<int>>ans(H, vector<int>(W, -1));
	int cnt = 1;
	for (int i = 0; i < H; i++) {
		int num = 0;
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '#')num++;
		}
		if (!num) {
			if (i) {
				for (int j = 0; j < W; j++) {
					ans[i][j] = ans[i - 1][j];
				}
			}
			continue;
		}
		int used = 0;
		for (int j = 0; j < W; j++) {
			ans[i][j] = cnt;
			if (s[i][j] == '#') {
				cnt++;
				used++;
				if (used == num)cnt--;
			}
		}
		cnt++;
	}
	for (int i = H - 1; i >= 0; i--) {
		int num = 0;
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '#')num++;
		}
		if (num)continue;
		if (i + 1 < H) {
			for (int j = 0; j < W; j++) {
				ans[i][j] = ans[i + 1][j];
			}
		}
	}
	for (auto i : ans) {
		for (auto j : i)cout << j << " "; 
			cout << endl;
	}
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
	int h,w;
	char tb[50][50];
	int used[50][50];
	cin>>h>>w;

	int sum=h*w;
	

	int black=0;
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin>>tb[i][j];
			if(tb[i][j]=='#')black++;
		}
	}
	h--; w--;
	queue<pii> que;
	que.push(pii(0,0));
	memset(used,-1,sizeof(used));
	while(que.size()){
		pii p=que.front();
		que.pop();

		if(p.first==h&&p.second==w)break;

		for (int i = 0; i < 4; i++){
			int nh=p.first+dy[i];
			int nw=p.second+dx[i];
			if(nh<0||nh>h||nw<0||nw>w)continue;
			if(tb[nh][nw]=='#'||used[nh][nw]!=-1)continue;
			que.push(pii(nh,nw));
			used[nh][nw]=used[p.first][p.second]+1;
		}

	}

	if(used[h][w]==-1){
		cout<<-1<<endl;
	}else{
		cout<<sum-2-black-used[h][w]<<endl;
	}


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.*;

class Main {

    private static Scanner sc = new Scanner(System.in);

    //ソート Arrays.sort(配列名);
    //逆順ソート Arrays.sort(配列名,  Collections.reverseOrder());


    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int[] d = new int[n];
        int ans=0;

        for(int i = 0;i < n; i++){
            d[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(d);
        ans = d[n/2]-d[n/2-1];

        System.out.println(ans);
    }
}


Measured memory_bytes: 51096
#include <iostream>
#include <deque>


using namespace std;


using ll = long long;


int main()
{
    deque<ll> b;
    ll n;

    cin >> n;

    for (ll i = 0; i < n; i++) {
        ll t;
        cin >> t;
        if (i % 2 == 0) {
            b.push_back(t);
        } else {
            b.push_front(t);
        }
    }

    if (n % 2 == 0) {
        for (auto e : b)
            cout << e << " ";
        cout << endl;
    } else {
        for (auto it = b.rbegin(); it != b.rend(); ++it)
            cout << *it << " ";
        cout << endl;
    }
}


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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
// end of Template

int n,k,dmax;
vi adj[100010];
int v[100010],f[100010];
bool vis[100010];
ll ans = 1;
ll md = 1000000007;
vll mul;
void bfs(){
    queue <int> q;
    q.push(1);

    while(!q.empty()){
        int node = q.front();
        q.pop();
        if(!vis[node]){
            vis[node]=true;

            ll m = k-2;
            if(node==1)m++;

            for(int i=0;i<adj[node].size();i++){
                int nex = adj[node][i];
                if(!vis[nex]){
                    mul.pb(m);
                    q.push(nex);
                    m--;
                }
            }
        }
    }

}
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for(int i=1;i<n;i++){
        int u,v;cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    bfs();

    mul.pb(k);
//    for(int i=2;i<=dmax;i++){
////        cout<<i<<" "<<f[i]<<newl;
//        v[i] = v[i-1] - 1;
//        if(i>3){v[i] += f[i-3];}
//
//        for(int j=1;j<=f[i];j++){
//            int ft = j-1;
//            ll temp = v[i]-ft;
//            temp = max(temp,(ll)0);
//            mul.pb(v[i]-ft);
//        }
//    }

    for(int i=0;i<mul.size();i++){
//        cout<<i<<" "<<mul[i]<<newl;
        ans = ((ans%md)*(mul[i]%md))%md;
    }
    cout<<ans<<newl;
}



Measured memory_bytes: 7672
//#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <math.h>
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
// template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
 
#define ll long long int
#define ull unsigned long long int
 
#define lp(i,n) 	    for(int i=0;i<(int)(n);i++)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);i++)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);i--)
 
#define all(v)  	 ((v).begin()), ((v).end())
#define sz(v)    	 ((int)((v).size()))
#define clr(v, d)    memset(v, d, sizeof(v))
#define PB           push_back
#define MP           make_pair
#define N 100006
 
#define PI 3.14159265359
 
ll gcd(ll a, ll b);
vector<string> split(string target,unsigned char c );
 
 
ll n,k,t,m,x,y,l,r;
 
bool isPrime(ll h); 
 
ll ans;

 
ll mod=1e9 +7;
bool cmp(pair<int,string>& a,pair<int,string>& b){
	if(a.first==b.first)
		return a.second<b.second;
	return a.first>b.first;
}


 
int main() {
// freopen("d.in","r",stdin); 
// 	freopen("d_out.txt","w",stdout); 
cout.precision(7);
ios_base::sync_with_stdio(false);
cin.tie(NULL);  cout.tie(NULL);
string s;
cin>>s;
s='0'+s;
reverse(all(s));
lp(i,sz(s)-1){
	if(s[i]>'5'){
		ans+=10-(s[i]-'0');
		s[i]='0';
		int j=i+1;
		while(s[j]=='9'){
			s[j]='0';
			j++;
		}
		s[j]=s[j]+1;
	}
	else if(s[i]=='5' && s[i+1]>='5'){
		ans+=10-(s[i]-'0');
		s[i]='0';
		int j=i+1;
		while(s[j]=='9'){
			s[j]='0';
			j++;
		}
		s[j]=s[j]+1;
	}
}
lp(i,sz(s))ans+=s[i]-'0';
cout<<ans;


	
 
 
}

ll gcd(ll a, ll b){
	return b==0?a:gcd(b,a%b);
}
 
 
vector<string> split(string target,unsigned char c ){
	string d="";
	vector<string>arr;
	for(auto n:target)
	{
		if(n!=c)
		d+=n;
		else if(d!="")
		arr.push_back(d),d="";
	}
	if (d!="")
	arr.push_back(d),d="";
	return arr;
}
// bool isPrime(ll h){
//      for(ll i=0;primes[i]*primes[i]<= h;i++)
//      if (h%primes[i]==0)
//      	return 0;
//      return h!=1;
//  }
 bool isPrime(ll g){
   if((g%2==0 && g>2) || g==1)return 0;
   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;
   return 1;   
 
 }

Measured memory_bytes: 2332
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using lint = long long;
using P = pair<int, int>;

int A, F, H, I, J, K, L, M, N, S, T, U;
// lint F, H, I, J, K, L, M, N, S, T, U;
// string S;
int ans;

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

	cin >> H >> A;

	if (H % A == 0) {
		ans = H / A;
	} else {
		ans = H / A + 1;
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    long long N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<long long> raw;
    raw.push_back(0);
    for(int i = 1; i < N; i++){
        if(S[i] != S[i - 1]) raw.push_back(i);
    }
    raw.push_back(N);
    long long siz = raw.size() - 1;
    long long ans = 0;
    for(int i = 0; i < raw.size(); i++){
        if(S[raw[i]] == '0') ans = max(ans, raw[min(i + 2 * K, siz)] - raw[i]);
        else ans = max(ans, raw[min(i + 2 * K + 1, siz)] - raw[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1528
import sys
n = int(sys.stdin.readline().rstrip("\n"))
x,y = 0,0
t = 0
i = 0
while i < n:
    t_,x_,y_ = map(int, sys.stdin.readline().rstrip("\n").split())
    d = abs((x_+y_)-(x+y))
    t_d = t_-t
    if t_d >= d:
        if (t_d-d) % 2 == 0:
            x,y = x_,y_
            t = t_
            i += 1
        else:
            print('No')
            break
    else:
        print('No')
        break
else:
    print('Yes')

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

int main()
{
	int X = 0, A = 0, B = 0;
	cin >> X >> A >> B;
	int J = B - A;
	if (J <= 0) {
		cout << "delicious" << endl;
	}
	else if (J <= X) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long 
//typedef pair<ll, ll> P;
//const ll INF=1LL<<60;
ll gcd(ll x,ll y){return y? gcd(y,x%y) :x;}

int main(){
    int h,w,n;
    cin>>h>>w>>n;
    int masu=h*w;
    vector<int>a(n),b(masu);
    int c[100][100];
    rep(i,n)cin>>a[i];
    int cnt=0;
    int kazu=0;
    rep(i,masu){
        kazu++;
        b[i]=cnt+1;
        if(kazu==a[cnt]){
            cnt++;
            kazu=0;
        }
    }
    int k=0;
    rep(i,h){
        rep(j,w){
            if(i%2==0)c[i][j]=b[k];
            else c[i][w-1-j]=b[k];
            k++;
        }
    }
    rep(i,h){
        rep(j,w){
            cout<<c[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
using namespace std;
typedef long long ll;

int main()
{
	vector<int> t(1, 0), x(1, 0), y(1, 0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		t.push_back(a);
		x.push_back(b);
		y.push_back(c);
	}
	for (int i = 0; i < n; i++) {
		int dxy = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		int dt = t[i + 1] - t[i];
		if (dt < dxy || (dxy + dt) % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1644
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;
int main(){
  int N;
  cin >> N;
  
  int A[N];
  int min = 10000000000;
  long long int sum=0;
  bool sign = true;
  
  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(A[i] < 0){
      sign = !sign;
      A[i] *= -1;
    }
    sum += A[i];
    if( A[i] < min){
      min = A[i];
    }
  }
  if(!sign){
    sum -= 2 * min;
  }
  cout << sum << endl;
  
  return 0; 
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
string s;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
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;
}

void solve() {
    return;
}

int main() {
    for (int i = 0; i < 3; ++i) {
        cin >> s;
        cout << s[i];
    }
    cout << endl;
    solve();
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    ll n,a,b;
    cin >> n >> a >> b;
    vector<int> x(n);
    for(int i = 0; i < n; i++) cin >> x[i];

    ll ans = 0;
    int now = x[0];

    for(int i = 1; i < n; i++){
        ll cost = x[i]-now;
        if(cost*a > b){
            now = x[i];
            ans += b;
        } else {
            now = x[i];
            ans += a*cost;
        }
    }

    cout << ans << endl;


    return 0;
}

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


int main()
{
	int a,b,c,cha;
	scanf("%d%d%d",&a,&b,&c);
	cha=(a-b);
	//printf("cha=%d\n",cha);
	if(cha>=c) printf("0");
	else printf("%d",c-cha);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <functional>
#include <list>

#define MOD (1000000000 + 7)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 3000000;

long long fac[MAX], finv[MAX], inv[MAX];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}
// テーブルを作る前処理
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;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
} 

vector<ll> divisor;
void list_divisor(ll n) {
    divisor.clear();
    for(int i = 1; i*i <= n; i++) {
        if(n % i == 0) {
            divisor.push_back(i);
            if(i*i != n) divisor.push_back(n/i);
        }
    }
    sort(divisor.begin(), divisor.end());
}

vector<bool> Eratosthenes(ll N) {
    vector<bool> primes(N, true);
    vector<ll> ret;
    primes[0] = false;
    primes[1] = false;
    for (ll i=2; pow(i,2)<=N; i++) {
        if (primes[i]) {
            for(int j=2; i*j<=N; j++) primes[i*j] = false;
            ret.push_back(primes[i]);
        }
    }
    return primes;//ret;
}

int main() {
    ll N;
    cin >> N;

    string c;
    cin >> c;

    vector<ll> w;
    vector<ll> r;
    for(ll i = 0; i < N; i++) {
        if(c[i] == 'R') r.push_back(i);
        else w.push_back(i);
    }

    if(w.size() == 0 || r.size() == 0) {
        cout << 0 << endl;
        return 0;
    }

    ll ret = 0;
    for(ll i = r.size()-1; i >= 0; i--) {
        ll w_index = r.size() - i - 1;
        if(w_index > w.size() - 1 || r[i] < w[w_index]) break;
        else ret++;
    }

    cout << ret << endl;
}


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

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

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

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

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

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

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

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

fn main() {
    input!{
        a: i32,
        b: i32,
        c: i32,
    }
    println!("{} {} {}", c, a, b);
}

Measured memory_bytes: 4352
# 166 B
N, K = list(map(int, input().split()))
A = []
for i in range(K):
    d = int(input())
    a = []
    if d > 1:
        a = list(map(int, input().split()))
        A.extend(a)
    else:
        A.append(int(input()))
        
print(N - len(set(A)))

Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>

using namespace std;

int main() {
    int n, x_ini = 0;
    string s;
    vector<int> x;
    cin >> n >> s;

    for (size_t i = 0; i < s.length(); i++)
    {
        if (i == 0)
        {
            if (s[i] == 'I')
            {
                x.emplace_back(1);
            }
            else
            {
                x.emplace_back(-1);
            }
        }
        else
        {
            if (s[i] == 'I')
            {
                x.emplace_back(x.back() + 1);
            }
            else
            {
                x.emplace_back(x.back() - 1);
            }
        }
    }

    auto max = max_element(x.begin(), x.end());

    if (*max < 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << *max << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//git pull --rebase origin master
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
ll int gcd(ll int a, ll int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
int tc=1;
void solve()
    { 
        string s;
        cin>>s;
        if(s[s.size()-1]=='s')
        s+="es";
        else 
        s+='s';
        cout<<s;
    }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

   // wi(t)
    {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
    u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}







Measured memory_bytes: 10700
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N], b[N];
int n;
int save[30][N];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
		cin >> b[i];
	for(int i = 0; i < 28; i++){
		for(int j = 0; j < n; j++)
			save[i][j] = b[j] % (1 << (i + 1));
		sort(save[i], save[i] + n);
	}
	int ans = 0;
	if(n & 1){
		for(int i = 0; i < n; i++)
			for(int j = 0; j < 28; j++)
				if((a[i] >> j) & 1)
					ans ^= (1 << j);
		for(int i = 0; i < n; i++)
			for(int j = 0; j < 28; j++)
				if((b[i] >> j) & 1)
					ans ^= (1 << j);
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 28; j++){
			int num = 1 << (j + 1);
			int me = a[i] % num;
			int cnt = n - (lower_bound(save[j], save[j] + n, num - me) - save[j]);
			if(cnt & 1)
				ans ^= num;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
int main() {
  char A, B;
  cin >> A >> B;
  if(A < B) {
    cout << "<" << endl;
  }
  if(A == B) {
    cout << "=" << endl;
  }
  if(A > B) {
    cout << ">" << endl;
  }
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll, ll>
#define vl vector<ll>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define N 100005
ll dp[100005][5];

int main()
{
    ll n;cin>>n;
    ll a[n][3];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    for(ll i=0;i<3;i++)
    dp[0][i]=a[0][i];
    for(ll i=1;i<n;i++)
    {
        for(ll j=0;j<3;j++)
        {
            if(j==0)
            dp[i][j]=a[i][j]+max(dp[i-1][j+1],dp[i-1][j+2]);
            else if(j==1)
            dp[i][j]=a[i][j]+max(dp[i-1][j-1],dp[i-1][j+1]);
            else if(j==2)
            dp[i][j]=a[i][j]+max(dp[i-1][j-1],dp[i-1][j-2]);
        }
    }
    ll mx=0;
    for(ll i=0;i<3;i++)
    mx=max(mx,dp[n-1][i]);
    cout<<mx<<"\n";
}   

Measured memory_bytes: 9844
n, m, c = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

ans = 0
n.times do
  a = gets.split.map(&:to_i)
  sum = 0
  m.times do |i|
    sum += a[i] * b[i]
  end
  ans += 1 if sum + c > 0
end

puts ans


Measured memory_bytes: 1788
a, b, k = map(int, input().split())

def euclidean(a,b):
    if a < b:
        tmp = a
        a = b
        b = tmp
    if a%b != 0:
        return euclidean(a%b, b)
    else:
        return b

n = euclidean(a, b)
for i in range(n , 0, -1):
  if a % i == 0 and b % i == 0:
    k -= 1
    if k ==0:
      print(i)
      exit()

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

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

    double a, b, x;
    cin >> a >> b >> x;
    if (x <= a * a * b / 2) {
        double h = x * 2 / (a * b);
        double k = (b * h) / sqrt(b * b + h * h);
        cout << fixed << setprecision(10) << asin(k / h) * (180 / M_PI) << endl;
    } else if (x == a * a * b) {
        cout << 0 << endl;
    } else {
        double l = (a * a * b - x) * 2 / (a * a);
        double m = l * a / sqrt(l * l + a * a);
        cout << fixed << setprecision(10) << acos(m / l) * (180 / M_PI) << endl;
    }

    return 0;
}


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

int main(){
    int n;
    cin >>n;
    vector<int> v;
    { string str;
        cin >> str;
        transform(begin(str), end(str), back_inserter(v),
            [](const char ch){ return ch == 'x' ? 1 : 0; }); }

    for(int i = 0; i < 4; ++i){
        vector<int> guess(n, 0);
        guess[0] = i%2;
        guess[1] = (i/2)%2;
        for(int j = 2; j < n; ++j) guess[j] = (guess[j-2] ^ guess[j-1] ^ v[j-1]);
        if((guess[0] ^ guess[1] ^ guess[n-1]) == v[0] &&
            (guess[0] ^ guess[n-1] ^ guess[n-2]) == v[n-1]){
            transform(begin(guess), end(guess), ostream_iterator<char>(cout, ""),
                [](const int x){ return x == 0 ? 'S' : 'W'; });
            return 0; } }
    cout << -1;
    return 0; }


Measured memory_bytes: 1272
// Date: 2020-03-22

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout<<#x<<" = "<<x<<endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int main() {
    int n, m;
    cin >> n >> m;
    int ans = n*(n-1)/2+m*(m-1)/2;
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

int main(){
    
    long a = 0;
    long goal;
    cin >> goal;
    
    a = (goal/11)*2;
    if ( goal%11 != 0 && goal%11 <= 6)
        a += 1;
    else if ( goal%11 > 6)
        a += 2;
    
    cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>

using namespace std;


struct edge{
	int to;
	int cost;
};

typedef pair<int,int> P;
int V;

const int INF = 1000000;

vector<edge> G[101];
int d[101];

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+101,INF);
	d[s] = 0;
	que.push(P(0,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first)
			continue;
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main(){

	int n,k;
	while(cin >> n >> k && !(n == 0 && k == 0)){
		for(int i = 0; i < 101; i++)
			G[i].clear();
		int id,a,b,c,dd,ee;
		for(int i = 0; i < k; i++){
			cin >> id;
			if(id == 0){
				cin >> a >> b;
				dijkstra(a);
				if(d[b] == INF)
					cout << -1 << endl;
				else
					cout << d[b] << endl;
			}
			else{
				cin >> c >> dd >> ee;
				edge e;
				e.cost = ee;
				e.to = c;
				G[dd].push_back(e);
				e.to = dd;
				G[c].push_back(e);
			}
		}
	}

	return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, m; cin >> n >> m;
  vll x(n);
  map<int, int> mp;
  REP(i, n) {
    cin >> x[i];
    mp[x[i]]++;
  }

  map<int, P> mp2;
  for(auto &e: mp) {
    if(e.second % 2) mp2[e.first % m].first++;
    mp2[e.first % m].second += e.second / 2;
  }

  vector<bool> sel(m);
  ll rem = 0;
  for(auto &e: mp2) {
    if(sel[e.first]) continue;
    sel[e.first] = true;
    if(e.first != 0) sel[m - e.first] = true;
    auto p1 = e.second;
    if(2 * e.first % m == 0) {
      while(p1.first > 1) p1.first -= 2;
      while(p1.first > 1 && p1.second > 0) p1.first -= 2;
      rem += p1.first;
    } else {
      auto p2 = mp2[m-e.first];
      while(p1.first > 0 && p2.first > 0) {
        p1.first--;
        p2.first--;
      }
      while(p1.first > 1 && p2.second > 0) {
        p1.first -= 2;
        p2.second--;
      }

      while(p2.first > 1 && p1.second > 0) {
        p2.first -= 2;
        p1.second--;
      }

      rem += p1.first + p2.first;
    }
    //cout << e << " " << rem << endl;
  }
  cout << (n - rem) / 2 << endl;



}
























Measured memory_bytes: 15060
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define MAX 100

int main()
{
  int A[MAX];
  int i, j,minj,N;
  int count = 0;
  scanf("%d", &N);
      for (i = 0; i<N;i++)
        scanf("%d", &A[i]);
 for(i=0;i<N;i++)
 {
     minj = i;
     for(j = i;j<N;j++)
     {
         if(A[j] < A[minj])
                minj = j;
     }
                if(A[i] != A[minj])
                {
                    swap(A[i], A[minj]);
                    count++;
                }
 }
          for(int a = 0;a<N-1;a++)
              {printf("%d", A[a]);
              printf(" ");}
          printf("%d\n", A[N-1]);
          printf("%d\n", count);
  return 0;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
// ver1.7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a,b,c,d;
  cin >> a>>b>>c>>d;
  int w=c-a,h=d-b;
  
  rep(i,0,h) cout << 'U';
  rep(i,0,w) cout << 'R';
  rep(i,0,h) cout << 'D';
  rep(i,0,w) cout << 'L';
  
  cout << 'L';
  
  rep(i,0,h+1) cout << 'U';
  rep(i,0,w+1) cout << 'R';
  cout << 'D' << 'R';
  rep(i,0,h+1) cout << 'D';
  rep(i,0,w+1) cout << 'L';
  cout << 'U' << endl;
  
  return 0;
}


Measured memory_bytes: 256
# coding:utf-8

import sys
import itertools

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
S = [c == 'o' for c in SI()]
S += S[:2]

SW = {'S': 'W', 'W': 'S'}
for a1, a2 in itertools.product('SW', repeat=2):
    M = [a1, a2]
    for i in range(n):
        if S[i + 1]:
            M.append(M[-2] if M[-1] == 'S' else SW[M[-2]])
        else:
            M.append(M[-2] if M[-1] == 'W' else SW[M[-2]])

    if M[0] == M[-2] and M[1] == M[-1]:
        print(*M[:-2], sep='')
        exit()

print(-1)


Measured memory_bytes: 8328
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    SP = []
    for i in range(n):
        s, p = map(str, input().split())
        SP.append([i + 1, s, int(p)])
    SP = sorted(SP, key=lambda x: x[2], reverse=True)
    SP = sorted(SP, key=lambda x: x[1])

    for idx, _,_ in SP:
        print(idx)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	   c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
vector<int> to[2][MAXN];
int fa[MAXN][20],dep[MAXN];
int N,X,Y,ans;
bool flag = 0;
int lca(int u,int v) {
    if(dep[u] < dep[v]) swap(u,v);
    int l = 18;
    while(dep[u] > dep[v]) {
        if(dep[fa[u][l]] >= dep[v]) {
            u = fa[u][l];
        }
        --l;
    }
    if(u == v) return u;
    l = 18;
    while(fa[u][0] != fa[v][0]) {
        if(fa[u][l] != fa[v][l]) {
            u = fa[u][l];
            v = fa[v][l];
        }
        --l;
    }
    return fa[u][0];
}
int dist(int u,int v) {
    return dep[u] + dep[v] - 2 * dep[lca(u,v)];
}
void dfs(int u) {
    for(auto t : to[1][u]) {
        if(t != fa[u][0]) {
            dep[t] = dep[u] + 1;
            fa[t][0] = u;
            dfs(t);
        }
    }
}
void dfs1(int u,int f,int d) {
    if(u == Y) return;
    ans = max(ans,dep[u] - 1);
    for(auto t : to[0][u]) {
        if(t == f) continue;
        if(dist(u,t) > 2) flag = 1;
        if(d + 1 < dep[t] - 1) dfs1(t,u,d + 1);
    }
}
void Solve() {
    read(N);read(X);read(Y);
    int a,b;
    for(int i = 1 ; i < N ; ++i) {
        read(a);read(b);
        to[0][a].pb(b);to[0][b].pb(a);
    }
    for(int i = 1 ; i < N ; ++i) {
        read(a);read(b);
        to[1][a].pb(b);to[1][b].pb(a);
    }
    dep[Y] = 1;
    dfs(Y);
    for(int j = 1 ; j <= 19 ; ++j) {
        for(int i = 1 ; i <= N ; ++i) {
            fa[i][j] = fa[fa[i][j - 1]][j - 1];
        }
    }
    dfs1(X,0,0);
    if(flag) {puts("-1");}
    else {out(2 * ans);enter;}
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 48384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
int main(){

	int N;

	std::cin >> N;
	int i=0;
	while(i*i<=N){
		i++;
	}
	std::cout << (i-1)*(i-1) <<std::endl;

	return 0;

} 



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

int main() {
    int N;
    cin >> N;
    vector<int>p(N);
    for (int i = 0; i < N; ++i) {
      cin >> p[i];
    }
    int flag = 0;
    for (int i = 0; i < N; ++i) {
        if(p[i] != i+1) flag++;
    }
    if(flag <= 2){
        cout << "YES";
    } else{
        cout << "NO";
    }
    return 0;
}

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

using namespace std;

#define pb push_back
const int maxi=1e6+2;
int a[maxi];
vector<int> v[maxi];
long long n,k;
string s;
long long ans;
int main()
{
   cin>>n>>k;

   long long  nula=0;
   long long  kp=0;
   for (int i=1;i<=n;i++)
    if (i%k==0) nula++; else
    if (i%k==k/2) kp++;

   ans=(nula*(nula-1)*(nula-2))+nula+3*(nula)*(nula-1);

   if (k%2==0)
   {
       ans+=(kp*(kp-1)*(kp-2))+kp+3*(kp)*(kp-1);;
   }

  cout<<ans<<endl;

  return 0;
}
//bicu tuzan ako ne budu dva constructive


Measured memory_bytes: 25340
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


if __name__ == "__main__":
    parts = str_in().split()
    a = int(parts[0])
    b = int(parts[1].replace(".", ""))
    out((a*b)//100)

Measured memory_bytes: 61936
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;

int main(){
long N, D;
cin >> N >> D;
long ans;
if(N % (2*D+1) == 0) ans = N / (2*D+1);
if(N % (2*D+1) != 0) ans = N / (2*D+1) + 1;
show(ans);



return 0;
}

Measured memory_bytes: 256