akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int a,b;
  cin>>a>>b;
  int res;
  for(int i=a;i<=b;i++){
    if(i/10000==i%10 && (i/1000)%10==(i%100)/10) res++;
  }
  cout<<res<<endl;
  return 0;
}

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

typedef struct directedGraph{
  int *vertex;
  int *next;
  int *start;
  int v,e;
  int pointer;
} graph;

graph* newGraph(const int v,const int e){
  graph *g=(graph *)malloc(sizeof(graph));
  g->vertex=(int *)calloc(e,sizeof(int));
  g->next=(int *)calloc(e,sizeof(int));
  g->start=(int *)calloc(v,sizeof(int));
  for(int i=0;i<v;i++) g->start[i]=-1;
  g->v=v;
  g->e=e;
  g->pointer=0;
  return g;
}

void freeGraph(graph *g){
  free(g->vertex);
  free(g->next);
  free(g->start);
  free(g);
  return;
}

void addEdge(graph *g,const int from,const int to){
  const int p=g->pointer;
  g->vertex[p]=to;
  g->next[p]=g->start[from];
  g->start[from]=p;
  g->pointer++;
  return;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  graph *g=newGraph(n,2*m);
  for(int i=0;i<m;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    a--; b--;
    addEdge(g,a,b);
    addEdge(g,b,a);
  }
  int *ans=(int *)calloc(2*n,sizeof(int));
  ans[n]=0;
  int *used=(int *)calloc(n,sizeof(int));
  used[0]=1;
  int l=n;
  int r=n;
  while(1){
    int ok=1;
    for(int p=g->start[ans[r]];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      if(!used[u]){
	ok=0;
	used[u]=1;
	ans[++r]=u;
	break;
      }
    }
    if(ok) break;
  }
  while(1){
    int ok=1;
    for(int p=g->start[ans[l]];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      if(!used[u]){
	ok=0;
	used[u]=1;
	ans[--l]=u;
	break;
      }
    }
    if(ok) break;
  }
  printf("%d\n",r-l+1);
  for(int i=l;i<=r;i++) printf("%d ",ans[i]+1);
  puts("");
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;
int a[110];

int solve(){
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int mn = inf;
    for(int i = -100; i <= 100; ++i){
        int sum = 0;
        for(int j = 0; j < n; ++j){
            sum += sqr(a[j] - i);
        }
        mn = min(mn, sum);
    }
    return mn;
}

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

    cout << solve() << "\n";
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		int[][] dp = new int[4][4001];
		for(int i=0;i<=1000;i++) dp[0][i] = 1;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j <= 4000; j++) {
				for (int k = 0; k <= 1000; k++) {
					if (j + k <= 4000) dp[i + 1][j + k] += dp[i][j];
				}
			}
		}
		while (sc.hasNext()) {
			int n = sc.nextInt();
			System.out.println(dp[3][n]);
		}
	}

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

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(char[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	boolean inner(int h, int w, int limH, int limW) {
		return 0 <= h && h < limH && 0 <= w && w < limW;
	}

	void swap(int[] x, int a, int b) {
		int tmp = x[a];
		x[a] = x[b];
		x[b] = tmp;
	}

	// find minimum i (a[i] >= border)
	int lower_bound(int a[], int border) {
		int l = -1;
		int r = a.length;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			if (border <= a[mid]) {
				r = mid;
			} else {
				l = mid;
			}
		}
		// r = l + 1
		return r;
	}

	boolean palindrome(String s) {
		for (int i = 0; i < s.length() / 2; i++) {
			if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
				return false;
			}
		}
		return true;
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}

		int[] nextIntArray(int n) {
			int[] in = new int[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextInt();
			}
			return in;
		}

		int[][] nextInt2dArray(int n, int m) {
			int[][] in = new int[n][m];
			for (int i = 0; i < n; i++) {
				in[i] = nextIntArray(m);
			}
			return in;
		}

		double[] nextDoubleArray(int n) {
			double[] in = new double[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextDouble();
			}
			return in;
		}

		long[] nextLongArray(int n) {
			long[] in = new long[n];
			for (int i = 0; i < n; i++) {
				in[i] = nextLong();
			}
			return in;
		}

		char[][] nextCharField(int n, int m) {
			char[][] in = new char[n][m];
			for (int i = 0; i < n; i++) {
				String s = sc.next();
				for (int j = 0; j < m; j++) {
					in[i][j] = s.charAt(j);
				}
			}
			return in;
		}
	}
}

Measured memory_bytes: 19300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
//cout << setprecision(20) << 


int main() {
    ll N, M, X; cin >> N >> M >> X;
    vector<ll> cost(N); 
    vector<vector<ll>> A(N);
    for (ll i = 0; i < N; ++i) {
        cin >> cost[i];
        for (ll j = 0; j < M; ++j) {
            ll tmp; cin >> tmp;
            A[i].push_back(tmp);
        }
    }

    ll ans = 1<<24;
    bool found_once = false;
    for (ll bit = 0; bit < (1<<N); ++bit) {
        ll tmp_cost = 0;
        vector<ll> sat(M, 0);
        for (ll i = 0; i < N; ++i) {
            if (bit & (1<<i)) {
                tmp_cost += cost[i];
                for (ll j = 0; j < M; ++j) {
                    sat[j] += A[i][j];
                }
            }
        }
        bool ok = true;
        for (ll i = 0; i < M; ++i) {
            if (sat[i] < X) ok = false;
        }
        if (ok) {
            found_once = true;
            ans = min(ans, tmp_cost);
        }
    }
    if (!found_once) ans = -1;
    cout << ans << endl;
}

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

using namespace std;

string shift(string s, int a, int b) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] < 'a' || 'z' < s[i]) continue;
    s[i] = (a * (s[i] - 'a') + b) % 26 + 'a';
  }
  return s;
}

void solve(string s) {
  for (int i = 0; i < 26; i++) {
    if (i % 2 == 0 || i == 13) continue;
    for (int j = 0; j < 26; j++) {
      string w = shift(s, i, j);
      if (w.find("that") != string::npos || w.find("this") != string::npos) {
        cout << w << endl;
        i = j = 26;
      }
    }
  }
}

int main(void) {
  int n;
  cin >> n;

  cin.ignore();
  for (int i = 0; i < n; i++) {
    string s;
    getline(cin, s);
    solve(s);
  }

  return 0;
}


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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;


int main(){
  int R,C,K;
  cin >> R >> C >> K;
  vector<vector<int>> item(3010, vector<int>(3010,0));
  
  int r,c,v;
  for(int i = 0; i<K; i++){
    cin >> r >> c >> v;
    item[r][c] = v;
  }
  
  vector<vector<vector<long long>>> dp(3010, vector<vector<long long>>(3010, vector<long long> (4, 0)));
  
  for(int i = 1; i<=3000; i++){
    for(int j = 1; j<=3000; j++){
      for(int k = 0; k<=3; k++){
        if(k==0){
          dp[i][j][k] = max(dp[i-1][j][3], dp[i][j-1][0]);
        }   
        else{
          if(item[i][j]==0){
             dp[i][j][k] = max(dp[i-1][j][3],dp[i][j-1][k]);
          }
          else{
            
             dp[i][j][k] = max(dp[i][j-1][k],max(dp[i-1][j][3],dp[i][j-1][k-1])+item[i][j]);
          }
        }
      }
    }
  }
  
  cout << dp[R][C][3] << endl;    
}

      
      
       





      
       





Measured memory_bytes: 676196
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n;
	ll m;
	cin >> n >> m;
	vector<ll> v(m);
	vector<ll> s(m);
	ll a,b,c;
	for(ll i = 0; i < m; i++) {
		ll x = 0;
		cin >> a >> b;
		for(ll j = 0; j < b; j++) {
			cin >> c;
			x = x | 1 <<(c - 1);
		}
		v[i] = a;
		s[i] = x;
	}
	vector<vector<ll>> dp(m+1,vector<ll>(1<<n,LINF));

	dp[0][0] = 0;
	for(ll i = 0; i < m; i++) {
		for(ll j = 0; j < (1 << n); j++) {
			dp[i+1][j] = min(dp[i][j],dp[i+1][j]);//i+1番目を使わなかった時
			dp[i+1][j|s[i]] = min(dp[i+1][j|s[i]],dp[i][j] + v[i]);//i+1番目を使った時
		}
	}
	if (dp[m][(1<<n)-1] != LINF){
		cout << dp[m][(1<<n) -1] << endl;
	}
	else{
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 32384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
int main(){
    int n,k;
    cin>>n>>k;
    int cnt=0;
    while(n!=0){
        n/=k;
        cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
st = 0
for i in range(N):
    st += B[A[i] - 1]
    if i >= 1 and A[i] == A[i - 1] + 1:
        st += C[A[i] - 2]
print(st)


Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

vector<string> map;
typedef struct 
{
    int x;
    int y;
}P;
queue<P> que;
int step[1000][1000];

bool CheclBoard(int H, int W)
{
    bool ret = true;
    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            if(map[i][j]!='#')
            {
                ret = false;
                break;
            }
        }
    }
    return ret;
}


int main(void)
{
    vector<P>move = {{0,1},{0,-1},{1,0},{-1,0}};
    int H, W;
    cin >> H >> W;
    map.resize(H);
    for(int i=0;i<H;i++) cin >> map[i];

    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            if(map[i][j]=='#')
            {
                que.push(P{i,j});            
                step[i][j]=0;
            }
        }
    }

    int maxNum = 0;    
    while(!que.empty())
    {
        P pos = que.front();
        que.pop();
        for(int i=0;i<4;i++)
        {
            int nX = pos.x + move[i].x;
            int nY = pos.y + move[i].y;

            if((nX>=0)&&(nX<H)&&(nY>=0)&&(nY<W)&&(map[nX][nY]!='#'))
            {
                map[nX][nY]='#';
                que.push(P{nX,nY});
                step[nX][nY]=step[pos.x][pos.y] + 1;
                if(maxNum < step[nX][nY]) maxNum = step[nX][nY];
            }
        }
    }
        
    cout << maxNum << endl;
    return 0;
}


Measured memory_bytes: 13456
lap_distance, house_count = gets.split.map(&:to_i)
distance_list = gets.split.map(&:to_i)

def section_data(d, p1, p2)
  {
    distance: d,
    start_point_index: p1,
    end_point_index: p2
  }
end

sections = distance_list.map.with_index do |distance, index|
  if index + 1 == distance_list.size
    section_data(distance_list[0] + (lap_distance - distance), 0, index + 1)
  else
    section_data(distance_list[index + 1] - distance, index, index + 1)
  end
end

longest_section = sections.max { |x, y| x[:distance] <=> y[:distance] }
index = sections.find_index(longest_section)
sections.delete_at(index)

p sections.inject(0) { |result, v| result + v[:distance].to_i }

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

int main(){
    int N;
    cin >> N;
    
    vector<vector<int>> c(10,vector<int>(10));
    
    /* c[i,j] 最高位がi, 最低位がjの個数 */
    
    for ( int i = 1; i <= N; ++ i){
        int a,b; a = 0; b = 0;
        int num = i;
        a = i % 10;
        while ( num > 0 ){
            b = num % 10;
            num = num / 10;
        }
        c.at(a).at(b) += 1;
    }
    
    int res = 0;
    for ( int i = 0; i < 10; ++i){
        for ( int j = 0; j < 10; ++j){
            res = res + c.at(i).at(j) * c.at(j).at(i);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
using namespace::std;
int main(){

  int N;
  cin>>N;
 long long int *A = new long long int[N+1];
 long long int *B = new long long int[N];
  for(int i=0;i<N+1;i++){
    cin>>A[i];
  }
    for(int i=0;i<N;i++){
    cin>>B[i];
  }
 long long int By=0;
 long long int Nc=A[N];
long long int Cc=A[N-1];
 long long int Tk=0; 
  for(int i=N-1;i>-1;i--){
    Cc=A[i];
    if((Nc-B[i])>=0){
      By=0;
      Tk=Tk+B[i];
    }else{
      By=B[i]-Nc;
      Tk=Tk+Nc;
    }
//   cout<<By<<" "<<Cc<<" "<<Tk<<" ";
    if((Cc-By)>0){
      Tk=Tk+By;
      Cc=Cc-By;
    }else{
      Tk=Tk+Cc;
      Cc=0;
    }
    Nc=Cc;

//   cout<<Tk<<endl;
  }
  cout<<Tk;
  
      
}


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

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

  int h, w, m;
  cin >> h >> w >> m;
  
  vector<int> vr(h), vc(w);
  set<P> sp;
  rep(i,m) {
    int r, c;
    cin >> r >> c;
    --r, --c;
    vr[r]++;
    vc[c]++;
    sp.emplace(r, c);
  }
  
  int mxr = 0, mxc = 0;
  rep(i,h) mxr = max(mxr, vr[i]);
  rep(j,w) mxc = max(mxc, vc[j]);
  
  vector<int> vmr, vmc;
  rep(i,h) {
    if (vr[i] == mxr) vmr.push_back(i);
  }
  rep(j,w) {
    if (vc[j] == mxc) vmc.push_back(j);
  }
  
  int ans = mxr + mxc;
  for (int i : vmr) for (int j : vmc) {
    if (sp.count(P(i,j)) == 0) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << ans-1 << endl;
}

Measured memory_bytes: 23784
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)
#define forg(i,gu) for (int i=gu;~i;i=e[i].next)
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
void getre(){int x=0;printf("%d\n",1/x);}
void gettle(){int res=1;while(1)res<<=1;printf("%d\n",res);}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}
template<typename N>N gcd(N a,N b){return b?gcd(b,a%b):a;}
template<typename N>inline int sgn(N a){return a>0?1:(a<0?-1:0);}
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
#ifdef JCVB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
typedef long long ll;
typedef double db;
inline ll sqr(ll a){return a*a;}
inline db sqrf(db a){return a*a;}
const int inf=0x3f3f3f3f;
const db pi=3.14159265358979323846264338327950288L;
const db eps=1e-6;
//const int mo=0;
//int qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}

int a[111111];
int cur=2;
int main()
{
#ifdef JCVB
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int _time_jc=clock();
#endif
	int n;
	gn(n);rep(i,1,n+1)gn(a[i]);

	ll ret=a[1]-1;
	rep(i,2,n+1)
		if(a[i]==cur){
			cur++;
		}else if(a[i]>cur){
			ret+=(a[i]-1)/cur;
		}
	cout<<ret<<endl;
	return 0;
}



Measured memory_bytes: 768
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    c = input().rstrip()
    print(chr(ord(c)+1))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-12
#define M_PI 3.141592653589793
#define bs 1000000007

#define ldouble long double

using namespace std;

long long INF = 1e9;
const int N = 300031;

int n,m;
vector<int> g[N];
vector<int> avec;
int used[N];

deque<int> ans;

int can_extend(int v)
{
	for (int i=0;i<g[v].size();i++)
	{
		int to=g[v][i];
		if (used[to])
			continue;
		return to;
	}
	return -1;
}

int main(){
	//freopen("tree.in","r",stdin);
	//freopen("tree.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin>>n>>m;
	for (int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int start=1;
	while (g[start].size()==0)
		++start;
	ans.push_back(1);
	used[1]=1;

	while (true)
	{
		int here=can_extend(ans.front());
		if (here!=-1)
		{
			ans.push_front(here);
			used[here]=1;
			continue;
		}
		here=can_extend(ans.back());
		if (here!=-1)
		{
			ans.push_back(here);
			used[here]=1;
			continue;
		}
		break;
	}

	while (ans.size())
	{
		int v=ans.front();
		ans.pop_front();
		avec.push_back(v);
	}

	cout<<avec.size()<<endl;
	for (int i=0;i<avec.size();i++)
	{
		if (i)
			cout<<" ";
		cout<<avec[i];
	}
	cout<<endl;

	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 12280
import copy

h, w, k = map(int, input().split())
ans = 0

matrix = [[0 for i in range(w)] for j in range(h)]

def delRow(a, mat):
    for i in range(w):
        mat[a][i] = 0

def delCol(b, mat):
    for j in range(h):
        mat[j][b] = 0

def sum2d(mat):
    s = 0
    for i in range(len(mat)):
        for j in range(len(mat[i])):
            s += mat[i][j]
    return s

for i in range(h):
    c = input()
    for j in range(w):
        if c[j] == '#':
            matrix[i][j] += 1


for i in range(2 ** h):
    for j in range(2 ** w):
        mat = copy.deepcopy(matrix)
        for l in range(h):
            if ((i >> l) & 1):
                delRow(l, mat)
        for l in range(w):
            if ((j >> l) & 1):
                delCol(l, mat)
        if sum2d(mat) == k:
            ans += 1
print(ans)


Measured memory_bytes: 9352
lftIdx, rgtIdx, ans = 0, 0, 0
lftFlg, rgtFlg = False, False
n, k = map(int, input().split())
s = input()


def move(lr, idx, flg):
    # lr: lft := "1", rgt := "0"
    # return: idx
    global s
    if flg and idx < n-1:
        idx += 1
    contains_zero = False
    while True:
        if idx == n-1:
            return idx
        if s[idx] == "0":
            contains_zero = True
        if contains_zero and s[idx] != s[idx+1] and s[idx+1] == lr:
            return idx
        idx += 1


def solv():
    global lftIdx, rgtIdx, ans, lftFlg, rgtFlg, n, k, s
    for i in range(k):
        rgtIdx = move("0", rgtIdx, rgtFlg)
        rgtFlg = True
    ans = max(ans, rgtIdx + 1)
    while n-1 > rgtIdx:
        rgtIdx = move("0", rgtIdx, rgtFlg)
        lftIdx = move("1", lftIdx, lftFlg)
        lftFlg = True
        ans = max(ans, rgtIdx - lftIdx)  # (rgtIdx + 1) - (lftIdx + 1)
    return


solv()
print(ans)


Measured memory_bytes: 3316
from collections import deque

def main():
    K = int(input())
    
    # bfs
    q = deque(range(1, 10))
    for _  in range(K-1):
        now = q.popleft()
        d1 = now % 10
        base = 10 * now
        
        for suffix in [d1 - 1, d1, d1 + 1]:
            if suffix not in [-1, 10]:
                new = base + suffix
                q.append(new)

    ans = q.popleft()
    print(ans)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 12404
import numpy as np
N, K, Q = map(int, input().split())
p = np.array([K - Q] * N)
for i in range(Q):
  A = int(input())
  p[A-1] = p[A-1] + 1
for s in p:
  if s > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 18740
#include<bits/stdc++.h>
using namespace std;
int ans;
int h,w;
string ma1[55];
string ma2[55];
int dp[55][55][55][55];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
struct node{int a,b,c,d;};
void bfs(int x1,int y1,int x2,int y2){
  node n=(node){x1,y1,x2,y2};
  queue<node> q;
  q.push(n);
  while(!q.empty()){
    node t=q.front();
    q.pop();
    int lx=t.a;
    int ly=t.b;
    int rx=t.c;
    int ry=t.d;
    if(ans)continue;
    if(dp[lx][ly][rx][ry])continue;
    if(ma1[lx][ly]=='%'&&ma2[rx][ry]=='%'){
      ans=1;
      return;
    }
    if(ma1[lx][ly]=='%'||ma2[rx][ry]=='%'){
      continue;
    }
    dp[lx][ly][rx][ry]=1;
    for(int i=0;i<4;i++){
      int nlx=lx+dx[i];
      int nly=ly+dy[i];
      int nrx=rx+dx[i];
      int nry=ry-dy[i];
      if(nlx==h||nlx<0)nlx=lx;
      if(nly==w||nly<0)nly=ly;
      if(ma1[nlx][nly]=='#')nlx=lx,nly=ly;
      if(nrx==h||nrx<0)nrx=rx;
      if(nry==w||nry<0)nry=ry;
      if(ma2[nrx][nry]=='#')nrx=rx,nry=ry;
      if(dp[nlx][nly][nrx][nry]==0){
	node d=(node){nlx,nly,nrx,nry};
	q.push(d);
      }
    }
  }
  return;
}

int main(){
  while(cin>>w>>h,w+h){
    ans=0;
    memset(dp,0,sizeof(dp));
    int sl[2],sr[2];
    for(int i=0;i<h;i++){
      cin>>ma1[i]>>ma2[i];
      for(int j=0;j<w;j++){
	if(ma1[i][j]=='L')sl[0]=i,sl[1]=j;
	if(ma2[i][j]=='R')sr[0]=i,sr[1]=j;
      }
    }
    bfs(sl[0],sl[1],sr[0],sr[1]);
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}



Measured memory_bytes: 40468
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define all(v) v.begin(), v.end()
using pint = pair<int, int>;
using tint = tuple<int, int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int X, N;
	cin >> X >> N;
	vector<int> v(N);
	rep(i, N) {
		cin >> v.at(i);
	}

	int a=-1, b=0, c=0, x, y, z;
	sort(all(v));
	bool f = true;
	bool s = true;
	rep(i, 102) {
		rep(j, N) {
			if (v.at(j) == X) {
				f = false;
				break;
			}
		}
		if (f) {
			std::cout << X << '\n';
			return 0;
		}
		X += a;
		a *= -1;
		if (s) {
			a++;
		} else {
			a--;
		}
		s = !s;
		f = true;
	}
}


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

int main() {
	map<string, int> days {
		{ "SUN", 7 },
		{ "MON", 6 },
		{ "TUE", 5 },
		{ "WED", 4 },
		{ "THU", 3 },
		{ "FRI", 2 },
		{ "SAT", 1 },
	};

	string s; cin >> s;

	cout << days[s] << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<stack>
#include<vector>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
stack<P> stu[10003];
vector<P> vec[10003];
int N,M,r;
int t[1003],n[1003],m[1003],s[1003];
int q;
int qs[55],qe[55],qm[55];

int cookies(int sx,int sy,int lx,int ly){
  return max(min(sy,ly)-max(sx,lx),0);
}

int main(){
  while(1){
    memset(t,0,sizeof(t));
    memset(n,0,sizeof(n));
    memset(m,0,sizeof(m));
    memset(s,0,sizeof(s));
    memset(qs,0,sizeof(qs));
    memset(qe,0,sizeof(qe));
    memset(qm,0,sizeof(qm));
    for(int i=0;i<10003;i++)vec[i].resize(0);
    for(int i=0;i<10003;i++){
      while(1){
        if(!stu[i].empty()) stu[i].pop();
        else break;
      }}

    scanf("%d%d",&N,&M);
    if(N==0 && M==0) break;
    scanf("%d",&r);
    for(int i=0;i<r;i++){
      scanf("%d%d%d%d",&t[i],&n[i],&m[i],&s[i]);
      if(s[i]==1) stu[m[i]].push(P(t[i],n[i]));
      if(s[i]==0) {
        P p=stu[m[i]].top();
        stu[m[i]].pop();
        if(stu[m[i]].empty()) vec[m[i]].push_back(P(p.first,t[i]));
      }
    }
    scanf("%d",&q);
    int i;
    for(i=0;i<q;i++) {
      scanf("%d%d%d",&qs[i],&qe[i],&qm[i]);

      int res=0;
      for(int j=0;j<vec[qm[i]].size();j++){
        res+=cookies(qs[i],qe[i],vec[qm[i]][j].first,vec[qm[i]][j].second);
      }

      printf("%d\n",res);
    }

  }
  return 0;
}

Measured memory_bytes: 8208
a, b = gets.split(" ").map(&:to_i)
humans = Array.new(b, 0)
max = 0
while a > 0 do
    for i in 0...humans.length do
        humans[i] += 1 if a > 0
        a -=1
    end
end
min = humans[0]
humans.each do |item|
    max = item if item > max
    min = item if item < min
end
 p (max - min).abs

Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;


signed main()
{
	fastio();
	int n;
	cin >> n;
	vector<int> a(n);
	vin(a);
	int sum = 0;
	for (int i = 0; i < n; ++i)
	{
		sum += a[i] - 1;
	}
	cout << sum;
	system("pause");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int first, second, third;
    first = N % 10;
    N /= 10;
    second = N % 10;
    N /= 10;
    third = N;
    if(first == 7 || second == 7 || third == 7){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
use text_io::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;

fn main() {
    let mut n:usize = read!();
    let mut v:Vec<usize> = Vec::new();
    let mut vv:Vec<usize> = Vec::new();
    for i in 0..n {
        let a:usize = read!();
        v.push(a);
        vv.push(a);
    }
    v.sort();
    v.reverse();
    for i in 0..n {
        if vv[i]==v[0] {
            println!("{}",v[1]);
        }
        else {
            println!("{}",v[0]);
        }
    }
}

Measured memory_bytes: 5832
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	cin>>n;
	int m;
	cin>>m;
	int h[n];
	int a[m],b[m];
	bool good[n];
	int ans=0;
	for(int i=0;i<n;i++)
	{
		good[i]=true;
	}
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	for(int i=0;i<m;i++)
	{
		cin>>a[i]>>b[i];
		if(h[a[i]-1]<h[b[i]-1])
		good[a[i]-1]=false;
		else if(h[a[i]-1]>h[b[i]-1])
		good[b[i]-1]=false;
		else{
			good[b[i]-1]=false;
			good[a[i]-1]=false;
		}
	}
	for(int i=0;i<n;i++)
	{
		ans+=(int)good[i];
	}
	cout<<ans<<endl;
}

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

using ll = long long;
using P = pair<int, int>;

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (i * j == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
module Main where

import Control.Applicative
import Numeric
import Data.Char
import Data.List
import Data.Ord

main :: IO ()
main = do
  { cs <- getContents
  ; putStr $ unlines
           $ map showCharCount
           $ mergeCharCounts
           $ charCounts
           $ alphas cs
  }
 
alphas :: String -> String
alphas = map toLower .  filter isAlpha

charCounts :: String -> [(Char, Int)]
charCounts = map count . group . sort

count :: String -> (Char, Int)
count s = (head s, length s)

initCharCounts :: [(Char, Int)]
initCharCounts = zip ['a'..'z'](repeat 0)

mergeCharCounts :: [(Char, Int)] -> [(Char, Int)]
mergeCharCounts = merge initCharCounts

merge :: [(Char, Int)] -> [(Char, Int)] -> [(Char, Int)]
merge [] [] = []
merge xs [] = xs
merge (x:xs) (y:ys) = case (comparing fst) x y of
  LT -> x : merge xs (y:ys)
  EQ -> y : merge xs ys
  _ -> error "Henn!"

showCharCount :: (Char, Int) -> String
showCharCount (c, n) = [c] ++ " : " ++ show n

--

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords .  map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;

int N, K;
vi h;
int main(){
    cin >> N >> K;
    h.resize(N);
    rep(i, N)cin >> h[i];
    sort(h.begin(), h.end());
    int minv = INF;
    for(int i = 0;i < N - K + 1;++i){
        minv = min(minv, h[i + K - 1] - h[i]);
    }
    cout << minv;
}


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

int main() {
    long long H;
    long long N;
    cin >> H >> N;
    long long A[N];
    for (long long i = 0; i < N; ++i){
        cin >> A[i];
    }
    long long sum = 0;
    for (long long i = 0; i < N; ++i) {
        sum += A[i]; 
    }
    if ((H - sum) <= 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main () {
 int n,a,fac2=0;
 scanf ("%d",&n);
 for (int i = 0; i < n; i++) {
   scanf ("%d",&a);
   while (a%2==0) a/=2, fac2++;
 }
 printf ("%d\n",fac2);
 return 0;
}


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


def main():
    sc = Scan()
    N, M = sc.intarr()
    array = []
    for i in range(M):
        p, s = sc.strarr()
        array.append([p, s])

    data = {}
    AC_cnt = 0
    WA_cnt = 0
    for ss in array:
        if ss[0] not in data:
            if ss[1] == 'WA':
                data[ss[0]] = [0, 1]
            elif ss[1] == 'AC':
                data[ss[0]] = [1, 0]
        elif data[ss[0]][0] == 0:
            if ss[1] == 'WA':
                data[ss[0]][1] += 1
            elif ss[1] == 'AC':
                data[ss[0]][0] += 1

    for key in data:
        if data[key][0] != 0:
            AC_cnt += 1
            WA_cnt += data[key][1]

    print(AC_cnt, WA_cnt)


def perm(p):
    if len(p) == 1:
        return [p]
    else:
        s = []
        for i in range(len(p)):
            q = p[i]
            r = perm(p[:i]+p[i+1:])
            for t in r:
                s.append([q] + t)
        return s


class Scan():

    def intarr(self):
        num_array = list(map(int, input().split()))
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  # 最小公倍数
    return a * b // gcd(a, b)


main()


Measured memory_bytes: 41892
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

#define ll long long

int main()
{
	const ll N = 300000;
	ll n;
	ll num;
	ll ans = 0;
	vector<ll> a(N);
	
	cin >> n;
	num = 3 * n;
	a.resize(num);
	for (ll i = 0; i < num; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	/*for (int i = 0; i < 3 * n; i++) {
		cout << a[i] << endl;
	}*/
	for (ll i = 0; i < n; i++) {
		ans += a[num - 2 - (2 * i)];
	}
	cout << ans << endl;

	return (0);
}

Measured memory_bytes: 2560
#include<stdio.h>
#include <string.h>
int main(void)
{
	int n,i,j;
	int cnt;
	char a[10],m[20],b[10];
	cnt=0;
	scanf("%s %d",a,&n);
	for (i=0;i<n;i++) {
		scanf("%s",m);
		strcpy(b,m);
		strcat(m,b);
		if (strstr(m,a)) {
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1052
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

typedef long long ll;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll prevArraySum,currentArraySum ;
  ll res , res1 = 1e15;

  rep(first,2){
    if(first % 2 && a[0] == 0){
      res = 1;
      prevArraySum = -1; currentArraySum = -1;
    }else if(first % 2 == 0 && a[0] == 0){
      res = 1;
      prevArraySum = 1; currentArraySum = 1;
    }else if(first % 2){
      res = 0;
      prevArraySum = a[0]; currentArraySum = a[0];
    }else if(a[0] > 0){
      res = a[0] + 1;
      prevArraySum = -1; currentArraySum = -1;
    }else{
      res = -a[0] + 1;
      prevArraySum = 1; currentArraySum = 1;
    }
    //cout << "debug point" << endl;
    FOR(i,1,n){
      if(prevArraySum > 0){//前回の累積和が正の場合
        currentArraySum = prevArraySum + a[i];
        if(currentArraySum >= 0){
          res += abs(-1 - currentArraySum);
          prevArraySum = -1;
        }else{
          prevArraySum = currentArraySum;
        }
      }else{//前回の累積和が負の場合
        currentArraySum = prevArraySum + a[i];
        if(currentArraySum <= 0){
          res += abs(1 - currentArraySum);
          prevArraySum = 1;
        }else{
          prevArraySum = currentArraySum;
        }
      }
    }
    res1 = min(res,res1);
  }

  cout << res1 << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, m, c[100001], d[100001], s[100001];
int main() {
  cin >> n >> m;
  for (i64 i = 0; i < n; ++i) {
    i64 x; cin >> x;
    c[x]++;
  }

  for (i64 x = 1; x <= 100000; ++x) {
    s[x % m] += c[x];
    d[x % m] += c[x] % 2;
  }

  i64 ans = s[0] / 2;
  if (m % 2 == 0) ans += s[m / 2] / 2;

  for (i64 i = 1; i <= (m - 1) / 2; ++i) {
    i64 x = i, y = m - i;
    if (s[x] <= s[y]) {
      ans += s[x] + min(s[y] - d[y], s[y] - s[x]) / 2;
    } else {
      ans += s[y] + min(s[x] - d[x], s[x] - s[y]) / 2;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

#define N 100

int bubbleSort(int *,int);

int main(){
  int s,t[N],i;
  scanf("%d",&s);

  for(i=0;i<s;i++)
    scanf("%d",&t[i]);

  printf("%d\n",bubbleSort(t,s));

  return 0;
}




int bubbleSort(int *t,int s){
  int  flag=1,j,swap,count=0,i;

  while(flag){
    flag=0;
    for(j=s-1;j>0;j--){
      if(t[j]<t[j-1]){
	swap=t[j];
	t[j]=t[j-1];
	t[j-1]=swap;
        flag=1;
	count++;
      }
    
    }
  }
  for(i=0;i<s-1;i++)
    printf("%d ",t[i]);
  printf("%d\n",t[s-1]);

  return count;
}




Measured memory_bytes: 2752
import sys
input = sys.stdin.readline

def main():
    A, B, C = map(int, input().split())

    ok = False
    for i in range(1, B+1):
        if (A * i) % B == C:
            ok = True
            break

    if ok:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
from sys import stdin
N,K=map(int,stdin.readline().split())
h=[int(i) for i in stdin.readline().split()][:N]
dp=[float('inf') for i in range(N)]
dp[0]=0
for i in range(N):
    for j in range(i+1,i+K+1):
        if j<N:
            dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]))
    #print(dp)
print(dp[-1])

Measured memory_bytes: 89540
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next(); //入力された文字列
    char st; //文字を入れる場所;
    char ch[] = {'A','C','G','T'}; //比較対象の文字列
    int count = 0; //カウント
    int count_max = 0; //カウントの最大地
    boolean con; //ループを中断させる為の論理型変数
    
    for(int i = 0; i < s.length();i++){ //全ての文字を参照するようにループ
    	st = s.charAt(i); //文字列
      	con = true; //続行条件を正に
      	count++; //カウント加算
      	for(int j = 0; j < 4 && con;j++){ //conがtrueもしくは比較対象の文字列全てを比較しおえるまでループ
          if(st == ch[j]) con = false; //比較対象の文字列と一致していればconをfalseにしてループ終了
        }
      	if(con) count = 0; //conがtrueのまま終了した場合カウントを0に
      	if(count > count_max) count_max = count; //カウントが最大値を上回っていれば更新
    }
    
    System.out.println(count_max); //最大値を出力
  }
}


Measured memory_bytes: 35632
n = int(input())
s = [input() for _ in range(n)]

inf = 10 ** 18
count = [inf] * 26
for t in s:
    c = [0] * 26
    for x in t:
        i = ord(x) - ord('a')
        c[i] += 1
    for i in range(26):
        count[i] = min(count[i], c[i])

ans = ''
for i in range(26):
    ans += chr(i + ord('a')) * count[i]
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long n = sc.nextLong();
		
		System.out.println(max(n));
	}

	static long max(long n) {
		if(n<10)
			return n;
		
		String s="";
		while(Long.parseLong(s+"9")<=n)
			s+="9";
		int i=1;
		long ans=Long.parseLong(s);
		for(i=1;i<10 && Long.parseLong(i+s)<=n;i++){
			ans = Long.parseLong(i+s);
		}
		int sum=0;
		while(ans>0){
			sum+=ans%10;
			ans/=10;
		}
		return sum;
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    long double pi = 3.1415926535897932384626433832795;
    int h,a,b,m;
    cin >> a >> b >> h >> m;
    long double x1,x2,y1,y2;
    m += h*60.0;
    x1 = a*sin(m*pi/360.0);
    y1 = a*cos(m*pi/360.0);
    x2 = b*sin(m*pi/30.0);
    y2 = b*cos(m*pi/30.0);

    cout << fixed << setprecision(12);
    cout << sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

Measured memory_bytes: 4088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int fib[50];

int f(int x){
    
    if (fib[x] != 0) return fib[x];
    else{
        return fib[x]=f(x-1)+f(x-2);
    }
}

int main(){
    fib[0]=1;
    fib[1]=1;
    int n;
    cin >> n;
    cout << f(n) << endl;   
    return 0;
}


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

using namespace std;

int main()
{
	
	int a , b ;
	char op ;
	
	cin>>a;
	cin>>op;
	cin>>b;
	
	if(op=='+')
	{
		cout<<a+b<<"\n";
	}
	
	else
	
	cout<<a-b<<"\n";
	
	
	
	
	
	
}



Measured memory_bytes: 256
import datetime
import sys

week = {0:'Monday', 1:'Tuesday', 2:'Wednesday', 3:'Thursday', 4:'Friday', 5:'Saturday', 6:'Sunday'}

f = sys.stdin
while True:
    month, date = map(int, f.readline().split())
    if month == 0:
        break
    day = datetime.date(2004, month, date)
    print(week[day.weekday()])

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll n,k;
	cin>>n>>k;
	ll sum[n+1];
	ll ans=1;
	sum[0]=0;
	for(int i=1;i<=n;++i){
		sum[i]=i+sum[i-1];
	}
	for(int i=k-1;i<n;++i){
		ans+=(sum[n]-sum[n-i-1])-sum[i]+1;
		ans%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5200
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var list = myconv(input[1],4);
  var output = 0;
  for(var i = 1; i <= list.length; i++){
    var tmp = list[i - 1];
    var tmp2 = list[tmp - 1];
    if(tmp2 == i){
       output++;
      list[i - 1] = null;
      list[tmp - 1] = null;
       }
  }
  myout(output);
}

Main(myin());


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;

    vll a;
    a.push_back(0);
    rep(i, n) {
        ll t;
        cin >> t;
        a.push_back(t);
    }
    a.push_back(0);

    ll sum = 0;
    rep(i, n + 1) {
        sum += abs(a[i + 1] - a[i]);
    }

    for (int i = 1; i <= n; i++) {
        cout << sum + abs(a[i - 1] - a[i + 1]) - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])) << endl;
    }
}

Measured memory_bytes: 2164
n = input()
test = [[0]*3 for i in range(101)]
a = [map(int, raw_input().split()) for i in range(n)]
ans = [0]*n
for i in range(n):
    for j in range(3):
        test[a[i][j]][j] += 1
for i in range(n):
    for j in range(3):
        if test[a[i][j]][j] < 2: ans[i] += a[i][j]
for i in range(n):
    print ans[i]

Measured memory_bytes: 6464