akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int arr[4][4];
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            cin>>arr[i][j];
        }
    }
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int a;
        cin>>a;
        for(int i=0; i<3; i++)
        {
            for(int j=0; j<3; j++)
            {
                if(arr[i][j]==a) arr[i][j]=-1;
            }
        }
    }
    if(arr[0][0]==-1 && arr[1][1]==-1 && arr[2][2]==-1) cout<<"Yes"<<endl;
    else if(arr[2][0]==-1 && arr[1][1]==-1 && arr[0][2]==-1) cout<<"Yes"<<endl;
    else  if(arr[0][0]==-1 && arr[0][1]==-1 && arr[0][2]==-1) cout<<"Yes"<<endl;
    else if(arr[1][0]==-1 && arr[1][1]==-1 && arr[1][2]==-1) cout<<"Yes"<<endl;
    else if(arr[2][0]==-1 && arr[2][1]==-1 && arr[2][2]==-1) cout<<"Yes"<<endl;
    else  if(arr[0][0]==-1 && arr[1][0]==-1 && arr[2][0]==-1) cout<<"Yes"<<endl;
    else if(arr[0][1]==-1 && arr[1][1]==-1 && arr[2][1]==-1) cout<<"Yes"<<endl;
    else if(arr[0][2]==-1 && arr[1][2]==-1 && arr[2][2]==-1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[100];
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a + n);
    cout << a[n - 1] - a[0];
}


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

int main(){

    int N , M , C;
    cin >> N >> M >> C;

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

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

    int ans = 0;
    for(int n = 0; n < N; n++){
        int sum = C;
        for(int m = 0; m < M; m++){
            sum += a[n][m] * b[m];
        }
        if(sum > 0) ans += 1; 
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream> 
using namespace std;
char a[16];
char b[16]={'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};
//b数组的值也可以是{67,79,68,69,70,69,83,84,73,86,65,76,50,48,49,54}；即这些字符的ASCII值； 
int cnt=0;//计数器 
int main()
{
    for(int i=0;i<16;i++)
    {
    	cin>>a[i];//输入 
	}
	for(int i=0;i<16;i++)
	{
		if(a[i]!=b[i])//比较：如果不一样，计数器就加1； 
			cnt++;
	}
	cout<<cnt;//输出计数器的值； 
	return 0;//养成一个好习惯； 
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BIMissYou solver = new BIMissYou();
        solver.solve(1, in, out);
        out.close();
    }

    static class BIMissYou {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            String str = s.nextString();
            for (int i = 0; i < str.length(); i++) {
                out.print('x');
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21460
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pi;
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair


int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};
bool v[50][50][50][50];
int f[50][50];
int x,y;
int tx,ty,kx,ky;


main(){
	while(cin>>x>>y,x){
		cin>>tx>>ty>>kx>>ky;
		--tx;--ty;--kx;--ky;
		rep(i,y)rep(j,x)cin>>f[j][i];
		memset(v,0,sizeof(v));

		v[tx][ty][kx][ky]=1;
		queue<pair<pair<pi,pi>,int> > Q;
		Q.push(mp(mp(mp(tx,ty),mp(kx,ky)),0));
		
		while(!Q.empty()){
			tx=Q.front().first.first.first;
			ty=Q.front().first.first.second;
			kx=Q.front().first.second.first;
			ky=Q.front().first.second.second;
			int time=Q.front().second;Q.pop();
			
			
			rep(d,4){
				int ntx=tx+dx[d],nty=ty+dy[d];
				int nkx=kx-dx[d],nky=ky-dy[d];
				
				if(ntx<0 || ntx>=x || nty<0 || nty>=y || f[ntx][nty])ntx=tx,nty=ty;
				if(nkx<0 || nkx>=x || nky<0 || nky>=y || f[nkx][nky])nkx=kx,nky=ky;
				if(v[ntx][nty][nkx][nky] || time>=99)continue;
				if(ntx==nkx && nty==nky){
					cout<<time+1<<endl;
					goto END;
				}
				
				Q.push(mp(mp(mp(ntx,nty),mp(nkx,nky)),time+1));
				v[ntx][nty][nkx][nky]=1;
			}
		}
		
		puts("NA");END:;
	}
}

Measured memory_bytes: 7196
#include <bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(a%2==0||b%2==0||c%2==0)
	{
		cout<<0;
		return 0;
	}
	cout<<min(min(a*b,a*c),b*c);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> W(N); 
  int sum=0;
  for (int i=0;i<N;++i){
    cin>>W[i];
    sum+=W[i];
  }
  int mini=sum;
  int tmp=0;
  for (int i=0;i<N;++i){
    tmp+=W[i];
    mini=min(mini,abs(tmp-(sum-tmp)));
  }
  cout<<mini<<endl;
}


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

#define deb(x) cerr<<"["#x<<" : "<<x<<" ]\n";
// 4x+7y=N;
int main()
{
	int N;
	cin >> N;
	for(int i = 0; i < N; i++) {
		if(N - i*4 < 0) break;
		if((N - i*4) % 7 == 0) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}


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


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

  int n;
  cin >> n;

  vector<int> a(n);

  rep(i,n) cin >> a[i];

  int cnt_even = 0;
  int cnt = 0;

  rep(i,n){
    if(a[i] % 2 == 0){
      ++cnt_even;
      if(a[i] % 3 == 0 || a[i] % 5 == 0){
        ++cnt;
      }
    }
  }

  if(cnt_even == cnt) cout << "APPROVED" << '\n';
  else cout << "DENIED" << '\n';

  return 0;

}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//FUNCTION

void solve(void)
{
  int N;
  cin>>N;
  vector<vector<double> > vvec (N,vector<double>(2,0));
  for (int i = 0; i < N; i++)
  {
    cin>>vvec[i][0]>>vvec[i][1];
  }
  double pN = 1;
  for (int i = 1; i < N+1; i++)
  {
    pN *= i;
  }
  double SUM = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = i+1; j < N; j++)
    {
      SUM += sqrt(pow(vvec[i][0] - vvec[j][0],2) + pow(vvec[i][1] - vvec[j][1],2) );
    }
  }
  
  double path = (N)*(N-1)/2;
  double ANS = SUM*(double)(N-1)/path;
  cout<<ANS<<endl;
  

  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 1000000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

ll N, W, w[111], v[111];

// dp[i][j]: i個めまでの品物を選べるときに量さj以下の時の価値の最大値
ll dp[111][100010];

int main() {
    cin >> N >> W;
    int w_, v_;
    rep1(i, N) {
        scanf("%d%d", &w_, &v_);
        w[i] = w_;
        v[i] = v_;
    }
    rep1(i, N) {
        rep1(j, W) {
            if (j - w[i] >= 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
            }
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        }
    }

    cout << dp[N][W];

    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 79360
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n: usize,
        arr: [usize; n],
        q: usize,
        bc: [(usize, usize); q],
    }

    let mut map: Vec<usize> = vec![0; 100_001];
    let mut sum: usize = 0;
    for a in arr {
        sum += a;
        map[a] += 1;
    }

    for (b, c) in bc {
        let tmp = map[b];
        sum = sum - b*tmp + c*tmp;
        println!("{}", sum);
        map[c] += tmp;
        map[b] = 0;
    }
}


Measured memory_bytes: 6836
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m;
    cin >> n >> m;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    lint ok    = 0;
    lint ng    = inf;
    auto check = [&](lint mid) {
        lint cnt = 0;
        for (int i = 0; i < n; ++i) {
            cnt += a.end() - lower_bound(a.begin(), a.end(), mid - a[i]);
        }
        return cnt >= m;
    };
    while (abs(ok - ng) != 1) {
        lint mid               = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    vector<lint> cum(n, 0);
    cum[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; --i) {
        cum[i] = cum[i + 1] + a[i];
    }
    lint cnt  = 0;
    lint ret  = 0;
    lint mini = inf;
    for (int i = 0; i < n; ++i) {
        lint c = a.end() - lower_bound(a.begin(), a.end(), ok - a[i]);
        if (c != 0) {
            cnt += c;
            ret += a[i] * c + cum[n - c];
            chmin(mini, a[i] + *next(lower_bound(a.begin(), a.end(), ok - a[i])));
        }
    }
    ret -= (cnt - m) * ok;
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//ruogu
const int N=2e5+5;
int dp[N],res=1,n;
vector<int>G[N];
//
void dfs(int x,int p){
	dp[x]=1;
	rep(i,G[x].size()){
		int to=G[x][i];
		if(to==p)continue;dfs(to,x);
		res=max(res,dp[x]+dp[to]);
		dp[x]=max(dp[x],dp[to]+1);
	}
}
int main(){
	n=getint();
	rep(i,n-1){
		int x=getint()-1,y=getint()-1;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs(0,-1);
	//cout<<res<<endl;
	if(res%3==2)cout<<"Second";
	else cout<<"First";
	return 0;
}


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

int main() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
}

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

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

const int MAX_DIGIT = 50;

int main(){
    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    rep(i, n)cin >> a[i];

    ll dp[100][2];
    rep(i, 100)dp[i][0] = -1, dp[i][1] = -1;
    dp[0][0] = 0;

    rep(i, MAX_DIGIT){
        //上からi桁目を立てた数値
        ll base = 1LL<<(MAX_DIGIT -1 - i);

        //数列Aの中でi桁目を立てている値の数
        ll cnt = 0;
        rep(j, n)if(a[j]&base)cnt++;

        ll cost0 = base * cnt;//xにおいて桁を立てなかった場合に得られるf(x)の値
        ll cost1 = base * (n-cnt);//xにおいて桁を立てた場合に得られるf(x)の値

        //すでに制約Kよりもxが小さいことが確定している場合、桁を立てるか立てないかは自由
        if(dp[i][1] != -1){
            dp[i+1][1] = max(dp[i+1][1], dp[i][1] + max(cost0, cost1));
        }
        
        //すでに制約Kギリギリの際に、Kのi桁めを下げ、制約よりxを小さくする
        if(dp[i][0] != -1)if(k&base){
            dp[i+1][1] = max(dp[i+1][1], dp[i][0] + cost0);
        }
        
        //制約Kギリギリを攻める
        if(dp[i][0] != -1){
            if(k&base)dp[i+1][0] = max(dp[i+1][0], dp[i][0] + cost1);
            else dp[i+1][0] = max(dp[i+1][0], dp[i][0] + cost0);
        }
    }

    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;



int main()
{
    int n;
    cin>>n;
    int ans=n%1000;
    if(ans!=0)
    {
        ans=1000-ans;
    }
    cout<<ans<<endl;

}


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


using namespace std;

#define inf 1e9+1 


#define int long long

int solve(int w,int n,int *weight,int *value)
{
	int maxval=n*1000;

	int dp[n+1][maxval+1];

	for(int i=0;i<=maxval;i++)
		dp[1][i]=inf;


	dp[1][0]=0;
	dp[1][value[1]]=weight[1];


	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<=maxval;j++)
		{
			dp[i][j]=dp[i-1][j];

			if(value[i]>j)
				continue;


			dp[i][j]=min(dp[i][j],weight[i]+dp[i-1][j-value[i]]);
		}
	}


	int ans=0;

	for(int i=0;i<=maxval;i++)
	{
		if(dp[n][i]<=w)
			ans=i;
	}


	return ans;
}

int32_t main()
{
	int n,w;
	cin>>n>>w;

	int weight[n+1],value[n+1];

	for(int i=1;i<=n;i++)
	{
		cin>>weight[i]>>value[i];
	}


	cout<<solve(w,n,weight,value)<<endl;

	return 0;


}

Measured memory_bytes: 78336
N = int(input())

A = [int(i) for i in input().split() ]

B = [int(i) for i in input().split() ]

C = [int(i) for i in input().split() ]

SUM = sum(B)

for i in range(N-1):
	if A[i] - A[i+1] == -1:
		
		SUM += C[A[i]-1]

print(SUM)


Measured memory_bytes: 38424
sa = input()
sb = input()
sc = input()

#dammy
sa=sa+'x'
sb=sb+'x'
sc=sc+'x'

tmp=sa[0]
sa = sa[1:]

while 1:
    if tmp=='a':
        tmp = sa[0]
        sa=sa[1:]
            
    elif tmp=='b':
        tmp = sb[0]
        sb=sb[1:]
    
    elif tmp=='c':
        tmp = sc[0]
        sc=sc[1:]
        
    elif tmp=='x':
        break

# print(sa)
# print(sb)
# print(sc)
if sa=='':
    print('A')
elif sb=='':
    print('B')
elif sc=='':
    print('C')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define MIN -1000000
const int MOD=1e9+7;
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
const int max_N=1e5+10;
vector<int> fives;
vector <pii> G[max_N],rg[max_N];
bool isprime[55600];
ll ans=0;
string s;
ll n,m;
ll a[100005];
ll b[100005];
unordered_map<ll,ll> um;
int main()
{
  memset(b,0,sizeof(b));
  cin >> n >> m;
  for(int i=0;i<n;i++)
    {
      cin >> a[i];
      b[i+1]=(b[i]+a[i])%m;
      //um[a[i]%m]++;
    }
  for(int i=0;i<=n;i++)
    {
      //cout << b[i] << endl;
      um[b[i]]++;
    }
  for(auto it=um.begin();it!=um.end();it++)
    {
      //cout << it->first << ' ' << it->second << endl;
      ans+=(it->second)*(it->second-1)/2;
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9868
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

int N, A, B, C, D;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N >> A >> B >> C >> D;

    REP(i, N) {
        int j = N - 1 - i;
        int low = A - D * i + C * j;
        int high = A - C * i + D * j;
        if (low <= B && B <= high) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;

    return 0;
}


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

#include <bits/stdc++.h>

using namespace std;

class DFriends {
public:
    void solve(std::istream& in, std::ostream& out) {
        int n, m;
        in >> n >> m;
        vector<vector<int>> g(n);
        for (int i = 0; i < m; ++i) {
            int a, b;
            in >> a >> b;
            --a; --b;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        vector<bool> visited(n);
        int size;
        function<void(int)> Dfs = [&](int v) {
            for (int to : g[v]) {
                if (visited[to]) continue;
                ++size;
                visited[to] = true;
                Dfs(to);
            }
        };
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            if (visited[i]) continue;
            size = 1;
            visited[i] = true;
            Dfs(i);
            ans = max(ans, size);
        }
        out << ans << '\n';
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    DFriends solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 26648
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  sum = N / 100000000 
    + N % 100000000 / 10000000
    + N % 10000000 / 1000000
    + N % 1000000 / 100000
    + N % 100000 / 10000
    + N % 10000 / 1000
    + N % 1000 / 100
    + N % 100 / 10
    + N % 10 ;
  
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    
  
  
}

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

int main(){
  int n;
  cin >> n;
  vi h(n);
  rep(i,n) cin >> h[i];
  vi dp(n);
  dp[0] = 0; 
  for(int i=1; i<n; i++){
    if(i==1) dp[i] = abs(h[i]-h[i-1]);
    else dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 4056
N = input()
A = ['7','5','3','']
num = ['']
for i in range(len(N)):
    num2 = []
    for n in num:
        for a in A:
            num2.append(n+a)
    num = num2

ans = []
for m in num:
    if len(set(m)) == 3 and int(m) <= int(N):
        ans.append(m)

print(len(set(ans)))

Measured memory_bytes: 24600
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<ll,ll>;

int main(){
    ll n; cin >> n;
    vector<P> cls(n);
    rep(i,n) {
        cls[i].second = i+1;
        cin >>cls[i].first;
    }
    sort(cls.begin(),cls.end());
    rep(i,n)
        cout << cls[i].second << " ";
    return 0;
}

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

#define ll long long
#define pll pair<ll, ll>
#define vll vector<ll>
#define rep(x, l, r) for (x = l; x < r; x++)

const ll mod=1000000007;

void solve()
{
	ll i, j, k, l, m, n, x, y, u, v, r, p,a,b,aa,bb;
	cin>>n;
	vector<ll> A(n),arr(n+1,0),brr(n+1,0);
	ll X=0;
    for(i=0;i<n;i++){
        cin>>A[i];
        X^=A[i];
    }
    for(i=0;i<n;i++){
        cout<<(X^A[i])<<" ";
    }

//    for(i=0;i<n;i++){
//        arr[i+1]=arr[i]^A[i];
//        brr[n-i-1]=brr[n-i]^A[n-i-1];
//    }
//    ll X=arr[n];
//    for(i=0;i<n;i++){
//        k=arr[i]
//    }
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
//    cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 7832
using System;
class Program{
    static void Main(){
        while(true)
        {
            string[] s = Console.ReadLine().Split(' ');
            int x,y;
            x = int.Parse(s[0]);
            y = int.Parse(s[1]);
            if(x==0 && y==0)break;
            if(x > y)
            {
                int tmp = x;
                x = y;
                y = tmp;
            }
            Console.WriteLine(x+" "+y);
        }
    }
}



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int k,s;
    cin >> k >> s;
    int ans=0;
    rep(x,0,k+1){
        rep(y,0,k+1){
            if(0<=s-x-y and s-x-y<=k) ++ans;
        }
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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


int main() {
    int n;cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    
    int ans=0;
    for(int i=0;i<n-2;i++){
        if(v[i]<=v[i+1] and v[i+1]<v[i+2]){
            ans++;
        }else if(v[i]>v[i+1] and v[i+1]>=v[i+2]){
            ans++;
        }//cout<<ans<<endl;
    }
    cout<<ans<<endl;
}

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

using namespace std;

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

int main(){
  int N, Q, ac = 0;
  string S;
  cin >> N >> Q >> S;
  vector<int> vec(N);
  rep(i,N-1) {
    if(S[i] == 'A' && S[i+1] == 'C') ++ac;
    vec[i+1] = ac;
  }
  rep(i,Q){
    int l, r;
    cin >> l >> r;
    cout << vec[r-1] - vec[l-1] << endl;
  }
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdio>

using namespace std;

int main(void)
{
	vector<int>num(3);
	int i;
	for (i = 0; i < 3; i++)
	{
		cin >> num[i];
	}
	sort(num.begin(), num.end());
	for (i = 0; i < 3; i++)
	{
		if (i != 2)
		{
			cout << num[i] << ' ';
		}
		else
		{
			cout << num[i] << endl;
		}
	}
	
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;

int main(void){
	set<int> set;
	int an, ans=0, s;
	cin>>s;
	an = s;
	set.insert(s);

	bool exist = false;
	int i=2;
	while(!exist) {
		if(an % 2 == 0) an = an / 2;
		else an = 3 * an + 1;

		if(set.find(an) != set.end()) {
			exist = true;
			ans = i;
		}
		set.insert(an);
		i++;
	}

	cout<< ans <<endl;

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> bot(N+1);
    
    for(int i=1; i<=N; i++){
        cin >> bot[i];
    }
    
    set<int> flgset;
    int x=1;
    bool ans;
    int ans_count=0;
    while(true){
        x = bot[x];
        ans_count++;
        
        if(x==2){
            ans = true;
            break;
        }else if(flgset.count(x)){
            ans = false;
            break;
        }
        flgset.insert(x);
    }
    
    if(ans){
        cout << ans_count << endl;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 5376
from collections import Counter

N,K,Q = map(int,input().split())
A = [0] * Q
for i in range(Q):
    A[i] = int(input())
A = Counter(A)

for i in range(1,N+1):
    if K-Q+A[i] > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 11892
import Control.Applicative

import Control.Monad
    (when)
    
operate :: String -> (Int -> Int -> Int)

operate op
    = case op of
        "+" -> (+)
        "-" -> (-)
        "*" -> (*)
        "/" -> div
        
solve :: Int -> String -> Int -> Int

solve a op b
    = operate op a b

input :: IO (Int, String, Int)

input
    = do
        [a, op, b] <- words <$> getLine
        return (read a, op, read b)

output :: Int -> String

output
    = show
    
loop :: IO ()

loop
    = do
        (a, op, b) <- input
        when (op /= "?") $ do
            putStrLn $ output $ solve a op b
            loop
            
main :: IO ()
    
main
    = loop

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

using namespace std;

typedef long long ll;

#define FOR(a, b, i) for(int i=a; i<b; i++)
#define RFOR(a, b, i) for(int i=a; i>=b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1e9+7
#define newline cout<<"\n"

const int nax = 3005;

ll dp[nax][nax];
void initialize()
{
    FOR(0, nax, i) FOR(0, nax, j) dp[i][j]=0;
}

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

    int n; cin>>n;
    vector<ll> v(n);
    initialize();

    FOR(0, n, i) cin>>v[i];

    // dp[i][j] means value of X-Y when first i elements from the left and j elements from right are removed
    // dp[0][n-1] is the answer

    RFOR(n-1, 0, L)
    {
        FOR(L, n, R)
        {
            if(L==R)
            {
                dp[L][R] = v[L];
            }
            else
            {
                dp[L][R] = max(v[L]-dp[L+1][R], v[R]-dp[L][R-1]);
            }
            
        }
    }
    cout<<dp[0][n-1]<<"\n";

    return 0;
}

Measured memory_bytes: 70784
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
using namespace std;
#define N (1000000000+7)
typedef pair<int,int> P;
typedef long long ll;
int d[100010][3];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int n,m;
char board[1010][1010];

struct edge{
    int to,cost;
};

int a[105],b[105];


vector<edge>graph[100010];

int main(void){
    int n,m;
    while(true){
        cin>>n>>m;
        if((n==0)&&(m==0))break;
        int suma=0,sumb=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            suma+=a[i];
        }
        for(int i=0;i<m;i++){
            cin>>b[i];
            sumb+=b[i];
        }
        int ans=1000000,x=-1,y=-1;
        bool flag=false;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(suma-a[i]+b[j]==sumb-b[j]+a[i]){
                    if(a[i]+b[j]<ans){
                        ans=a[i]+b[j];
                        x=a[i];
                        y=b[j];
                        flag=true;
                    }
                }
            }
        }
        if(flag){
            cout<<x<<" "<<y<<endl;
        }
        else{
            cout<<-1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5440
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	cnt := 0
	for i := 1; i < 1000; i++ {
		cand := i + i/10%10*1000 + i%10*10000
		if b >= cand && cand >= a {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
//Zory-2019
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void writeln(int num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<int,int>
	#define PB push_back
	inline void chmax(ll &x,const ll y) {x=x>y?x:y;}
	inline void chmin(ll &x,const ll y) {x=x<y?x:y;}

	const int MAX_N=5e5+10;
	int a[MAX_N],ct[MAX_N];
	vector<int> ans;
	void main()
	{
		int n;scanf("%d",&n);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]),ct[a[i]]++;
		for(int i=1;i<=n;i++) ct[i]+=ct[i-1];
		for(int i=n;i>=1;i--)
		{
			for(int j=i;j>=1;j--) if(ct[j]<j) {puts("-1");return;}

			bool ok=0;
			for(int j=i;j>=1;j--) if(j==a[j])
			{
				ans.PB(j);for(int t=j;t<=i;t++) ct[t]--;
				for(int t=j;t<=i-1;t++) swap(a[t],a[t+1]);
				ok=1;break;
			}
			if(ok==0) {puts("-1");return;}
		}
		reverse(ans.begin(),ans.end());
		for(int t=0;t<(int)ans.size();t++) printf("%d\n",ans[t]);
	}
};
int main()
{
	srand(time(0));
	mine::main();
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
struct node{
	string name;
	int t,id;
	bool operator<(const node &a) const{
		if (name != a.name){
			return name < a.name;
		}
		return t > a.t;
	}
}per[110];
int main(){
	int n;
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>per[i].name>>per[i].t;
		per[i].id = i;
	}	
	sort(per+1,per+1+n);
	for (int i=1;i<=n;i++) cout<<per[i].id<<endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    while(cin>>h>>w, h!=0){
        rep(i,h){
            rep(j,w){
                if ((i+j)&1) cout<<".";
                else cout<<"#";
            }
            cout<<"\n";
        }
        cout<<"\n";
    }
    return 0;
}



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

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == ',') {
            cout << " ";
        }
        else cout << s[i];
    }

    return 0;
}

Measured memory_bytes: 3656
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;

int main() {
int H,W,D;
cin>>H>>W>>D;
map<int,int> mapx,mapy;
rep3(i,H){
  rep3(j,W){
    int A;
    cin>>A;
    mapx[A]=i;
    mapy[A]=j;
  }
}
int cons[H*W+1];
rep3(i,D){
  for(int j=i;j<=H*W;j+=D){
    if(i==j) cons[i]=0;
    else cons[j]=cons[j-D]+abs(mapx[j]-mapx[j-D])+abs(mapy[j]-mapy[j-D]);
  }
}

int Q;
cin>>Q;
ll ans[Q];
rep(i,Q){
  
  int L,R;
  cin>>L>>R;
  ans[i]=cons[R]-cons[L];
}
rep(i,Q){
cout<<ans[i]<<endl;
}
return 0;
}

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


using namespace std;
using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

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

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

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

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


// edit

ll N;

ll check(ll x) {
    vector<ll> r = {0, -1};
    vector<ll> m = {x, 2 * N / x};

    auto res = crt(r, m);
    if (res == make_pair(0ll, 0ll)) {
        return -1;
    }
    ll ret = res.first;
    if (ret <= 0) ret += res.second;
    return ret;
}

void solve() {
    cin >> N;
    ll ans = LINF;
    for (ll x = 1; x * x <= 2 * N; ++x) {
        if (2 * N % x) continue;

        ll tapi = check(x);
        if (tapi != -1) chmin(ans, tapi);
        ll tapu = check(2 * N / x);
        if (tapu != -1) chmin(ans, tapu);
    }
    cout << ans << endl;

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 3160
import java.util.Scanner;

//A Thief
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int Case = 1;
		while(true){
			int W = sc.nextInt();
			if(W==0)break;
			int n = sc.nextInt();
			int[] w = new int[n+1];
			int[] v = new int[n+1];
			for(int i=1;i<=n;i++){
				String[] s = sc.next().split(",");
				v[i] = Integer.parseInt(s[0]);
				w[i] = Integer.parseInt(s[1]);
			}
			int[][] dp = new int[n+1][W+1];
			int maxV = Integer.MIN_VALUE;
			int minW = Integer.MAX_VALUE;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=W;j++){
					if(j-w[i]>=0){
						dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
						if(maxV < dp[i][j]){
							maxV = dp[i][j];
							minW = j;
						}
						else if(maxV == dp[i][j]){
							minW = Math.min(minW, j);
						}
					}
					else dp[i][j] = dp[i-1][j];
				}
			}
			System.out.println("Case " + Case++ + ":\n" + maxV + "\n" + minW);
			
		}
	}
}

Measured memory_bytes: 40524
n = int(input())
title = []
p_time = []
for i in range(n):
  buf = input().split()
  title.append(buf[0])
  p_time.append(int(buf[1]))
s_title = input()
for i in range(n):
  p_time.pop(0)
  if title[i] == s_title:
    break
print(sum(p_time))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
inline void read(int &a){
	a=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch<='9'&&ch>='0') a=a*10+ch-'0',ch=getchar();
}
const int MOD=1e9+7;
int dp[4010][4010],fac[8010],inv_fac[8010];
int inv[8010],x[200100],y[200100];
int n,tot;
inline int qpow(int a,int b){
	long long bas=a,ans=1;
	while(b){
		if(b&1) ans=ans*bas%MOD;
		bas=bas*bas%MOD;
		b>>=1;
	}
	return ans;
}
inline int C(int a,int b){
	return 1ll*fac[b]*inv_fac[a]%MOD*inv_fac[b-a]%MOD;
}
int main(){
	scanf("%d",&n);
	fac[0]=1;
	for(int i=1;i<=8000;i++) fac[i]=1ll*fac[i-1]*i%MOD;
	for(int i=1;i<=8000;i++) inv_fac[i]=qpow(fac[i],MOD-2);
	for(int i=0,a,b;i<n;i++){
		read(a);read(b);
		x[i]=a,y[i]=b;
		tot=(tot-C(b+b,b+b+a+a)+MOD)%MOD;
		dp[2001-a][2001-b]++;
	}
	for(int i=1;i<=4001;i++){
		for(int j=1;j<=4001;j++){
			dp[i][j]+=dp[i-1][j]+dp[i][j-1];
			if(dp[i][j]>=MOD) dp[i][j]-=MOD;
		}
	}
	for(int i=0;i<n;i++) tot=(tot+dp[2001+x[i]][2001+y[i]])%MOD;
	printf("%d\n",1ll*tot*qpow(2,MOD-2)%MOD);
	return 0;
}

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

int main(){
	int n;
	string s,t,l="";
	cin>>n>>s>>t;
	for(int i=0;i<n;i++){
		l+=s[i];
		l+=t[i];
	}
	cout<<l<<endl;
	return 0;
}

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

using namespace std;

const int Nmax = 1e5 + 5;

int N, M, Q, i, p, j;
vector<int> v[Nmax];
int a[Nmax], last[Nmax];
bool used[Nmax];

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> M >> Q;
    for(i=1; i<=Q; ++i)
    {
        cin >> a[i];
        v[a[i]].push_back(i);
    }

    vector<int> ans;

    for(i=Q; i; --i)
        if(!used[a[i]]) ans.push_back(a[i]), used[a[i]] = 1;

    for(i=1; i<=M; ++i)
        if(!used[i]) ans.push_back(i);

    for(i=1; i<=N; ++i) last[i] = Q;

    memset(used, 0, sizeof(used));

    bool bad = 0;
    for(auto it : ans)
    {
        p = v[it].size() - 1;
        for(j=1; j<=N && !bad; ++j)
        {
            while(p>=0 && v[it][p] > last[j]) --p;
            if(p>=0) last[j] = v[it][p], p--;
                else bad = 1;
        }

        if(bad) break;
        used[it] = 1;
    }

    vector<int> ans2;
    for(i=1; i<=M; ++i)
        if(!used[i]) ans2.push_back(i);

    for(i=1; i<=ans2.size(); ++i)
        if(ans[ans.size()-i] != ans2[ans2.size()-i])
        {
            cout << "No\n";
            return 0;
        }

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


Measured memory_bytes: 7800
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define in insert
#define all(x) x.begin(),x.end()
#define zapp ios::sync_with_stdio(false);cin.tie(0)
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll inv(ll x){return power(x, MOD - 2);}
const long long int MAXN = 1e18;
//const bool is_in = container.find(element) != container.end();
int main()
{
	zapp;
	ll n;
	cin>>n;
	ll a[n],i;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll mul = 1;
	bool poss = true;
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
		if(a[i]!=0 && MAXN/a[i] >= mul)
		{
			mul = mul*a[i];
		}
		else if(a[i] == 0)
		{
			mul = 0;
			break;
		}
		else
		{
			poss = false;
			break;
		}
	}
	if(!poss)
		cout<<"-1";
	else
		cout<<mul;
}




Measured memory_bytes: 4428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <typename T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const vector<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
void ce(void){cerr << '\n';}
template <typename T>
void ce(const T n){cerr << n << '\n';}
template <typename T>
void cesp(const T n){cerr << n << ' ';}
template <typename T>
void ce(initializer_list<T> v){for(T i : v) cesp(i); ce();}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18L+1;
constexpr ll MOD = 1e9L+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
	ll n, m, c;
	cin >> n >> m >> c;
	Vec b(m);
	rep(i, m) cin >> b[i];

	ll ans = 0;
	rep(i, n){
		ll sum = c;
		rep(j, m){
			ll a;
			cin >> a;
			sum += b[j] * a;
		}
		if(sum > 0) ans++;
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 3632