akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	
*/

int n;
int solve()
{
	unordered_set<int> numbers;
	while(n--)
	{
		int no;
		cin >> no;

		if(numbers.find(no) == numbers.end())
			numbers.insert(no);
		else
			numbers.erase(no);
	}
	return sz(numbers);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
	//freopen("tmp.out", "w", stderr);
#endif
	cin >> n;
	
	cout << solve() << endl;

	return 0;
}

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

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var list = new List<int>();
        for (int i = 0; i < n; i++) list.Add(int.Parse(Console.ReadLine()));
        int now = list.First();
        for (int i = 0; i < n; i++)
        {
            if (now == 2)
            {
                Console.WriteLine(i + 1);
                break;
            }
            if (i == n - 1) Console.WriteLine(-1);
            now = list[now - 1];
        }
    }
}

Measured memory_bytes: 14048
#include<cstdio>

int main(){
	int n;
	char s[100001];
	scanf("%d",&n);
	scanf("%s",s);
	for(int usisan=0;usisan<8;usisan++){
		bool ary[100000];
		bool flag = true;
		for(int i=0;i<n;i++){
			if(i<3){
				ary[i] = (usisan >> i)  & 1;
			}else{
				if(s[i-1]==s[i-2]) ary[i] = ary[i-3];
				else ary[i] = !ary[i-3];
			}
		}
		if((s[n-1]=='o'&&(ary[0]+ary[n-1]+ary[n-2])%2==0)) continue;
		if((s[n-1]=='x'&&(ary[0]+ary[n-1]+ary[n-2])%2==1)) continue;
		if((s[0]=='o'&&(ary[0]+ary[n-1]+ary[1])%2==0)) continue;
		if((s[0]=='x'&&(ary[0]+ary[n-1]+ary[1])%2==1)) continue;
		if((s[1]=='o'&&(ary[0]+ary[2]+ary[1])%2==0)) continue;
		if((s[1]=='x'&&(ary[0]+ary[2]+ary[1])%2==1)) continue;
		for(int i=0;i<n;i++){
			if(ary[i]==1) printf("S");
			else printf("W");
		}
		printf("\n");
		return 0;
	}
	printf("-1\n");
	return 0;
}


Measured memory_bytes: 512
#include<complex>
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
typedef long double ld;
typedef complex<ld> P;
#define X real
#define Y imag
vector<P> data;
namespace std{
bool operator<(P a,P b){
return a.X()!=b.X()? a.X()<b.X():a.Y()<b.Y();
}
}
double cross(P a,P b){
return imag(conj(a)*b);
}
double dot(P a,P b){
return real(conj(a)*b);
}
int ccw(P a,P b,P c){
b-=a;c-=a;
if(cross(b,c)>0)return 1; //counter clockwise
if(cross(b,c)<0)return -1; //clockwise
if(dot(b,c)<0)return 2; //c--a--b on line
if(norm(b)<norm(c))return -2; //a--b--c on line
return 0;
}
vector<P> convex_hull(vector<P> ps){
sort(ps.begin(),ps.end());
vector<P> ch(ps.size()*2);
int k=0;
for(int i=0;i<ps.size();ch[k++]=ps[i++]){
while(k>=2 && ccw(ch[k-2],ch[k-1],ps[i])<=0)--k;
}
for(int i=ps.size()-2,t=k+1;i>=0;ch[k++]=ps[i--]){
while(k>=t&&ccw(ch[k-2],ch[k-1],ps[i])<=0)--k;
}
ch.resize(k-1);
return ch;
}
int solve(){
vector<P> res = convex_hull(data);
return res.size();
}
int main(){
int n;
while(cin>>n){
if(n==0)break;
data.clear();
for(int i=0;i<n;i++){
ld a,b;
char c;
cin>>a>>c>>b;
data.push_back(P(a,b));
}
cout<<n-solve()<<endl;
}
}

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

#define H 6
#define W 6

int h, w, k;
char c[H][W];

int main(void)
{
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> c[i][j];
        }
    }
    
    int cntK = 0;
    for (int i = 0; i < pow(2,h+w); i++){
        int cntBrack = 0;
        int isRed[H+W];
        for (int j = 0; j < h+w; j++){
            isRed[j] = (i>>j)&1;
        }
        
        for (int j = 0; j < h; j++){
            for (int a = 0; a < w; a++){
                if(isRed[j] || isRed[h+a]){
                    continue;
                }
                if (c[j][a]=='#'){
                    cntBrack++;
                }
            }
        }
        if (cntBrack==k){
            cntK++;
        }
    }
    
    cout << cntK << endl;
    return 0;
}


Measured memory_bytes: 4008
import java.util.*;
import java.util.function.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int[][] A = new int[H][W];
    int[][] B = new int[H][W];
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) A[i][j] = sc.nextInt();
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) B[i][j] = sc.nextInt();
    sc.close();
    
    int m = (H + W) * 80;
    boolean[][][] dp = new boolean[H + 1][W + 1][m * 2 + 1];
    dp[0][1][m] = true;
//    for (int i = 0; i < H + 1; i++) dp[i][0][m] = true;
//    for (int j = 0; j < W + 1; j++) dp[0][j][m] = true;
    for (int i = 1; i < H + 1; i++) {
      for (int j = 1; j < W + 1; j++) {
        int c = Math.abs(A[i - 1][j - 1] - B[i - 1][j - 1]);
        boolean[] d = dp[i][j];
//        if (i == 0 && j == 0) {
//          d[m - c] = true;
//          d[m + c] = true;
//        } else {
          for (int k = 0; k < d.length; k++) {
            if (dp[i - 1][j][k]) {
              d[k - c] = true;
              d[k + c] = true;
            }
            if (dp[i][j - 1][k]) {
              d[k - c] = true;
              d[k + c] = true;
            }
          }
//        }
      }
    }
//    boolean[] d = dp[H - 1][W - 1];
    boolean[] d = dp[H][W];
    int ans = d.length;
    for (int k = 0; k < d.length; k++)
      if (d[k])
        ans = Math.min(ans, Math.abs(m - k));
    System.out.println(ans);
  }
}


Measured memory_bytes: 245376
N = int(input())
F = []
for i in range(N):
    F.append(list(map(int, input().split())))
P = []
for i in range(N):
    P.append(list(map(int, input().split())))

maxprofit = -(10 ** 10)
for i in range(1, 2 ** 10):
    conflicts = [0] * N
    for t in range(10):
        opening = bool(i & (1 << t))
        for j in range(N):
            if F[j][t] and opening:
                conflicts[j] += 1
    profit = 0
    for j in range(N):
        profit += P[j][conflicts[j]]
    if maxprofit < profit:
        maxprofit = profit
        maxstate = i

print(maxprofit)


Measured memory_bytes: 42480
from sys import stdin
from sys import setrecursionlimit
from math import ceil
from collections import Counter, deque, defaultdict
setrecursionlimit(1000000)

# INF = float('inf')
INF = int(1e10)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    n = int(input())
    sum = 0
    for i in range(1, n + 1):
        if i % 3 != 0 and i % 5 != 0:
            sum += i
    print(sum)

if __name__ == '__main__':
    main()

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

int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    db k,x;
    cin>>k>>x;
    db d=500;
    if(k*d>=x) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()



int main() {
	ll arr[101] = { 0 };
	arr[2] = 1;
	fori(i, 3, 101) if (i % 2 == 0) arr[i] = 1 + arr[i / 2];

	ll N;
	cin >> N;
	ll ans = 1;
	fori(i, 1, N + 1) if (arr[ans] < arr[i]) ans = i;
	
	cout << ans << endl;
}


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

using namespace std;


int main(int argc, char** argv) {
    long long n, ans;
    std::vector<long long> w(5);
    cin >> n >> w[0] >> w[1] >> w[2] >> w[3] >> w[4];

    long long smallest = 1e15;
    smallest += 1;

    for (int i = 0; i < 5; ++i) {
        if (w[i] < smallest) {
            smallest = w[i];
        }
    }
    ans = 4 + (n / smallest) + ((n % smallest) ? 1:0);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	static int digit(String num) {
		int sum = 0;
		for(int i = 0; i < num.length(); i++) {
			char ch = num.charAt(i);
			int digit = ch - '0';
			sum += digit;
		}
		return sum;
	}
	
	public static void main(String[] a) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()) {
			String num = sc.nextLine();
			if(num.equals("0")) {
				break;
			}
			System.out.println(digit(num));
		}
		sc.close();
	}

}



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

int main(){
  set<int> S;
  int q, query, x;
  cin >> q;
  for(int i = 0; i < q; i++){
    cin >> query >> x;
    if(query == 0){
      S.insert(x);
      cout << S.size() << endl;
    }else if(query == 1){
      auto it = S.find(x);
      if(it != S.end()){
        cout << 1 << endl;
      }else{
        cout << 0 << endl;
      }
    }else{
      S.erase(x);
    }
  }
  return 0;
}


Measured memory_bytes: 12460
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    int n;
    cin >> n;
    int a,t;
    t=0;
    for(int i=0;i<n;i++){
        cin >> a;
        if(a%2==1)t=1;
    }
    if(t==0)cout << "second";
    else cout << "first";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=int(1e5+5);
typedef long long LL;
#define INF LL(1e15)
LL s1,s2,as,n;
LL sz[MAXN],fh[MAXN];
char c[5];
int main()
{
	scanf("%lld",&n);
	scanf("%lld",&as);
	getchar();
	for(LL i=1;i<=n-1;i++) {
		scanf("%s",c);
		scanf("%d",&sz[i]);
		fh[i]=c[0];
	}
	s1=s2=-INF;
	for(LL i=1;i<=n-1;i++) {
		if(fh[i]=='-') {
			as-=sz[i];
			s1-=sz[i];
			s2+=sz[i];
			s1=max(s1,s2);
			s2=max(as,s2);
		}
		else {
			as+=sz[i];
			s1+=sz[i];
			s2-=sz[i];
		}
		s2=max(s1,s2);
		as=max(s2,as);
	}
	printf("%lld",as);
}
/*5
7 - 8 + 9 - 10 - 2*/

Measured memory_bytes: 1664
#include<iostream>
#include <vector>
using namespace std;
#define MOD 1000000007

int main()
{
	int h,w;
	cin >> h>>w;
	vector<int> dp(w+1,0);
	dp[0]=1;
	for(int i=0;i<h;i++)
	{
		vector<char> temp(w+1);
		for (int j = 1; j <= w; ++j)
		{
			cin >> temp[j];
			if(temp[j]=='.')
			{
				dp[j] = dp[j]%MOD+dp[j-1]%MOD;
			}
			else
				dp[j] = 0;
		}
		dp[0]=0;
	}
	cout << dp[w]%MOD;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long int
int main(void){
    // Your code here!
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 int i,k,n,d,c,x;
 c=0;
 map<int,int> m;
 cin >> n >> k;
 while(k--)
 {
  cin >> d;
  while(d--)
  {
   cin >> x;
   m[x]++;
  }
 }
 for(i=1;i<=n;i++)
 {
  if(m.find(i)==m.end())
  c++;
 }
 cout << c;
 return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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 (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

vector<ll> B,C,D,E;

int main(){
    ll N,A;
    cin >> N;
    rep(i,N){
        cin >> A;
        if(A<0){
            C.pb(A);
        }
        else{
            B.pb(A);
        }
    }
    if(B.size()>0){
        sort(ALL(B));
    }
    if(C.size()>0){
        sort(ALL(C));
    }
    ll T;
    if(B.size()==0){
        T=C[C.size()-1];
        rep(i,C.size()-1){
            D.pb(T);
            E.pb(C[i]);
            T=T-C[i];
        }
    }
    else if(C.size()==0){
        T=B[0];
        rep(i,B.size()-2){
            D.pb(T);
            E.pb(B[i+1]);
            T=T-B[i+1];
        }
        D.pb(B[B.size()-1]);
        E.pb(T);
        T=B[B.size()-1]-T;
    }
    else{
        T=C[0];
        rep(i,B.size()-1){
            D.pb(T);
            E.pb(B[i]);
            T=T-B[i];
        }
        D.pb(B[B.size()-1]);
        E.pb(T);
        T=B[B.size()-1]-T;
        rep(i,C.size()-1){
            D.pb(T);
            E.pb(C[i+1]);
            T=T-C[i+1];
        }
    }


    cout << T << endl;
    rep(i,D.size()){
        cout << D[i] << " " << E[i] << endl;
    }
}

Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll A;
  string S;
  cin>>A>>S;
  ll b1=(S[0]-'0')*100;
  ll b2=(S[2]-'0')*10;
  ll b3=(S[3]-'0');
  ll B=b1+b2+b3;
  ll ans=A*B/100;
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <deque>
#include <string>

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie( 0);

    const int INF = 1E9;
    int n, m;
    string s;
    cin >> n >> m >> s;

    vector<int> d(n + 1), p(n + 1);
    deque<int> nx = { n };

    for (int i = n - 1; i >= 0; i--)
    {
        if (s[i] == '1') d[i] = INF;
        else
        {
            while (!nx.empty() && nx.back() > i + m)
                nx.pop_back();
            if (nx.empty())
                d[i] = INF;
            else
            {
                p[i] = nx.back();
                d[i] = d[p[i]] + 1;
                while (!nx.empty() && d[nx.front()] >= d[i])
                    nx.pop_front();
                nx.push_front(i);
            }
        }
    }

    if (d[0] >= INF)
        cout << "-1\n";
    else
    {
        int x = 0;
        while (x < n)
        {
            cout << p[x] - x << "\n";
            x = p[x];
        }
    }

    return 0;
}


Measured memory_bytes: 1488
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<String> one = nextStrArray();
		double T = Double.parseDouble(one.get(0));
		double X = Double.parseDouble(one.get(1));
		myout(T / X);
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 33452
import java.util.Scanner


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val row = sc.next()
    (n, row)
  }


  case class SeqForCumulative[T](list: IndexedSeq[T])(implicit num: Numeric[T]) {
    val cumulative: IndexedSeq[T] = list.scanLeft(num.zero)(num.plus)

    def partial(start: Int, end: Int): T = num.minus(cumulative(end), cumulative(start))
  }

  def solve(n: Int, row: String): Int = {
    val indicatorE = row.map(elem => if (elem == 'E') 1 else 0)
    val indicatorW = row.map(elem => if (elem == 'W') 1 else 0)

    val cumulativeE = SeqForCumulative(indicatorE)
    val cumulativeW = SeqForCumulative(indicatorW)

    // リーダーがlearder番目のとき、リーダーの方向を向いていない人数
    val numNotFaceLeader = (leader: Int) => cumulativeW.partial(0, leader) + cumulativeE.partial(leader + 1, n)

    (0 until n).map(numNotFaceLeader).min
  }


  def main(args: Array[String]): Unit = {
    val (n, row) = read()
    println(solve(n, row))
  }
}

Measured memory_bytes: 68052
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

struct Grid
{
    int x=0;
    int y=0;
};

int Magic(Grid from,Grid to)
{
    return abs(to.x-from.x)+abs(to.y-from.y);
}

int main()
{
    int H,W,D;
    cin>>H>>W>>D;
    vector<Grid> G(H*W);
    for (int i=0; i<H*W; ++i)
    {
        int a;
        cin>>a;
        G[a-1].x=i%W;
        G[a-1].y=i/W;
    }
    
    vector<int> M(H*W,0);
    for (int i=0; i<H*W; ++i)
    {
        if(i-D>=0)
        {
            M[i] = M[i-D] +Magic(G[i-D],G[i] );
        }
    }
    
    int Q;
    cin>>Q;
    
    vector<int> ans(Q,0);
    for (int i=0; i<Q; ++i) {
        int L,R;
        cin>>L>>R;
        ans[i]=M[R-1]-M[L-1];
    }
    
    for (int i=0; i<Q; ++i)
    {
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define drep(i,a,b) for(int i=(a); i>=(b);i--) 

const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;

char s[maxn];
vector<int>l,r;
int v[maxn],ans[maxn];

int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   cin >> s;
   int n = strlen(s);
   rep(i,0,n){
      if(s[i] == 'L') l.push_back(i);
      else r.push_back(i);
   }
   for(int i = 0; i < l.size(); i++){
        int pos = lower_bound(r.begin(),r.end(),l[i])-r.begin() - 1;
        v[l[i]] = r[max(0,pos)];
   }
   for(int i = 0; i < r.size(); i++){
        int pos = lower_bound(l.begin(),l.end(),r[i])-l.begin();
        v[r[i]] = l[max(0,pos)];
   }
   //for(int i = 0 ; i < n; i++) cout << v[i] << " ";
   rep(i,0,n){
      if(s[i] == 'R') ans[(v[i] - 1) + (v[i] - i + 1) % 2]++;
      else ans[v[i] + 1 - (i - v[i] - 1) % 2]++;
   }
   rep(i,0,n) cout << ans[i] << " ";
   return 0;
}

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

int main(){
  int n,m;
  cin>>n>>m;
  string s1=to_string(n);
  string s2=to_string(m);
  for(int i=1;i<m;i++)s1.push_back((char)(n+'0'));
  for(int i=1;i<n;i++)s2.push_back((char)(m+'0'));
  if(s1<s2) cout<<s1<<"\n";
  else cout<<s2<<"\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);
      	String s = sc.nextLine();
      	int count = 0;
      	int i = 0, j = s.length() - 1;
      	while( i < j){
          if(s.charAt(i) != s.charAt(j)){
            count++;
          }
          i++;
          j--;
        }
      System.out.println(count);
    }
}


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

int main(){
  int A,B,C,X,count;
  cin >> A>>B>>C>>X;
  
  int a,b,c,xa,xb;
  //何枚500円が使えるか計算
  a = ((X-X%500)/500)+1;
  //所持枚数を超えていたら所持枚数に変更
  if(a>A){
    a = A+1;
  }
  for(int i=0;i<a;i++){
    xa = X - 500*i;
    b = ((xa-xa%100)/100)+1;
    if(b>B){
      b = B+1;
    }
    for(int j=0;j<b;j++){
      xb = xa - 100*j;
      c = xb/50;
      if(c<=C){
        count++;
      }
    }
  }
  cout <<count;
}

Measured memory_bytes: 256
import sys
from collections import deque
n, q = map(int, input().split())

deq = deque()
arrays = {str(i): deque() for i in range(n)}

lines = sys.stdin.readlines()
for i in range(q):
    query, *arg = lines[i].split()
    if query == '0':    # push t x
        arrays[arg[0]].append(arg[1])
    elif query == '1':  # top
        if len(arrays[arg[0]]):
            print(arrays[arg[0]][-1])
    elif query == '2':  # pop
        if len(arrays[arg[0]]):
            arrays[arg[0]].pop()
    else:
        raise AssertionError


Measured memory_bytes: 36468
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int a[200005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int c = 1;
	for (i = 0; i < n; i++)
	{
		if (a[i] == c)
			c++;
	}
	if (c == 1)
		printf("-1\n");
	else
		printf("%d\n", n - c + 1);
	return 0;
}

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


int main(){


    string a, b, c;

 
    cin >> a >> b >> c;


    if( a.at( a.size() - 1 ) == b.at(0) && b.at( b.size() - 1 ) == c.at(0) ) cout << "YES" << endl;

    else cout << "NO" << endl;


    return 0;


    }

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

struct Node{
	long id, left, right, parent;
};

void preorderWalk(struct Node T[], long id){
	cout << " " << id;
	if (T[id].left != -1) preorderWalk(T, T[id].left);
	if (T[id].right != -1) preorderWalk(T, T[id].right);
}

void inorderWalk(struct Node T[], long id){
	if (T[id].left != -1) inorderWalk(T, T[id].left);
	cout << " " << id;
	if (T[id].right != -1) inorderWalk(T, T[id].right);
}

void postorderWalk(struct Node T[], long id){
	if (T[id].left != -1) postorderWalk(T, T[id].left);
	if (T[id].right != -1) postorderWalk(T, T[id].right);
	cout << " " << id;
}

int main(){
	long n;
	cin >> n;
	struct Node T[25];
	for (long i = 0; i < n; i++){
		T[i].id = T[i].left = T[i].right = T[i].parent = -1;
	}
	for (long i = 0; i < n; i++){
		long id, left, right;
		cin >> id >> left >> right;
		T[id].id = T[left].parent = T[right].parent = id;
		T[id].left = left;
		T[id].right = right;
	}
	long rootid = -1;
	for (long i = 0; i < n; i++){
		if (T[i].parent == -1){
			rootid = i;
			break;
		}
	}
	cout << "Preorder" << endl;
	preorderWalk(T, rootid);
	cout << endl;
	cout << "Inorder" << endl;
	inorderWalk(T, rootid);
	cout << endl;
	cout << "Postorder" << endl;
	postorderWalk(T, rootid);
	cout << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<cmath>
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<stack>
#include<vector>
#include<string.h>
#include<string>
#include<iomanip>
#include <sstream>
#include<map>
#include<complex>
#include<set>
using namespace std;
#define rep(i,t,n)  for(ll i =(t);i<=(n);++i)
#define per(i,n,t)  for(int i =(n);i>=(t);--i)
#define mmm(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define Decimal fixed<<setprecision(20)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 2e3 + 5;
typedef double db;



const int N = 10;
bool ok(int x) { return x >= 1 && x <= 9; }
int main() {
	FAST_IO;
	ll n;
	cin >> n;
	ll ans = 1e18;
	for (ll i = 1; i*i <= n; i++) if(n%i==0){
		ans = min(i + n / i, ans);
	}
	cout << ans - 2 << endl;
}         
/*
2
A 0 0 2
B 1 0 2


*/


Measured memory_bytes: 256
use proconio::*;

fn run() {
    input! {
        x: usize,
        y: usize,
    }
    let mut ans = "No";
    for i in 0..=100 {
        for j in 0..=100 {
            if i + j == x && 2 * i + 4 * j == y {
                ans = "Yes";
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}

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

int main() {
  string s;
  cin >> s;
  bool flag = true;
  rep(i,s.size()) {
    if (i%2==0 && s[i]=='L' || i%2!=0 && s[i]=='R') {
      flag = false;
      break;
    }
  }
  if (flag) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	cout << (A * B) << endl;

	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

    ll a,b,n;
    cin>>a>>b>>n;
    
    ll x=min(b-1,n);
    ll ans = (a*x)/b - a*(x/b);
    
    ll limit = x + 100000;

    for(int i=ans;i<min(n,limit);i++){
        ans = max(ans,((a*x)/b - a*(x/b)));
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3636
class Combi():
    def __init__(self, N, mod):
        self.power = [1 for _ in range(N+1)]
        self.rev = [1 for _ in range(N+1)]
        self.mod = mod
        for i in range(2, N+1):
            self.power[i] = (self.power[i-1]*i) % self.mod
        self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
        for j in range(N, 0, -1):
            self.rev[j-1] = (self.rev[j]*j) % self.mod

    def com(self, K, R):
        if K < R:
            return 0
        else:
            return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod

    def pom(self, K, R):
        if K < R:
            return 0
        else:
            return (self.power[K])*(self.rev[K-R]) % self.mod


def main():
    mod = 10**9+7
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    c = Combi(N, mod)
    res = 0
    for i, v in enumerate(A):
        res += c.com(i, K-1)*v
        res -= c.com(N-1-i, K-1)*v
        res %= mod
    print(res)
    return


if __name__ == "__main__":
    main()

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

using namespace std;
using ll = long long;
vector<ll> ch[26];

int main () {
	ll n;
	cin >> n;
	int ar[n];
	int mi = 100000000;
	for (int i = 0; i < n; i++) {
		cin >> ar[i];
	}
	for (int i = 1; i <= 100; i++) {
		int di = 0;
		for (int j = 0; j < n; j++) {
			di += (ar[j] - i) * (ar[j] - i);
		}
		mi = min (di, mi);
	}
	cout << mi << "\n";
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define MOD 1000000007
#define y1 dskgj
#define y2 dskfj
#define SQ 320
#define N 8388607
typedef int ll;
using namespace std;
ll n,i,j,k,x,y,z,m,q,h,l,timer;
ll sugar[3005], water[3005];
int main() {
    //freopen("input.txt","r",stdin);
    ll A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;
    for (i = 0; i <= 30; i++)
        for (j = 0; j <= 30; j++)
            if (i*A*100 + j*B*100 <= 3000)
                water[i*A*100 + j*B*100] = 1;
    for (i = 0; i <= 3000; i++)
        for (j = 0; j <= 3000; j++)
            if (i*C + j*D <= 3000)
                sugar[i*C + j*D] = 1;
    double min_val = -1;
    for (i = 1; i <= F; i++)
        for (j = 0; j <= F; j++)
            if (i+j <= F && sugar[j] && water[i])
            {
                if (j*100 <= E*i && 1.*j/(i+j) >= min_val)
                {
                    min_val = 1.*j/(i+j);
                    x = j;
                    y = i+j;
                }
            }
    cout << y << " " << x << endl;
    return 0;
}


Measured memory_bytes: 256
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
ll f(ll a,ll b)
{
    ll cnt=0,cnt2=0;
    while(a){
        a/=10;
        cnt++;
    }
    while(b){
        b/=10;
        cnt2++;
    }
    return max(cnt2,cnt);
}
void Dufaux()
{
    ll n,minn=INT_MAX;
    cin>>n;
    ll limit=sqrt(n);
    for(int i=1;i<=limit;i++){
        if(n%i==0){
            ll ans=f(i,n/i);
            minn=min(ans,minn);
        }
    }
    cout<<minn<<endl;
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 3660
/*
* @Author: AsilenceBTF
* @Buff: ︿(￣︶￣)︿  芜湖塔台 起飞
* @Date: 2019-06-20 09:22:24
 * @LastEditTime: 2020-09-16 17:12:50
*/

#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define ALL(x) x.begin(), x.end()
#define INF 0x3f3f3f3f
#define debug(x) cout << "##### " << x << endl; 
typedef long long ll;

// #define cin in
// #define cout out
// ifstream in("in.txt");
// ofstream out("out.txt");

const int MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<ll> v, w;
    for(int i = 1; i <= n; ++i){
        ll x, y; cin >> x >> y;
        v.push_back(x + y);
        w.push_back(x - y);
    } 
    sort(ALL(v));
    sort(ALL(w));
    cout << max(v.back() - v[0], w.back() - w[0]) << endl;
}

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

int counta = 0;
vector <int> v{};
vector<vector<int>> edge(30,vector<int>{});
vector<int> parmi{1};

void zentansaku(){
    if(!v.empty()){
        for(int i = 0;i < v.size();++i){
            int vi = v[i];
            int vback = v.back();
            v[i] = vback;
            v.pop_back();
            parmi.push_back(vi);
            zentansaku();
            parmi.pop_back();
            v[i] = vi;
            v.push_back(vback);
        }
    }
    else{
        bool can = 1; 
        for(int i = 0;i<parmi.size()-1;++i){
            bool ok = 0;
            for(int x:edge[parmi[i]]){
                if(x == parmi[i+1]){
                    ok =1;
                }
            }
            if(!ok){
                can = 0;
                break;
            }
        }
        if(can) counta++;
    }
}

int main(){
    int N,M;
    cin >> N >> M;
    for(int i = 0;i<M;++i){
        int a,b;
        cin >> a >> b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    for(int i=1;i<N;++i){
        v.push_back(i+1);
    }
    zentansaku();
    cout << counta << endl;
    int l;
    cin >>l;
}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (int i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n;
        cin>>n;
        ll a[n],ans=0;
        loop(i,0,n-1) cin>>a[i];
        sort(a,a+n);
        loop(i,0,n-3)
        {
            loop(j,i+1,n-2)
            {
                loop(k,j+1,n-1)
                {
                    if(a[i]+a[j]>a[k] and a[i]!=a[j] and a[j]!=a[k] and a[i]!=a[k]) ans++;
                }
            }
        }
        cout<<ans;

    }
    return 0;
}


Measured memory_bytes: 3660
n = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
n = len(L)
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if L[i] + L[j] > L[k] and L[i] < L[j] < L[k]:
                ans += 1
print(ans)

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

using namespace std;

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class ABC_129_C
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);

        int[] A = new int[M];
        for (int i = 0; i < M; i++)
        {
            A[i] = int.Parse(Console.ReadLine());
            if(i>0 && A[i-1]+1==A[i])
            {
                Console.WriteLine(0);
                return;
            }
        }

        int bi = M==0 ? -1: 0;
        long[] pattern = new long[N+1];
        pattern[0] = 1L;
        for (int i = 0; i < N; i++)
        {
            if (bi >= 0 && bi < M && A[bi] == i)
            {
                pattern[i] = 0L;
                bi++;
            }
            pattern[i+1] += pattern[i] % 1000000007L;
            if(i+1<N) pattern[i+2] += pattern[i] % 1000000007L;
        }

        Console.WriteLine(pattern[N] % 1000000007L);
    }
}

Measured memory_bytes: 13180
import math
import numpy as np

n = int(input())
a = list(map(int, input().split()))

# a = np.array(a)
# ans = []
# while a.min() != 9999999:
#     min_index = a.argmin()
#     ans.append(min_index+1)
#     a[min_index] = 9999999

# print(' '.join([str(_) for _ in ans]))

l = []
for i in range(n):
    l.append([i+1, a[i]])

sl = sorted(l, key=lambda x: x[1])
sl0 = [r[0] for r in sl]
print(' '.join([str(_) for _ in sl0]))


Measured memory_bytes: 52164
//arc069_d.cpp
//Sun Jan 12 18:18:40 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

char temp[100000];
int n;
string s;

bool check(char x, char y){
	fill(temp,temp+100000,'A');
	temp[0] = x;
	temp[1] = y;
	for (int i=1;i<n-1;i++){
		if (s[i]=='o'){
			if (temp[i]=='S'){
				temp[i+1] = temp[i-1];
			}else {
				if (temp[i-1]=='S'){
					temp[i+1] = 'W';
				}else {
					temp[i+1] = 'S';
				}
			}
		}else {
			if (temp[i]=='S'){
				if (temp[i-1]=='S'){
					temp[i+1] = 'W';
				}else {
					temp[i+1] = 'S';
				}
			}else {
				temp[i+1] = temp[i-1];
			}
		}
	}
	if (s[n-1]=='o'){
		if ((temp[n-1] == 'S' && temp[0]==temp[n-2]) ||
			(temp[n-1] == 'W' && temp[0]!=temp[n-2])){
			return true;
		}
	}else {
		if ((temp[n-1] == 'W' && temp[0]==temp[n-2]) ||
			(temp[n-1] == 'S' && temp[0]!=temp[n-2])){
			return true;
		}
	}
	return false;
}


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

	bool test1 = check('S','S');
	if ((temp[n-1]=='S' && s[0] == 'o' && test1) ||
		(temp[n-1]=='W' && s[0] == 'x' && test1)){
		for (int i=0;i<n;i++){
			cout << temp[i];
		}
		printf("\n");
		return 0;
	}

	bool test2 = check('S','W');
	if ((temp[n-1]=='W' && s[0] == 'o' && test2) ||
		(temp[n-1]=='S' && s[0] == 'x' && test2)){
		for (int i=0;i<n;i++){
			cout << temp[i];
		}
		printf("\n");
		return 0;
	}

	bool test3 = check('W','S');
	if ((temp[n-1]=='W' && s[0] == 'o' && test3) ||
		(temp[n-1]=='S' && s[0] == 'x' && test3)){
		for (int i=0;i<n;i++){
			cout << temp[i];
		}
		printf("\n");
		return 0;
	}

	bool test4 = check('W','W');
	if ((temp[n-1]=='S' && s[0] == 'o' && test4) ||
		(temp[n-1]=='W' && s[0] == 'x' && test4)){
		for (int i=0;i<n;i++){
			cout << temp[i];
		}
		printf("\n");
		return 0;
	}
	cout << -1 << endl;
}

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

int W,H;
int sy, sx, gy, gx;

ll numh,numb;

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

bool movable(vector<vector<char>> &c, vector<vector<int>> &mat, int h, int w, int y, int x) {
  if ((h+y<0) || (h+y>=H) || (w+x<0) || (w+x>=W)) {
    return false;
  }
  else if (mat[h+y][w+x]!=INF || (c[h][w]==c[h+y][w+x])) {
    return false;
  }
  else {
    return true;
  }
}


void dfs(vector<vector<char>> &c, vector<vector<int>> &mat, int h , int w) {
    bool m = false;
    rep(i,4) {
        if (movable(c,mat,h,w,dy[i],dx[i])) {
            m = true;
            mat[h+dy[i]][w+dx[i]] = 1;
            if (c[h+dy[i]][w+dx[i]]=='.'){
                numh++;
            }
            else {
                numb++;
            }
            dfs(c,mat,h+dy[i],w+dx[i]);
        }
    }
    if (!m) {
        return;
    }
}

int main() {

  cin >> H >> W;

  vector<vector<char>> c(H,vector<char> (W));
  
  vector<P> st;
  rep(h,H) {
      string S;
      cin >> S;
      rep(w,S.size()){
          c[h][w] = S[w];
          if (S[w]=='#') {
              st.push_back(make_pair(h,w));
          }
      }
  }
  vector<vector<int>> mat(H,vector<int> (W, INF));

  ll ans = 0;
  rep(i,st.size()) {
      int h,w;
      h = st[i].first;
      w = st[i].second;
      if (mat[h][w]==INF) {
          mat[h][w] = 1;
        numh = numb = 0;
        numb = 1;
        dfs(c,mat,h,w);
        ans += numh*numb;
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 9208
#include <iostream>

using namespace std;

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

    if (k >= 1 << m) {
        cout << -1 << endl;
    } else if (m == 1) {
        if (k == 0) {
            cout << "0 0 1 1" << endl;
        } else {
            cout << -1 << endl;
        }
    } else {
        cout << k << " ";
        for (int i = 0; i < 1 << m; i++) {
            if (i != k) {
                cout << i << " ";
            }
        }
        cout << k << " ";
        for (int i = (1 << m) - 1; i >= 0; i--) {
            if (i != k) {
                cout << i;
                if (i == 0 || i == 1 && k == 0) {
                    cout << endl;
                } else {
                    cout << " ";
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

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

	constexpr int INF = (1 << 29);

	int n;
	cin >> n;

	vector<pair<int, int>> problems(n);
	for(auto &e : problems) cin >> e.second >> e.first;
	sort(problems.begin(), problems.end());

	vector<int> dp(n + 1, INF);
	dp[0] = 0;

	for(int i = 0; i < n; ++i) {
		for(int j = i; j >= 0; --j) {
			if(dp[j] + problems[i].second <= problems[i].first) {
				chmin(dp[j + 1], dp[j] + problems[i].second);
			}
		}
	}

	for(int i = n; i >= 0; --i) {
		if(dp[i] != INF) {
			cout << i << endl;
			break;
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1200
c = list(list(map(int, input().split())) for _ in range(3))
c00 = c[0][0]
c11 = c[1][1]
c22 = c[2][2]
for a0 in range(c00 + 1):
    for a1 in range(c11 + 1):
        for a2 in range(c22 + 1):
            A = [a0, a1, a2]
            B = [c00 - a0, c11 - a1, c22 - a2]
            tmp = []
            for a in A:
                row = []
                for b in B:
                    row.append(a + b)
                tmp.append(row)
            if tmp == c:
                print('Yes')
                exit()
print('No')



Measured memory_bytes: 3064
#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>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する

void solve(int n, int m) {
    vector<int> h, w, sh, sw;
    sh.push_back(0);
    sw.push_back(0);
    rep(i, 0, n) {
        int tmp;
        cin >> tmp;
        h.push_back(tmp);
        if (sh.size() == 0) sh.push_back(tmp);
        else sh.push_back(sh.back() + tmp);
    }
    rep(i, 0, m) {
        int tmp;
        cin >> tmp;
        w.push_back(tmp);
        if (sw.size() == 0) sw.push_back(tmp);
        else sw.push_back(sw.back() + tmp);
    }
    map<int, int> mph, mpw;
    for (int i = 0; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            mph[sh[j] - sh[i]]++;
        }
    }
    for (int i = 0; i <= m; i++) {
        for (int j = i + 1; j <= m; j++) {
            mpw[sw[j] - sw[i]]++;
        }
    }
    ll ans = 0;
    for(auto it : mph){
        if(mpw.find(it.first) != mpw.end()){
            ans += it.second * mpw[it.first];
        }
    }
    cout << ans << endl;


}

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

    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0) break;
        solve(n, m);
    }


    return 0;
}



Measured memory_bytes: 29808